#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ fork();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int main(int argc, char *argv[], char *envp[]) {
  int error = 1, status;
  pid_t childPID;
  printf("%d. Parent\n", error);
  *((char *)0xffffffff80000000 + 0xb8000) = 65;
  *((char *)0xffffffff80000000 + 0xb8000 + 0x1) = 0x07;
  if ((childPID = fork()) == 0) {
    printf("%d. Infinite child\n", error);
    sleep(111);
  } else {
    waitpid(childPID, &status, 0);
  }
  printf("%d. Parent Infinite\n", error);
  while (1)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff80000000,%rax
movb   $0x41,0xb8000(%rax)
mov    $0xffffffff80000000,%rax
movb   $0x7,0xb8001(%rax)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    11bd <main+0x7d>
mov    -0x1c(%rbp),%esi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
mov    $0x6f,%edi
call   1050 <sleep@plt>
jmp    11cb <main+0x8b>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    -0x1c(%rbp),%esi
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    11da <main+0x9a>

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
movb   $0x41,0xffffffff800b8000
41
movb   $0x7,0xffffffff800b8001
07
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     117d <main+0x3d>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1040 <waitpid@plt>
jmp    1198 <main+0x58>
lea    0xe88(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    $0x6f,%edi
call   1050 <sleep@plt>
lea    0xe81(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
nopl   0x0(%rax)
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [12 x i8] c"%d. Parent\0A\00"
@.str.1 = [20 x i8] c"%d. Infinite child\0A\00"
@.str.2 = [21 x i8] c"%d. Parent Infinite\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 1, i32* %8
%11 = load i32, i32* %8
%12 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
store i8 65, i8* getelementptr inbounds (i8, i8* inttoptr (i64 -2147483648 to i8*), i64 753664)
store i8 7, i8* getelementptr inbounds (i8, i8* inttoptr (i64 -2147483648 to i8*), i64 753665)
%13 = call i32 (...) @fork()
store i32 %13, i32* %10
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* %8
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 @sleep(i32 111)
br label %22
19: ; preds = %3
%20 = load i32, i32* %10
%21 = call i32 @waitpid(i32 %20, i32* %9, i32 0)
br label %22
22: ; preds = %19, %15
%23 = load i32, i32* %8
%24 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %25
br label %25
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d. Parent\0A\00"
@.str.1 = [20 x i8] c"%d. Infinite child\0A\00"
@.str.2 = [21 x i8] c"%d. Parent Infinite\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 1)
store i8 65, i8* inttoptr (i64 -2146729984 to i8*)
store i8 7, i8* inttoptr (i64 -2146729983 to i8*)
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = tail call i32 @sleep(i32 111)
br label %14
12: ; preds = %3
%13 = call i32 @waitpid(i32 %7, i32* %4, i32 0)
br label %14
14: ; preds = %12, %9
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %16
16: ; preds = %16, %14
br label %16
}