#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*/ _log(int, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int execv(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int waitpid(int, int *, int /*<<< orphan*/);
int run(char **argv) {
  int child, status, pid;
  if (child = fork()) {
    do
      pid = waitpid(child, &status, 0);
    while (pid != child);
  } else {
    int x = execv(argv[0], argv);
    _log(1, "failed to execute %s: %s\n", argv[0], strerror(errno));
    exit(x);
  }
  return status;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     11a6 <run+0x46>
jmp    1184 <run+0x24>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1184 <run+0x24>
jmp    11f1 <run+0x91>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <execv@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xe1c(%rip),%rsi
call   1030 <_log@plt>
mov    -0x18(%rbp),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     119b <run+0x3b>
mov    %eax,%ebp
lea    0x4(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    %ebp,%eax
jne    1180 <run+0x20>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1070 <execv@plt>
mov    %eax,%ebp
mov    (%rbx),%rbx
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe40(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1030 <_log@plt>
mov    %ebp,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"failed to execute %s: %s\0A\00"
@errno = global i32 0
define i32 @run(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %2
%7 = call i32 (...) @fork()
store i32 %7, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %1
br label %10
10: ; preds = %13, %9
%11 = load i32, i32* %3
%12 = call i32 @waitpid(i32 %11, i32* %4, i32 0)
store i32 %12, i32* %5
br label %13
13: ; preds = %10
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp ne i32 %14, %15
br i1 %16, label %10, label %17
17: ; preds = %13
br label %32
18: ; preds = %1
%19 = load i8**, i8*** %2
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %2
%23 = call i32 @execv(i8* %21, i8** %22)
store i32 %23, i32* %6
%24 = load i8**, i8*** %2
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i32, i32* @errno
%28 = call i32 @strerror(i32 %27)
%29 = call i32 @_log(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %28)
%30 = load i32, i32* %6
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %17
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [26 x i8] c"failed to execute %s: %s\0A\00"
@errno = global i32 0
define i32 @run(i8** %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1, %6
%7 = call i32 @waitpid(i32 %4, i32* %2, i32 0)
%8 = icmp eq i32 %7, %4
br i1 %8, label %17, label %6
9: ; preds = %1
%10 = load i8*, i8** %0
%11 = tail call i32 @execv(i8* %10, i8** %0)
%12 = load i8*, i8** %0
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @_log(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %14)
%16 = tail call i32 @exit(i32 %11)
unreachable
17: ; preds = %6
%18 = load i32, i32* %2
ret i32 %18
}