#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 */
scalar_t__ execvp(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  pid_t pid;
  pid = fork();
  if (pid == -1) {
    exit(-1);
  } else if (pid == 0) {
    if (execvp("./hello", NULL) < 0) {
      printf("fail :(\n");
      exit(-1);
    }
  } else {
    printf("child pid = %d\n", pid);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    116d <main+0x2d>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11ae <main+0x6e>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <execvp@plt>
cmp    $0x0,%rax
jge    11a9 <main+0x69>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
jmp    11bf <main+0x7f>
mov    -0x8(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c4 <main+0x84>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1173 <main+0x23>
cmp    $0xffffffff,%eax
je     118a <main+0x3a>
lea    0xea0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1186 <main+0x36>
lea    0xe86(%rip),%rdi
xor    %esi,%esi
call   1050 <execvp@plt>
test   %rax,%rax
js     1194 <main+0x44>
xor    %eax,%eax
pop    %rcx
ret
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [8 x i8] c"./hello\00"
@.str.2 = [16 x i8] c"child pid = %d\0A\00"
@str = [8 x i8] c"fail :(\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %10 [
i32 -1, label %2
i32 0, label %4
]
2: ; preds = %0
%3 = tail call i32 @exit(i32 -1)
unreachable
4: ; preds = %0
%5 = tail call i64 @execvp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %12
12: ; preds = %10, %4
ret i32 0
}