#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(int);
int /*<<< orphan*/ initialize_idt();
char *itos(int);
int /*<<< orphan*/ kill();
int /*<<< orphan*/ makeAttr(int, int);
int print(char *, int, int /*<<< orphan*/);
void main() {
  initialize_idt();
  clear(5);
  int offset = print("Hello from the C kernel!", 0, makeAttr(3, 4));
  offset = print("Some more text, but using fancy offsets so the first text "
                 "isn't written over!",
                 offset, makeAttr(10, 1));
  offset =
      print("Some more text\nbut with\nline\nbreaks!", offset, makeAttr(4, 1));
  offset = print("key press:", offset, makeAttr(15, 0));
  offset = print(itos(12345678), offset, makeAttr(15, 0));
  kill();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <initialize_idt@plt>
mov    $0x5,%edi
call   1070 <clear@plt>
mov    $0x3,%edi
mov    $0x4,%esi
call   1040 <makeAttr@plt>
mov    %eax,%edx
lea    0xe6f(%rip),%rdi
xor    %esi,%esi
call   1050 <print@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xa,%edi
mov    $0x1,%esi
call   1040 <makeAttr@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe5d(%rip),%rdi
call   1050 <print@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x4,%edi
mov    $0x1,%esi
call   1040 <makeAttr@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
lea    0xe82(%rip),%rdi
call   1050 <print@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0xf,%edi
xor    %esi,%esi
call   1040 <makeAttr@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe81(%rip),%rdi
call   1050 <print@plt>
mov    %eax,-0x4(%rbp)
mov    $0xbc614e,%edi
call   1080 <itos@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0xf,%edi
xor    %esi,%esi
call   1040 <makeAttr@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    %eax,%edx
call   1050 <print@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1060 <kill@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <initialize_idt@plt>
mov    $0x5,%edi
call   1070 <clear@plt>
mov    $0x3,%edi
mov    $0x4,%esi
call   1040 <makeAttr@plt>
lea    0xe76(%rip),%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <print@plt>
mov    %eax,%ebx
mov    $0xa,%edi
mov    $0x1,%esi
call   1040 <makeAttr@plt>
lea    0xe6e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <print@plt>
mov    %eax,%ebx
mov    $0x4,%edi
mov    $0x1,%esi
call   1040 <makeAttr@plt>
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <print@plt>
mov    %eax,%ebx
mov    $0xf,%edi
xor    %esi,%esi
call   1040 <makeAttr@plt>
lea    0xea2(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <print@plt>
mov    %eax,%ebp
mov    $0xbc614e,%edi
call   1080 <itos@plt>
mov    %rax,%rbx
mov    $0xf,%edi
xor    %esi,%esi
call   1040 <makeAttr@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <print@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <kill@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Hello from the C kernel!\00"
@.str.1 = [78 x i8] c"Some more text, but using fancy offsets so the first text isn't written over!\00"
@.str.2 = [37 x i8] c"Some more text\0Abut with\0Aline\0Abreaks!\00"
@.str.3 = [11 x i8] c"key press:\00"
define void @main() {
%1 = alloca i32
%2 = call i32 (...) @initialize_idt()
%3 = call i32 @clear(i32 5)
%4 = call i32 @makeAttr(i32 3, i32 4)
%5 = call i32 @print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = call i32 @makeAttr(i32 10, i32 1)
%8 = call i32 @print(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %7)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = call i32 @makeAttr(i32 4, i32 1)
%11 = call i32 @print(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %10)
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = call i32 @makeAttr(i32 15, i32 0)
%14 = call i32 @print(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %13)
store i32 %14, i32* %1
%15 = call i8* @itos(i32 12345678)
%16 = load i32, i32* %1
%17 = call i32 @makeAttr(i32 15, i32 0)
%18 = call i32 @print(i8* %15, i32 %16, i32 %17)
store i32 %18, i32* %1
%19 = call i32 (...) @kill()
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Hello from the C kernel!\00"
@.str.1 = [78 x i8] c"Some more text, but using fancy offsets so the first text isn't written over!\00"
@.str.2 = [37 x i8] c"Some more text\0Abut with\0Aline\0Abreaks!\00"
@.str.3 = [11 x i8] c"key press:\00"
define void @main() {
%1 = tail call i32 (...) @initialize_idt()
%2 = tail call i32 @clear(i32 5)
%3 = tail call i32 @makeAttr(i32 3, i32 4)
%4 = tail call i32 @print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 0, i32 %3)
%5 = tail call i32 @makeAttr(i32 10, i32 1)
%6 = tail call i32 @print(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %5)
%7 = tail call i32 @makeAttr(i32 4, i32 1)
%8 = tail call i32 @print(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %7)
%9 = tail call i32 @makeAttr(i32 15, i32 0)
%10 = tail call i32 @print(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %8, i32 %9)
%11 = tail call i8* @itos(i32 12345678)
%12 = tail call i32 @makeAttr(i32 15, i32 0)
%13 = tail call i32 @print(i8* %11, i32 %10, i32 %12)
%14 = tail call i32 (...) @kill()
ret void
}