#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 */
struct multiboot {
  int dummy;
};

/* Variables and functions */
scalar_t__ gdt_init();
int /*<<< orphan*/ heap_init();
scalar_t__ idt_init();
int /*<<< orphan*/ kprintf(char *);
int /*<<< orphan*/ kputs(char *);
scalar_t__ pic_init();
scalar_t__ pmm_init(struct multiboot *);
scalar_t__ sched_init();
int /*<<< orphan*/ vmm_init();
void setup_system(struct multiboot *mb) {
  kprintf("Init "
          "GDT"
          "... ");
  if (gdt_init())
    kputs("["
          "\x1B[32m"
          "OK"
          "\x1B[0m"
          "]");
  else
    kputs("["
          "\x1B[31m"
          "FAIL"
          "\x1B[0m"
          "]");
  ;
  kprintf("Init "
          "IDT"
          "... ");
  if (idt_init())
    kputs("["
          "\x1B[32m"
          "OK"
          "\x1B[0m"
          "]");
  else
    kputs("["
          "\x1B[31m"
          "FAIL"
          "\x1B[0m"
          "]");
  ;
  kprintf("Init "
          "PIC"
          "... ");
  if (pic_init())
    kputs("["
          "\x1B[32m"
          "OK"
          "\x1B[0m"
          "]");
  else
    kputs("["
          "\x1B[31m"
          "FAIL"
          "\x1B[0m"
          "]");
  ;
  kprintf("Init "
          "PMM"
          "... ");
  if (pmm_init(mb))
    kputs("["
          "\x1B[32m"
          "OK"
          "\x1B[0m"
          "]");
  else
    kputs("["
          "\x1B[31m"
          "FAIL"
          "\x1B[0m"
          "]");
  ;
  heap_init();
  vmm_init();
  kprintf("Init "
          "Scheduler"
          "... ");
  if (sched_init())
    kputs("["
          "\x1B[32m"
          "OK"
          "\x1B[0m"
          "]");
  else
    kputs("["
          "\x1B[31m"
          "FAIL"
          "\x1B[0m"
          "]");
  ;
}


x86 assembly (clang, -O0):
<setup_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5d(%rip),%rdi
call   1090 <kprintf@plt>
mov    $0x0,%al
call   1080 <gdt_init@plt>
cmp    $0x0,%rax
je     11ca <setup_system+0x3a>
lea    0xe4d(%rip),%rdi
call   1070 <kputs@plt>
jmp    11d6 <setup_system+0x46>
lea    0xe4a(%rip),%rdi
call   1070 <kputs@plt>
lea    0xe4e(%rip),%rdi
call   1090 <kprintf@plt>
mov    $0x0,%al
call   1060 <idt_init@plt>
cmp    $0x0,%rax
je     1204 <setup_system+0x74>
lea    0xe13(%rip),%rdi
call   1070 <kputs@plt>
jmp    1210 <setup_system+0x80>
lea    0xe10(%rip),%rdi
call   1070 <kputs@plt>
lea    0xe21(%rip),%rdi
call   1090 <kprintf@plt>
mov    $0x0,%al
call   1040 <pic_init@plt>
cmp    $0x0,%rax
je     123e <setup_system+0xae>
lea    0xdd9(%rip),%rdi
call   1070 <kputs@plt>
jmp    124a <setup_system+0xba>
lea    0xdd6(%rip),%rdi
call   1070 <kputs@plt>
lea    0xdf4(%rip),%rdi
call   1090 <kprintf@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <pmm_init@plt>
cmp    $0x0,%rax
je     127a <setup_system+0xea>
lea    0xd9d(%rip),%rdi
call   1070 <kputs@plt>
jmp    1286 <setup_system+0xf6>
lea    0xd9a(%rip),%rdi
call   1070 <kputs@plt>
mov    $0x0,%al
call   10a0 <heap_init@plt>
mov    $0x0,%al
call   1050 <vmm_init@plt>
lea    0xdb7(%rip),%rdi
call   1090 <kprintf@plt>
mov    $0x0,%al
call   1030 <sched_init@plt>
cmp    $0x0,%rax
je     12c2 <setup_system+0x132>
lea    0xd55(%rip),%rdi
call   1070 <kputs@plt>
jmp    12ce <setup_system+0x13e>
lea    0xd52(%rip),%rdi
call   1070 <kputs@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_system>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe61(%rip),%rdi
call   1090 <kprintf@plt>
xor    %eax,%eax
call   1080 <gdt_init@plt>
test   %rax,%rax
lea    0xe66(%rip),%r15
lea    0xe51(%rip),%rbx
mov    %rbx,%rdi
cmove  %r15,%rdi
call   1070 <kputs@plt>
lea    0xe5c(%rip),%rdi
call   1090 <kprintf@plt>
xor    %eax,%eax
call   1060 <idt_init@plt>
test   %rax,%rax
mov    %rbx,%rdi
cmove  %r15,%rdi
call   1070 <kputs@plt>
lea    0xe47(%rip),%rdi
call   1090 <kprintf@plt>
xor    %eax,%eax
call   1040 <pic_init@plt>
test   %rax,%rax
mov    %rbx,%rdi
cmove  %r15,%rdi
call   1070 <kputs@plt>
lea    0xe32(%rip),%rdi
call   1090 <kprintf@plt>
mov    %r14,%rdi
call   10b0 <pmm_init@plt>
test   %rax,%rax
mov    %rbx,%rdi
cmove  %r15,%rdi
call   1070 <kputs@plt>
xor    %eax,%eax
call   10a0 <heap_init@plt>
xor    %eax,%eax
call   1050 <vmm_init@plt>
lea    0xe0e(%rip),%rdi
call   1090 <kprintf@plt>
xor    %eax,%eax
call   1030 <sched_init@plt>
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <kputs@plt>

