#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*/ NF_Page_Erase(int);
int /*<<< orphan*/ NF_Page_Read(int, unsigned char *, int);
int /*<<< orphan*/ NF_Page_Write(int, unsigned char *, int);
int /*<<< orphan*/ init_irq();
int /*<<< orphan*/ key_init();
int /*<<< orphan*/ led_init();
int /*<<< orphan*/ led_off();
int /*<<< orphan*/ led_on();
int gboot_main() {
  unsigned char buf[2048];
  led_init();
  key_init();
  init_irq();
  NF_Page_Erase(5 * 128 + 1);
  buf[0] = 100;
  NF_Page_Write(5 * 128 + 1, buf, 2048);
  buf[0] = 10;
  NF_Page_Read(5 * 128 + 1, buf, 2048);
  if (buf[0] == 100)
    led_on();
  else if (buf[0] == 10)
    led_off();
  else
    ;
  while (1)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<gboot_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
mov    $0x0,%al
call   1080 <led_init@plt>
mov    $0x0,%al
call   1030 <key_init@plt>
mov    $0x0,%al
call   1050 <init_irq@plt>
mov    $0x281,%edi
call   10a0 <NF_Page_Erase@plt>
movb   $0x64,-0x800(%rbp)
lea    -0x800(%rbp),%rsi
mov    $0x281,%edi
mov    $0x800,%edx
call   1070 <NF_Page_Write@plt>
movb   $0xa,-0x800(%rbp)
lea    -0x800(%rbp),%rsi
mov    $0x281,%edi
mov    $0x800,%edx
call   1060 <NF_Page_Read@plt>
movzbl -0x800(%rbp),%eax
cmp    $0x64,%eax
jne    1200 <gboot_main+0x80>
mov    $0x0,%al
call   1090 <led_on@plt>
jmp    1226 <gboot_main+0xa6>
movzbl -0x800(%rbp),%eax
cmp    $0xa,%eax
jne    121c <gboot_main+0x9c>
mov    $0x0,%al
call   1040 <led_off@plt>
jmp    1221 <gboot_main+0xa1>
jmp    1221 <gboot_main+0xa1>
jmp    1226 <gboot_main+0xa6>
jmp    122b <gboot_main+0xab>
jmp    122b <gboot_main+0xab>

x86 assembly (clang, -O2):
<gboot_main>:
push   %rbx
sub    $0x800,%rsp
xor    %eax,%eax
call   1080 <led_init@plt>
xor    %eax,%eax
call   1030 <key_init@plt>
xor    %eax,%eax
call   1050 <init_irq@plt>
mov    $0x281,%edi
call   10a0 <NF_Page_Erase@plt>
movb   $0x64,(%rsp)
mov    %rsp,%rbx
mov    $0x281,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1070 <NF_Page_Write@plt>
movb   $0xa,(%rsp)
mov    $0x281,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1060 <NF_Page_Read@plt>
mov    (%rsp),%al
cmp    $0xa,%al
je     11ea <gboot_main+0x6a>
cmp    $0x64,%al
jne    1200 <gboot_main+0x80>
xor    %eax,%eax
call   1090 <led_on@plt>
jmp    1200 <gboot_main+0x80>
xor    %eax,%eax
call   1040 <led_off@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
jmp    1200 <gboot_main+0x80>

LLVM IR (-O0):
define i32 @gboot_main() {
%1 = alloca [2048 x i8]
%2 = call i32 (...) @led_init()
%3 = call i32 (...) @key_init()
%4 = call i32 (...) @init_irq()
%5 = call i32 @NF_Page_Erase(i32 641)
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
store i8 100, i8* %6
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%8 = call i32 @NF_Page_Write(i32 641, i8* %7, i32 2048)
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
store i8 10, i8* %9
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%11 = call i32 @NF_Page_Read(i32 641, i8* %10, i32 2048)
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp eq i32 %14, 100
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (...) @led_on()
br label %27
18: ; preds = %0
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (...) @led_off()
br label %26
25: ; preds = %18
br label %26
26: ; preds = %25, %23
br label %27
27: ; preds = %26, %16
br label %28
28: ; preds = %27, %28
br label %28
}

LLVM IR (-O2):
define i32 @gboot_main() {
%1 = alloca [2048 x i8]
%2 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @led_init()
%4 = tail call i32 (...) @key_init()
%5 = tail call i32 (...) @init_irq()
%6 = tail call i32 @NF_Page_Erase(i32 641)
store i8 100, i8* %2
%7 = call i32 @NF_Page_Write(i32 641, i8* %2, i32 2048)
store i8 10, i8* %2
%8 = call i32 @NF_Page_Read(i32 641, i8* %2, i32 2048)
%9 = load i8, i8* %2
switch i8 %9, label %14 [
i8 100, label %10
i8 10, label %12
]
10: ; preds = %0
%11 = call i32 (...) @led_on()
br label %14
12: ; preds = %0
%13 = call i32 (...) @led_off()
br label %14
14: ; preds = %0, %12, %10
br label %15
15: ; preds = %14, %15
br label %15
}