#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ ok_init_write(int);
int /*<<< orphan*/ ok_led_init();
int /*<<< orphan*/ uart_getc();
int /*<<< orphan*/ uart_init();
int /*<<< orphan*/ uart_putc(int /*<<< orphan*/);
int /*<<< orphan*/ uart_puts(char *);
void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags) {
  (void)r0;
  (void)r1;
  (void)atags;
  ok_led_init();
  uart_init();
  uint8_t data;
  data = 0;
  ok_init_write(data);
  uart_puts("Hello, kernel World!\r\n");
  while (true) {
    data = !data;
    ok_init_write(data);
    uart_putc(uart_getc());
  }
}


x86 assembly (clang, -O0):
<kernel_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1050 <ok_led_init@plt>
mov    $0x0,%al
call   1040 <uart_init@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <ok_init_write@plt>
lea    0xe6b(%rip),%rdi
call   1080 <uart_puts@plt>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x12(%rbp)
and    $0x1,%al
mov    %al,-0x11(%rbp)
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <ok_init_write@plt>
mov    $0x0,%al
call   1060 <uart_getc@plt>
mov    %eax,%edi
call   1030 <uart_putc@plt>
jmp    119a <kernel_main+0x3a>

x86 assembly (clang, -O2):
<kernel_main>:
push   %rbx
xor    %eax,%eax
call   1050 <ok_led_init@plt>
xor    %eax,%eax
call   1040 <uart_init@plt>
xor    %edi,%edi
call   1070 <ok_init_write@plt>
lea    0xe83(%rip),%rdi
call   1080 <uart_puts@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    $0x1,%ebx
mov    %ebx,%edi
call   1070 <ok_init_write@plt>
xor    %eax,%eax
call   1060 <uart_getc@plt>
mov    %eax,%edi
call   1030 <uart_putc@plt>
jmp    1190 <kernel_main+0x30>

LLVM IR (-O0):
@.str = [23 x i8] c"Hello, kernel World!\0D\0A\00"
define void @kernel_main(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 (...) @ok_led_init()
%12 = call i32 (...) @uart_init()
store i32 0, i32* %7
%13 = load i32, i32* %7
%14 = call i32 @ok_init_write(i32 %13)
%15 = call i32 @uart_puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %3, %16
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
%20 = zext i1 %19 to i32
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = call i32 @ok_init_write(i32 %21)
%23 = call i32 (...) @uart_getc()
%24 = call i32 @uart_putc(i32 %23)
br label %16
}

LLVM IR (-O2):
@.str = [23 x i8] c"Hello, kernel World!\0D\0A\00"
define void @kernel_main(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 (...) @ok_led_init()
%5 = tail call i32 (...) @uart_init()
%6 = tail call i32 @ok_init_write(i32 0)
%7 = tail call i32 @uart_puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %8, %3
%9 = phi i32 [ 0, %3 ], [ %10, %8 ]
%10 = xor i32 %9, 1
%11 = tail call i32 @ok_init_write(i32 %10)
%12 = tail call i32 (...) @uart_getc()
%13 = tail call i32 @uart_putc(i32 %12)
br label %8
}