#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*/ sw_printf(char *, ...);
int /*<<< orphan*/ sw_sdram_init();
int /*<<< orphan*/ sw_shell_main();
int sw_trygetchar(void *);
int /*<<< orphan*/ sw_uartdbg_nofifo_init();
int /*<<< orphan*/ sw_usleep(int);
int sw_xboot_main(void) {
  int i;
  int waitsec;
  char *promt = "input any key to enter x-boot: ";
  sw_uartdbg_nofifo_init();
  sw_sdram_init();
  waitsec = 3;
  sw_printf("\n\n\n\r");
  sw_printf("%s: %u\r", promt, waitsec);
  for (i = waitsec; i > 0; i--) {
    sw_usleep(1000 * 1000);
    waitsec--;
    if (sw_trygetchar(((void *)0)) == 1) {
      sw_printf("\n\n\rstart x-boot, please wait...\n\n\r");
      sw_shell_main();
    }
    sw_printf("%s: %u\r", promt, waitsec);
  }
  sw_printf("\n\n\rstart Linux kernel, please wait...\n\r");
  for (;;) {
    sw_printf(".");
    sw_usleep(888 * 1000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<sw_xboot_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <sw_uartdbg_nofifo_init@plt>
mov    $0x0,%al
call   1070 <sw_sdram_init@plt>
movl   $0x3,-0x8(%rbp)
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <sw_printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <sw_printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1218 <sw_xboot_main+0xb8>
mov    $0xf4240,%edi
call   1080 <sw_usleep@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <sw_trygetchar@plt>
cmp    $0x1,%eax
jne    11f5 <sw_xboot_main+0x95>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <sw_printf@plt>
mov    $0x0,%al
call   1030 <sw_shell_main@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <sw_printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <sw_xboot_main+0x51>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <sw_printf@plt>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <sw_printf@plt>
mov    $0xd8cc0,%edi
call   1080 <sw_usleep@plt>
jmp    1226 <sw_xboot_main+0xc6>

x86 assembly (clang, -O2):
<sw_xboot_main>:
push   %rbx
xor    %eax,%eax
call   1040 <sw_uartdbg_nofifo_init@plt>
xor    %eax,%eax
call   1070 <sw_sdram_init@plt>
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1050 <sw_printf@plt>
lea    0xea1(%rip),%rdi
lea    0xe75(%rip),%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1050 <sw_printf@plt>
mov    $0xf4240,%edi
call   1080 <sw_usleep@plt>
xor    %edi,%edi
call   1060 <sw_trygetchar@plt>
cmp    $0x1,%eax
jne    11c2 <sw_xboot_main+0x62>
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1050 <sw_printf@plt>
xor    %eax,%eax
call   1030 <sw_shell_main@plt>
lea    0xe5c(%rip),%rdi
lea    0xe30(%rip),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <sw_printf@plt>
mov    $0xf4240,%edi
call   1080 <sw_usleep@plt>
xor    %edi,%edi
call   1060 <sw_trygetchar@plt>
cmp    $0x1,%eax
jne    1207 <sw_xboot_main+0xa7>
lea    0xe34(%rip),%rdi
xor    %eax,%eax
call   1050 <sw_printf@plt>
xor    %eax,%eax
call   1030 <sw_shell_main@plt>
lea    0xe17(%rip),%rdi
lea    0xdeb(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <sw_printf@plt>
mov    $0xf4240,%edi
call   1080 <sw_usleep@plt>
xor    %edi,%edi
call   1060 <sw_trygetchar@plt>
cmp    $0x1,%eax
jne    124c <sw_xboot_main+0xec>
lea    0xdef(%rip),%rdi
xor    %eax,%eax
call   1050 <sw_printf@plt>
xor    %eax,%eax
call   1030 <sw_shell_main@plt>
lea    0xdd2(%rip),%rdi
lea    0xda6(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <sw_printf@plt>
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1050 <sw_printf@plt>
lea    0xe00(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sw_printf@plt>
mov    $0xd8cc0,%edi
call   1080 <sw_usleep@plt>
jmp    1280 <sw_xboot_main+0x120>

LLVM IR (-O0):
@.str = [32 x i8] c"input any key to enter x-boot: \00"
@.str.1 = [5 x i8] c"\0A\0A\0A\0D\00"
@.str.2 = [8 x i8] c"%s: %u\0D\00"
@.str.3 = [35 x i8] c"\0A\0A\0Dstart x-boot, please wait...\0A\0A\0D\00"
@.str.4 = [40 x i8] c"\0A\0A\0Dstart Linux kernel, please wait...\0A\0D\00"
@.str.5 = [2 x i8] c".\00"
define i32 @sw_xboot_main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = call i32 (...) @sw_uartdbg_nofifo_init()
%5 = call i32 (...) @sw_sdram_init()
store i32 3, i32* %2
%6 = call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32 %8)
%10 = load i32, i32* %2
store i32 %10, i32* %1
br label %11
11: ; preds = %27, %0
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = call i32 @sw_usleep(i32 1000000)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
%18 = call i32 @sw_trygetchar(i8* null)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 (...) @sw_shell_main()
br label %23
23: ; preds = %20, %14
%24 = load i8*, i8** %3
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %25)
br label %27
27: ; preds = %23
%28 = load i32, i32* %1
%29 = add nsw i32 %28, -1
store i32 %29, i32* %1
br label %11
30: ; preds = %11
%31 = call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %32, %30
%33 = call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @sw_usleep(i32 888000)
br label %32
}

LLVM IR (-O2):
@.str = [32 x i8] c"input any key to enter x-boot: \00"
@.str.1 = [5 x i8] c"\0A\0A\0A\0D\00"
@.str.2 = [8 x i8] c"%s: %u\0D\00"
@.str.3 = [35 x i8] c"\0A\0A\0Dstart x-boot, please wait...\0A\0A\0D\00"
@.str.4 = [40 x i8] c"\0A\0A\0Dstart Linux kernel, please wait...\0A\0D\00"
@.str.5 = [2 x i8] c".\00"
define i32 @sw_xboot_main() {
%1 = tail call i32 (...) @sw_uartdbg_nofifo_init()
%2 = tail call i32 (...) @sw_sdram_init()
%3 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 3)
%5 = tail call i32 @sw_usleep(i32 1000000)
%6 = tail call i32 @sw_trygetchar(i8* null)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 (...) @sw_shell_main()
br label %11
11: ; preds = %8, %0
%12 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 2)
%13 = tail call i32 @sw_usleep(i32 1000000)
%14 = tail call i32 @sw_trygetchar(i8* null)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 (...) @sw_shell_main()
br label %19
19: ; preds = %16, %11
%20 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 1)
%21 = tail call i32 @sw_usleep(i32 1000000)
%22 = tail call i32 @sw_trygetchar(i8* null)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%26 = tail call i32 (...) @sw_shell_main()
br label %27
27: ; preds = %24, %19
%28 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 0)
%29 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %30, %27
%31 = tail call i32 (i8*, ...) @sw_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%32 = tail call i32 @sw_usleep(i32 888000)
br label %30
}