// File: /workspace/github_c_makefile_star2_O0/TeaInside[P]teavpn/src/third_party/thpool/thpool.c
// Function: thpool_init
struct thpool_* thpool_init(int num_threads){

	threads_on_hold   = 0;
	threads_keepalive = 1;

	if (num_threads < 0){
		num_threads = 0;
	}

	/* Make new thread pool */
	thpool_* thpool_p;
	thpool_p = (struct thpool_*)malloc(sizeof(struct thpool_));
	if (thpool_p == NULL){
		err("thpool_init(): Could not allocate memory for thread pool\n");
		return NULL;
	}
	thpool_p->num_threads_alive   = 0;
	thpool_p->num_threads_working = 0;

	/* Initialise the job queue */
	if (jobqueue_init(&thpool_p->__jobqueue) == -1){
		err("thpool_init(): Could not allocate memory for job queue\n");
		free(thpool_p);
		return NULL;
	}

	/* Make threads in pool */
	thpool_p->threads = (struct thread**)malloc(num_threads * sizeof(struct thread *));
	if (thpool_p->threads == NULL){
		err("thpool_init(): Could not allocate memory for threads\n");
		jobqueue_destroy(&thpool_p->__jobqueue);
		free(thpool_p);
		return NULL;
	}

	pthread_mutex_init(&(thpool_p->thcount_lock), NULL);
	pthread_cond_init(&thpool_p->threads_all_idle, NULL);

	/* Thread init */
	int n;
	for (n=0; n<num_threads; n++){
		thread_init(thpool_p, &thpool_p->threads[n], n);
#if THPOOL_DEBUG
			printf("THPOOL_DEBUG: Created thread %d in pool \n", n);
#endif
	}

	/* Wait for threads to initialize */
	while (thpool_p->num_threads_alive != num_threads) {}

	return thpool_p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0xc(%rbp)
movl $0x0, 0x5ce3(%rip)      # 0xe428
movl $0x1, 0x5cdd(%rip)      # 0xe42c
cmpl $0x0, -0xc(%rbp)
jge 0x875c
movl $0x0, -0xc(%rbp)
movl $0xb0, %edi
callq 0x22c0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x8796
movq 0x5880(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x2bbe(%rip), %rsi      # 0xb340
movb $0x0, %al
callq 0x2240
movq $0x0, -0x8(%rbp)
jmp 0x88b7
movq -0x18(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x18(%rbp), %rdi
addq $0x68, %rdi
callq 0x88d0
cmpl $-0x1, %eax
jne 0x87ec
movq 0x5833(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x2bab(%rip), %rsi      # 0xb37a
movb $0x0, %al
callq 0x2240
movq -0x18(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x88b7
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
callq 0x22c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x8845
movq 0x57e4(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x2b94(%rip), %rsi      # 0xb3b2
movb $0x0, %al
callq 0x2240
movq -0x18(%rbp), %rdi
addq $0x68, %rdi
callq 0x8960
movq -0x18(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x88b7
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x23e0
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22a0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x889f
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movslq -0x1c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl -0x1c(%rbp), %edx
callq 0x8990
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x886e
jmp 0x88a1
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0xc(%rbp), %eax
je 0x88af
jmp 0x88a1
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)