#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*/ clear_screen();
int /*<<< orphan*/ fb_init();
int /*<<< orphan*/ fb_write_text(char *, int);
int /*<<< orphan*/ serial_init();
int /*<<< orphan*/ serial_write_text(int, char *, int);
void kmain() {
  serial_init();
  fb_init();
  clear_screen();
  serial_write_text(0x3F8, "Booted.\n", 8);
  int i;
  for (i = 0; i < 300; ++i) {
    fb_write_text(
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62);
  }
  serial_write_text(0x3F8, "Shutting down.\n", 14);
  return;
}


x86 assembly (clang, -O0):
<kmain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <serial_init@plt>
mov    $0x0,%al
call   1040 <fb_init@plt>
mov    $0x0,%al
call   1050 <clear_screen@plt>
mov    $0x3f8,%edi
lea    0xe87(%rip),%rsi
mov    $0x8,%edx
call   1030 <serial_write_text@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x12c,-0x4(%rbp)
jge    11b6 <kmain+0x66>
lea    0xe6b(%rip),%rdi
mov    $0x3e,%esi
call   1060 <fb_write_text@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    118a <kmain+0x3a>
mov    $0x3f8,%edi
lea    0xe86(%rip),%rsi
mov    $0xe,%edx
call   1030 <serial_write_text@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kmain>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <serial_init@plt>
xor    %eax,%eax
call   1040 <fb_init@plt>
xor    %eax,%eax
call   1050 <clear_screen@plt>
lea    0xe91(%rip),%rsi
mov    $0x3f8,%edi
mov    $0x8,%edx
call   1030 <serial_write_text@plt>
mov    $0x12c,%ebp
lea    0xe7f(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x3e,%esi
call   1060 <fb_write_text@plt>
add    $0xffffffff,%ebp
jne    1190 <kmain+0x40>
lea    0xe9f(%rip),%rsi
mov    $0x3f8,%edi
mov    $0xe,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <serial_write_text@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Booted.\0A\00"
@.str.1 = [63 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\00"
@.str.2 = [16 x i8] c"Shutting down.\0A\00"
define void @kmain() {
%1 = alloca i32
%2 = call i32 (...) @serial_init()
%3 = call i32 (...) @fb_init()
%4 = call i32 (...) @clear_screen()
%5 = call i32 @serial_write_text(i32 1016, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
store i32 0, i32* %1
br label %6
6: ; preds = %11, %0
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 300
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = call i32 @fb_write_text(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i32 62)
br label %11
11: ; preds = %9
%12 = load i32, i32* %1
%13 = add nsw i32 %12, 1
store i32 %13, i32* %1
br label %6
14: ; preds = %6
%15 = call i32 @serial_write_text(i32 1016, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 14)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"Booted.\0A\00"
@.str.1 = [63 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\00"
@.str.2 = [16 x i8] c"Shutting down.\0A\00"
define void @kmain() {
%1 = tail call i32 (...) @serial_init()
%2 = tail call i32 (...) @fb_init()
%3 = tail call i32 (...) @clear_screen()
%4 = tail call i32 @serial_write_text(i32 1016, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %8, %5 ]
%7 = tail call i32 @fb_write_text(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i32 62)
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i32 %8, 300
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = tail call i32 @serial_write_text(i32 1016, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 14)
ret void
}