#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*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int wait(int *);
int execute(char *arglist[]) {
  pid_t pid;
  int exit_status;
  if (arglist[0] == NULL)
    return 0;
  pid = fork();
  if (pid == -1) {
    perror("fork() failed");
    exit(1);
  } else if (pid == 0) {
    signal(SIGINT, SIG_DFL);
    signal(SIGQUIT, SIG_DFL);
    execvp(arglist[0], arglist);
    perror("execvp() failed");
    exit(1);
  }
  while (1) {
    if (wait(&exit_status) == pid)
      break;
  }
  printf("Child exited with status %d, %d\n", exit_status >> 8,
         exit_status & 0x7F);
  return exit_status;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1196 <execute+0x26>
movl   $0x0,-0x4(%rbp)
jmp    1262 <execute+0xf2>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c0 <execute+0x50>
lea    0xe4f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    121e <execute+0xae>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execvp@plt>
lea    0xdff(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1223 <execute+0xb3>
jmp    1228 <execute+0xb8>
lea    -0x18(%rbp),%rdi
call   1080 <wait@plt>
cmp    -0x14(%rbp),%eax
jne    123f <execute+0xcf>
jmp    1244 <execute+0xd4>
jmp    1228 <execute+0xb8>
mov    -0x18(%rbp),%esi
sar    $0x8,%esi
mov    -0x18(%rbp),%edx
and    $0x7f,%edx
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbp
push   %rbx
push   %rax
cmpq   $0x0,(%rdi)
je     11ca <execute+0x5a>
mov    %rdi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11d3 <execute+0x63>
mov    %eax,%ebp
test   %eax,%eax
je     11dc <execute+0x6c>
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <wait@plt>
cmp    %ebp,%eax
jne    11a0 <execute+0x30>
mov    0x4(%rsp),%edx
mov    %edx,%esi
sar    $0x8,%esi
and    $0x7f,%edx
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    0x4(%rsp),%eax
jmp    11cc <execute+0x5c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe26(%rip),%rdi
jmp    1217 <execute+0xa7>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    0x2de4(%rip),%rbp
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1060 <execvp@plt>
lea    0xdf7(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"fork() failed\00"
@SIGINT = global i32 0
@SIG_DFL = global i32 0
@SIGQUIT = global i32 0
@.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 = load i8**, i8*** %3
%7 = getelementptr inbounds i8*, i8** %6, i64 0
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %50
11: ; preds = %1
%12 = call i32 (...) @fork()
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = load i32, i32* @SIGINT
%23 = load i32, i32* @SIG_DFL
%24 = call i32 @signal(i32 %22, i32 %23)
%25 = load i32, i32* @SIGQUIT
%26 = load i32, i32* @SIG_DFL
%27 = call i32 @signal(i32 %25, i32 %26)
%28 = load i8**, i8*** %3
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %3
%32 = call i32 @execvp(i8* %30, i8** %31)
%33 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %18
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36, %42
%38 = call i32 @wait(i32* %5)
%39 = load i32, i32* %4
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37
br label %43
42: ; preds = %37
br label %37
43: ; preds = %41
%44 = load i32, i32* %5
%45 = ashr i32 %44, 8
%46 = load i32, i32* %5
%47 = and i32 %46, 127
%48 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %47)
%49 = load i32, i32* %5
store i32 %49, i32* %2
br label %50
50: ; preds = %43, %10
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [14 x i8] c"fork() failed\00"
@SIGINT = global i32 0
@SIG_DFL = global i32 0
@SIGQUIT = global i32 0
@.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 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %31, label %6
6: ; preds = %1
%7 = tail call i32 (...) @fork()
switch i32 %7, label %22 [
i32 -1, label %8
i32 0, label %11
]
8: ; preds = %6
%9 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %6
%12 = load i32, i32* @SIGINT
%13 = load i32, i32* @SIG_DFL
%14 = tail call i32 @signal(i32 %12, i32 %13)
%15 = load i32, i32* @SIGQUIT
%16 = load i32, i32* @SIG_DFL
%17 = tail call i32 @signal(i32 %15, i32 %16)
%18 = load i8*, i8** %0
%19 = tail call i32 @execvp(i8* %18, i8** %0)
%20 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %6, %22
%23 = call i32 @wait(i32* %2)
%24 = icmp eq i32 %23, %7
br i1 %24, label %25, label %22
25: ; preds = %22
%26 = load i32, i32* %2
%27 = ashr i32 %26, 8
%28 = and i32 %26, 127
%29 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28)
%30 = load i32, i32* %2
br label %31
31: ; preds = %1, %25
%32 = phi i32 [ %30, %25 ], [ 0, %1 ]
ret i32 %32
}