#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*/ err_sys(char *);
int /*<<< orphan*/ execv(char *, char **);
scalar_t__ vfork();
int /*<<< orphan*/ wait(int *);
void run_command(char *command, char *argv[]) {
  pid_t pid;
  int status;
  if ((pid = vfork()) < 0) {
    err_sys("fork error");
  } else if (pid > 0) {
    wait(&status);
  } else {
    execv(command, argv);
  }
}


x86 assembly (clang, -O0):
<run_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <vfork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1176 <run_command+0x36>
lea    0xe94(%rip),%rdi
call   1030 <err_sys@plt>
jmp    11a1 <run_command+0x61>
cmpq   $0x0,-0x18(%rbp)
jle    118f <run_command+0x4f>
lea    -0x1c(%rbp),%rdi
call   1050 <wait@plt>
jmp    119c <run_command+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execv@plt>
jmp    11a1 <run_command+0x61>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_command>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <vfork@plt>
test   %rax,%rax
js     116a <run_command+0x2a>
je     117d <run_command+0x3d>
lea    0x4(%rsp),%rdi
call   1050 <wait@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe8f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <err_sys@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <execv@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"fork error\00"
define void @run_command(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = call i64 (...) @vfork()
store i64 %7, i64* %5
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %21
11: ; preds = %2
%12 = load i64, i64* %5
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @wait(i32* %6)
br label %20
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i8**, i8*** %4
%19 = call i32 @execv(i8* %17, i8** %18)
br label %20
20: ; preds = %16, %14
br label %21
21: ; preds = %20, %9
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"fork error\00"
define void @run_command(i8* %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @vfork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %15
9: ; preds = %2
%10 = icmp eq i64 %5, 0
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = call i32 @wait(i32* %3)
br label %15
13: ; preds = %9
%14 = tail call i32 @execv(i8* %0, i8** %1)
br label %15
15: ; preds = %11, %13, %7
ret void
}