LLVM IR (-O0):
%struct.multiboot = type { i32 }
@.str = [13 x i8] c"Init GDT... \00"
@.str.1 = [14 x i8] c"[\1B[32mOK\1B[0m]\00"
@.str.2 = [16 x i8] c"[\1B[31mFAIL\1B[0m]\00"
@.str.3 = [13 x i8] c"Init IDT... \00"
@.str.4 = [13 x i8] c"Init PIC... \00"
@.str.5 = [13 x i8] c"Init PMM... \00"
@.str.6 = [19 x i8] c"Init Scheduler... \00"
define void @setup_system(%struct.multiboot* %0) {
%2 = alloca %struct.multiboot*
store %struct.multiboot* %0, %struct.multiboot** %2
%3 = call i32 @kprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = call i64 (...) @gdt_init()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @kputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %10
8: ; preds = %1
%9 = call i32 @kputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = call i32 @kprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%12 = call i64 (...) @idt_init()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @kputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %18
16: ; preds = %10
%17 = call i32 @kputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = call i32 @kprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%20 = call i64 (...) @pic_init()
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @kputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %26
24: ; preds = %18
%25 = call i32 @kputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
%27 = call i32 @kprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%28 = load %struct.multiboot*, %struct.multiboot** %2
%29 = call i64 @pmm_init(%struct.multiboot* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @kputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %35
33: ; preds = %26
%34 = call i32 @kputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %31
%36 = call i32 (...) @heap_init()
%37 = call i32 (...) @vmm_init()
%38 = call i32 @kprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%39 = call i64 (...) @sched_init()
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @kputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %45
43: ; preds = %35
%44 = call i32 @kputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %41
ret void
}

LLVM IR (-O2):
%struct.multiboot = type { i32 }
@.str = [13 x i8] c"Init GDT... \00"
@.str.1 = [14 x i8] c"[\1B[32mOK\1B[0m]\00"
@.str.2 = [16 x i8] c"[\1B[31mFAIL\1B[0m]\00"
@.str.3 = [13 x i8] c"Init IDT... \00"
@.str.4 = [13 x i8] c"Init PIC... \00"
@.str.5 = [13 x i8] c"Init PMM... \00"
@.str.6 = [19 x i8] c"Init Scheduler... \00"
define void @setup_system(%struct.multiboot* %0) {
%2 = tail call i32 @kprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 (...) @gdt_init()
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%6 = tail call i32 @kputs(i8* %5)
%7 = tail call i32 @kprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i64 (...) @idt_init()
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%11 = tail call i32 @kputs(i8* %10)
%12 = tail call i32 @kprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i64 (...) @pic_init()
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%16 = tail call i32 @kputs(i8* %15)
%17 = tail call i32 @kprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%18 = tail call i64 @pmm_init(%struct.multiboot* %0)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%21 = tail call i32 @kputs(i8* %20)
%22 = tail call i32 (...) @heap_init()
%23 = tail call i32 (...) @vmm_init()
%24 = tail call i32 @kprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%25 = tail call i64 (...) @sched_init()
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%28 = tail call i32 @kputs(i8* %27)
ret void
}