int main() {
  printf("Hello embedded world, from Andrew Song!\n");
  exportGPIOFile(30);
  writeToLED("/sys/class/leds/beaglebone:green:usr0/trigger", "none");
  int counter = 0;
  while (counter < 10) {
    char buff[1024];
    saveGPIOValue(buff);
    buff[strcspn(buff, "\n")] = 0;
    int pinVal = atoi(buff);
    _Bool flag = checkIfPressed(buff);
    int times = 1;
    if (flag)
      times = 3;
    if (flag) {
      counter++;
      flashNTimes(times);
    } else {
      counter = 0;
      flashNTimes(times);
    }
    printf("Flashing %d time(s): Joystick = %d & counter = %d\n", times,
           !pinVal, counter);
    sleep(0, 600000000);
  }
  printf("Thank you for the blinks!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1e,%edi
mov    $0x0,%al
call   1030 <exportGPIOFile@plt>
lea    0xe66(%rip),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1070 <writeToLED@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    12d3 <main+0x143>
lea    -0x410(%rbp),%rdi
mov    $0x0,%al
call   1060 <saveGPIOValue@plt>
lea    -0x410(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1050 <strcspn@plt>
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
mov    $0x0,%al
call   10a0 <atoi@plt>
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x0,%al
call   1080 <checkIfPressed@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
mov    %al,-0x415(%rbp)
movl   $0x1,-0x41c(%rbp)
testb  $0x1,-0x415(%rbp)
je     125c <main+0xcc>
movl   $0x3,-0x41c(%rbp)
testb  $0x1,-0x415(%rbp)
je     1284 <main+0xf4>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x41c(%rbp),%edi
mov    $0x0,%al
call   1090 <flashNTimes@plt>
jmp    1298 <main+0x108>
movl   $0x0,-0x8(%rbp)
mov    -0x41c(%rbp),%edi
mov    $0x0,%al
call   1090 <flashNTimes@plt>
mov    -0x41c(%rbp),%esi
cmpl   $0x0,-0x414(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edx
mov    -0x8(%rbp),%ecx
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
mov    $0x23c34600,%esi
mov    $0x0,%al
call   10b0 <sleep@plt>
jmp    11d8 <main+0x48>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xeae(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1e,%edi
xor    %eax,%eax
call   1030 <exportGPIOFile@plt>
lea    0xe30(%rip),%rdi
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1080 <writeToLED@plt>
mov    %rsp,%r12
lea    0xe7c(%rip),%r14
lea    0xe44(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <saveGPIOValue@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <strcspn@plt>
movb   $0x0,(%rsp,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   10b0 <atoi@plt>
mov    %eax,%r13d
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <checkIfPressed@plt>
add    $0x1,%ebp
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
lea    0x1(%rcx,%rcx,1),%ebx
cmove  %eax,%ebp
mov    %ebx,%edi
xor    %eax,%eax
call   10a0 <flashNTimes@plt>
xor    %edx,%edx
test   %r13d,%r13d
sete   %dl
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
mov    $0x23c34600,%esi
xor    %eax,%eax
call   10c0 <sleep@plt>
cmp    $0xa,%ebp
jl     1200 <main+0x60>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Hello embedded world, from Andrew Song!\0A\00"
@.str.1 = [46 x i8] c"/sys/class/leds/beaglebone:green:usr0/trigger\00"
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [51 x i8] c"Flashing %d time(s): Joystick = %d & counter = %d\0A\00"
@.str.5 = [27 x i8] c"Thank you for the blinks!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i32, ...) bitcast (i32 (...)* @exportGPIOFile to i32 (i32, ...)*)(i32 30)
%9 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @writeToLED to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %10
10: ; preds = %39, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %48
13: ; preds = %10
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @saveGPIOValue to i32 (i8*, ...)*)(i8* %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i64 @strcspn(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %19)
store i32 %20, i32* %4
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @checkIfPressed to i32 (i8*, ...)*)(i8* %21)
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i8
store i8 %24, i8* %5
store i32 1, i32* %6
%25 = load i8, i8* %5
%26 = trunc i8 %25 to i1
br i1 %26, label %27, label %28
27: ; preds = %13
store i32 3, i32* %6
br label %28
28: ; preds = %27, %13
%29 = load i8, i8* %5
%30 = trunc i8 %29 to i1
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
%34 = load i32, i32* %6
%35 = call i32 (i32, ...) bitcast (i32 (...)* @flashNTimes to i32 (i32, ...)*)(i32 %34)
br label %39
36: ; preds = %28
store i32 0, i32* %2
%37 = load i32, i32* %6
%38 = call i32 (i32, ...) bitcast (i32 (...)* @flashNTimes to i32 (i32, ...)*)(i32 %37)
br label %39
39: ; preds = %36, %31
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 0
%43 = xor i1 %42, true
%44 = zext i1 %43 to i32
%45 = load i32, i32* %2
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %40, i32 %44, i32 %45)
%47 = call i32 (i32, i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, i32, ...)*)(i32 0, i32 600000000)
br label %10
48: ; preds = %10
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [46 x i8] c"/sys/class/leds/beaglebone:green:usr0/trigger\00"
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [51 x i8] c"Flashing %d time(s): Joystick = %d & counter = %d\0A\00"
@str = [40 x i8] c"Hello embedded world, from Andrew Song!\00"
@str.6 = [26 x i8] c"Thank you for the blinks!\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @exportGPIOFile to i32 (i32, ...)*)(i32 30)
%4 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @writeToLED to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %16, %6 ]
%8 = call i32 (i8*, ...) bitcast (i32 (...)* @saveGPIOValue to i32 (i8*, ...)*)(i8* %5)
%9 = call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %5)
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @checkIfPressed to i32 (i8*, ...)*)(i8* %5)
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 1, i32 3
%15 = add nsw i32 %7, 1
%16 = select i1 %13, i32 0, i32 %15
%17 = call i32 (i32, ...) bitcast (i32 (...)* @flashNTimes to i32 (i32, ...)*)(i32 %14)
%18 = icmp eq i32 %11, 0
%19 = zext i1 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %14, i32 %19, i32 %16)
%21 = call i32 (i32, i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, i32, ...)*)(i32 0, i32 600000000)
%22 = icmp slt i32 %16, 10
br i1 %22, label %6, label %23
23: ; preds = %6
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
ret i32 0
}