// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/bio.c
// Function: bioProcessBackgroundJobs
void *bioProcessBackgroundJobs(void *arg) {
    struct bio_job *job;
    unsigned long type = (unsigned long) arg;
    sigset_t sigset;

    /* Check that the type is within the right interval. */
    if (type >= BIO_NUM_OPS) {
        serverLog(LL_WARNING,
            "Warning: bio thread started with wrong type %lu",type);
        return NULL;
    }

    /* Make the thread killable at any time, so that bioKillThreads()
     * can work reliably. */
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

    pthread_mutex_lock(&bio_mutex[type]);
    /* Block SIGALRM so we are sure that only the main thread will
     * receive the watchdog signal. */
    sigemptyset(&sigset);
    sigaddset(&sigset, SIGALRM);
    if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
        serverLog(LL_WARNING,
            "Warning: can't mask SIGALRM in bio.c thread: %s", strerror(errno));

    while(1) {
        listNode *ln;

        /* The loop always starts with the lock hold. */
        if (listLength(bio_jobs[type]) == 0) {
            pthread_cond_wait(&bio_condvar[type],&bio_mutex[type]);
            continue;
        }
        /* Pop the job from the queue. */
        ln = listFirst(bio_jobs[type]);
        job = ln->value;
        /* It is now possible to unlock the background system as we know have
         * a stand alone job structure to process.*/
        pthread_mutex_unlock(&bio_mutex[type]);

        /* Process the job accordingly to its type. */
        if (type == BIO_CLOSE_FILE) {
            close((long)job->arg1);
        } else if (type == BIO_AOF_FSYNC) {
            aof_fsync((long)job->arg1);
        } else {
            serverPanic("Wrong job type in bioProcessBackgroundJobs().");
        }
        zfree(job);

        /* Lock again before reiterating the loop, if there are no longer
         * jobs to process we'll block again in pthread_cond_wait(). */
        pthread_mutex_lock(&bio_mutex[type]);
        listDelNode(bio_jobs[type],ln);
        bio_pending[type]--;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
cmpq $0x2, %rdi
jb 0x72449
leaq 0x58d22(%rip), %rsi     # 0xcb148
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2fdad
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
xorl %esi, %esi
callq 0x26050
movl $0x1, %edi
xorl %esi, %esi
callq 0x26610
leaq (%rbx,%rbx,4), %rax
leaq 0xa4177(%rip), %rcx     # 0x1165e0
leaq (%rcx,%rax,8), %r14
movq %r14, %rdi
callq 0x26b20
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x26ac0
movq %r15, %rdi
movl $0xe, %esi
callq 0x268c0
xorl %edi, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x26170
testl %eax, %eax
je 0x724c1
callq 0x26880
movl (%rax), %edi
callq 0x26680
leaq 0x58cc6(%rip), %rsi     # 0xcb178
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
leaq (%rbx,%rbx,2), %rax
shlq $0x4, %rax
leaq 0xa4160(%rip), %r15     # 0x116630
addq %rax, %r15
leaq 0xa41b6(%rip), %rbp     # 0x116690
movq (%rbp,%rbx,8), %rax
cmpq $0x0, 0x28(%rax)
je 0x72506
movq (%rax), %r12
movq 0x10(%r12), %r13
movq %r14, %rdi
callq 0x26c30
movl 0x8(%r13), %edi
testq %rbx, %rbx
je 0x72513
callq 0x26570
jmp 0x72518
movq %r15, %rdi
movq %r14, %rsi
callq 0x26980
jmp 0x724da
callq 0x26180
movq %r13, %rdi
callq 0x38413
movq %r14, %rdi
callq 0x26b20
movq (%rbp,%rbx,8), %rdi
movq %r12, %rsi
callq 0x2b331
leaq 0xa4164(%rip), %rax     # 0x1166a0
decq (%rax,%rbx,8)
jmp 0x724da