#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 */
scalar_t__ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pr_exit(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int status;
  pid_t pid;
  if (argc < 2) {
    printf("command-line argument required\n");
    exit(0);
  }
  if ((pid = fork()) < 0) {
    printf("fork error\n");
    exit(0);
  } else if (pid == 0) {
    if (execl(argv[1], argv[1], (char *)0) < 0) {
      printf("execl error\n");
      return 0;
    }
  }
  if (waitpid(pid, &status, 0) < 0) {
    printf("waitpid error\n");
    return 0;
  }
  printf("status = %d\n", status);
  pr_exit(status);
  exit(0);
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    1195 <main+0x35>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    11bf <main+0x5f>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    120c <main+0xac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execl@plt>
cmp    $0x0,%rax
jge    1207 <main+0xa7>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1264 <main+0x104>
jmp    120c <main+0xac>
jmp    1211 <main+0xb1>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    1244 <main+0xe4>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1264 <main+0x104>
mov    -0x14(%rbp),%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <pr_exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    11d3 <main+0x63>
mov    %rsi,%r14
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11dc <main+0x6c>
mov    %rax,%rbx
jne    11a0 <main+0x30>
mov    0x8(%r14),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1080 <execl@plt>
test   %rax,%rax
js     11ca <main+0x5a>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <waitpid@plt>
test   %rax,%rax
jns    11ef <main+0x7f>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4a(%rip),%rdi
jmp    11bb <main+0x4b>
lea    0xe58(%rip),%rdi
jmp    11e3 <main+0x73>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x4(%rsp),%esi
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"command-line argument required\0A\00"
@.str.1 = [12 x i8] c"fork error\0A\00"
@.str.2 = [13 x i8] c"execl error\0A\00"
@.str.3 = [15 x i8] c"waitpid error\0A\00"
@.str.4 = [13 x i8] c"status = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = call i64 (...) @fork()
store i64 %14, i64* %7
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %13
%20 = load i64, i64* %7
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @execl(i8* %25, i8* %28, i8* null)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %47
33: ; preds = %22
br label %34
34: ; preds = %33, %19
br label %35
35: ; preds = %34
%36 = load i64, i64* %7
%37 = call i64 @waitpid(i64 %36, i32* %6, i32 0)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %47
41: ; preds = %35
%42 = load i32, i32* %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %6
%45 = call i32 @pr_exit(i32 %44)
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %39, %31
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str.4 = [13 x i8] c"status = %d\0A\00"
@str = [14 x i8] c"waitpid error\00"
@str.5 = [12 x i8] c"execl error\00"
@str.6 = [11 x i8] c"fork error\00"
@str.7 = [31 x i8] c"command-line argument required\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = tail call i64 (...) @fork()
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %9
%16 = icmp eq i64 %10, 0
br i1 %16, label %17, label %24
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i64 @execl(i8* %19, i8* %19, i8* null)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
br label %35
24: ; preds = %15, %17
%25 = call i64 @waitpid(i64 %10, i32* %3, i32 0)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %35
29: ; preds = %24
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %3
%33 = call i32 @pr_exit(i32 %32)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %27, %22
ret i32 0
}