#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 int pid_t;

/* Variables and functions */
int WEXITSTATUS(int);
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ execlp(char const *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int vfork();
int /*<<< orphan*/ wait(int *);
int execute_child(const char *prog) {
  int status;
  pid_t child;
  child = vfork();
  if (child == 0) {
    execlp(prog, prog, NULL);
    perror("Could not execute specified prog");
    _exit(1);
  } else if (child == 1)
    return 1;
  wait(&status);
  return WEXITSTATUS(status);
}


x86 assembly (clang, -O0):
<execute_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
call   1060 <vfork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a5 <execute_child+0x45>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execlp@plt>
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
cmpl   $0x1,-0x18(%rbp)
jne    11bb <execute_child+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11d4 <execute_child+0x74>
jmp    11c0 <execute_child+0x60>
lea    -0x14(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x14(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_child>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1060 <vfork@plt>
mov    %eax,%ecx
cmp    $0x1,%eax
je     118d <execute_child+0x2d>
test   %eax,%eax
je     1195 <execute_child+0x35>
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
mov    %eax,%edx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1070 <execlp@plt>
lea    0xe55(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"Could not execute specified prog\00"
define i32 @execute_child(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 @vfork()
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @execlp(i8* %10, i8* %11, i32* null)
%13 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @_exit(i32 1)
unreachable
15: ; preds = %1
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 1, i32* %2
br label %24
19: ; preds = %15
br label %20
20: ; preds = %19
%21 = call i32 @wait(i32* %4)
%22 = load i32, i32* %4
%23 = call i32 @WEXITSTATUS(i32 %22)
store i32 %23, i32* %2
br label %24
24: ; preds = %20, %18
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [33 x i8] c"Could not execute specified prog\00"
define i32 @execute_child(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @vfork()
switch i32 %4, label %9 [
i32 0, label %5
i32 1, label %13
]
5: ; preds = %1
%6 = call i32 @execlp(i8* %0, i8* %0, i32* null)
%7 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @_exit(i32 1)
unreachable
9: ; preds = %1
%10 = call i32 @wait(i32* %2)
%11 = load i32, i32* %2
%12 = call i32 @WEXITSTATUS(i32 %11)
br label %13
13: ; preds = %1, %9
%14 = phi i32 [ %12, %9 ], [ %4, %1 ]
ret i32 %14
}