#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*/ button_init();
int /*<<< orphan*/ irq_init();
int /*<<< orphan*/ led_init();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ uart_init();
int gboot_main() {
  unsigned char buff[10];
  int num = 0;
  led_init();
  button_init();
  irq_init();
  uart_init();
  while (1) {
    printf("\n****************************************\n\r");
    printf("\n*****************GBOOT******************\n\r");
    printf("1:Download Linux Kernel from TFTP Server!\n\r");
    printf("2:Boot Linux from RAM !\n\r");
    printf("3:Boot Linux from Nand Flash !\n\r");
    printf("\nPlease Select : ");
    scanf("%d", &num);
    switch (num) {
    case 1:
      printf("selected 1 !\n\r");
      break;
    case 2:
      printf("selected 2 !\n\r");
      break;
    case 3:
      printf("selected 3 !\n\r");
      break;
    default:
      printf("Error : This is a wrong slection !\n\r");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<gboot_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1060 <led_init@plt>
mov    $0x0,%al
call   1050 <button_init@plt>
mov    $0x0,%al
call   1070 <irq_init@plt>
mov    $0x0,%al
call   1030 <uart_init@plt>
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
call   1040 <printf@plt>
lea    0xef1(%rip),%rdi
call   1040 <printf@plt>
lea    0xef7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     1219 <gboot_main+0xb9>
jmp    11f7 <gboot_main+0x97>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     122a <gboot_main+0xca>
jmp    1208 <gboot_main+0xa8>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     123b <gboot_main+0xdb>
jmp    124c <gboot_main+0xec>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
jmp    1258 <gboot_main+0xf8>
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
jmp    1258 <gboot_main+0xf8>
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
jmp    1258 <gboot_main+0xf8>
lea    0xeae(%rip),%rdi
call   1040 <printf@plt>
jmp    118b <gboot_main+0x2b>

x86 assembly (clang, -O2):
<gboot_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
call   1060 <led_init@plt>
xor    %eax,%eax
call   1050 <button_init@plt>
xor    %eax,%eax
call   1070 <irq_init@plt>
xor    %eax,%eax
call   1030 <uart_init@plt>
lea    0xf08(%rip),%rbx
lea    0xf22(%rip),%rbp
lea    0xf2d(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xf51(%rip),%r12
lea    0xf71(%rip),%r13
jmp    11c5 <gboot_main+0x65>
nopl   0x0(%rax)
call   1040 <printf@plt>
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
mov    %r12,%rdi
cmp    $0x2,%eax
ja     11c0 <gboot_main+0x60>
cltq
movslq 0x0(%r13,%rax,4),%rdi
add    %r13,%rdi
jmp    11c0 <gboot_main+0x60>

LLVM IR (-O0):
@.str = [44 x i8] c"\0A****************************************\0A\0D\00"
@.str.1 = [44 x i8] c"\0A*****************GBOOT******************\0A\0D\00"
@.str.2 = [44 x i8] c"1:Download Linux Kernel from TFTP Server!\0A\0D\00"
@.str.3 = [26 x i8] c"2:Boot Linux from RAM !\0A\0D\00"
@.str.4 = [33 x i8] c"3:Boot Linux from Nand Flash !\0A\0D\00"
@.str.5 = [18 x i8] c"\0APlease Select : \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [15 x i8] c"selected 1 !\0A\0D\00"
@.str.8 = [15 x i8] c"selected 2 !\0A\0D\00"
@.str.9 = [15 x i8] c"selected 3 !\0A\0D\00"
@.str.10 = [37 x i8] c"Error : This is a wrong slection !\0A\0D\00"
define i32 @gboot_main() {
%1 = alloca [10 x i8]
%2 = alloca i32
store i32 0, i32* %2
%3 = call i32 (...) @led_init()
%4 = call i32 (...) @button_init()
%5 = call i32 (...) @irq_init()
%6 = call i32 (...) @uart_init()
br label %7
7: ; preds = %0, %24
%8 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
switch i32 %15, label %22 [
i32 1, label %16
i32 2, label %18
i32 3, label %20
]
16: ; preds = %7
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %24
18: ; preds = %7
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %24
20: ; preds = %7
%21 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %24
22: ; preds = %7
%23 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %18, %16
br label %7
}

LLVM IR (-O2):
@.str = [44 x i8] c"\0A****************************************\0A\0D\00"
@.str.1 = [44 x i8] c"\0A*****************GBOOT******************\0A\0D\00"
@.str.2 = [44 x i8] c"1:Download Linux Kernel from TFTP Server!\0A\0D\00"
@.str.3 = [26 x i8] c"2:Boot Linux from RAM !\0A\0D\00"
@.str.4 = [33 x i8] c"3:Boot Linux from Nand Flash !\0A\0D\00"
@.str.5 = [18 x i8] c"\0APlease Select : \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [15 x i8] c"selected 1 !\0A\0D\00"
@.str.8 = [15 x i8] c"selected 2 !\0A\0D\00"
@.str.9 = [15 x i8] c"selected 3 !\0A\0D\00"
@.str.10 = [37 x i8] c"Error : This is a wrong slection !\0A\0D\00"
@reltable.gboot_main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.7 to i64), i64 ptrtoint ([3 x i32]* @reltable.gboot_main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.8 to i64), i64 ptrtoint ([3 x i32]* @reltable.gboot_main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.9 to i64), i64 ptrtoint ([3 x i32]* @reltable.gboot_main to i64)) to i32)]
define i32 @gboot_main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (...) @led_init()
%4 = tail call i32 (...) @button_init()
%5 = tail call i32 (...) @irq_init()
%6 = tail call i32 (...) @uart_init()
br label %7
7: ; preds = %22, %0
%8 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
%16 = add i32 %15, -1
%17 = icmp ult i32 %16, 3
br i1 %17, label %18, label %22
18: ; preds = %7
%19 = sext i32 %16 to i64
%20 = shl i64 %19, 2
%21 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.gboot_main to i8*), i64 %20)
br label %22
22: ; preds = %7, %18
%23 = phi i8* [ %21, %18 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), %7 ]
%24 = call i32 @printf(i8* dereferenceable(1) %23)
br label %7
}