#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 /*<<< 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[]) {
  pid_t pid;
  int exit_status;
  pid = fork();
  switch (pid) {
  case -1:
    perror("fork() failed");
    exit(1);
  case 0:
    execvp(arglist[0], arglist);
    perror("execvp() failed");
    exit(1);
  default:
    break;
  }
  while (1) {
    if (wait(&exit_status) == pid)
      break;
  }
  printf("Child exited with status %d, %d\n", exit_status >> 8,
         exit_status & 0x7F);
}


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    0xe47(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11db <execute+0x7b>
jmp    11e0 <execute+0x80>
lea    -0x18(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x14(%rbp),%eax
jne    11f7 <execute+0x97>
jmp    11fc <execute+0x9c>
jmp    11e0 <execute+0x80>
mov    -0x18(%rbp),%esi
sar    $0x8,%esi
mov    -0x18(%rbp),%edx
and    $0x7f,%edx
lea    0xe0f(%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     11ac <execute+0x4c>
mov    %eax,%ebx
test   %eax,%eax
je     11b5 <execute+0x55>
lea    0x4(%rsp),%r14
xchg   %ax,%ax
mov    %r14,%rdi
call   1070 <wait@plt>
cmp    %ebx,%eax
jne    1180 <execute+0x20>
mov    0x4(%rsp),%edx
mov    %edx,%esi
sar    $0x8,%esi
and    $0x7f,%edx
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4d(%rip),%rdi
jmp    11c7 <execute+0x67>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1050 <execvp@plt>
lea    0xe47(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"fork() failed\00"
@.str.1 = [16 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 ([14 x i8], [14 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 ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %1
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20, %26
%22 = call i32 @wait(i32* %5)
%23 = load i32, i32* %4
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
br label %27
26: ; preds = %21
br label %21
27: ; preds = %25
%28 = load i32, i32* %5
%29 = ashr i32 %28, 8
%30 = load i32, i32* %5
%31 = and i32 %30, 127
%32 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %31)
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [14 x i8] c"fork() failed\00"
@.str.1 = [16 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 ([14 x i8], [14 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 ([16 x i8], [16 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, 127
%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
}