#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*/ auto_run();
int /*<<< orphan*/ command_help();
int /*<<< orphan*/ command_hexdump(char *);
int /*<<< orphan*/ command_load();
int /*<<< orphan*/ command_loadrom();
int /*<<< orphan*/ command_regdump();
int /*<<< orphan*/ command_run(char *);
int /*<<< orphan*/ kgets(char *);
int /*<<< orphan*/ kprintf(char *, ...);
int /*<<< orphan*/ led_init();
int /*<<< orphan*/ mem_init();
int /*<<< orphan*/ pll_init();
int /*<<< orphan*/ rled_off();
int /*<<< orphan*/ rled_on();
int /*<<< orphan*/ sci_init();
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ sw_init();
scalar_t__ sw_is_on();
int main(void) {
  led_init();
  sw_init();
  rled_on();
  pll_init();
  sci_init();
  mem_init();
  kprintf("Clock Frequency ...\n");
  kprintf(" System Clock (ICLK): %dHz\n", ((12000000UL) * 8));
  kprintf(" Bus    Clock (BCLK): %dHz\n", ((12000000UL) * 2));
  kprintf(" Module Clock (PCLK): %dHz\n", ((12000000UL) * 4));
  kprintf("--- Welcome to extboot! ---\n");
  rled_off();
  if (sw_is_on()) {
    auto_run();
  }
  while (1) {
    char buf[32];
    kprintf("extboot> ");
    kgets(buf);
    if (strcmp(buf, "help") == 0) {
      command_help();
    } else if (strcmp(buf, "load") == 0) {
      command_load();
    } else if (strcmp(buf, "loadrom") == 0) {
      command_loadrom();
    } else if (strncmp(buf, "run", 3) == 0) {
      command_run(buf + 3);
    } else if (strncmp(buf, "hexdump", 7) == 0) {
      command_hexdump(buf + 7);
    } else if (strcmp(buf, "regdump") == 0) {
      command_regdump();
    } else {
      kprintf("unknown.\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10d0 <led_init@plt>
mov    $0x0,%al
call   10c0 <sw_init@plt>
mov    $0x0,%al
call   1080 <rled_on@plt>
mov    $0x0,%al
call   1130 <pll_init@plt>
mov    $0x0,%al
call   10a0 <sci_init@plt>
mov    $0x0,%al
call   10f0 <mem_init@plt>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1150 <kprintf@plt>
lea    0xd97(%rip),%rdi
mov    $0x5b8d800,%esi
mov    $0x0,%al
call   1150 <kprintf@plt>
lea    0xda0(%rip),%rdi
mov    $0x16e3600,%esi
mov    $0x0,%al
call   1150 <kprintf@plt>
lea    0xda9(%rip),%rdi
mov    $0x2dc6c00,%esi
mov    $0x0,%al
call   1150 <kprintf@plt>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1150 <kprintf@plt>
mov    $0x0,%al
call   1110 <rled_off@plt>
mov    $0x0,%al
call   1090 <sw_is_on@plt>
cmp    $0x0,%rax
je     12dd <main+0xad>
mov    $0x0,%al
call   1030 <auto_run@plt>
jmp    12e2 <main+0xb2>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1150 <kprintf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <kgets@plt>
lea    -0x30(%rbp),%rdi
lea    0xd8c(%rip),%rsi
call   1100 <strcmp@plt>
cmp    $0x0,%rax
jne    131f <main+0xef>
mov    $0x0,%al
call   1060 <command_help@plt>
jmp    141a <main+0x1ea>
lea    -0x30(%rbp),%rdi
lea    0xd6b(%rip),%rsi
call   1100 <strcmp@plt>
cmp    $0x0,%rax
jne    1345 <main+0x115>
mov    $0x0,%al
call   10b0 <command_load@plt>
jmp    1415 <main+0x1e5>
lea    -0x30(%rbp),%rdi
lea    0xd4a(%rip),%rsi
call   1100 <strcmp@plt>
cmp    $0x0,%rax
jne    136b <main+0x13b>
mov    $0x0,%al
call   1070 <command_loadrom@plt>
jmp    1410 <main+0x1e0>
lea    -0x30(%rbp),%rdi
lea    0xd2c(%rip),%rsi
mov    $0x3,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    139c <main+0x16c>
lea    -0x30(%rbp),%rdi
add    $0x3,%rdi
call   1120 <command_run@plt>
jmp    140b <main+0x1db>
lea    -0x30(%rbp),%rdi
lea    0xcff(%rip),%rsi
mov    $0x7,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    13cd <main+0x19d>
lea    -0x30(%rbp),%rdi
add    $0x7,%rdi
call   1140 <command_hexdump@plt>
jmp    1406 <main+0x1d6>
lea    -0x30(%rbp),%rdi
lea    0xcd6(%rip),%rsi
call   1100 <strcmp@plt>
cmp    $0x0,%rax
jne    13f3 <main+0x1c3>
mov    $0x0,%al
call   10e0 <command_regdump@plt>
jmp    1401 <main+0x1d1>
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1150 <kprintf@plt>
jmp    1406 <main+0x1d6>
jmp    140b <main+0x1db>
jmp    1410 <main+0x1e0>
jmp    1415 <main+0x1e5>
jmp    141a <main+0x1ea>
jmp    12e2 <main+0xb2>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   10d0 <led_init@plt>
xor    %eax,%eax
call   10c0 <sw_init@plt>
xor    %eax,%eax
call   1080 <rled_on@plt>
xor    %eax,%eax
call   1130 <pll_init@plt>
xor    %eax,%eax
call   10a0 <sci_init@plt>
xor    %eax,%eax
call   10f0 <mem_init@plt>
lea    0xd91(%rip),%rdi
xor    %eax,%eax
call   1150 <kprintf@plt>
lea    0xd98(%rip),%rdi
mov    $0x5b8d800,%esi
xor    %eax,%eax
call   1150 <kprintf@plt>
lea    0xda1(%rip),%rdi
mov    $0x16e3600,%esi
xor    %eax,%eax
call   1150 <kprintf@plt>
lea    0xdaa(%rip),%rdi
mov    $0x2dc6c00,%esi
xor    %eax,%eax
call   1150 <kprintf@plt>
lea    0xdb3(%rip),%rdi
xor    %eax,%eax
call   1150 <kprintf@plt>
xor    %eax,%eax
call   1110 <rled_off@plt>
xor    %eax,%eax
call   1090 <sw_is_on@plt>
test   %rax,%rax
je     12d7 <main+0xa7>
xor    %eax,%eax
call   1030 <auto_run@plt>
lea    0xda8(%rip),%r12
mov    %rsp,%rbx
lea    0xda8(%rip),%r13
lea    0xda6(%rip),%rbp
lea    0xda4(%rip),%r14
lea    0xda5(%rip),%r15
jmp    1307 <main+0xd7>
nop
xor    %eax,%eax
call   1060 <command_help@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1150 <kprintf@plt>
mov    %rbx,%rdi
call   1040 <kgets@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1100 <strcmp@plt>
test   %rax,%rax
je     1300 <main+0xd0>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1100 <strcmp@plt>
test   %rax,%rax
je     13a0 <main+0x170>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1100 <strcmp@plt>
test   %rax,%rax
je     13ac <main+0x17c>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     13b8 <main+0x188>
mov    %rbx,%rdi
lea    0xd3e(%rip),%rsi
mov    $0x7,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     13c7 <main+0x197>
mov    %rbx,%rdi
lea    0xd2d(%rip),%rsi
call   1100 <strcmp@plt>
test   %rax,%rax
je     13d6 <main+0x1a6>
lea    0xd24(%rip),%rdi
xor    %eax,%eax
call   1150 <kprintf@plt>
jmp    1307 <main+0xd7>
xchg   %ax,%ax
xor    %eax,%eax
call   10b0 <command_load@plt>
jmp    1307 <main+0xd7>
xor    %eax,%eax
call   1070 <command_loadrom@plt>
jmp    1307 <main+0xd7>
lea    0x3(%rsp),%rdi
call   1120 <command_run@plt>
jmp    1307 <main+0xd7>
lea    0x7(%rsp),%rdi
call   1140 <command_hexdump@plt>
jmp    1307 <main+0xd7>
xor    %eax,%eax
call   10e0 <command_regdump@plt>
jmp    1307 <main+0xd7>

LLVM IR (-O0):
@.str = [21 x i8] c"Clock Frequency ...\0A\00"
@.str.1 = [28 x i8] c" System Clock (ICLK): %dHz\0A\00"
@.str.2 = [28 x i8] c" Bus Clock (BCLK): %dHz\0A\00"
@.str.3 = [28 x i8] c" Module Clock (PCLK): %dHz\0A\00"
@.str.4 = [29 x i8] c"--- Welcome to extboot! ---\0A\00"
@.str.5 = [10 x i8] c"extboot> \00"
@.str.6 = [5 x i8] c"help\00"
@.str.7 = [5 x i8] c"load\00"
@.str.8 = [8 x i8] c"loadrom\00"
@.str.9 = [4 x i8] c"run\00"
@.str.10 = [8 x i8] c"hexdump\00"
@.str.11 = [8 x i8] c"regdump\00"
@.str.12 = [10 x i8] c"unknown.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
store i32 0, i32* %1
%3 = call i32 (...) @led_init()
%4 = call i32 (...) @sw_init()
%5 = call i32 (...) @rled_on()
%6 = call i32 (...) @pll_init()
%7 = call i32 (...) @sci_init()
%8 = call i32 (...) @mem_init()
%9 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 96000000)
%11 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 24000000)
%12 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i64 48000000)
%13 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (...) @rled_off()
%15 = call i64 (...) @sw_is_on()
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 (...) @auto_run()
br label %19
19: ; preds = %17, %0
br label %20
20: ; preds = %19, %70
%21 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%23 = call i32 @kgets(i8* %22)
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 (...) @command_help()
br label %70
29: ; preds = %20
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 (...) @command_load()
br label %69
35: ; preds = %29
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (...) @command_loadrom()
br label %68
41: ; preds = %35
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%43 = call i64 @strncmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%47 = getelementptr inbounds i8, i8* %46, i64 3
%48 = call i32 @command_run(i8* %47)
br label %67
49: ; preds = %41
%50 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%51 = call i64 @strncmp(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i32 7)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%55 = getelementptr inbounds i8, i8* %54, i64 7
%56 = call i32 @command_hexdump(i8* %55)
br label %66
57: ; preds = %49
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 (...) @command_regdump()
br label %65
63: ; preds = %57
%64 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0))
br label %65
65: ; preds = %63, %61
br label %66
66: ; preds = %65, %53
br label %67
67: ; preds = %66, %45
br label %68
68: ; preds = %67, %39
br label %69
69: ; preds = %68, %33
br label %70
70: ; preds = %69, %27
br label %20
}

