#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 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 exceute command");
  } 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    117d <execute+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    1228 <execute+0xd8>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11a1 <execute+0x51>
lea    0xe69(%rip),%rdi
call   1040 <perror@plt>
jmp    1228 <execute+0xd8>
cmpl   $0x0,-0x14(%rbp)
jne    11fa <execute+0xaa>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%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    0xe15(%rip),%rdi
call   1040 <perror@plt>
jmp    1223 <execute+0xd3>
lea    -0x18(%rbp),%rdi
call   1060 <wait@plt>
cmp    $0xffffffff,%eax
jne    1218 <execute+0xc8>
lea    0xe09(%rip),%rdi
call   1040 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1228 <execute+0xd8>
jmp    1228 <execute+0xd8>
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     118a <execute+0x3a>
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1194 <execute+0x44>
cmp    $0xffffffff,%eax
je     11d1 <execute+0x81>
lea    0x4(%rsp),%rdi
call   1060 <wait@plt>
cmp    $0xffffffff,%eax
je     11df <execute+0x8f>
mov    0x4(%rsp),%eax
jmp    118c <execute+0x3c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%r14
mov    (%r14),%esi
call   1030 <signal@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1030 <signal@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
lea    0xe36(%rip),%rdi
jmp    11d8 <execute+0x88>
lea    0xe28(%rip),%rdi
call   1040 <perror@plt>
jmp    118c <execute+0x3c>
lea    0xe36(%rip),%rdi
call   1040 <perror@plt>
jmp    1184 <execute+0x34>

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 exceute 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 %40
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 %32
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))
br label %39
32: ; preds = %16
%33 = call i32 @wait(i32* %5)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = load i32, i32* %5
store i32 %38, i32* %2
br label %40
39: ; preds = %19
br label %40
40: ; preds = %10, %37, %39, %14
%41 = load i32, i32* %2
ret i32 %41
}

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 exceute 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 %27, label %6
6: ; preds = %1
%7 = tail call i32 (...) @fork()
switch i32 %7, label %20 [
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 %27
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))
br label %27
20: ; preds = %6
%21 = call i32 @wait(i32* %2)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %2
br label %27
27: ; preds = %8, %10, %1, %25
%28 = phi i32 [ %26, %25 ], [ 0, %1 ], [ undef, %10 ], [ undef, %8 ]
ret i32 %28
}