#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 open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ shell();
void main() {
  printf("Michiru Operating System\n");
  printf("Based on Riku kernel\n");
  printf("---\n");
  printf("Successfully entered userland.\n");
  printf("ANSI test : \n");
  printf("\tBlack: \033[30;40mBLACK\033[0m\n");
  printf("\tRed: \033[31;40mRED\033[0m\n");
  printf("\tGreen: \033[32;40mGREEN\033[0m\n");
  printf("\tYellow: \033[33;40mYELLOW\033[0m\n");
  printf("\tBlue: \033[34;40mBLUE\033[0m\n");
  printf("\tMagenta: \033[35;40mMAGENTA\033[0m\n");
  printf("\tCyan: \033[36;40mCYAN\033[0m\n");
  printf("\tWhite: \033[37;40mWHITE\033[0m\n");
  printf("Done. If we're alive until now, then everything is fine ~\n");
  printf("opening file...\n");
  int f = open("B:/motd", 0x0);
  printf("f=%d\n", f);
  char buffer[512];
  read(f, buffer, 512);
  printf("%s", buffer);
  printf("\nBoot banner:\n");
  int f2 = open("B:/banner", 0x0);
  read(f2, buffer, 512);
  printf("%s", buffer);
  shell();
  for (;;)
    ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf61(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xf55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read@plt>
lea    -0x210(%rbp),%rsi
lea    0xf32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf28(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x214(%rbp)
mov    -0x214(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read@plt>
lea    -0x210(%rbp),%rsi
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <shell@plt>
jmp    12bd <main+0x17d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
lea    0xef5(%rip),%rdi
call   1030 <puts@plt>
lea    0xf03(%rip),%rdi
call   1030 <puts@plt>
lea    0xf13(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1f(%rip),%rdi
call   1030 <puts@plt>
lea    0xf31(%rip),%rdi
call   1030 <puts@plt>
lea    0xf3d(%rip),%rdi
call   1030 <puts@plt>
lea    0xf4b(%rip),%rdi
call   1030 <puts@plt>
lea    0xf79(%rip),%rdi
call   1030 <puts@plt>
lea    0xdec(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xde4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1050 <read@plt>
lea    0xdc8(%rip),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf37(%rip),%rdi
call   1030 <puts@plt>
lea    0xdab(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <shell@plt>
jmp    1290 <main+0x140>

LLVM IR (-O0):
@.str = [26 x i8] c"Michiru Operating System\0A\00"
@.str.1 = [22 x i8] c"Based on Riku kernel\0A\00"
@.str.2 = [5 x i8] c"---\0A\00"
@.str.3 = [32 x i8] c"Successfully entered userland.\0A\00"
@.str.4 = [14 x i8] c"ANSI test : \0A\00"
@.str.5 = [27 x i8] c"\09Black: \1B[30;40mBLACK\1B[0m\0A\00"
@.str.6 = [23 x i8] c"\09Red: \1B[31;40mRED\1B[0m\0A\00"
@.str.7 = [27 x i8] c"\09Green: \1B[32;40mGREEN\1B[0m\0A\00"
@.str.8 = [29 x i8] c"\09Yellow: \1B[33;40mYELLOW\1B[0m\0A\00"
@.str.9 = [25 x i8] c"\09Blue: \1B[34;40mBLUE\1B[0m\0A\00"
@.str.10 = [31 x i8] c"\09Magenta: \1B[35;40mMAGENTA\1B[0m\0A\00"
@.str.11 = [25 x i8] c"\09Cyan: \1B[36;40mCYAN\1B[0m\0A\00"
@.str.12 = [27 x i8] c"\09White: \1B[37;40mWHITE\1B[0m\0A\00"
@.str.13 = [59 x i8] c"Done. If we're alive until now, then everything is fine ~\0A\00"
@.str.14 = [17 x i8] c"opening file...\0A\00"
@.str.15 = [8 x i8] c"B:/motd\00"
@.str.16 = [6 x i8] c"f=%d\0A\00"
@.str.17 = [3 x i8] c"%s\00"
@.str.18 = [15 x i8] c"\0ABoot banner:\0A\00"
@.str.19 = [10 x i8] c"B:/banner\00"
define void @main() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.13, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0))
%19 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0), i32 0)
store i32 %19, i32* %1
%20 = load i32, i32* %1
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %1
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%24 = call i32 @read(i32 %22, i8* %23, i32 512)
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.18, i64 0, i64 0))
%28 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0), i32 0)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 512)
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i8* %32)
%34 = call i32 (...) @shell()
br label %35
35: ; preds = %35, %0
br label %35
}

LLVM IR (-O2):
@.str.15 = [8 x i8] c"B:/motd\00"
@.str.16 = [6 x i8] c"f=%d\0A\00"
@.str.17 = [3 x i8] c"%s\00"
@.str.19 = [10 x i8] c"B:/banner\00"
@str = [25 x i8] c"Michiru Operating System\00"
@str.20 = [21 x i8] c"Based on Riku kernel\00"
@str.21 = [4 x i8] c"---\00"
@str.22 = [31 x i8] c"Successfully entered userland.\00"
@str.23 = [13 x i8] c"ANSI test : \00"
@str.24 = [26 x i8] c"\09Black: \1B[30;40mBLACK\1B[0m\00"
@str.25 = [22 x i8] c"\09Red: \1B[31;40mRED\1B[0m\00"
@str.26 = [26 x i8] c"\09Green: \1B[32;40mGREEN\1B[0m\00"
@str.27 = [28 x i8] c"\09Yellow: \1B[33;40mYELLOW\1B[0m\00"
@str.28 = [24 x i8] c"\09Blue: \1B[34;40mBLUE\1B[0m\00"
@str.29 = [30 x i8] c"\09Magenta: \1B[35;40mMAGENTA\1B[0m\00"
@str.30 = [24 x i8] c"\09Cyan: \1B[36;40mCYAN\1B[0m\00"
@str.31 = [26 x i8] c"\09White: \1B[37;40mWHITE\1B[0m\00"
@str.32 = [58 x i8] c"Done. If we're alive until now, then everything is fine ~\00"
@str.33 = [16 x i8] c"opening file...\00"
@str.34 = [14 x i8] c"\0ABoot banner:\00"
define void @main() {
%1 = alloca [512 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.20, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.21, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.22, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.23, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.24, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.25, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.26, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.27, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.28, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.29, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.30, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.31, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.32, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.33, i64 0, i64 0))
%17 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0), i32 0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%20 = call i32 @read(i32 %17, i8* %19, i32 512)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i8* %19)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.34, i64 0, i64 0))
%23 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0), i32 0)
%24 = call i32 @read(i32 %23, i8* %19, i32 512)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.17, i64 0, i64 0), i8* %19)
%26 = call i32 (...) @shell()
br label %27
27: ; preds = %27, %0
br label %27
}