#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int test_busydestroy();
int test_fork();
int test_init();
int test_jobs(int, int);
int test_threaded_addjob(int, int, int, int);
int main(void) {
  int ret;
  ret = test_init();
  if (ret != 0) {
    fprintf(stderr, "test_init failed\n");
    return 1;
  }
  ret = test_fork();
  if (ret != 0) {
    fprintf(stderr, "test_fork failed\n");
    return 1;
  }
  ret = test_jobs(10, 10000);
  if (ret != 0) {
    fprintf(stderr, "test_jobs failed\n");
    return 1;
  }
  ret = test_busydestroy();
  if (ret != 0) {
    fprintf(stderr, "test_busydestroy failed\n");
    return 1;
  }
  ret = test_threaded_addjob(1, 10, 5, 5000);
  if (ret != 0) {
    fprintf(stderr, "test_jobs failed\n");
    return 1;
  }
  ret = test_threaded_addjob(3, 10, 5, 5000);
  if (ret != 0) {
    fprintf(stderr, "test_jobs failed\n");
    return 1;
  }
  printf("success\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <test_init@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b4 <main+0x44>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x18c>
mov    $0x0,%al
call   1060 <test_fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e9 <main+0x79>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x18c>
mov    $0xa,%edi
mov    $0x2710,%esi
call   1090 <test_jobs@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1226 <main+0xb6>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x18c>
mov    $0x0,%al
call   1080 <test_busydestroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     125b <main+0xeb>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x18c>
mov    $0x1,%edi
mov    $0xa,%esi
mov    $0x5,%edx
mov    $0x1388,%ecx
call   1040 <test_threaded_addjob@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12a2 <main+0x132>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xd93(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x18c>
mov    $0x3,%edi
mov    $0xa,%esi
mov    $0x5,%edx
mov    $0x1388,%ecx
call   1040 <test_threaded_addjob@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12e9 <main+0x179>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x18c>
lea    0xd5f(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <test_init@plt>
test   %eax,%eax
je     118e <main+0x1e>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
jmp    11eb <main+0x7b>
xor    %eax,%eax
call   1060 <test_fork@plt>
test   %eax,%eax
je     11ab <main+0x3b>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
jmp    11eb <main+0x7b>
mov    $0xa,%edi
mov    $0x2710,%esi
call   1090 <test_jobs@plt>
test   %eax,%eax
je     11d0 <main+0x60>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
jmp    11eb <main+0x7b>
xor    %eax,%eax
call   1080 <test_busydestroy@plt>
test   %eax,%eax
je     11f9 <main+0x89>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0xa,%esi
mov    $0x5,%edx
mov    $0x1388,%ecx
call   1050 <test_threaded_addjob@plt>
test   %eax,%eax
jne    1238 <main+0xc8>
mov    $0x3,%edi
mov    $0xa,%esi
mov    $0x5,%edx
mov    $0x1388,%ecx
call   1050 <test_threaded_addjob@plt>
test   %eax,%eax
je     124f <main+0xdf>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11f5 <main+0x85>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    11f5 <main+0x85>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"test_init failed\0A\00"
@.str.1 = [18 x i8] c"test_fork failed\0A\00"
@.str.2 = [18 x i8] c"test_jobs failed\0A\00"
@.str.3 = [25 x i8] c"test_busydestroy failed\0A\00"
@.str.4 = [9 x i8] c"success\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @test_init()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %46
9: ; preds = %0
%10 = call i32 (...) @test_fork()
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %46
16: ; preds = %9
%17 = call i32 @test_jobs(i32 10, i32 10000)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %46
23: ; preds = %16
%24 = call i32 (...) @test_busydestroy()
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %46
30: ; preds = %23
%31 = call i32 @test_threaded_addjob(i32 1, i32 10, i32 5, i32 5000)
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %46
37: ; preds = %30
%38 = call i32 @test_threaded_addjob(i32 3, i32 10, i32 5, i32 5000)
store i32 %38, i32* %2
%39 = load i32, i32* %2
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %46
44: ; preds = %37
%45 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %46
46: ; preds = %44, %41, %34, %27, %20, %13, %6
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"test_init failed\0A\00"
@.str.1 = [18 x i8] c"test_fork failed\0A\00"
@.str.2 = [18 x i8] c"test_jobs failed\0A\00"
@.str.3 = [25 x i8] c"test_busydestroy failed\0A\00"
@str = [8 x i8] c"success\00"
define i32 @main() {
%1 = tail call i32 (...) @test_init()
%2 = icmp eq i32 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %38
6: ; preds = %0
%7 = tail call i32 (...) @test_fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %38
12: ; preds = %6
%13 = tail call i32 @test_jobs(i32 10, i32 10000)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %38
18: ; preds = %12
%19 = tail call i32 (...) @test_busydestroy()
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %38
24: ; preds = %18
%25 = tail call i32 @test_threaded_addjob(i32 1, i32 10, i32 5, i32 5000)
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %38
30: ; preds = %24
%31 = tail call i32 @test_threaded_addjob(i32 3, i32 10, i32 5, i32 5000)
%32 = icmp eq i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %38
36: ; preds = %30
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %36, %33, %27, %21, %15, %9, %3
%39 = phi i32 [ 1, %3 ], [ 1, %9 ], [ 1, %15 ], [ 1, %21 ], [ 1, %27 ], [ 1, %33 ], [ 0, %36 ]
ret i32 %39
}