#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*/ init_key();
int /*<<< orphan*/ init_led();
int /*<<< orphan*/ init_uart();
int /*<<< orphan*/ reboot();
char uart_getc();
int /*<<< orphan*/ uart_printf(char *);
int /*<<< orphan*/ uart_puts(char *);
int /*<<< orphan*/ update_program();
int boot(void) {
  init_uart();
  init_led();
  init_key();
  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("***************************");
    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':
      uart_puts("Begin to run uC/OS-II...");
      return 0;
    default:
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<boot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <init_uart@plt>
mov    $0x0,%al
call   1040 <init_led@plt>
mov    $0x0,%al
call   1070 <init_key@plt>
lea    0xe5c(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe52(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe62(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe69(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe68(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe6d(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe7d(%rip),%rdi
call   1030 <uart_printf@plt>
xor    %eax,%eax
call   1080 <uart_getc@plt>
mov    %al,-0x1(%rbp)
lea    0xdff(%rip),%rdi
call   10a0 <uart_puts@plt>
movsbl -0x1(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x61,%eax
je     123e <boot+0xbe>
jmp    121c <boot+0x9c>
mov    -0x8(%rbp),%eax
sub    $0x62,%eax
je     124a <boot+0xca>
jmp    122d <boot+0xad>
mov    -0x8(%rbp),%eax
sub    $0x63,%eax
je     1262 <boot+0xe2>
jmp    1276 <boot+0xf6>
mov    $0x0,%al
call   1050 <update_program@plt>
jmp    127b <boot+0xfb>
mov    $0x0,%al
call   1090 <reboot@plt>
lea    0xe16(%rip),%rdi
call   10a0 <uart_puts@plt>
jmp    125d <boot+0xdd>
lea    0xe13(%rip),%rdi
call   10a0 <uart_puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret
jmp    127b <boot+0xfb>
jmp    119d <boot+0x1d>

x86 assembly (clang, -O2):
<boot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <init_uart@plt>
xor    %eax,%eax
call   1040 <init_led@plt>
xor    %eax,%eax
call   1070 <init_key@plt>
lea    0xe8a(%rip),%r13
lea    0xe8e(%rip),%rbx
lea    0xe98(%rip),%rbp
lea    0xead(%rip),%r14
lea    0xe3e(%rip),%r15
jmp    11d7 <boot+0x57>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <update_program@plt>
lea    0xe22(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe18(%rip),%rdi
call   10a0 <uart_puts@plt>
lea    0xe28(%rip),%rdi
call   10a0 <uart_puts@plt>
mov    %r13,%rdi
call   10a0 <uart_puts@plt>
mov    %rbx,%rdi
call   10a0 <uart_puts@plt>
mov    %rbp,%rdi
call   10a0 <uart_puts@plt>
mov    %r14,%rdi
call   1030 <uart_printf@plt>
xor    %eax,%eax
call   1080 <uart_getc@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   10a0 <uart_puts@plt>
movsbl %r12b,%eax
cmp    $0x61,%eax
je     11d0 <boot+0x50>
cmp    $0x62,%eax
je     125d <boot+0xdd>
cmp    $0x63,%eax
jne    11d7 <boot+0x57>
lea    0xe35(%rip),%rdi
call   10a0 <uart_puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1090 <reboot@plt>
lea    0xe03(%rip),%rdi
call   10a0 <uart_puts@plt>
jmp    1270 <boot+0xf0>

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 = [28 x i8] c"***************************\00"
@.str.6 = [5 x i8] c" >> \00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [14 x i8] c"Rebooting ...\00"
@.str.9 = [25 x i8] c"Begin to run uC/OS-II...\00"
define i32 @boot() {
%1 = alloca i8
%2 = call i32 (...) @init_uart()
%3 = call i32 (...) @init_led()
%4 = call i32 (...) @init_key()
br label %5
5: ; preds = %0, %26
%6 = call i32 @uart_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @uart_puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @uart_puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @uart_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @uart_puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @uart_puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 @uart_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, 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.7, i64 0, i64 0))
%15 = load i8, i8* %1
%16 = sext i8 %15 to i32
switch i32 %16, label %25 [
i32 97, label %17
i32 98, label %19
i32 99, label %23
]
17: ; preds = %5
%18 = call i32 (...) @update_program()
br label %26
19: ; preds = %5
%20 = call i32 (...) @reboot()
%21 = call i32 @uart_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %22
22: ; preds = %19, %22
br label %22
23: ; preds = %5
%24 = call i32 @uart_puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
25: ; preds = %5
br label %26
26: ; preds = %25, %17
br label %5
}

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 = [28 x i8] c"***************************\00"
@.str.6 = [5 x i8] c" >> \00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [14 x i8] c"Rebooting ...\00"
@.str.9 = [25 x i8] c"Begin to run uC/OS-II...\00"
define i32 @boot() {
%1 = tail call i32 (...) @init_uart()
%2 = tail call i32 (...) @init_led()
%3 = tail call i32 (...) @init_key()
br label %4
4: ; preds = %17, %0
%5 = tail call i32 @uart_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @uart_puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @uart_puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @uart_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @uart_puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 @uart_puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%11 = tail call i32 @uart_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, 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.7, 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 %22
]
15: ; preds = %4
%16 = tail call i32 (...) @update_program()
br label %17
17: ; preds = %15, %4
br label %4
18: ; preds = %4
%19 = tail call i32 (...) @reboot()
%20 = tail call i32 @uart_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %21
21: ; preds = %21, %18
br label %21
22: ; preds = %4
%23 = tail call i32 @uart_puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}