#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*/ WEXITSTATUS(int);
int execv(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid = fork();
  if (pid == 0) {
    char *childArgvArray[2];
    char *s = (char *)("/usr/bin/chfn");
    childArgvArray[0] = (char *)s;
    childArgvArray[1] = (char *)("--help");
    int err = execv(s, childArgvArray);
    fprintf(stdout, "%s\n", "Child report: Execve failed ");
  } else {
    int status;
    waitpid(pid, &status, 0);
    fprintf(stdout, "%s%d\n", "status", status);
    if (status != 0)
      fprintf(stdout, "%s%d\n",
              "Parent report: Child process failed. Status of the child "
              "process is ",
              WEXITSTATUS(status));
    else
      fprintf(stdout, "%s\n",
              "Parent report: Child process exited successfully");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cd <main+0x7d>
lea    0xe7d(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe78(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <execv@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
lea    0xe58(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    125d <main+0x10d>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%ecx
lea    0xe47(%rip),%rsi
lea    0xe46(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0x0,-0x40(%rbp)
je     123a <main+0xea>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%ecx
lea    0xe0f(%rip),%rsi
lea    0xe15(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1258 <main+0x108>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
lea    0xe37(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    125d <main+0x10d>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11b8 <main+0x68>
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    0x2e6b(%rip),%rbx
mov    (%rbx),%edi
mov    (%rsp),%ecx
lea    0xeb5(%rip),%rsi
lea    0xeb4(%rip),%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rsp),%edi
mov    (%rbx),%ebx
test   %edi,%edi
je     11f0 <main+0xa0>
call   1040 <WEXITSTATUS@plt>
lea    0xe92(%rip),%rsi
lea    0xe98(%rip),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1207 <main+0xb7>
lea    0xe41(%rip),%rdi
mov    %rdi,(%rsp)
lea    0xe44(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %rsp,%rsi
call   1060 <execv@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
lea    0xe2b(%rip),%rdx
jmp    1200 <main+0xb0>
lea    0xe1e(%rip),%rsi
lea    0xe8a(%rip),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/usr/bin/chfn\00"
@.str.1 = [7 x i8] c"--help\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [29 x i8] c"Child report: Execve failed \00"
@.str.4 = [6 x i8] c"%s%d\0A\00"
@.str.5 = [7 x i8] c"status\00"
@.str.6 = [69 x i8] c"Parent report: Child process failed. Status of the child process is \00"
@.str.7 = [49 x i8] c"Parent report: Child process exited successfully\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [2 x i8*]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i64 (...) @fork()
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %8
%15 = load i8*, i8** %8
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* %15, i8** %16
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %17
%18 = load i8*, i8** %8
%19 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%20 = call i32 @execv(i8* %18, i8** %19)
store i32 %20, i32* %9
%21 = load i32, i32* @stdout
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %40
23: ; preds = %2
%24 = load i64, i64* %6
%25 = call i32 @waitpid(i64 %24, i32* %10, i32 0)
%26 = load i32, i32* @stdout
%27 = load i32, i32* %10
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %23
%32 = load i32, i32* @stdout
%33 = load i32, i32* %10
%34 = call i32 @WEXITSTATUS(i32 %33)
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 %34)
br label %39
36: ; preds = %23
%37 = load i32, i32* @stdout
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %39
39: ; preds = %36, %31
br label %40
40: ; preds = %39, %14
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/usr/bin/chfn\00"
@.str.1 = [7 x i8] c"--help\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [29 x i8] c"Child report: Execve failed \00"
@.str.4 = [6 x i8] c"%s%d\0A\00"
@.str.5 = [7 x i8] c"status\00"
@.str.6 = [69 x i8] c"Parent report: Child process failed. Status of the child process is \00"
@.str.7 = [49 x i8] c"Parent report: Child process exited successfully\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i8*]
%4 = alloca i32
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = bitcast [2 x i8*]* %3 to i8*
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %9)
%12 = load i32, i32* @stdout
%13 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %29
14: ; preds = %2
%15 = bitcast i32* %4 to i8*
%16 = call i32 @waitpid(i64 %5, i32* %4, i32 0)
%17 = load i32, i32* @stdout
%18 = load i32, i32* %4
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
%22 = load i32, i32* @stdout
br i1 %21, label %26, label %23
23: ; preds = %14
%24 = call i32 @WEXITSTATUS(i32 %20)
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 %24)
br label %28
26: ; preds = %14
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
br label %29
29: ; preds = %28, %7
ret i32 0
}