#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*/ 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();
  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   1080 <led_init@plt>
mov    $0x0,%al
call   1070 <button_init@plt>
mov    $0x0,%al
call   10a0 <irq_init@plt>
mov    $0x0,%al
call   1040 <uart_init@plt>
mov    $0x0,%al
call   1030 <dma_init@plt>
mov    $0x0,%al
call   10b0 <dma_start@plt>
mov    $0x0,%al
call   1090 <lcd_init@plt>
mov    $0x0,%al
call   1050 <lcd_test@plt>
lea    0xe12(%rip),%rdi
call   1060 <printf@plt>
lea    0xe32(%rip),%rdi
call   1060 <printf@plt>
lea    0xe52(%rip),%rdi
call   1060 <printf@plt>
lea    0xe72(%rip),%rdi
call   1060 <printf@plt>
lea    0xe80(%rip),%rdi
call   1060 <printf@plt>
lea    0xe95(%rip),%rdi
call   1060 <printf@plt>
lea    0xe9b(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10c0 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     1275 <gboot_main+0xd5>
jmp    1253 <gboot_main+0xb3>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     1286 <gboot_main+0xe6>
jmp    1264 <gboot_main+0xc4>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     1297 <gboot_main+0xf7>
jmp    12a8 <gboot_main+0x108>
lea    0xe58(%rip),%rdi
call   1060 <printf@plt>
jmp    12b4 <gboot_main+0x114>
lea    0xe56(%rip),%rdi
call   1060 <printf@plt>
jmp    12b4 <gboot_main+0x114>
lea    0xe54(%rip),%rdi
call   1060 <printf@plt>
jmp    12b4 <gboot_main+0x114>
lea    0xe52(%rip),%rdi
call   1060 <printf@plt>
jmp    11e7 <gboot_main+0x47>

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   1080 <led_init@plt>
xor    %eax,%eax
call   1070 <button_init@plt>
xor    %eax,%eax
call   10a0 <irq_init@plt>
xor    %eax,%eax
call   1040 <uart_init@plt>
xor    %eax,%eax
call   1030 <dma_init@plt>
xor    %eax,%eax
call   10b0 <dma_start@plt>
xor    %eax,%eax
call   1090 <lcd_init@plt>
xor    %eax,%eax
call   1050 <lcd_test@plt>
lea    0xeac(%rip),%rbx
lea    0xec6(%rip),%rbp
lea    0xed1(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xef5(%rip),%r12
lea    0xf15(%rip),%r13
jmp    1225 <gboot_main+0x85>
cs nopw 0x0(%rax,%rax,1)
nop
call   1060 <printf@plt>
lea    0xdd4(%rip),%rdi
call   1060 <printf@plt>
lea    0xdf4(%rip),%rdi
call   1060 <printf@plt>
lea    0xe14(%rip),%rdi
call   1060 <printf@plt>
lea    0xe34(%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   10c0 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
mov    %r12,%rdi
cmp    $0x2,%eax
ja     1220 <gboot_main+0x80>
cltq
movslq 0x0(%r13,%rax,4),%rdi
add    %r13,%rdi
jmp    1220 <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()
br label %11
11: ; preds = %0, %28
%12 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
switch i32 %19, label %26 [
i32 1, label %20
i32 2, label %22
i32 3, label %24
]
20: ; preds = %11
%21 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %28
22: ; preds = %11
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %28
24: ; preds = %11
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %28
26: ; preds = %11
%27 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
br label %28
28: ; preds = %26, %24, %22, %20
br label %11
}

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