#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_Erase(int);
int /*<<< orphan*/ NF_PageRead(int, unsigned char *);
int /*<<< orphan*/ NF_WritePage(int, unsigned char *);
int /*<<< orphan*/ button_init();
int /*<<< orphan*/ init_irq();
int /*<<< orphan*/ led_init();
int /*<<< orphan*/ led_off();
int /*<<< orphan*/ led_on();
int /*<<< orphan*/ nand_readid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ uart_init();
int gboot_main() {
  int i;
  unsigned char buf[1024 * 4];
  uart_init();
  led_init();
  printf("======== led_init done ==========\n");
  button_init();
  init_irq();
  led_off();
  NF_Erase(0x20000000);
  buf[0] = 100;
  NF_WritePage(0x20000000, buf);
  buf[0] = 10;
  NF_PageRead(0x20000000, buf);
  if (buf[0] == 100) {
    printf("read right data........\n");
    printf("buf[0] = %d\n", buf[0]);
    led_on();
  }
  nand_readid();
  while (1)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<gboot_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
mov    $0x0,%al
call   1060 <uart_init@plt>
mov    $0x0,%al
call   1090 <led_init@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1080 <button_init@plt>
mov    $0x0,%al
call   1050 <init_irq@plt>
mov    $0x0,%al
call   1040 <led_off@plt>
mov    $0x20000000,%edi
call   10c0 <NF_Erase@plt>
movb   $0x64,-0x1010(%rbp)
lea    -0x1010(%rbp),%rsi
mov    $0x20000000,%edi
call   10b0 <NF_WritePage@plt>
movb   $0xa,-0x1010(%rbp)
lea    -0x1010(%rbp),%rsi
mov    $0x20000000,%edi
call   10d0 <NF_PageRead@plt>
movzbl -0x1010(%rbp),%eax
cmp    $0x64,%eax
jne    1260 <gboot_main+0xb0>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movzbl -0x1010(%rbp),%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <led_on@plt>
mov    $0x0,%al
call   1030 <nand_readid@plt>
jmp    1267 <gboot_main+0xb7>

x86 assembly (clang, -O2):
<gboot_main>:
push   %rbx
sub    $0x1000,%rsp
xor    %eax,%eax
call   1070 <uart_init@plt>
xor    %eax,%eax
call   10a0 <led_init@plt>
lea    0xe30(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1090 <button_init@plt>
xor    %eax,%eax
call   1060 <init_irq@plt>
xor    %eax,%eax
call   1040 <led_off@plt>
mov    $0x20000000,%edi
call   10d0 <NF_Erase@plt>
movb   $0x64,(%rsp)
mov    %rsp,%rbx
mov    $0x20000000,%edi
mov    %rbx,%rsi
call   10c0 <NF_WritePage@plt>
movb   $0xa,(%rsp)
mov    $0x20000000,%edi
mov    %rbx,%rsi
call   10e0 <NF_PageRead@plt>
cmpb   $0x64,(%rsp)
jne    1251 <gboot_main+0x91>
lea    0xdfc(%rip),%rdi
call   1050 <puts@plt>
movzbl (%rsp),%esi
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
call   10b0 <led_on@plt>
xor    %eax,%eax
call   1030 <nand_readid@plt>
nopl   0x0(%rax,%rax,1)
jmp    1260 <gboot_main+0xa0>

LLVM IR (-O0):
@.str = [35 x i8] c"======== led_init done ==========\0A\00"
@.str.1 = [25 x i8] c"read right data........\0A\00"
@.str.2 = [13 x i8] c"buf[0] = %d\0A\00"
define i32 @gboot_main() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = call i32 (...) @uart_init()
%4 = call i32 (...) @led_init()
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (...) @button_init()
%7 = call i32 (...) @init_irq()
%8 = call i32 (...) @led_off()
%9 = call i32 @NF_Erase(i32 536870912)
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
store i8 100, i8* %10
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%12 = call i32 @NF_WritePage(i32 536870912, i8* %11)
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
store i8 10, i8* %13
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%15 = call i32 @NF_PageRead(i32 536870912, i8* %14)
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 100
br i1 %19, label %20, label %27
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = call i32 (...) @led_on()
br label %27
27: ; preds = %20, %0
%28 = call i32 (...) @nand_readid()
br label %29
29: ; preds = %27, %29
br label %29
}

LLVM IR (-O2):
@.str.2 = [13 x i8] c"buf[0] = %d\0A\00"
@str = [34 x i8] c"======== led_init done ==========\00"
@str.3 = [24 x i8] c"read right data........\00"
define i32 @gboot_main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @uart_init()
%4 = tail call i32 (...) @led_init()
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (...) @button_init()
%7 = tail call i32 (...) @init_irq()
%8 = tail call i32 (...) @led_off()
%9 = tail call i32 @NF_Erase(i32 536870912)
store i8 100, i8* %2
%10 = call i32 @NF_WritePage(i32 536870912, i8* %2)
store i8 10, i8* %2
%11 = call i32 @NF_PageRead(i32 536870912, i8* %2)
%12 = load i8, i8* %2
%13 = icmp eq i8 %12, 100
br i1 %13, label %14, label %20
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.3, i64 0, i64 0))
%16 = load i8, i8* %2
%17 = zext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @led_on()
br label %20
20: ; preds = %14, %0
%21 = call i32 (...) @nand_readid()
br label %22
22: ; preds = %22, %20
br label %22
}