#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*/ assertion_failure(char *, char *, char *, int);
int fork();
int getpid();
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ spin(char *);
void Init() {
  int fd_stdin = open("/dev_tty0", 2);
  if (fd_stdin == 0)
    ;
  else
    assertion_failure("fd_stdin == 0",
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/liangbizhi/bzOS/refs/"
                      "heads/master/kernel/main.c",
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/liangbizhi/bzOS/refs/"
                      "heads/master/kernel/main.c",
                      143);
  ;
  int fd_stdout = open("/dev_tty0", 2);
  if (fd_stdout == 1)
    ;
  else
    assertion_failure("fd_stdout == 1",
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/liangbizhi/bzOS/refs/"
                      "heads/master/kernel/main.c",
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/liangbizhi/bzOS/refs/"
                      "heads/master/kernel/main.c",
                      145);
  ;
  printf("Init() is running...\n");
  int pid = fork();
  if (pid != 0) {
    printf("parent is running, child pid: %d\n", pid);
    spin("parent");
  } else {
    printf("child is running, pid: %d\n", getpid());
    spin("child");
  }
}


x86 assembly (clang, -O0):
<Init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
mov    $0x2,%esi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    118b <Init+0x2b>
jmp    11a6 <Init+0x46>
lea    0xe78(%rip),%rdi
lea    0xe7f(%rip),%rdx
mov    $0x8f,%ecx
mov    %rdx,%rsi
call   1050 <assertion_failure@plt>
lea    0xe53(%rip),%rdi
mov    $0x2,%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c9 <Init+0x69>
jmp    11e4 <Init+0x84>
lea    0xed2(%rip),%rdi
lea    0xe41(%rip),%rdx
mov    $0x91,%ecx
mov    %rdx,%rsi
call   1050 <assertion_failure@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1228 <Init+0xc8>
mov    -0xc(%rbp),%esi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
call   1070 <spin@plt>
jmp    124b <Init+0xeb>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
call   1070 <spin@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Init>:
push   %rax
lea    0xe88(%rip),%rdi
mov    $0x2,%esi
call   1070 <open@plt>
test   %eax,%eax
je     11a1 <Init+0x31>
lea    0xe7d(%rip),%rdi
lea    0xe84(%rip),%rdx
mov    %rdx,%rsi
mov    $0x8f,%ecx
call   1060 <assertion_failure@plt>
lea    0xe58(%rip),%rdi
mov    $0x2,%esi
call   1070 <open@plt>
cmp    $0x1,%eax
je     11d2 <Init+0x62>
lea    0xee4(%rip),%rdi
lea    0xe53(%rip),%rdx
mov    %rdx,%rsi
mov    $0x91,%ecx
call   1060 <assertion_failure@plt>
lea    0xf22(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1206 <Init+0x96>
lea    0xec1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed3(%rip),%rdi
pop    %rax
jmp    1080 <spin@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xec6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed1(%rip),%rdi
pop    %rax
jmp    1080 <spin@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev_tty0\00"
@.str.1 = [14 x i8] c"fd_stdin == 0\00"
@.str.2 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/liangbizhi/bzOS/refs/heads/master/kernel/main.c\00"
@.str.3 = [15 x i8] c"fd_stdout == 1\00"
@.str.4 = [22 x i8] c"Init() is running...\0A\00"
@.str.5 = [34 x i8] c"parent is running, child pid: %d\0A\00"
@.str.6 = [7 x i8] c"parent\00"
@.str.7 = [27 x i8] c"child is running, pid: %d\0A\00"
@.str.8 = [6 x i8] c"child\00"
define void @Init() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
br label %10
8: ; preds = %0
%9 = call i32 @assertion_failure(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 143)
br label %10
10: ; preds = %8, %7
%11 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %10
br label %17
15: ; preds = %10
%16 = call i32 @assertion_failure(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 145)
br label %17
17: ; preds = %15, %14
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 (...) @fork()
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = call i32 @spin(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %30
26: ; preds = %17
%27 = call i32 (...) @getpid()
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%29 = call i32 @spin(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %30
30: ; preds = %26, %22
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev_tty0\00"
@.str.1 = [14 x i8] c"fd_stdin == 0\00"
@.str.2 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/liangbizhi/bzOS/refs/heads/master/kernel/main.c\00"
@.str.3 = [15 x i8] c"fd_stdout == 1\00"
@.str.5 = [34 x i8] c"parent is running, child pid: %d\0A\00"
@.str.6 = [7 x i8] c"parent\00"
@.str.7 = [27 x i8] c"child is running, pid: %d\0A\00"
@.str.8 = [6 x i8] c"child\00"
@str = [21 x i8] c"Init() is running...\00"
define void @Init() {
%1 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 2)
%2 = icmp eq i32 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @assertion_failure(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 143)
br label %5
5: ; preds = %0, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 2)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @assertion_failure(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 145)
br label %10
10: ; preds = %5, %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 (...) @fork()
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %12)
br label %19
16: ; preds = %10
%17 = tail call i32 (...) @getpid()
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %14
%20 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), %16 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), %14 ]
%21 = tail call i32 @spin(i8* %20)
ret void
}