#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 */
struct threadpool_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ tpool_exit(struct threadpool_t *);
struct threadpool_t *tpool_init(int, int);
int test_1() {
  printf("[+] Test-1: START\n");
  struct threadpool_t *pool;
  if ((pool = tpool_init(128, 1000)) == NULL) {
    printf("  [!] ERROR: POOL == NULL\n");
    return 1;
  }
  printf("  [*] Created threadpool_t with %d threads and queue size of %d\n",
         128, 1000);
  if (tpool_exit(pool)) {
    printf("  [!] ERROR: FREE POOL FAILURE\n");
    return 1;
  }
  printf(
      "  [*] Shutting down threadpool_t with %d threads and queue size of %d\n",
      128, 1000);
  printf("[+] Test-1: SUCCESSFUL\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x80,%edi
mov    $0x3e8,%esi
call   1040 <tpool_init@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    117d <test_1+0x4d>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ef <test_1+0xbf>
lea    0xeaa(%rip),%rdi
mov    $0x80,%esi
mov    $0x3e8,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <tpool_exit@plt>
cmp    $0x0,%rax
je     11c2 <test_1+0x92>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ef <test_1+0xbf>
lea    0xec6(%rip),%rdi
mov    $0x80,%esi
mov    $0x3e8,%edx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_1>:
push   %rbp
push   %rbx
push   %rax
lea    0xf3e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x80,%edi
mov    $0x3e8,%esi
call   1050 <tpool_init@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1199 <test_1+0x59>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
mov    $0x80,%esi
mov    $0x3e8,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <tpool_exit@plt>
test   %rax,%rax
je     11a2 <test_1+0x62>
lea    0xf1a(%rip),%rdi
jmp    11c3 <test_1+0x83>
lea    0xf30(%rip),%rdi
jmp    11c3 <test_1+0x83>
lea    0xe98(%rip),%rdi
mov    $0x80,%esi
mov    $0x3e8,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
xor    %ebp,%ebp
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.threadpool_t = type { i32 }
@.str = [19 x i8] c"[+] Test-1: START\0A\00"
@.str.1 = [27 x i8] c" [!] ERROR: POOL == NULL\0A\00"
@.str.2 = [65 x i8] c" [*] Created threadpool_t with %d threads and queue size of %d\0A\00"
@.str.3 = [32 x i8] c" [!] ERROR: FREE POOL FAILURE\0A\00"
@.str.4 = [71 x i8] c" [*] Shutting down threadpool_t with %d threads and queue size of %d\0A\00"
@.str.5 = [24 x i8] c"[+] Test-1: SUCCESSFUL\0A\00"
define i32 @test_1() {
%1 = alloca i32
%2 = alloca %struct.threadpool_t*
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = call %struct.threadpool_t* @tpool_init(i32 128, i32 1000)
store %struct.threadpool_t* %4, %struct.threadpool_t** %2
%5 = icmp eq %struct.threadpool_t* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %18
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i32 128, i32 1000)
%10 = load %struct.threadpool_t*, %struct.threadpool_t** %2
%11 = call i64 @tpool_exit(%struct.threadpool_t* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %18
15: ; preds = %8
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0), i32 128, i32 1000)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %18
18: ; preds = %15, %13, %6
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
%struct.threadpool_t = type { i32 }
@.str.2 = [65 x i8] c" [*] Created threadpool_t with %d threads and queue size of %d\0A\00"
@.str.4 = [71 x i8] c" [*] Shutting down threadpool_t with %d threads and queue size of %d\0A\00"
@str = [18 x i8] c"[+] Test-1: START\00"
@str.6 = [23 x i8] c"[+] Test-1: SUCCESSFUL\00"
@str.7 = [31 x i8] c" [!] ERROR: FREE POOL FAILURE\00"
@str.8 = [26 x i8] c" [!] ERROR: POOL == NULL\00"
define i32 @test_1() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%2 = tail call %struct.threadpool_t* @tpool_init(i32 128, i32 1000)
%3 = icmp eq %struct.threadpool_t* %2, null
br i1 %3, label %10, label %4
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i32 128, i32 1000)
%6 = tail call i64 @tpool_exit(%struct.threadpool_t* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0), i32 128, i32 1000)
br label %10
10: ; preds = %4, %0, %8
%11 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0), %8 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0), %0 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @str.7, i64 0, i64 0), %4 ]
%12 = phi i32 [ 0, %8 ], [ 1, %0 ], [ 1, %4 ]
%13 = tail call i32 @puts(i8* dereferenceable(1) %11)
ret i32 %12
}