#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*/ 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*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int wait(int *);
int execute(char *argv[]) {
  int pid;
  int child_info = -1;
  if (argv[0] == NULL)
    return 0;
  if ((pid = fork()) == -1)
    perror("fork");
  else if (pid == 0) {
    signal(SIGINT, SIG_DFL);
    signal(SIGQUIT, SIG_DFL);
    execvp(argv[0], argv);
    perror("cannot execute command");
    exit(1);
  } else {
    if (wait(&child_info) == -1)
      perror("wait");
  }
  return child_info;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    118d <execute+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    123d <execute+0xdd>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11b1 <execute+0x51>
lea    0xe59(%rip),%rdi
call   1040 <perror@plt>
jmp    1237 <execute+0xd7>
cmpl   $0x0,-0x14(%rbp)
jne    120f <execute+0xaf>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%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    0xe05(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1070 <wait@plt>
cmp    $0xffffffff,%eax
jne    122d <execute+0xcd>
lea    0xdf4(%rip),%rdi
call   1040 <perror@plt>
jmp    1232 <execute+0xd2>
jmp    1237 <execute+0xd7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %r14
push   %rbx
push   %rax
movl   $0xffffffff,0x4(%rsp)
ff
cmpq   $0x0,(%rdi)
je     119a <execute+0x3a>
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11a4 <execute+0x44>
test   %eax,%eax
je     11bb <execute+0x5b>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
cmp    $0xffffffff,%eax
je     11ad <execute+0x4d>
mov    0x4(%rsp),%eax
jmp    119c <execute+0x3c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe55(%rip),%rdi
jmp    11b4 <execute+0x54>
lea    0xe68(%rip),%rdi
call   1040 <perror@plt>
jmp    1194 <execute+0x34>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%r14
mov    (%r14),%esi
call   1030 <signal@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1030 <signal@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
lea    0xe0f(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%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"
@.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
store i32 -1, i32* %5
%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 %42
11: ; preds = %1
%12 = call i32 (...) @fork()
store i32 %12, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %40
16: ; preds = %11
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = load i32, i32* @SIGINT
%21 = load i32, i32* @SIG_DFL
%22 = call i32 @signal(i32 %20, i32 %21)
%23 = load i32, i32* @SIGQUIT
%24 = load i32, i32* @SIG_DFL
%25 = call i32 @signal(i32 %23, i32 %24)
%26 = load i8**, i8*** %3
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %3
%30 = call i32 @execvp(i8* %28, i8** %29)
%31 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %16
%34 = call i32 @wait(i32* %5)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39, %14
%41 = load i32, i32* %5
store i32 %41, i32* %2
br label %42
42: ; preds = %40, %10
%43 = load i32, i32* %2
ret i32 %43
}

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"
@.str.2 = [5 x i8] c"wait\00"
define i32 @execute(i8** %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %28, label %6
6: ; preds = %1
%7 = tail call i32 (...) @fork()
switch i32 %7, label %21 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %6
%9 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %26
10: ; preds = %6
%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 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %6
%22 = call i32 @wait(i32* %2)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %21, %8
%27 = load i32, i32* %2
br label %28
28: ; preds = %1, %26
%29 = phi i32 [ %27, %26 ], [ 0, %1 ]
ret i32 %29
}