#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
scalar_t__ execl(char *, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ waitpid(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid;
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Err.(%s) fork() failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    if (execl("/usr/bin/gcc", "gcc", "-v", "02_fork_1.c", (char *)0) < 0) {
      fprintf(stderr, "Err.(%s) execl() failed\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  if (waitpid(pid, NULL, 0) < 0) {
    fprintf(stderr, "Err.(%s) waitpid() failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


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)
cmp    $0x0,%rax
jge    11c5 <main+0x65>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe4e(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    123f <main+0xdf>
lea    0xe41(%rip),%rdi
lea    0xe43(%rip),%rsi
lea    0xe40(%rip),%rdx
lea    0xe3c(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <execl@plt>
cmp    $0x0,%rax
jge    123a <main+0xda>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe0d(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    123f <main+0xdf>
jmp    1244 <main+0xe4>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0x0,%rax
jge    1297 <main+0x137>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xdc9(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11b7 <main+0x57>
mov    %rax,%rbx
jne    119b <main+0x3b>
lea    0xe9f(%rip),%rdi
lea    0xea1(%rip),%rsi
lea    0xe9e(%rip),%rdx
lea    0xe9a(%rip),%rcx
xor    %r8d,%r8d
call   1070 <execl@plt>
test   %rax,%rax
js     11f7 <main+0x97>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %rax,%rax
js     11d7 <main+0x77>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2e22(%rip),%rax
mov    (%rax),%ebx
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe2b(%rip),%rsi
jmp    1215 <main+0xb5>
mov    0x2e02(%rip),%rax
mov    (%rax),%ebx
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe58(%rip),%rsi
jmp    1215 <main+0xb5>
mov    0x2de2(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe1f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Err.(%s) fork() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"/usr/bin/gcc\00"
@.str.2 = [4 x i8] c"gcc\00"
@.str.3 = [3 x i8] c"-v\00"
@.str.4 = [12 x i8] c"02_fork_1.c\00"
@.str.5 = [25 x i8] c"Err.(%s) execl() failed\0A\00"
@.str.6 = [27 x i8] c"Err.(%s) waitpid() failed\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i64, i64* %6
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = call i64 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* null)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %19
br label %30
30: ; preds = %29, %16
br label %31
31: ; preds = %30
%32 = load i64, i64* %6
%33 = call i64 @waitpid(i64 %32, i32* null, i32 0)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %31
%43 = load i32, i32* @EXIT_SUCCESS
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Err.(%s) fork() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"/usr/bin/gcc\00"
@.str.2 = [4 x i8] c"gcc\00"
@.str.3 = [3 x i8] c"-v\00"
@.str.4 = [12 x i8] c"02_fork_1.c\00"
@.str.5 = [25 x i8] c"Err.(%s) execl() failed\0A\00"
@.str.6 = [27 x i8] c"Err.(%s) waitpid() failed\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = icmp eq i64 %3, 0
br i1 %13, label %14, label %24
14: ; preds = %12
%15 = tail call i64 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* null)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %12, %14
%25 = tail call i64 @waitpid(i64 %3, i32* null, i32 0)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %24
%35 = load i32, i32* @EXIT_SUCCESS
ret i32 %35
}