#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 fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int pid;
  if (pid = fork()) {
    fprintf(stderr, "parent: I see kid with pid = %d\n", pid);
    sleep(1);
    fprintf(stderr, "parent: dying\n");
  } else {
    fprintf(stderr, "child: I'm here\n");
    sleep(10);
    fprintf(stderr, "child: dying\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1199 <main+0x69>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11d1 <main+0xa1>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xa,%edi
call   1040 <sleep@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
mov    0x2e9e(%rip),%r14
mov    (%r14),%edi
test   %eax,%eax
je     1167 <main+0x37>
lea    0xeb0(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xec1(%rip),%rbx
mov    $0x1,%edi
jmp    1181 <main+0x51>
lea    0xec2(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xec5(%rip),%rbx
mov    $0xa,%edi
call   1040 <sleep@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"parent: I see kid with pid = %d\0A\00"
@.str.1 = [15 x i8] c"parent: dying\0A\00"
@.str.2 = [17 x i8] c"child: I'm here\0A\00"
@.str.3 = [14 x i8] c"child: dying\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* %6
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @sleep(i32 1)
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @sleep(i32 10)
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %16, %9
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"parent: I see kid with pid = %d\0A\00"
@.str.1 = [15 x i8] c"parent: dying\0A\00"
@.str.2 = [17 x i8] c"child: I'm here\0A\00"
@.str.3 = [14 x i8] c"child: dying\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
%5 = load i32, i32* @stderr
br i1 %4, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %10
8: ; preds = %2
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = phi i32 [ 10, %8 ], [ 1, %6 ]
%12 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %6 ]
%13 = tail call i32 @sleep(i32 %11)
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* %12)
ret i32 0
}