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

/* Variables and functions */
int WEXITSTATUS(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ printf(char *, scalar_t__, int);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  pid_t pid = fork();
  if (pid == 0) {
    exit(getpid());
  } else {
    int status = 0;
    waitpid(pid, &status, 0);
    printf("0x%x exited with 0x%x\n", pid, WEXITSTATUS(status));
  }
  exit(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    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <main+0x3a>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1070 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    117f <main+0x1f>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1070 <exit@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xe57(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"0x%x exited with 0x%x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (...) @getpid()
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
store i32 0, i32* %7
%15 = load i64, i64* %6
%16 = call i32 @waitpid(i64 %15, i32* %7, i32 0)
%17 = load i64, i64* %6
%18 = load i32, i32* %7
%19 = call i32 @WEXITSTATUS(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %17, i32 %19)
br label %21
21: ; preds = %14
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [23 x i8] c"0x%x exited with 0x%x\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%11 = call i32 @waitpid(i64 %4, i32* %3, i32 0)
%12 = load i32, i32* %3
%13 = call i32 @WEXITSTATUS(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %4, i32 %13)
%15 = call i32 @exit(i32 0)
unreachable
}