#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*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
void run(char *argv0, char **argv) {
  int pid;
  pid = fork();
  switch (pid) {
  case -1:
    perror("fork");
    exit(1);
    break;
  case 0:
    break;
  default:
    wait(NULL);
    return;
  }
  execvp(argv0, argv);
  perror("argv0");
  exit(1);
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xffffffff,%eax
je     118e <run+0x3e>
jmp    117e <run+0x2e>
mov    -0x18(%rbp),%eax
test   %eax,%eax
je     11a4 <run+0x54>
jmp    11a9 <run+0x59>
lea    0xe6b(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11b8 <run+0x68>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <execvp@plt>
lea    0xe39(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<run>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1178 <run+0x28>
cmp    $0xffffffff,%eax
je     118c <run+0x3c>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <wait@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <execvp@plt>
lea    0xe7b(%rip),%rdi
jmp    1193 <run+0x43>
lea    0xe6d(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [6 x i8] c"argv0\00"
define void @run(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%6 = call i32 (...) @fork()
store i32 %6, i32* %5
%7 = load i32, i32* %5
switch i32 %7, label %12 [
i32 -1, label %8
i32 0, label %11
]
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %2
br label %14
12: ; preds = %2
%13 = call i32 @wait(i32* null)
ret void
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = load i8**, i8*** %4
%17 = call i32 @execvp(i8* %15, i8** %16)
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [6 x i8] c"argv0\00"
define void @run(i8* %0, i8** %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %7 [
i32 -1, label %4
i32 0, label %9
]
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = tail call i32 @wait(i32* null)
ret void
9: ; preds = %2
%10 = tail call i32 @execvp(i8* %0, i8** %1)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
}