#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 */
int /*<<< orphan*/ led_off(int);
int /*<<< orphan*/ led_on(int);
void switch_led(int led, int button, int *marker) {
  int counter = 0;
  if (((*(volatile unsigned long *)(0xE0028000 + 0x00)) & button) == 0) {
    while (((*(volatile unsigned long *)(0xE0028000 + 0x00)) & button) == 0)
      counter++;
    if (counter >= 1000) {
      if (*marker == 0) {
        led_on(led);
        (*marker) = 1;
      } else {
        led_off(led);
        (*marker) = 0;
      }
      counter = 0;
    }
  }
}


x86 assembly (clang, -O0):
<switch_led>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0xe0028000,%eax
mov    (%rax),%rax
movslq -0x8(%rbp),%rcx
and    %rcx,%rax
cmp    $0x0,%rax
jne    11cd <switch_led+0xad>
jmp    1157 <switch_led+0x37>
mov    $0xe0028000,%eax
mov    (%rax),%rax
movslq -0x8(%rbp),%rcx
and    %rcx,%rax
cmp    $0x0,%rax
jne    117e <switch_led+0x5e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <switch_led+0x37>
cmpl   $0x3e8,-0x14(%rbp)
jl     11c8 <switch_led+0xa8>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11af <switch_led+0x8f>
mov    -0x4(%rbp),%edi
call   1040 <led_on@plt>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    11c1 <switch_led+0xa1>
mov    -0x4(%rbp),%edi
call   1030 <led_off@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
jmp    11cd <switch_led+0xad>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<switch_led>:
push   %rbx
mov    %rdx,%rbx
mov    $0xe0028000,%eax
movslq %esi,%rcx
mov    (%rax),%rdx
and    %rcx,%rdx
je     1136 <switch_led+0x16>
pop    %rbx
ret
mov    $0xffffffff,%edx
nopl   0x0(%rax,%rax,1)
mov    (%rax),%rsi
and    %rcx,%rsi
add    $0x1,%edx
test   %rsi,%rsi
je     1140 <switch_led+0x20>
cmp    $0x3e8,%edx
jb     1134 <switch_led+0x14>
cmpl   $0x0,(%rbx)
je     1164 <switch_led+0x44>
call   1030 <led_off@plt>
xor    %eax,%eax
jmp    116e <switch_led+0x4e>
call   1040 <led_on@plt>
mov    $0x1,%eax
mov    %eax,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @switch_led(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
%8 = load volatile i64, i64* inttoptr (i64 3758260224 to i64*)
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = and i64 %8, %10
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %40
13: ; preds = %3
br label %14
14: ; preds = %20, %13
%15 = load volatile i64, i64* inttoptr (i64 3758260224 to i64*)
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = and i64 %15, %17
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
br label %14
23: ; preds = %14
%24 = load i32, i32* %7
%25 = icmp sge i32 %24, 1000
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* %4
%32 = call i32 @led_on(i32 %31)
%33 = load i32*, i32** %6
store i32 1, i32* %33
br label %38
34: ; preds = %26
%35 = load i32, i32* %4
%36 = call i32 @led_off(i32 %35)
%37 = load i32*, i32** %6
store i32 0, i32* %37
br label %38
38: ; preds = %34, %30
store i32 0, i32* %7
br label %39
39: ; preds = %38, %23
br label %40
40: ; preds = %39, %3
ret void
}

LLVM IR (-O2):
define void @switch_led(i32 %0, i32 %1, i32* nocapture %2) {
%4 = load volatile i64, i64* inttoptr (i64 3758260224 to i64*)
%5 = sext i32 %1 to i64
%6 = and i64 %4, %5
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %3, %8
%9 = phi i32 [ %13, %8 ], [ 0, %3 ]
%10 = load volatile i64, i64* inttoptr (i64 3758260224 to i64*)
%11 = and i64 %10, %5
%12 = icmp eq i64 %11, 0
%13 = add nuw nsw i32 %9, 1
br i1 %12, label %8, label %14
14: ; preds = %8
%15 = icmp ugt i32 %9, 999
br i1 %15, label %16, label %25
16: ; preds = %14
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @led_on(i32 %0)
br label %23
21: ; preds = %16
%22 = tail call i32 @led_off(i32 %0)
br label %23
23: ; preds = %21, %19
%24 = phi i32 [ 0, %21 ], [ 1, %19 ]
store i32 %24, i32* %2
br label %25
25: ; preds = %14, %23, %3
ret void
}