#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_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_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     11a4 <main+0x44>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <main+0x157>
mov    $0xa,%edi
mov    $0x2710,%esi
call   1080 <test_jobs@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e1 <main+0x81>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <main+0x157>
mov    $0x0,%al
call   1070 <test_busydestroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1216 <main+0xb6>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <main+0x157>
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     125d <main+0xfd>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <main+0x157>
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     12a4 <main+0x144>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <main+0x157>
lea    0xd92(%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     117e <main+0x1e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
jmp    11be <main+0x5e>
mov    $0xa,%edi
mov    $0x2710,%esi
call   1080 <test_jobs@plt>
test   %eax,%eax
je     11a3 <main+0x43>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
jmp    11be <main+0x5e>
xor    %eax,%eax
call   1070 <test_busydestroy@plt>
test   %eax,%eax
je     11cc <main+0x6c>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1060 <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    120b <main+0xab>
mov    $0x3,%edi
mov    $0xa,%esi
mov    $0x5,%edx
mov    $0x1388,%ecx
call   1050 <test_threaded_addjob@plt>
test   %eax,%eax
je     1222 <main+0xc2>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11c8 <main+0x68>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    11c8 <main+0x68>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"test_init failed\0A\00"
@.str.1 = [18 x i8] c"test_jobs failed\0A\00"
@.str.2 = [25 x i8] c"test_busydestroy failed\0A\00"
@.str.3 = [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 %39
9: ; preds = %0
%10 = call i32 @test_jobs(i32 10, i32 10000)
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 %39
16: ; preds = %9
%17 = call i32 (...) @test_busydestroy()
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 ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %39
23: ; preds = %16
%24 = call i32 @test_threaded_addjob(i32 1, i32 10, i32 5, i32 5000)
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 ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %39
30: ; preds = %23
%31 = call i32 @test_threaded_addjob(i32 3, 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.1, i64 0, i64 0))
store i32 1, i32* %1
br label %39
37: ; preds = %30
%38 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %39
39: ; preds = %37, %34, %27, %20, %13, %6
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"test_init failed\0A\00"
@.str.1 = [18 x i8] c"test_jobs failed\0A\00"
@.str.2 = [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 %32
6: ; preds = %0
%7 = tail call i32 @test_jobs(i32 10, i32 10000)
%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 %32
12: ; preds = %6
%13 = tail call i32 (...) @test_busydestroy()
%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 ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %32
18: ; preds = %12
%19 = tail call i32 @test_threaded_addjob(i32 1, i32 10, i32 5, i32 5000)
%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 ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %32
24: ; preds = %18
%25 = tail call i32 @test_threaded_addjob(i32 3, 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.1, i64 0, i64 0))
br label %32
30: ; preds = %24
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %27, %21, %15, %9, %3
%33 = phi i32 [ 1, %3 ], [ 1, %9 ], [ 1, %15 ], [ 1, %21 ], [ 1, %27 ], [ 0, %30 ]
ret i32 %33
}