#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 *);
int execute(char *arglist[]) {
  int pid, exitstatus;
  pid = fork();
  switch (pid) {
  case -1:
    perror("fork failed");
    exit(1);
  case 0:
    execvp(arglist[0], arglist);
    perror("execvp failed");
    exit(1);
  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,-0x10(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     119a <execute+0x3a>
jmp    118a <execute+0x2a>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     11b0 <execute+0x50>
jmp    11d6 <execute+0x76>
lea    0xe5f(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <execvp@plt>
lea    0xe45(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11db <execute+0x7b>
lea    -0x18(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x14(%rbp),%eax
je     11f2 <execute+0x92>
jmp    11db <execute+0x7b>
mov    -0x18(%rbp),%esi
sar    $0x8,%esi
mov    -0x18(%rbp),%edx
and    $0xff,%edx
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
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     11b4 <execute+0x54>
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    0xe7c(%rip),%rdi
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4e(%rip),%rdi
jmp    11c6 <execute+0x66>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1050 <execvp@plt>
lea    0xe46(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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