#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 /*<<< orphan*/ wait(int *);
void execute(char *arglist[]) {
  int pid, existstatus;
  pid = fork();
  switch (pid) {
  case -1:
    perror("fork failed!");
    exit(1);
  case 0:
    execvp(arglist[0], arglist);
    perror("execvp failed");
    exit(1);
  default:
    wait(&existstatus);
    printf("child exited with status %d, %d\n", existstatus >> 8,
           existstatus & 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     119a <execute+0x3a>
jmp    118a <execute+0x2a>
mov    -0x14(%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    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <execvp@plt>
lea    0xe46(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x10(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x10(%rbp),%esi
sar    $0x8,%esi
mov    -0x10(%rbp),%edx
and    $0xff,%edx
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     119f <execute+0x3f>
cmp    $0xffffffff,%eax
je     11b3 <execute+0x53>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
mov    0xc(%rsp),%esi
movzbl %sil,%edx
sar    $0x8,%esi
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
lea    0xe5c(%rip),%rdi
jmp    11ba <execute+0x5a>
lea    0xe46(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [13 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 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 %18 [
i32 -1, label %7
i32 0, label %10
]
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i8**, i8*** %2
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %2
%15 = call i32 @execvp(i8* %13, i8** %14)
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = call i32 @wait(i32* %4)
%20 = load i32, i32* %4
%21 = ashr i32 %20, 8
%22 = load i32, i32* %4
%23 = and i32 %22, 255
%24 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %23)
br label %25
25: ; preds = %18
ret void
}

LLVM IR (-O2):
@.str = [13 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 void @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 ([13 x i8], [13 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
%14 = call i32 @wait(i32* %2)
%15 = load i32, i32* %2
%16 = ashr i32 %15, 8
%17 = and i32 %15, 255
%18 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %17)
ret void
}