void kernel_main() {
  arch_init();
  board_init();
  __libc_init_array();
  kputs("Plaid kernel startup\r\n");
  char *str;
  str = (char *)malloc(15);
  if (str == 0) {
    printf("no memory!\r\n");
  } else {
    strcpy(str, "malloc");
    printf("dynamic alloc str = %s, Address = %02x\r\n", str, str);
  }
  const char *p = "world";
  printf("static alloc str = %s, Address = %02x\r\n", p, p);
  for (;;) {
  }
}


x86 assembly (clang, -O0):
<kernel_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <arch_init@plt>
mov    $0x0,%al
call   1090 <board_init@plt>
mov    $0x0,%al
call   1040 <__libc_init_array@plt>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1080 <kputs@plt>
mov    $0xf,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c7 <kernel_main+0x57>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11ed <kernel_main+0x7d>
mov    -0x8(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe60(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    120e <kernel_main+0x9e>

x86 assembly (clang, -O2):
<kernel_main>:
push   %rax
xor    %eax,%eax
call   1050 <arch_init@plt>
xor    %eax,%eax
call   1090 <board_init@plt>
xor    %eax,%eax
call   1040 <__libc_init_array@plt>
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1080 <kputs@plt>
mov    $0xf,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11c6 <kernel_main+0x56>
movl   $0x636f6c,0x3(%rax)
movl   $0x6c6c616d,(%rax)
lea    0xe67(%rip),%rdi
mov    %rax,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11d2 <kernel_main+0x62>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe74(%rip),%rdi
lea    0xe67(%rip),%rdx
mov    %rdx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
nopw   0x0(%rax,%rax,1)
jmp    11f0 <kernel_main+0x80>

LLVM IR (-O0):
@.str = [23 x i8] c"Plaid kernel startup\0D\0A\00"
@.str.1 = [13 x i8] c"no memory!\0D\0A\00"
@.str.2 = [7 x i8] c"malloc\00"
@.str.3 = [41 x i8] c"dynamic alloc str = %s, Address = %02x\0D\0A\00"
@.str.4 = [6 x i8] c"world\00"
@.str.5 = [40 x i8] c"static alloc str = %s, Address = %02x\0D\0A\00"
define void @kernel_main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i32 (...) @arch_init()
%4 = call i32 (...) @board_init()
%5 = call i32 (...) @__libc_init_array()
%6 = call i32 (i8*, ...) bitcast (i32 (...)* @kputs to i32 (i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = call i8* @malloc(i64 15)
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %18
12: ; preds = %0
%13 = load i8*, i8** %1
%14 = call i8* @strcpy(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %1
%16 = load i8*, i8** %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %16)
br label %18
18: ; preds = %12, %10
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %2
%19 = load i8*, i8** %2
%20 = load i8*, i8** %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %19, i8* %20)
br label %22
22: ; preds = %22, %18
br label %22
}

LLVM IR (-O2):
@.str = [23 x i8] c"Plaid kernel startup\0D\0A\00"
@.str.2 = [7 x i8] c"malloc\00"
@.str.3 = [41 x i8] c"dynamic alloc str = %s, Address = %02x\0D\0A\00"
@.str.4 = [6 x i8] c"world\00"
@.str.5 = [40 x i8] c"static alloc str = %s, Address = %02x\0D\0A\00"
@str = [12 x i8] c"no memory!\0D\00"
define void @kernel_main() {
%1 = tail call i32 (...) @arch_init()
%2 = tail call i32 (...) @board_init()
%3 = tail call i32 (...) @__libc_init_array()
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @kputs to i32 (i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%5 = tail call dereferenceable_or_null(15) i8* @malloc(i64 15)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %11
9: ; preds = %0
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(7) %5, i8* align 1 dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 7, i1 false)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %5)
br label %11
11: ; preds = %9, %7
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %13, %11
br label %13
}