#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*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void child_process(int fd) {
  int i;
  char buffer[100];
  printf("PID: %d, Parent PID: %d\n", getpid(), getppid());
  for (i = 0; i < 10; ++i) {
    snprintf(buffer, sizeof(buffer), "%d: %d\n", getpid(), i);
    write(fd, buffer, strlen(buffer));
  }
  close(fd);
  if (getpid() % 2) {
    exit(0);
  } else {
    abort();
  }
}


x86 assembly (clang, -O0):
<child_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,-0x74(%rbp)
mov    $0x0,%al
call   10a0 <getppid@plt>
mov    -0x74(%rbp),%esi
mov    %eax,%edx
lea    0xe45(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    123a <child_process+0xaa>
lea    -0x70(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%ecx
mov    -0x8(%rbp),%r8d
mov    $0x64,%esi
lea    0xe1d(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x84(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c7 <child_process+0x37>
mov    -0x4(%rbp),%edi
call   1090 <close@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1261 <child_process+0xd1>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<child_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10a0 <getppid@plt>
lea    0xe4f(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1070 <printf@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe51(%rip),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x1,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x2,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x3,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x4,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x5,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x6,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x7,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x8,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    $0x9,%r8d
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
test   $0x1,%al
jne    13d8 <child_process+0x248>
xor    %eax,%eax
call   1030 <abort@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"PID: %d, Parent PID: %d\0A\00"
@.str.1 = [8 x i8] c"%d: %d\0A\00"
define void @child_process(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 %0, i32* %2
%5 = call i32 (...) @getpid()
%6 = call i32 (...) @getppid()
%7 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
store i32 0, i32* %3
br label %8
8: ; preds = %21, %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%13 = call i32 (...) @getpid()
%14 = load i32, i32* %3
%15 = call i32 @snprintf(i8* %12, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* %2
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @write(i32 %16, i8* %17, i32 %19)
br label %21
21: ; preds = %11
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %8
24: ; preds = %8
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
%27 = call i32 (...) @getpid()
%28 = srem i32 %27, 2
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %24
%33 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
@.str = [25 x i8] c"PID: %d, Parent PID: %d\0A\00"
@.str.1 = [8 x i8] c"%d: %d\0A\00"
define void @child_process(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (...) @getppid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = call i32 (...) @getpid()
%8 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 0)
%9 = call i32 @strlen(i8* %3)
%10 = call i32 @write(i32 %0, i8* %3, i32 %9)
%11 = call i32 (...) @getpid()
%12 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 1)
%13 = call i32 @strlen(i8* %3)
%14 = call i32 @write(i32 %0, i8* %3, i32 %13)
%15 = call i32 (...) @getpid()
%16 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 2)
%17 = call i32 @strlen(i8* %3)
%18 = call i32 @write(i32 %0, i8* %3, i32 %17)
%19 = call i32 (...) @getpid()
%20 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 3)
%21 = call i32 @strlen(i8* %3)
%22 = call i32 @write(i32 %0, i8* %3, i32 %21)
%23 = call i32 (...) @getpid()
%24 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 4)
%25 = call i32 @strlen(i8* %3)
%26 = call i32 @write(i32 %0, i8* %3, i32 %25)
%27 = call i32 (...) @getpid()
%28 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 5)
%29 = call i32 @strlen(i8* %3)
%30 = call i32 @write(i32 %0, i8* %3, i32 %29)
%31 = call i32 (...) @getpid()
%32 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 6)
%33 = call i32 @strlen(i8* %3)
%34 = call i32 @write(i32 %0, i8* %3, i32 %33)
%35 = call i32 (...) @getpid()
%36 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 7)
%37 = call i32 @strlen(i8* %3)
%38 = call i32 @write(i32 %0, i8* %3, i32 %37)
%39 = call i32 (...) @getpid()
%40 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 8)
%41 = call i32 @strlen(i8* %3)
%42 = call i32 @write(i32 %0, i8* %3, i32 %41)
%43 = call i32 (...) @getpid()
%44 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 9)
%45 = call i32 @strlen(i8* %3)
%46 = call i32 @write(i32 %0, i8* %3, i32 %45)
%47 = call i32 @close(i32 %0)
%48 = call i32 (...) @getpid()
%49 = and i32 %48, 1
%50 = icmp eq i32 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %1
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %1
%54 = call i32 (...) @abort()
unreachable
}