#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*/ 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();
  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   1070 <led_init@plt>
mov    $0x0,%al
call   1060 <button_init@plt>
mov    $0x0,%al
call   1080 <irq_init@plt>
mov    $0x0,%al
call   1040 <uart_init@plt>
mov    $0x0,%al
call   1030 <dma_init@plt>
mov    $0x0,%al
call   1090 <dma_start@plt>
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
lea    0xea0(%rip),%rdi
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
call   1050 <printf@plt>
lea    0xec3(%rip),%rdi
call   1050 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     1247 <gboot_main+0xc7>
jmp    1225 <gboot_main+0xa5>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     1258 <gboot_main+0xd8>
jmp    1236 <gboot_main+0xb6>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     1269 <gboot_main+0xe9>
jmp    127a <gboot_main+0xfa>
lea    0xe86(%rip),%rdi
call   1050 <printf@plt>
jmp    1286 <gboot_main+0x106>
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
jmp    1286 <gboot_main+0x106>
lea    0xe82(%rip),%rdi
call   1050 <printf@plt>
jmp    1286 <gboot_main+0x106>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
jmp    11b9 <gboot_main+0x39>

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   1070 <led_init@plt>
xor    %eax,%eax
call   1060 <button_init@plt>
xor    %eax,%eax
call   1080 <irq_init@plt>
xor    %eax,%eax
call   1040 <uart_init@plt>
xor    %eax,%eax
call   1030 <dma_init@plt>
xor    %eax,%eax
call   1090 <dma_start@plt>
lea    0xeda(%rip),%rbx
lea    0xef4(%rip),%rbp
lea    0xeff(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xf23(%rip),%r12
lea    0xf43(%rip),%r13
jmp    11f5 <gboot_main+0x75>
nopw   0x0(%rax,%rax,1)
call   1050 <printf@plt>
lea    0xe04(%rip),%rdi
call   1050 <printf@plt>
lea    0xe24(%rip),%rdi
call   1050 <printf@plt>
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
mov    %r12,%rdi
cmp    $0x2,%eax
ja     11f0 <gboot_main+0x70>
cltq
movslq 0x0(%r13,%rax,4),%rdi
add    %r13,%rdi
jmp    11f0 <gboot_main+0x70>

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

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