#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 */
scalar_t__ fork();
int /*<<< orphan*/ primes(int);
int /*<<< orphan*/ tables(int);
int spawn(int j) {
  pid_t child_pid;
  child_pid = fork();
  if (child_pid != 0) {
    return child_pid;
  } else {
    if (j == 1) {
      tables(100);
    } else if (j == 2) {
      primes(100);
    }
    return child_pid;
  }
}


x86 assembly (clang, -O0):
<spawn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115d <spawn+0x2d>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1196 <spawn+0x66>
cmpl   $0x1,-0x8(%rbp)
jne    1176 <spawn+0x46>
mov    $0x64,%edi
call   1030 <tables@plt>
jmp    118f <spawn+0x5f>
cmpl   $0x2,-0x8(%rbp)
jne    118a <spawn+0x5a>
mov    $0x64,%edi
call   1050 <primes@plt>
jmp    118f <spawn+0x5f>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spawn>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fork@plt>
test   %rax,%rax
je     114e <spawn+0x1e>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0x2,%ebp
je     1164 <spawn+0x34>
cmp    $0x1,%ebp
jne    1145 <spawn+0x15>
mov    $0x64,%edi
call   1030 <tables@plt>
jmp    1145 <spawn+0x15>
mov    $0x64,%edi
call   1050 <primes@plt>
jmp    1145 <spawn+0x15>

LLVM IR (-O0):
define i32 @spawn(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 %0, i32* %3
%5 = call i64 (...) @fork()
store i64 %5, i64* %4
%6 = load i64, i64* %4
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i64, i64* %4
%10 = trunc i64 %9 to i32
store i32 %10, i32* %2
br label %25
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @tables(i32 100)
br label %22
16: ; preds = %11
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @primes(i32 100)
br label %21
21: ; preds = %19, %16
br label %22
22: ; preds = %21, %14
%23 = load i64, i64* %4
%24 = trunc i64 %23 to i32
store i32 %24, i32* %2
br label %25
25: ; preds = %22, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @spawn(i32 %0) {
%2 = tail call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = trunc i64 %2 to i32
br label %11
6: ; preds = %1
switch i32 %0, label %11 [
i32 1, label %7
i32 2, label %9
]
7: ; preds = %6
%8 = tail call i32 @tables(i32 100)
br label %11
9: ; preds = %6
%10 = tail call i32 @primes(i32 100)
br label %11
11: ; preds = %7, %9, %6, %4
%12 = phi i32 [ %5, %4 ], [ 0, %6 ], [ 0, %9 ], [ 0, %7 ]
ret i32 %12
}