#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*/ dma_init();
int /*<<< orphan*/ dma_start();
int /*<<< orphan*/ irq_init();
int /*<<< orphan*/ lcd_init();
int /*<<< orphan*/ lcd_test();
int /*<<< orphan*/ led_init();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ touchscreen_init();
int /*<<< orphan*/ uart_init();
int gboot_main() {
  unsigned char buff[10];
  int num = 0;
  led_init();
  button_init();
  irq_init();
  uart_init();
  dma_init();
  dma_start();
  lcd_init();
  lcd_test();
  touchscreen_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   1090 <led_init@plt>
mov    $0x0,%al
call   1080 <button_init@plt>
mov    $0x0,%al
call   10b0 <irq_init@plt>
mov    $0x0,%al
call   1040 <uart_init@plt>
mov    $0x0,%al
call   1030 <dma_init@plt>
mov    $0x0,%al
call   10c0 <dma_start@plt>
mov    $0x0,%al
call   10a0 <lcd_init@plt>
mov    $0x0,%al
call   1050 <lcd_test@plt>
mov    $0x0,%al
call   1070 <touchscreen_init@plt>
lea    0xdfb(%rip),%rdi
call   1060 <printf@plt>
lea    0xe1b(%rip),%rdi
call   1060 <printf@plt>
lea    0xe3b(%rip),%rdi
call   1060 <printf@plt>
lea    0xe5b(%rip),%rdi
call   1060 <printf@plt>
lea    0xe69(%rip),%rdi
call   1060 <printf@plt>
lea    0xe7e(%rip),%rdi
call   1060 <printf@plt>
lea    0xe84(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10d0 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     128c <gboot_main+0xdc>
jmp    126a <gboot_main+0xba>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     129d <gboot_main+0xed>
jmp    127b <gboot_main+0xcb>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     12ae <gboot_main+0xfe>
jmp    12bf <gboot_main+0x10f>
lea    0xe41(%rip),%rdi
call   1060 <printf@plt>
jmp    12cb <gboot_main+0x11b>
lea    0xe3f(%rip),%rdi
call   1060 <printf@plt>
jmp    12cb <gboot_main+0x11b>
lea    0xe3d(%rip),%rdi
call   1060 <printf@plt>
jmp    12cb <gboot_main+0x11b>
lea    0xe3b(%rip),%rdi
call   1060 <printf@plt>
jmp    11fe <gboot_main+0x4e>

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   1090 <led_init@plt>
xor    %eax,%eax
call   1080 <button_init@plt>
xor    %eax,%eax
call   10b0 <irq_init@plt>
xor    %eax,%eax
call   1040 <uart_init@plt>
xor    %eax,%eax
call   1030 <dma_init@plt>
xor    %eax,%eax
call   10c0 <dma_start@plt>
xor    %eax,%eax
call   10a0 <lcd_init@plt>
xor    %eax,%eax
call   1050 <lcd_test@plt>
xor    %eax,%eax
call   1070 <touchscreen_init@plt>
lea    0xe95(%rip),%rbx
lea    0xeaf(%rip),%rbp
lea    0xeba(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xede(%rip),%r12
lea    0xefe(%rip),%r13
jmp    1235 <gboot_main+0x85>
nopl   0x0(%rax)
call   1060 <printf@plt>
lea    0xdc4(%rip),%rdi
call   1060 <printf@plt>
lea    0xde4(%rip),%rdi
call   1060 <printf@plt>
lea    0xe04(%rip),%rdi
call   1060 <printf@plt>
lea    0xe24(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10d0 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
mov    %r12,%rdi
cmp    $0x2,%eax
ja     1230 <gboot_main+0x80>
cltq
movslq 0x0(%r13,%rax,4),%rdi
add    %r13,%rdi
jmp    1230 <gboot_main+0x80>

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()
%7 = call i32 (...) @dma_init()
%8 = call i32 (...) @dma_start()
%9 = call i32 (...) @lcd_init()
%10 = call i32 (...) @lcd_test()
%11 = call i32 (...) @touchscreen_init()
br label %12
12: ; preds = %0, %29
%13 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%20 = load i32, i32* %2
switch i32 %20, label %27 [
i32 1, label %21
i32 2, label %23
i32 3, label %25
]
21: ; preds = %12
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %29
23: ; preds = %12
%24 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %29
25: ; preds = %12
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %29
27: ; preds = %12
%28 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
br label %29
29: ; preds = %27, %25, %23, %21
br label %12
}

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()
%7 = tail call i32 (...) @dma_init()
%8 = tail call i32 (...) @dma_start()
%9 = tail call i32 (...) @lcd_init()
%10 = tail call i32 (...) @lcd_test()
%11 = tail call i32 (...) @touchscreen_init()
br label %12
12: ; preds = %27, %0
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%20 = load i32, i32* %1
%21 = add i32 %20, -1
%22 = icmp ult i32 %21, 3
br i1 %22, label %23, label %27
23: ; preds = %12
%24 = sext i32 %21 to i64
%25 = shl i64 %24, 2
%26 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.gboot_main to i8*), i64 %25)
br label %27
27: ; preds = %12, %23
%28 = phi i8* [ %26, %23 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), %12 ]
%29 = call i32 @printf(i8* dereferenceable(1) %28)
br label %12
}