#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_on();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ uart_init();
int gboot_main() {
  int num;
  unsigned char buff[2048];
  led_init();
  key_init();
  init_irq();
  uart_init();
  NF_Page_Erase(2048 * 135 + 1);
  buff[0] = 100;
  NF_Page_Write(2048 * 135 + 1, buff, 2048);
  buff[0] = 10;
  NF_Page_Read(2048 * 135 + 1, buff, 2048);
  printf("%d\n", buff[0]);
  led_on();
  while (1) {
    printf("\n\r#######################################\n\r");
    printf("\n\r################TINY6410###############\n\r");
    printf("1:Download Linux Kernel from TFTP Server!\n\r");
    printf("2:Boot Linux from RAM!\n\r");
    printf("3:Boor Linux from Nand Flash!\n\r");
    printf("\n Plese Select:");
    scanf("%d", &num);
    switch (num) {
    case 1:
      break;
    case 2:
      break;
    case 3:
      break;
    default:
      printf("Error: wrong selection!\n\r");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<gboot_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    $0x0,%al
call   1090 <led_init@plt>
mov    $0x0,%al
call   1030 <key_init@plt>
mov    $0x0,%al
call   1040 <init_irq@plt>
mov    $0x0,%al
call   1060 <uart_init@plt>
mov    $0x43801,%edi
call   10b0 <NF_Page_Erase@plt>
movb   $0x64,-0x810(%rbp)
lea    -0x810(%rbp),%rsi
mov    $0x43801,%edi
mov    $0x800,%edx
call   1080 <NF_Page_Write@plt>
movb   $0xa,-0x810(%rbp)
lea    -0x810(%rbp),%rsi
mov    $0x43801,%edi
mov    $0x800,%edx
call   1050 <NF_Page_Read@plt>
movzbl -0x810(%rbp),%esi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <led_on@plt>
lea    0xdd6(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x815(%rbp)
call   1070 <printf@plt>
mov    -0x815(%rbp),%al
lea    0xde8(%rip),%rdi
call   1070 <printf@plt>
mov    -0x815(%rbp),%al
lea    0xe02(%rip),%rdi
call   1070 <printf@plt>
mov    -0x815(%rbp),%al
lea    0xe1c(%rip),%rdi
call   1070 <printf@plt>
mov    -0x815(%rbp),%al
lea    0xe23(%rip),%rdi
call   1070 <printf@plt>
mov    -0x815(%rbp),%al
lea    0xe31(%rip),%rdi
call   1070 <printf@plt>
lea    0xe35(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   10c0 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x814(%rbp)
sub    $0x1,%eax
je     12e4 <gboot_main+0x144>
jmp    12bc <gboot_main+0x11c>
mov    -0x814(%rbp),%eax
sub    $0x2,%eax
je     12e9 <gboot_main+0x149>
jmp    12d0 <gboot_main+0x130>
mov    -0x814(%rbp),%eax
sub    $0x3,%eax
je     12ee <gboot_main+0x14e>
jmp    12f3 <gboot_main+0x153>
jmp    1301 <gboot_main+0x161>
jmp    1301 <gboot_main+0x161>
jmp    1301 <gboot_main+0x161>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1227 <gboot_main+0x87>

x86 assembly (clang, -O2):
<gboot_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
xor    %eax,%eax
call   1090 <led_init@plt>
xor    %eax,%eax
call   1030 <key_init@plt>
xor    %eax,%eax
call   1040 <init_irq@plt>
xor    %eax,%eax
call   1060 <uart_init@plt>
mov    $0x43801,%edi
call   10b0 <NF_Page_Erase@plt>
movb   $0x64,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    $0x43801,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1080 <NF_Page_Write@plt>
movb   $0xa,0x10(%rsp)
mov    $0x43801,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1050 <NF_Page_Read@plt>
movzbl 0x10(%rsp),%esi
lea    0xdea(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10a0 <led_on@plt>
lea    0xe31(%rip),%r12
lea    0xe56(%rip),%r13
lea    0xe68(%rip),%rbx
lea    0xe81(%rip),%rbp
lea    0xe8a(%rip),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
lea    0xdad(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdcb(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10c0 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
jb     1250 <gboot_main+0xb0>
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1250 <gboot_main+0xb0>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [44 x i8] c"\0A\0D#######################################\0A\0D\00"
@.str.2 = [44 x i8] c"\0A\0D################TINY6410###############\0A\0D\00"
@.str.3 = [44 x i8] c"1:Download Linux Kernel from TFTP Server!\0A\0D\00"
@.str.4 = [25 x i8] c"2:Boot Linux from RAM!\0A\0D\00"
@.str.5 = [32 x i8] c"3:Boor Linux from Nand Flash!\0A\0D\00"
@.str.6 = [16 x i8] c"\0A Plese Select:\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [26 x i8] c"Error: wrong selection!\0A\0D\00"
define i32 @gboot_main() {
%1 = alloca i32
%2 = alloca [2048 x i8]
%3 = call i32 (...) @led_init()
%4 = call i32 (...) @key_init()
%5 = call i32 (...) @init_irq()
%6 = call i32 (...) @uart_init()
%7 = call i32 @NF_Page_Erase(i32 276481)
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
store i8 100, i8* %8
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%10 = call i32 @NF_Page_Write(i32 276481, i8* %9, i32 2048)
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
store i8 10, i8* %11
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%13 = call i32 @NF_Page_Read(i32 276481, i8* %12, i32 2048)
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 (...) @led_on()
br label %19
19: ; preds = %0, %33
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%27 = load i32, i32* %1
switch i32 %27, label %31 [
i32 1, label %28
i32 2, label %29
i32 3, label %30
]
28: ; preds = %19
br label %33
29: ; preds = %19
br label %33
30: ; preds = %19
br label %33
31: ; preds = %19
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
br label %33
33: ; preds = %31, %30, %29, %28
br label %19
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [44 x i8] c"\0A\0D#######################################\0A\0D\00"
@.str.2 = [44 x i8] c"\0A\0D################TINY6410###############\0A\0D\00"
@.str.3 = [44 x i8] c"1:Download Linux Kernel from TFTP Server!\0A\0D\00"
@.str.4 = [25 x i8] c"2:Boot Linux from RAM!\0A\0D\00"
@.str.5 = [32 x i8] c"3:Boor Linux from Nand Flash!\0A\0D\00"
@.str.6 = [16 x i8] c"\0A Plese Select:\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [26 x i8] c"Error: wrong selection!\0A\0D\00"
define i32 @gboot_main() {
%1 = alloca i32
%2 = alloca [2048 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @led_init()
%6 = tail call i32 (...) @key_init()
%7 = tail call i32 (...) @init_irq()
%8 = tail call i32 (...) @uart_init()
%9 = tail call i32 @NF_Page_Erase(i32 276481)
store i8 100, i8* %4
%10 = call i32 @NF_Page_Write(i32 276481, i8* %4, i32 2048)
store i8 10, i8* %4
%11 = call i32 @NF_Page_Read(i32 276481, i8* %4, i32 2048)
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 (...) @led_on()
br label %16
16: ; preds = %27, %0
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%24 = load i32, i32* %1
%25 = add i32 %24, -1
%26 = icmp ult i32 %25, 3
br i1 %26, label %27, label %28
27: ; preds = %16, %28
br label %16
28: ; preds = %16
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
br label %27
}