#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*/ detect_cpu();
int /*<<< orphan*/ detect_pci();
int /*<<< orphan*/ init_term();
int /*<<< orphan*/ printk(char *);
void kernel_main(unsigned long magic) {
  init_term();
  printk("Booting Iron kernel\n");
  if (magic != 0x2BADB002) {
    printk("Iron not booted with Multiboot\n");
    return;
  }
  if (!detect_cpu()) {
    return;
  }
  printk("Detecting PCI cards\n");
  detect_pci();
}


x86 assembly (clang, -O0):
<kernel_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <init_term@plt>
lea    0xea6(%rip),%rdi
call   1030 <printk@plt>
cmpq   $0x2badb002,-0x8(%rbp)
2b
je     117e <kernel_main+0x3e>
lea    0xea1(%rip),%rdi
call   1030 <printk@plt>
jmp    11a6 <kernel_main+0x66>
mov    $0x0,%al
call   1050 <detect_cpu@plt>
cmp    $0x0,%eax
jne    1193 <kernel_main+0x53>
jmp    11a6 <kernel_main+0x66>
lea    0xe9b(%rip),%rdi
call   1030 <printk@plt>
mov    $0x0,%al
call   1040 <detect_pci@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_main>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <init_term@plt>
lea    0xeae(%rip),%rdi
call   1030 <printk@plt>
cmp    $0x2badb002,%rbx
jne    117f <kernel_main+0x3f>
xor    %eax,%eax
call   1050 <detect_cpu@plt>
test   %eax,%eax
je     118c <kernel_main+0x4c>
lea    0xec3(%rip),%rdi
call   1030 <printk@plt>
xor    %eax,%eax
pop    %rbx
jmp    1040 <detect_pci@plt>
lea    0xe8f(%rip),%rdi
pop    %rbx
jmp    1030 <printk@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Booting Iron kernel\0A\00"
@.str.1 = [32 x i8] c"Iron not booted with Multiboot\0A\00"
@.str.2 = [21 x i8] c"Detecting PCI cards\0A\00"
define void @kernel_main(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = call i32 (...) @init_term()
%4 = call i32 @printk(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = load i64, i64* %2
%6 = icmp ne i64 %5, 732803074
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @printk(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %16
9: ; preds = %1
%10 = call i32 (...) @detect_cpu()
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %9
br label %16
13: ; preds = %9
%14 = call i32 @printk(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (...) @detect_pci()
br label %16
16: ; preds = %13, %12, %7
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Booting Iron kernel\0A\00"
@.str.1 = [32 x i8] c"Iron not booted with Multiboot\0A\00"
@.str.2 = [21 x i8] c"Detecting PCI cards\0A\00"
define void @kernel_main(i64 %0) {
%2 = tail call i32 (...) @init_term()
%3 = tail call i32 @printk(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %0, 732803074
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @printk(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %13
7: ; preds = %1
%8 = tail call i32 (...) @detect_cpu()
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @printk(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 (...) @detect_pci()
br label %13
13: ; preds = %7, %10, %5
ret void
}