LLVM IR (-O2):
@.str = [21 x i8] c"Clock Frequency ...\0A\00"
@.str.1 = [28 x i8] c" System Clock (ICLK): %dHz\0A\00"
@.str.2 = [28 x i8] c" Bus Clock (BCLK): %dHz\0A\00"
@.str.3 = [28 x i8] c" Module Clock (PCLK): %dHz\0A\00"
@.str.4 = [29 x i8] c"--- Welcome to extboot! ---\0A\00"
@.str.5 = [10 x i8] c"extboot> \00"
@.str.6 = [5 x i8] c"help\00"
@.str.7 = [5 x i8] c"load\00"
@.str.8 = [8 x i8] c"loadrom\00"
@.str.9 = [4 x i8] c"run\00"
@.str.10 = [8 x i8] c"hexdump\00"
@.str.11 = [8 x i8] c"regdump\00"
@.str.12 = [10 x i8] c"unknown.\0A\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = tail call i32 (...) @led_init()
%3 = tail call i32 (...) @sw_init()
%4 = tail call i32 (...) @rled_on()
%5 = tail call i32 (...) @pll_init()
%6 = tail call i32 (...) @sci_init()
%7 = tail call i32 (...) @mem_init()
%8 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 96000000)
%10 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 24000000)
%11 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i64 48000000)
%12 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 (...) @rled_off()
%14 = tail call i64 (...) @sw_is_on()
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %0
%17 = tail call i32 (...) @auto_run()
br label %18
18: ; preds = %16, %0
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 7
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 3
br label %22
22: ; preds = %18, %56
%23 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @kgets(i8* %19)
%25 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 (...) @command_help()
br label %56
29: ; preds = %22
%30 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (...) @command_load()
br label %56
34: ; preds = %29
%35 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (...) @command_loadrom()
br label %56
39: ; preds = %34
%40 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @command_run(i8* %21)
br label %56
44: ; preds = %39
%45 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i32 7)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @command_hexdump(i8* %20)
br label %56
49: ; preds = %44
%50 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 (...) @command_regdump()
br label %56
54: ; preds = %49
%55 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0))
br label %56
56: ; preds = %32, %42, %52, %54, %47, %37, %27
br label %22
}