#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int wait(int *);
int main() {
  pid_t i, j;
  int status;
  if ((i = fork()) == 0) {
    fprintf(stderr, "child begin. pid=[%d]\n", getpid());
    sleep(30);
    fprintf(stderr, "child end .pid=[%d]\n", getpid());
    exit(10);
  }
  j = wait(&status);
  fprintf(stderr, "child pid=[%d],exit pid[%d],status[%d]\n", i, j, status);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    11e2 <main+0x82>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%edx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1e,%edi
call   1060 <sleep@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%edx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xa,%edi
call   1050 <exit@plt>
lea    -0x10(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0xc(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11a5 <main+0x45>
mov    %eax,%ebx
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%edi
mov    0x4(%rsp),%r8d
lea    0xe9c(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e34(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe43(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1e,%edi
call   1060 <sleep@plt>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe34(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xa,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"child begin. pid=[%d]\0A\00"
@.str.1 = [21 x i8] c"child end .pid=[%d]\0A\00"
@.str.2 = [40 x i8] c"child pid=[%d],exit pid[%d],status[%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 (...) @getpid()
%10 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @sleep(i32 30)
%12 = load i32, i32* @stderr
%13 = call i32 (...) @getpid()
%14 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 10)
unreachable
16: ; preds = %0
%17 = call i32 @wait(i32* %4)
store i32 %17, i32* %3
%18 = load i32, i32* @stderr
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20, i32 %21)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"child begin. pid=[%d]\0A\00"
@.str.1 = [21 x i8] c"child end .pid=[%d]\0A\00"
@.str.2 = [40 x i8] c"child pid=[%d],exit pid[%d],status[%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @sleep(i32 30)
%10 = load i32, i32* @stderr
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 @exit(i32 10)
unreachable
14: ; preds = %0
%15 = call i32 @wait(i32* %1)
%16 = load i32, i32* @stderr
%17 = load i32, i32* %1
%18 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %15, i32 %17)
ret i32 0
}