Photo Interrupter Switch on a gear

I am new to arduino and this is my first project, or rather a project that my friend is working on and I decided to help him with the coding. I am studying coding so decided to try my hand at the language that is Arduino and it would seem that I have already hit a wall.

The code bellow is for a spinning gear with 36 "teeth" and the purpose of it is to reset the counter every time it makes a full circle. The current iteration of the code is doing what it is supposed to, how ever, it only works if it starts spinning from the starting position of the gear. What I need is, for it to be able to recognize where the beginning of the gear is even if it starts spinning from the middle. (the start has about 4x wider gap between the last and the first "teeth" than the ones in between)

From what I gather, I am supposed to use the pulseIn function, but I might be completely off, and even if I am not, I still don't know where or how to begin using the aforementioned function.

As the title says I am using a Photo Interrupter switch to determine the location of the "teeth" and a Arduino Leonardo, if that matters.

Would appreciate any help I could get with this, and I do apologize, if my description has not been helpful enough or if I am using the wrong section of the forum for this question.

volatile unsigned int counter = 0;
int n=37;

void setup(){
  Serial.begin(9600);
  pinMode(2,INPUT);
  attachInterrupt(digitalPinToInterrupt(2),ai0,RISING);
  
}

void loop(){
  Serial.println (counter);
  if(counter==n){
    counter=1;
  }
  
}

void ai0(){
  counter++;
}

Some possibilities:

Add a 'home' sensor that somehow detects a target on the gear that dentifies the start position. When the target is sensed you know you're at the home position and can take appropriate action.

Add some hardware (simplest form would be two momentary switches) to manually inc/decrement the current count to match the actual position of the gear. This would imply some sort of visual feedback (LCD/LED display) for the operator. Keep in mind, this may be impossible in the final product.

A rather uncommon hobbyist solution could be an absolute encoder - which will inherently retain its position through a power outage.

You described your home position as having a much wider gap, you said you have 36 teeth and you made no mention of having erratic results in your counting.

So make a array say rotatecount(36)
Now instead of just doing counter++ add in something like
rotatecount(counter) = mills

Now you just need to reset “counter” back to 0 once it hits 36
And now you just need to compare the current rotatecount(count) to previous two rotatecount values to see if the substantial time difference was on that count..