#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(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ prepGusintah(char *);
int setpgid(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void runBackGround(int num, char *process) {
  pid_t pid = fork();
  int r;
  if (pid < 0) {
    fprintf(stderr, "fork failed for background\n");
    exit(1);
  }
  if (pid == 0) {
    r = setpgid(0, 0);
    prepGusintah(process);
    exit(1);
  } else {
    r = setpgid(pid, 0);
    fprintf(stderr, "[%d] %d\n", num, pid);
  }
}


x86 assembly (clang, -O0):
<runBackGround>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1196 <runBackGround+0x46>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11c2 <runBackGround+0x72>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1050 <setpgid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <prepGusintah@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <setpgid@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runBackGround>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1194 <runBackGround+0x44>
je     11b5 <runBackGround+0x65>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <setpgid@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <setpgid@plt>
mov    %r14,%rdi
call   1030 <prepGusintah@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"fork failed for background\0A\00"
@.str.1 = [9 x i8] c"[%d] %d\0A\00"
define void @runBackGround(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = call i64 (...) @fork()
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i64, i64* %5
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = call i32 @setpgid(i64 0, i32 0)
store i32 %18, i32* %6
%19 = load i8*, i8** %4
%20 = call i32 @prepGusintah(i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i64, i64* %5
%24 = call i32 @setpgid(i64 %23, i32 0)
store i32 %24, i32* %6
%25 = load i32, i32* @stderr
%26 = load i32, i32* %3
%27 = load i64, i64* %5
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %26, i64 %27)
br label %29
29: ; preds = %22
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"fork failed for background\0A\00"
@.str.1 = [9 x i8] c"[%d] %d\0A\00"
define void @runBackGround(i32 %0, i8* %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = icmp eq i64 %3, 0
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = tail call i32 @setpgid(i64 0, i32 0)
%13 = tail call i32 @prepGusintah(i8* %1)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = tail call i32 @setpgid(i64 %3, i32 0)
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %0, i64 %3)
ret void
}