// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/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_newjob_cond[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);

        /* Unblock threads blocked on bioWaitStepOfType() if any. */
        pthread_cond_broadcast(&bio_step_cond[type]);

        /* 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 0x2f393
leaq 0x28139(%rip), %rsi     # 0x574a9
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x19fb1
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 0x12290
movl $0x1, %edi
xorl %esi, %esi
callq 0x127d0
leaq (%rbx,%rbx,4), %rax
leaq 0x541fd(%rip), %rcx     # 0x835b0
leaq (%rcx,%rax,8), %r14
movq %r14, %rdi
callq 0x12960
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x124f0
movq %r15, %rdi
movl $0xe, %esi
callq 0x12920
xorl %edi, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x12640
testl %eax, %eax
je 0x2f40b
callq 0x120d0
movl (%rax), %edi
callq 0x128f0
leaq 0x280dd(%rip), %rsi     # 0x574d9
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x19fb1
movq %rbx, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
leaq 0x54243(%rip), %r15     # 0x83660
addq %rax, %r15
leaq 0x541d9(%rip), %rcx     # 0x83600
addq %rax, %rcx
movq %rcx, (%rsp)
leaq 0x5428b(%rip), %r12     # 0x836c0
movq (%r12,%rbx,8), %rax
cmpq $0x0, 0x28(%rax)
je 0x2f45e
movq (%rax), %r13
movq 0x10(%r13), %rbp
movq %r14, %rdi
callq 0x125c0
movl 0x8(%rbp), %edi
testq %rbx, %rbx
je 0x2f46c
callq 0x120e0
jmp 0x2f471
movq (%rsp), %rdi
movq %r14, %rsi
callq 0x12200
jmp 0x2f435
callq 0x123b0
movq %rbp, %rdi
callq 0x1ffff
movq %r15, %rdi
callq 0x12140
movq %r14, %rdi
callq 0x12960
movq (%r12,%rbx,8), %rdi
movq %r13, %rsi
callq 0x16be4
leaq 0x54234(%rip), %rax     # 0x836d0
decq (%rax,%rbx,8)
jmp 0x2f435