// File: /workspace/github_c_makefile_star2_O0/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/utility/threadpool/threadpool.c
// Function: threadpool_create
threadpool_t *threadpool_create(int thread_count, int queue_size, int flags)
{
    threadpool_t *pool;
    int i;
    (void) flags;

    if(thread_count <= 0 || thread_count > MAX_THREADS || queue_size <= 0 || queue_size > MAX_QUEUE) {
        return NULL;
    }

    if((pool = (threadpool_t *)malloc(sizeof(threadpool_t))) == NULL) {
        goto err;
    }

    /* Initialize */
    pool->thread_count = 0;
    pool->queue_size = queue_size;
    pool->head = pool->tail = pool->count = 0;
    pool->shutdown = pool->started = 0;

    /* Allocate thread and task queue */
    pool->threads = (pthread_t *)malloc(sizeof(pthread_t) * thread_count);
    pool->queue = (threadpool_task_t *)malloc
        (sizeof(threadpool_task_t) * queue_size);

    /* Initialize mutex and conditional variable first */
    if((pthread_mutex_init(&(pool->lock), NULL) != 0) ||
       (pthread_cond_init(&(pool->notify), NULL) != 0) ||
       (pool->threads == NULL) ||
       (pool->queue == NULL)) {
        goto err;
    }

    /* Start worker threads */
    for(i = 0; i < thread_count; i++) {
        if(pthread_create(&(pool->threads[i]), NULL,
                          threadpool_thread, (void*)pool) != 0) {
            threadpool_destroy(pool, 0);
            return NULL;
        }
        pool->thread_count++;
        pool->started++;
    }

    return pool;

 err:
    if(pool) {
        threadpool_free(pool);
    }
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpl $0x0, -0xc(%rbp)
jle 0xce8c
cmpl $0x40, -0xc(%rbp)
jg 0xce8c
cmpl $0x0, -0x10(%rbp)
jle 0xce8c
cmpl $0x10000, -0x10(%rbp)   # imm = 0x10000
jle 0xce99
movq $0x0, -0x8(%rbp)
jmp 0xd011
movl $0x88, %edi
callq 0x4798
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0xceb2
jmp 0xcff9
movq -0x20(%rbp), %rax
movl $0x0, 0x68(%rax)
movl -0x10(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x78(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x74(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x70(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x80(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x7c(%rax)
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
callq 0x4798
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x58(%rax)
movslq -0x10(%rbp), %rdi
shlq $0x4, %rdi
callq 0x4798
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4750
cmpl $0x0, %eax
jne 0xcf6f
movq -0x20(%rbp), %rdi
addq $0x28, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4450
cmpl $0x0, %eax
jne 0xcf6f
movq -0x20(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0xcf6f
movq -0x20(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0xcf74
jmp 0xcff9
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xcfef
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rdi
movslq -0x24(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0x7b(%rip), %rdx        # 0xd020
callq 0x4590
cmpl $0x0, %eax
je 0xcfc4
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x4650
movq $0x0, -0x8(%rbp)
jmp 0xd011
movq -0x20(%rbp), %rax
movl 0x68(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x68(%rax)
movq -0x20(%rbp), %rax
movl 0x80(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x80(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xcf7b
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xd011
cmpq $0x0, -0x20(%rbp)
je 0xd009
movq -0x20(%rbp), %rdi
callq 0x4420
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)