#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*/ EXIT_FAILURE;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int wait(int *);
extern int execute(char **arglist) {
  if (arglist[0] == NULL)
    return 0;
  int pid = fork();
  int child_status = -1;
  if (pid == -1) {
    perror("fork");
    return child_status;
  } else if (pid == 0) {
    signal(SIGINT, SIG_DFL);
    signal(SIGQUIT, SIG_DFL);
    execvp(arglist[0], arglist);
    perror("cannot execute command");
    exit(EXIT_FAILURE);
  } else {
    signal(SIGINT, SIG_IGN);
    signal(SIGQUIT, SIG_IGN);
    if (wait(&child_status) == -1)
      perror("wait");
    signal(SIGINT, SIG_DFL);
    signal(SIGQUIT, SIG_DFL);
    return child_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    1186 <execute+0x26>
movl   $0x0,-0x4(%rbp)
jmp    129a <execute+0x13a>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b8 <execute+0x58>
lea    0xe58(%rip),%rdi
call   1040 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    129a <execute+0x13a>
cmpl   $0x0,-0x14(%rbp)
jne    121a <execute+0xba>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <execvp@plt>
lea    0xdfe(%rip),%rdi
call   1040 <perror@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
lea    -0x18(%rbp),%rdi
call   1070 <wait@plt>
cmp    $0xffffffff,%eax
jne    1266 <execute+0x106>
lea    0xdbb(%rip),%rdi
call   1040 <perror@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@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   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmpq   $0x0,(%rdi)
je     11e7 <execute+0x87>
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
movl   $0xffffffff,0xc(%rsp)
ff
cmp    $0xffffffff,%eax
je     11f3 <execute+0x93>
test   %eax,%eax
je     1214 <execute+0xb4>
mov    0x2e53(%rip),%r14
mov    (%r14),%edi
mov    0x2e39(%rip),%rbx
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    0x2e33(%rip),%r15
mov    (%r15),%edi
mov    (%rbx),%esi
call   1030 <signal@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    $0xffffffff,%eax
je     1206 <execute+0xa6>
mov    (%r14),%edi
mov    0x2df0(%rip),%rbx
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    (%r15),%edi
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    0xc(%rsp),%eax
jmp    11e9 <execute+0x89>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe06(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    11e9 <execute+0x89>
lea    0xe0f(%rip),%rdi
call   1040 <perror@plt>
jmp    11c6 <execute+0x66>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    0x2d9c(%rip),%r14
mov    (%r14),%esi
call   1030 <signal@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1030 <signal@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
lea    0xdb6(%rip),%rdi
call   1040 <perror@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@SIGINT = global i32 0
@SIG_DFL = global i32 0
@SIGQUIT = global i32 0
@.str.1 = [23 x i8] c"cannot execute command\00"
@EXIT_FAILURE = global i32 0
@SIG_IGN = global i32 0
@.str.2 = [5 x i8] c"wait\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 %55
11: ; preds = %1
%12 = call i32 (...) @fork()
store i32 %12, i32* %4
store i32 -1, i32* %5
%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 ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %5
store i32 %17, i32* %2
br label %55
18: ; preds = %11
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %36
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 ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %18
%37 = load i32, i32* @SIGINT
%38 = load i32, i32* @SIG_IGN
%39 = call i32 @signal(i32 %37, i32 %38)
%40 = load i32, i32* @SIGQUIT
%41 = load i32, i32* @SIG_IGN
%42 = call i32 @signal(i32 %40, i32 %41)
%43 = call i32 @wait(i32* %5)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %36
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %36
%48 = load i32, i32* @SIGINT
%49 = load i32, i32* @SIG_DFL
%50 = call i32 @signal(i32 %48, i32 %49)
%51 = load i32, i32* @SIGQUIT
%52 = load i32, i32* @SIG_DFL
%53 = call i32 @signal(i32 %51, i32 %52)
%54 = load i32, i32* %5
store i32 %54, i32* %2
br label %55
55: ; preds = %47, %15, %10
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@SIGINT = global i32 0
@SIG_DFL = global i32 0
@SIGQUIT = global i32 0
@.str.1 = [23 x i8] c"cannot execute command\00"
@EXIT_FAILURE = global i32 0
@SIG_IGN = global i32 0
@.str.2 = [5 x i8] c"wait\00"
define i32 @execute(i8** %0) {
%2 = alloca i32
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %43, label %5
5: ; preds = %1
%6 = tail call i32 (...) @fork()
%7 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
switch i32 %6, label %22 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %5
%9 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %41
10: ; preds = %5
%11 = load i32, i32* @SIGINT
%12 = load i32, i32* @SIG_DFL
%13 = tail call i32 @signal(i32 %11, i32 %12)
%14 = load i32, i32* @SIGQUIT
%15 = load i32, i32* @SIG_DFL
%16 = tail call i32 @signal(i32 %14, i32 %15)
%17 = load i8*, i8** %0
%18 = tail call i32 @execvp(i8* %17, i8** %0)
%19 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %5
%23 = load i32, i32* @SIGINT
%24 = load i32, i32* @SIG_IGN
%25 = tail call i32 @signal(i32 %23, i32 %24)
%26 = load i32, i32* @SIGQUIT
%27 = load i32, i32* @SIG_IGN
%28 = tail call i32 @signal(i32 %26, i32 %27)
%29 = call i32 @wait(i32* %2)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %22
%34 = load i32, i32* @SIGINT
%35 = load i32, i32* @SIG_DFL
%36 = call i32 @signal(i32 %34, i32 %35)
%37 = load i32, i32* @SIGQUIT
%38 = load i32, i32* @SIG_DFL
%39 = call i32 @signal(i32 %37, i32 %38)
%40 = load i32, i32* %2
br label %41
41: ; preds = %33, %8
%42 = phi i32 [ %40, %33 ], [ -1, %8 ]
br label %43
43: ; preds = %1, %41
%44 = phi i32 [ %42, %41 ], [ 0, %1 ]
ret i32 %44
}