#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*/ WNOHANG;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
void _spawn_job(char *path, char **argv) {
  int status;
  pid_t pid;
  while ((pid = fork()) < 0)
    usleep(100);
  if (pid == 0) {
    close(1);
    close(2);
    execv(path, argv);
    exit(0);
  }
  waitpid(-1, &status, WNOHANG);
}


x86 assembly (clang, -O0):
<_spawn_job>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1194 <_spawn_job+0x34>
mov    $0x64,%edi
call   1080 <usleep@plt>
jmp    1170 <_spawn_job+0x10>
cmpq   $0x0,-0x20(%rbp)
jne    11c7 <_spawn_job+0x67>
mov    $0x1,%edi
call   1030 <close@plt>
mov    $0x2,%edi
call   1030 <close@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execv@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x14(%rbp),%rsi
call   1040 <waitpid@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_spawn_job>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jns    1188 <_spawn_job+0x28>
mov    $0x64,%edi
call   1080 <usleep@plt>
jmp    1170 <_spawn_job+0x10>
test   %rax,%rax
je     11ad <_spawn_job+0x4d>
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rsi
mov    $0xffffffff,%edi
call   1040 <waitpid@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%edi
call   1030 <close@plt>
mov    $0x2,%edi
call   1030 <close@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <execv@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@WNOHANG = global i32 0
define void @_spawn_job(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
br label %7
7: ; preds = %10, %2
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @usleep(i32 100)
br label %7
12: ; preds = %7
%13 = load i64, i64* %6
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = call i32 @close(i32 1)
%17 = call i32 @close(i32 2)
%18 = load i8*, i8** %3
%19 = load i8**, i8*** %4
%20 = call i32 @execv(i8* %18, i8** %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %12
%23 = load i32, i32* @WNOHANG
%24 = call i32 @waitpid(i32 -1, i32* %5, i32 %23)
ret void
}

LLVM IR (-O2):
@WNOHANG = global i32 0
define void @_spawn_job(i8* %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2, %7
%8 = tail call i32 @usleep(i32 100)
%9 = tail call i64 (...) @fork()
%10 = icmp slt i64 %9, 0
br i1 %10, label %7, label %11
11: ; preds = %7, %2
%12 = phi i64 [ %5, %2 ], [ %9, %7 ]
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = tail call i32 @close(i32 1)
%16 = tail call i32 @close(i32 2)
%17 = tail call i32 @execv(i8* %0, i8** %1)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %11
%20 = load i32, i32* @WNOHANG
%21 = call i32 @waitpid(i32 -1, i32* %3, i32 %20)
ret void
}