#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int run(char **param) {
  pid_t p = fork();
  if (p < 0) {
    printf("cannot fork process");
    return 1;
  } else if (p == 0) {
    execvp(param[0], param);
    return 0;
  } else {
    int c;
    waitpid(p, &c, 0);
    return 1;
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    117a <run+0x3a>
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b7 <run+0x77>
cmpq   $0x0,-0x18(%rbp)
jne    11a1 <run+0x61>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <execvp@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <run+0x77>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     1167 <run+0x27>
je     117a <run+0x3a>
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <waitpid@plt>
jmp    1173 <run+0x33>
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
jmp    1187 <run+0x47>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"cannot fork process\00"
define i32 @run(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i32
store i8** %0, i8*** %3
%6 = call i64 (...) @fork()
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %23
11: ; preds = %1
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %3
%19 = call i32 @execvp(i8* %17, i8** %18)
store i32 0, i32* %2
br label %23
20: ; preds = %11
%21 = load i64, i64* %4
%22 = call i32 @waitpid(i64 %21, i32* %5, i32 0)
store i32 1, i32* %2
br label %23
23: ; preds = %20, %14, %9
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [20 x i8] c"cannot fork process\00"
define i32 @run(i8** %0) {
%2 = alloca i32
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = icmp eq i64 %3, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = load i8*, i8** %0
%11 = tail call i32 @execvp(i8* %10, i8** %0)
br label %15
12: ; preds = %7
%13 = bitcast i32* %2 to i8*
%14 = call i32 @waitpid(i64 %3, i32* %2, i32 0)
br label %15
15: ; preds = %12, %9, %5
%16 = phi i32 [ 1, %5 ], [ 0, %9 ], [ 1, %12 ]
ret i32 %16
}