#include <avr/cpufunc.h>
#include <util/atomic.h>
#include <stdint.h>

volatile uint8_t g;
volatile bool flag;

ISR(TCA1_CMP0_vect) {
  ++g;
  if (g > 100) flag = true;
}

int main(void) {
  while (true) {
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
      if (flag) {
        flag = false;
      }
    }
  }
}

########################################################

00000304 <__ctors_end>:
 304:	11 24       	eor	r1, r1
 306:	1f be       	out	0x3f, r1	; 63
 308:	cf ef       	ldi	r28, 0xFF	; 255
 30a:	cd bf       	out	0x3d, r28	; 61
 30c:	df e7       	ldi	r29, 0x7F	; 127
 30e:	de bf       	out	0x3e, r29	; 62

00000310 <__do_clear_bss>:
 310:	20 e4       	ldi	r18, 0x40	; 64

00000312 <.Loc.1>:
 312:	a0 e0       	ldi	r26, 0x00	; 0

00000314 <.Loc.2>:
 314:	b0 e4       	ldi	r27, 0x40	; 64

00000316 <.Loc.3>:
 316:	01 c0       	rjmp	.+2      	; 0x31a <.Loc.5>

00000318 <.Loc.4>:
 318:	1d 92       	st	X+, r1

0000031a <.Loc.5>:
 31a:	a2 30       	cpi	r26, 0x02	; 2

0000031c <.Loc.6>:
 31c:	b2 07       	cpc	r27, r18

0000031e <.Loc.7>:
 31e:	e1 f7       	brne	.-8      	; 0x318 <.Loc.4>

00000320 <L0^A>:
 320:	15 d0       	rcall	.+42     	; 0x34c <main>
 322:	1d c0       	rjmp	.+58     	; 0x35e <_exit>

00000324 <__bad_interrupt>:
 324:	6d cf       	rjmp	.-294    	; 0x200 <__vectors>

00000326 <__vector_49>:

volatile uint8_t g;
volatile bool flag;


ISR(TCA1_CMP0_vect) {
 326:	8f 93       	push	r24
 328:	8f b7       	in	r24, 0x3f	; 63
 32a:	8f 93       	push	r24

0000032c <.Loc.1>:
  ++g;
 32c:	80 91 01 40 	lds	r24, 0x4001	; 0x804001 <g>
 330:	8f 5f       	subi	r24, 0xFF	; 255
 332:	80 93 01 40 	sts	0x4001, r24	; 0x804001 <g>

00000336 <.Loc.2>:
  if (g > 100) flag = true;
 336:	80 91 01 40 	lds	r24, 0x4001	; 0x804001 <g>

0000033a <.Loc.4>:
 33a:	85 36       	cpi	r24, 0x65	; 101
 33c:	18 f0       	brcs	.+6      	; 0x344 <.L1>

0000033e <.Loc.5>:
 33e:	81 e0       	ldi	r24, 0x01	; 1
 340:	80 93 00 40 	sts	0x4000, r24	; 0x804000 <flag>

00000344 <.L1>:
}
 344:	8f 91       	pop	r24
 346:	8f bf       	out	0x3f, r24	; 63
 348:	8f 91       	pop	r24
 34a:	18 95       	reti

0000034c <main>:
int main(void)
{
  while (true)
  {
      ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
 34c:	8f b7       	in	r24, 0x3f	; 63

0000034e <.LBB8>:
    return 1;
}

static __inline__ uint8_t __iCliRetVal(void)
{
    cli();
 34e:	f8 94       	cli

00000350 <.LBE8>:
      {
        if (flag) {
 350:	90 91 00 40 	lds	r25, 0x4000	; 0x804000 <flag>

00000354 <.Loc.18>:
 354:	91 11       	cpse	r25, r1

00000356 <.Loc.19>:
          flag = false;
 356:	10 92 00 40 	sts	0x4000, r1	; 0x804000 <flag>

0000035a <.LBB10>:
    (void)__s;
}

static __inline__ void __iRestore(const  uint8_t *__s)
{
    SREG = *__s;
 35a:	8f bf       	out	0x3f, r24	; 63

0000035c <.LBE10>:
        }
      }
  }
 35c:	f7 cf       	rjmp	.-18     	; 0x34c <main>

0000035e <_exit>:
 35e:	f8 94       	cli

00000360 <__stop_program>:
 360:	ff cf       	rjmp	.-2      	; 0x360 <__stop_program>
