#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*/ hc05_test();
int /*<<< orphan*/ init_uart();
int /*<<< orphan*/ reboot();
int /*<<< orphan*/ set_hc05();
char uart_getc();
int /*<<< orphan*/ uart_printf(char *);
int /*<<< orphan*/ uart_puts(char *);
int /*<<< orphan*/ update_program();
int boot(void) {
  init_uart();
  while (1) {
    uart_puts("\n");
    uart_puts("***** Bootloader Menu *****");
    uart_puts("[a] Update program");
    uart_puts("[b] Reboot");
    uart_puts("[c] Run uC/OS-II");
    uart_puts("[d] ATK-HC05 settings");
    uart_puts("[e] test mode");
    uart_puts("***************************");
    uart_printf(" >> ");
    char ch = uart_getc();
    uart_puts("");
    switch (ch) {
    case 'a':
      update_program();
      break;
    case 'b':
      reboot();
      uart_puts("Rebooting ...");
      while (1)
        ;
    case 'c':
      return 0;
    case 'd':
      set_hc05();
      break;
    case 'e':
      hc05_test();
    default:
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<boot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <init_uart@plt>
lea    0xe7e(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe74(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe84(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe8b(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe8a(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe8f(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe99(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe9b(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xeab(%rip),%rdi
call   1030 <uart_printf@plt>
xor    %eax,%eax
call   1080 <uart_getc@plt>
mov    %al,-0x1(%rbp)
lea    0xe09(%rip),%rdi
call   10a0 <uart_puts@plt>
movsbl -0x1(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4,%eax
ja     127a <boot+0xfa>
mov    -0x10(%rbp),%rax
lea    0xdce(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <update_program@plt>
jmp    127f <boot+0xff>
mov    $0x0,%al
call   1090 <reboot@plt>
lea    0xe51(%rip),%rdi
call   10a0 <uart_puts@plt>
jmp    125a <boot+0xda>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1050 <set_hc05@plt>
jmp    127f <boot+0xff>
mov    $0x0,%al
call   1060 <hc05_test@plt>
jmp    127f <boot+0xff>
jmp    118f <boot+0xf>

x86 assembly (clang, -O2):
<boot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <init_uart@plt>
lea    0xede(%rip),%r14
lea    0xee5(%rip),%r15
lea    0xefa(%rip),%r12
lea    0xe67(%rip),%r13
lea    0xe4b(%rip),%rbp
jmp    11c7 <boot+0x47>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <hc05_test@plt>
lea    0xe46(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe3c(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe4c(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe53(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe52(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe57(%rip),%rdi
call   10a0 <uart_puts@plt>
mov    %r14,%rdi
call   10a0 <uart_puts@plt>
mov    %r15,%rdi
call   10a0 <uart_puts@plt>
mov    %r12,%rdi
call   1030 <uart_printf@plt>
xor    %eax,%eax
call   1080 <uart_getc@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   10a0 <uart_puts@plt>
movsbl %bl,%eax
add    $0xffffff9f,%eax
cmp    $0x4,%eax
ja     11c7 <boot+0x47>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %eax,%eax
call   1040 <update_program@plt>
jmp    11c7 <boot+0x47>
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <set_hc05@plt>
jmp    11c7 <boot+0x47>
xor    %eax,%eax
call   1090 <reboot@plt>
lea    0xe2c(%rip),%rdi
call   10a0 <uart_puts@plt>
nop
jmp    1280 <boot+0x100>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [28 x i8] c"***** Bootloader Menu *****\00"
@.str.2 = [19 x i8] c"[a] Update program\00"
@.str.3 = [11 x i8] c"[b] Reboot\00"
@.str.4 = [17 x i8] c"[c] Run uC/OS-II\00"
@.str.5 = [22 x i8] c"[d] ATK-HC05 settings\00"
@.str.6 = [14 x i8] c"[e] test mode\00"
@.str.7 = [28 x i8] c"***************************\00"
@.str.8 = [5 x i8] c" >> \00"
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [14 x i8] c"Rebooting ...\00"
define i32 @boot() {
%1 = alloca i8
%2 = call i32 (...) @init_uart()
br label %3
3: ; preds = %0, %29
%4 = call i32 @uart_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @uart_puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @uart_puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @uart_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @uart_puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @uart_puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%10 = call i32 @uart_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 @uart_puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%12 = call i32 @uart_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%13 = call signext i8 (...) @uart_getc()
store i8 %13, i8* %1
%14 = call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
%15 = load i8, i8* %1
%16 = sext i8 %15 to i32
switch i32 %16, label %28 [
i32 97, label %17
i32 98, label %19
i32 99, label %23
i32 100, label %24
i32 101, label %26
]
17: ; preds = %3
%18 = call i32 (...) @update_program()
br label %29
19: ; preds = %3
%20 = call i32 (...) @reboot()
%21 = call i32 @uart_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
br label %22
22: ; preds = %19, %22
br label %22
23: ; preds = %3
ret i32 0
24: ; preds = %3
%25 = call i32 (...) @set_hc05()
br label %29
26: ; preds = %3
%27 = call i32 (...) @hc05_test()
br label %28
28: ; preds = %3, %26
br label %29
29: ; preds = %28, %24, %17
br label %3
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [28 x i8] c"***** Bootloader Menu *****\00"
@.str.2 = [19 x i8] c"[a] Update program\00"
@.str.3 = [11 x i8] c"[b] Reboot\00"
@.str.4 = [17 x i8] c"[c] Run uC/OS-II\00"
@.str.5 = [22 x i8] c"[d] ATK-HC05 settings\00"
@.str.6 = [14 x i8] c"[e] test mode\00"
@.str.7 = [28 x i8] c"***************************\00"
@.str.8 = [5 x i8] c" >> \00"
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [14 x i8] c"Rebooting ...\00"
define i32 @boot() {
%1 = tail call i32 (...) @init_uart()
br label %2
2: ; preds = %17, %0
%3 = tail call i32 @uart_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @uart_puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @uart_puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @uart_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @uart_puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 @uart_puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%9 = tail call i32 @uart_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%10 = tail call i32 @uart_puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%11 = tail call i32 @uart_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%12 = tail call signext i8 (...) @uart_getc()
%13 = tail call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
%14 = sext i8 %12 to i32
switch i32 %14, label %17 [
i32 97, label %15
i32 98, label %18
i32 99, label %26
i32 100, label %22
i32 101, label %24
]
15: ; preds = %2
%16 = tail call i32 (...) @update_program()
br label %17
17: ; preds = %15, %22, %2, %24
br label %2
18: ; preds = %2
%19 = tail call i32 (...) @reboot()
%20 = tail call i32 @uart_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
br label %21
21: ; preds = %21, %18
br label %21
22: ; preds = %2
%23 = tail call i32 (...) @set_hc05()
br label %17
24: ; preds = %2
%25 = tail call i32 (...) @hc05_test()
br label %17
26: ; preds = %2
ret i32 0
}