#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
unsigned long TimerGet();
void LedToggle(void) {
  static unsigned char led_toggle_state = 0;
  static unsigned long timer_counter_last = 0;
  unsigned long timer_counter_now;
  timer_counter_now = TimerGet();
  if ((timer_counter_now - timer_counter_last) < (500)) {
    return;
  }
  if (led_toggle_state == 0) {
    led_toggle_state = 1;
    (*((volatile unsigned long *)0xE002801C)) = 0x00800000;
  } else {
    led_toggle_state = 0;
    (*((volatile unsigned long *)0xE0028014)) = 0x00800000;
  }
  timer_counter_last = timer_counter_now;
}


x86 assembly (clang, -O0):
<LedToggle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <TimerGet@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
sub    0x2f0a(%rip),%rax
cmp    $0x1f4,%rax
jae    113f <LedToggle+0x2f>
jmp    1185 <LedToggle+0x75>
movzbl 0x2eea(%rip),%eax
cmp    $0x0,%eax
jne    1167 <LedToggle+0x57>
movb   $0x1,0x2eda(%rip)
mov    $0xe002801c,%eax
movq   $0x800000,(%rax)
jmp    117a <LedToggle+0x6a>
movb   $0x0,0x2ec2(%rip)
mov    $0xe0028014,%eax
movq   $0x800000,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,0x2eb3(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LedToggle>:
push   %rax
xor    %eax,%eax
call   1030 <TimerGet@plt>
mov    %rax,%rcx
sub    0x2f16(%rip),%rcx
cmp    $0x1f4,%rcx
jb     1157 <LedToggle+0x47>
mov    0x2eff(%rip),%cl
mov    $0xe0028014,%edx
lea    0x8(%rdx),%rsi
test   %cl,%cl
cmovne %rdx,%rsi
xor    $0x1,%cl
mov    %cl,0x2ee7(%rip)
movq   $0x800000,(%rsi)
mov    %rax,0x2ee1(%rip)
pop    %rax
ret

LLVM IR (-O0):
@LedToggle.led_toggle_state = internal global i8 0
@LedToggle.timer_counter_last = internal global i64 0
define void @LedToggle() {
%1 = alloca i64
%2 = call i64 (...) @TimerGet()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = load i64, i64* @LedToggle.timer_counter_last
%5 = sub i64 %3, %4
%6 = icmp ult i64 %5, 500
br i1 %6, label %7, label %8
7: ; preds = %0
br label %16
8: ; preds = %0
%9 = load i8, i8* @LedToggle.led_toggle_state
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i8 1, i8* @LedToggle.led_toggle_state
store volatile i64 8388608, i64* inttoptr (i64 3758260252 to i64*)
br label %14
13: ; preds = %8
store i8 0, i8* @LedToggle.led_toggle_state
store volatile i64 8388608, i64* inttoptr (i64 3758260244 to i64*)
br label %14
14: ; preds = %13, %12
%15 = load i64, i64* %1
store i64 %15, i64* @LedToggle.timer_counter_last
br label %16
16: ; preds = %14, %7
ret void
}

LLVM IR (-O2):
@LedToggle.led_toggle_state = internal unnamed_addr global i1 false
@LedToggle.timer_counter_last = internal unnamed_addr global i64 0
define void @LedToggle() {
%1 = tail call i64 (...) @TimerGet()
%2 = load i64, i64* @LedToggle.timer_counter_last
%3 = sub i64 %1, %2
%4 = icmp ult i64 %3, 500
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = load i1, i1* @LedToggle.led_toggle_state
%7 = xor i1 %6, true
%8 = select i1 %6, i64* inttoptr (i64 3758260244 to i64*), i64* inttoptr (i64 3758260252 to i64*)
store i1 %7, i1* @LedToggle.led_toggle_state
store volatile i64 8388608, i64* %8
store i64 %1, i64* @LedToggle.timer_counter_last
br label %9
9: ; preds = %0, %5
ret void
}