#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 */

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int wait(int *);
void execute(char *arglist[]) {
  int pid, exitStatus;
  pid = fork();
  switch (pid) {
  case 0:
    execvp(arglist[0], arglist);
    perror("execvp failed");
    exit(1);
    break;
  case -1:
    perror("fork");
    break;
  default:
    while (wait(&exitStatus) != pid) {
    }
    printf("child exited with status %d, %d\n", exitStatus >> 8,
           exitStatus & 0377);
  }
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xffffffff,%eax
je     11c0 <execute+0x60>
jmp    118a <execute+0x2a>
mov    -0x14(%rbp),%eax
test   %eax,%eax
jne    11d1 <execute+0x71>
jmp    119a <execute+0x3a>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <execvp@plt>
lea    0xe4f(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe47(%rip),%rdi
call   1040 <perror@plt>
jmp    1208 <execute+0xa8>
jmp    11d6 <execute+0x76>
lea    -0x10(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0xc(%rbp),%eax
je     11ed <execute+0x8d>
jmp    11d6 <execute+0x76>
mov    -0x10(%rbp),%esi
sar    $0x8,%esi
mov    -0x10(%rbp),%edx
and    $0xff,%edx
lea    0xe10(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11ab <execute+0x4b>
mov    %eax,%ebx
test   %eax,%eax
je     11be <execute+0x5e>
lea    0x4(%rsp),%r14
xchg   %ax,%ax
mov    %r14,%rdi
call   1070 <wait@plt>
cmp    %ebx,%eax
jne    1180 <execute+0x20>
mov    0x4(%rsp),%esi
movzbl %sil,%edx
sar    $0x8,%esi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5c(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <perror@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1050 <execvp@plt>
lea    0xe30(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"execvp failed\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [33 x i8] c"child exited with status %d, %d\0A\00"
define void @execute(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
store i8** %0, i8*** %2
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
switch i32 %6, label %17 [
i32 0, label %7
i32 -1, label %15
]
7: ; preds = %1
%8 = load i8**, i8*** %2
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = load i8**, i8*** %2
%12 = call i32 @execvp(i8* %10, i8** %11)
%13 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %29
17: ; preds = %1
br label %18
18: ; preds = %22, %17
%19 = call i32 @wait(i32* %4)
%20 = load i32, i32* %3
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
br label %18
23: ; preds = %18
%24 = load i32, i32* %4
%25 = ashr i32 %24, 8
%26 = load i32, i32* %4
%27 = and i32 %26, 255
%28 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %27)
br label %29
29: ; preds = %23, %15
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"execvp failed\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [33 x i8] c"child exited with status %d, %d\0A\00"
define void @execute(i8** %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @fork()
switch i32 %4, label %12 [
i32 0, label %5
i32 -1, label %10
]
5: ; preds = %1
%6 = load i8*, i8** %0
%7 = tail call i32 @execvp(i8* %6, i8** %0)
%8 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %20
12: ; preds = %1, %12
%13 = call i32 @wait(i32* %2)
%14 = icmp eq i32 %13, %4
br i1 %14, label %15, label %12
15: ; preds = %12
%16 = load i32, i32* %2
%17 = ashr i32 %16, 8
%18 = and i32 %16, 255
%19 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
br label %20
20: ; preds = %15, %10
ret void
}