#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*/ EXIT_FAILURE;
int /*<<< orphan*/ execvp(char const *, char *const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int fork_exec(const char *path, char *const *argv) {
  ;
  ;
  for (char *const *arg = argv; *arg != NULL; arg++) {
    ;
    ;
  }
  pid_t pid = fork();
  if (pid == 0) {
    execvp(path, argv);
    exit(EXIT_FAILURE);
  } else {
    return pid;
  }
}


x86 assembly (clang, -O0):
<fork_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     116c <fork_exec+0x3c>
jmp    115b <fork_exec+0x2b>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    1148 <fork_exec+0x18>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119d <fork_exec+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <execvp@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork_exec>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     114e <fork_exec+0x1e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <execvp@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define i32 @fork_exec(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = load i8**, i8*** %4
store i8** %7, i8*** %5
br label %8
8: ; preds = %13, %2
%9 = load i8**, i8*** %5
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8
br label %13
13: ; preds = %12
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i32 1
store i8** %15, i8*** %5
br label %8
16: ; preds = %8
%17 = call i64 (...) @fork()
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = load i8**, i8*** %4
%23 = call i32 @execvp(i8* %21, i8** %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
%27 = load i64, i64* %6
%28 = trunc i64 %27 to i32
ret i32 %28
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i32 @fork_exec(i8* %0, i8** %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @execvp(i8* %0, i8** %1)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = trunc i64 %3 to i32
ret i32 %10
}