#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 /*<<< orphan*/ 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 *)("/bin/date");
    childArgvArray[0] = (char *)s;
    childArgvArray[1] = NULL;
    execv(s, childArgvArray);
    fprintf(stdout, "%s\n", "Child report: Execve failed ");
  } else {
    int status;
    waitpid(pid, &status, 0);
    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    $0x40,%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    11c7 <main+0x77>
lea    0xe7d(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <execv@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
lea    0xe53(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1236 <main+0xe6>
mov    -0x18(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmpl   $0x0,-0x3c(%rbp)
je     1213 <main+0xc3>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%ecx
lea    0xe2b(%rip),%rsi
lea    0xe2a(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1231 <main+0xe1>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
lea    0xe4c(%rip),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1236 <main+0xe6>
xor    %eax,%eax
add    $0x40,%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     119e <main+0x4e>
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    (%rsp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%ebx
test   %edi,%edi
je     11d3 <main+0x83>
call   1040 <WEXITSTATUS@plt>
lea    0xea1(%rip),%rsi
lea    0xea0(%rip),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11ea <main+0x9a>
lea    0xe5b(%rip),%rdi
mov    %rdi,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
call   1060 <execv@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
lea    0xe3d(%rip),%rdx
jmp    11e3 <main+0x93>
lea    0xe30(%rip),%rsi
lea    0xe95(%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 = [10 x i8] c"/bin/date\00"
@stdout = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [29 x i8] c"Child report: Execve failed \00"
@.str.3 = [6 x i8] c"%s%d\0A\00"
@.str.4 = [69 x i8] c"Parent report: Child process failed. Status of the child process is \00"
@.str.5 = [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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i64 (...) @fork()
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %8
%14 = load i8*, i8** %8
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* %14, i8** %15
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* null, i8** %16
%17 = load i8*, i8** %8
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%19 = call i32 @execv(i8* %17, i8** %18)
%20 = load i32, i32* @stdout
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %36
22: ; preds = %2
%23 = load i64, i64* %6
%24 = call i32 @waitpid(i64 %23, i32* %9, i32 0)
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* @stdout
%29 = load i32, i32* %9
%30 = call i32 @WEXITSTATUS(i32 %29)
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %35
32: ; preds = %22
%33 = load i32, i32* @stdout
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %32, %27
br label %36
36: ; preds = %35, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/bin/date\00"
@stdout = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [29 x i8] c"Child report: Execve failed \00"
@.str.3 = [6 x i8] c"%s%d\0A\00"
@.str.4 = [69 x i8] c"Parent report: Child process failed. Status of the child process is \00"
@.str.5 = [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 ([10 x i8], [10 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* null, i8** %10
%11 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 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.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %26
14: ; preds = %2
%15 = bitcast i32* %4 to i8*
%16 = call i32 @waitpid(i64 %5, i32* %4, i32 0)
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
%19 = load i32, i32* @stdout
br i1 %18, label %23, label %20
20: ; preds = %14
%21 = call i32 @WEXITSTATUS(i32 %17)
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %14
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
br label %26
26: ; preds = %25, %7
ret i32 0
}