#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);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <command> <arg>\n", argv[0]);
    exit(1);
  }
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "fork(2) failed\n");
    exit(1);
  }
  if (pid == 0) {
    execl(argv[1], argv[1], argv[2], NULL);
    perror(argv[1]);
    exit(99);
  }
  int status;
  waitpid(pid, &status, 0);
  printf("child (PID=%d) finished: ", pid);
  if (WIFEXITED(status)) {
    printf("exit, status=%d\n", WEXITSTATUS(status));
  } else if (WIFSIGNALED(status)) {
    printf("signal, sig=%d\n", WTERMSIG(status));
  } else {
    printf("abnormal exit\n");
  }
  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   $0x3,-0x8(%rbp)
je     11f8 <main+0x48>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    122f <main+0x7f>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1272 <main+0xc2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   10c0 <execl@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    $0x63,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    -0x18(%rbp),%rsi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12c2 <main+0x112>
mov    -0x1c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1304 <main+0x154>
mov    -0x1c(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     12f1 <main+0x141>
mov    -0x1c(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ff <main+0x14f>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1304 <main+0x154>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11f9 <main+0x39>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
jns    121d <main+0x5d>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdf4(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jne    1244 <main+0x84>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10d0 <execl@plt>
mov    0x8(%rbx),%rdi
call   10a0 <perror@plt>
mov    $0x63,%edi
call   10c0 <exit@plt>
mov    %rax,%r14
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1090 <waitpid@plt>
lea    0xdce(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
call   10b0 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
jne    1296 <main+0xd6>
call   1050 <WIFSIGNALED@plt>
test   %rax,%rax
jne    12a4 <main+0xe4>
lea    0xddc(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
call   1080 <WEXITSTATUS@plt>
lea    0xda3(%rip),%rdi
jmp    12b4 <main+0xf4>
mov    0x4(%rsp),%edi
call   1070 <WTERMSIG@plt>
lea    0xda2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s <command> <arg>\0A\00"
@.str.1 = [16 x i8] c"fork(2) failed\0A\00"
@.str.2 = [26 x i8] c"child (PID=%d) finished: \00"
@.str.3 = [17 x i8] c"exit, status=%d\0A\00"
@.str.4 = [16 x i8] c"signal, sig=%d\0A\00"
@.str.5 = [15 x i8] c"abnormal exit\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 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i64 (...) @fork()
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = load i64, i64* %6
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @execl(i8* %31, i8* %34, i8* %37, i32* null)
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @perror(i8* %41)
%43 = call i32 @exit(i32 99)
unreachable
44: ; preds = %25
%45 = load i64, i64* %6
%46 = call i32 @waitpid(i64 %45, i32* %7, i32 0)
%47 = load i64, i64* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %47)
%49 = load i32, i32* %7
%50 = call i64 @WIFEXITED(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %44
%53 = load i32, i32* %7
%54 = call i32 @WEXITSTATUS(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %54)
br label %67
56: ; preds = %44
%57 = load i32, i32* %7
%58 = call i64 @WIFSIGNALED(i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i32, i32* %7
%62 = call i32 @WTERMSIG(i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %62)
br label %66
64: ; preds = %56
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
br label %67
67: ; preds = %66, %52
%68 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s <command> <arg>\0A\00"
@.str.1 = [16 x i8] c"fork(2) failed\0A\00"
@.str.2 = [26 x i8] c"child (PID=%d) finished: \00"
@.str.3 = [17 x i8] c"exit, status=%d\0A\00"
@.str.4 = [16 x i8] c"signal, sig=%d\0A\00"
@str = [14 x i8] c"abnormal exit\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 3
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i64 (...) @fork()
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = icmp eq i64 %11, 0
br i1 %18, label %19, label %28
19: ; preds = %17
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @execl(i8* %21, i8* %21, i8* %23, i32* null)
%25 = load i8*, i8** %20
%26 = tail call i32 @perror(i8* %25)
%27 = tail call i32 @exit(i32 99)
unreachable
28: ; preds = %17
%29 = bitcast i32* %3 to i8*
%30 = call i32 @waitpid(i64 %11, i32* %3, i32 0)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %11)
%32 = load i32, i32* %3
%33 = call i64 @WIFEXITED(i32 %32)
%34 = icmp eq i64 %33, 0
%35 = load i32, i32* %3
br i1 %34, label %39, label %36
36: ; preds = %28
%37 = call i32 @WEXITSTATUS(i32 %35)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %48
39: ; preds = %28
%40 = call i64 @WIFSIGNALED(i32 %35)
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i32, i32* %3
%44 = call i32 @WTERMSIG(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %48
46: ; preds = %39
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %42, %46, %36
%49 = call i32 @exit(i32 0)
unreachable
}