#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*/ cmd_run(char *);
int /*<<< orphan*/ sw_beep_init();
int /*<<< orphan*/ sw_beep_off();
int /*<<< orphan*/ sw_beep_on();
int /*<<< orphan*/ sw_getn(char *, int);
int /*<<< orphan*/ sw_printf(char *);
int /*<<< orphan*/ sw_uartdbg_nofifo_init();
int /*<<< orphan*/ sw_usleep(int);
int sw_shell_main() {
  int i;
  char cmd_buf[128];
  sw_beep_init();
  sw_uartdbg_nofifo_init();
  for (i = 0; i < 3; i++) {
    sw_beep_on();
    sw_usleep(150 * 1000);
    sw_beep_off();
    sw_usleep(50 * 1000);
  }
  for (;;) {
    sw_printf("x-boot# ");
    sw_getn(cmd_buf, 128);
    cmd_run(cmd_buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<sw_shell_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    $0x0,%al
call   1090 <sw_beep_init@plt>
mov    $0x0,%al
call   1060 <sw_uartdbg_nofifo_init@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jge    11da <sw_shell_main+0x5a>
mov    $0x0,%al
call   1050 <sw_beep_on@plt>
mov    $0x249f0,%edi
call   10a0 <sw_usleep@plt>
mov    $0x0,%al
call   1080 <sw_beep_off@plt>
mov    $0xc350,%edi
call   10a0 <sw_usleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <sw_shell_main+0x20>
jmp    11df <sw_shell_main+0x5f>
lea    0xe1a(%rip),%rdi
call   1070 <sw_printf@plt>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1040 <sw_getn@plt>
lea    -0x90(%rbp),%rdi
call   1030 <cmd_run@plt>
jmp    11df <sw_shell_main+0x5f>

x86 assembly (clang, -O2):
<sw_shell_main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
xor    %eax,%eax
call   1090 <sw_beep_init@plt>
xor    %eax,%eax
call   1060 <sw_uartdbg_nofifo_init@plt>
xor    %eax,%eax
call   1050 <sw_beep_on@plt>
mov    $0x249f0,%edi
call   10a0 <sw_usleep@plt>
xor    %eax,%eax
call   1080 <sw_beep_off@plt>
mov    $0xc350,%edi
call   10a0 <sw_usleep@plt>
xor    %eax,%eax
call   1050 <sw_beep_on@plt>
mov    $0x249f0,%edi
call   10a0 <sw_usleep@plt>
xor    %eax,%eax
call   1080 <sw_beep_off@plt>
mov    $0xc350,%edi
call   10a0 <sw_usleep@plt>
xor    %eax,%eax
call   1050 <sw_beep_on@plt>
mov    $0x249f0,%edi
call   10a0 <sw_usleep@plt>
xor    %eax,%eax
call   1080 <sw_beep_off@plt>
mov    $0xc350,%edi
call   10a0 <sw_usleep@plt>
lea    0xdfb(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <sw_printf@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
call   1040 <sw_getn@plt>
mov    %rbx,%rdi
call   1030 <cmd_run@plt>
jmp    1210 <sw_shell_main+0x90>

LLVM IR (-O0):
@.str = [9 x i8] c"x-boot# \00"
define i32 @sw_shell_main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = call i32 (...) @sw_beep_init()
%4 = call i32 (...) @sw_uartdbg_nofifo_init()
store i32 0, i32* %1
br label %5
5: ; preds = %13, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = call i32 (...) @sw_beep_on()
%10 = call i32 @sw_usleep(i32 150000)
%11 = call i32 (...) @sw_beep_off()
%12 = call i32 @sw_usleep(i32 50000)
br label %13
13: ; preds = %8
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
br label %5
16: ; preds = %5
br label %17
17: ; preds = %17, %16
%18 = call i32 @sw_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%20 = call i32 @sw_getn(i8* %19, i32 128)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%22 = call i32 @cmd_run(i8* %21)
br label %17
}

LLVM IR (-O2):
@.str = [9 x i8] c"x-boot# \00"
define i32 @sw_shell_main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @sw_beep_init()
%4 = tail call i32 (...) @sw_uartdbg_nofifo_init()
%5 = tail call i32 (...) @sw_beep_on()
%6 = tail call i32 @sw_usleep(i32 150000)
%7 = tail call i32 (...) @sw_beep_off()
%8 = tail call i32 @sw_usleep(i32 50000)
%9 = tail call i32 (...) @sw_beep_on()
%10 = tail call i32 @sw_usleep(i32 150000)
%11 = tail call i32 (...) @sw_beep_off()
%12 = tail call i32 @sw_usleep(i32 50000)
%13 = tail call i32 (...) @sw_beep_on()
%14 = tail call i32 @sw_usleep(i32 150000)
%15 = tail call i32 (...) @sw_beep_off()
%16 = tail call i32 @sw_usleep(i32 50000)
br label %17
17: ; preds = %0, %17
%18 = call i32 @sw_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @sw_getn(i8* %2, i32 128)
%20 = call i32 @cmd_run(i8* %2)
br label %17
}