// File: /workspace/github_c_makefile_star2_O1/madler[P]pigz/pigz.c
// Function: outb
local int outb(void *desc, unsigned char *buf, unsigned len) {
    (void)desc;

#ifndef NOTHREAD
    static thread *wr, *ch;

    if (g.procs > 1) {
        // if first time, initialize state and launch threads
        if (outb_write_more == NULL) {
            outb_write_more = new_lock(0);
            outb_check_more = new_lock(0);
            wr = launch(outb_write, NULL);
            ch = launch(outb_check, NULL);
        }

        // wait for previous write and check threads to complete
        possess(outb_check_more);
        wait_for(outb_check_more, TO_BE, 0);
        possess(outb_write_more);
        wait_for(outb_write_more, TO_BE, 0);

        // copy the output and alert the worker bees
        out_len = len;
        if (len) {
            g.out_tot += len;
            memcpy(out_copy, buf, len);
        }
        twist(outb_write_more, TO, 1);
        twist(outb_check_more, TO, 1);

        // if requested with len == 0, clean up -- terminate and join write and
        // check threads, free lock
        if (len == 0 && outb_write_more != NULL) {
            join(ch);
            join(wr);
            free_lock(outb_check_more);
            free_lock(outb_write_more);
            outb_write_more = NULL;
        }

        // return for more decompression while last buffer is being written and
        // having its check value calculated -- we wait for those to finish the
        // next time this function is called
        return 0;
    }
#endif

    // if just one process or no threads, then do it without threads
    if (len) {
        if (g.decode == 1)
            writen(g.outd, buf, len);
        g.out_check = CHECK(g.out_check, buf, len);
        g.out_tot += len;
    }
    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %edx, %ebx
movq %rsi, %r14
cmpl $0x2, 0x13b13(%rip)     # 0x1d3f0
jl 0x9a97
cmpq $0x0, 0x2bc15(%rip)     # 0x35500
jne 0x995a
leaq 0xba0c(%rip), %r15      # 0x15300
movl $0xd4e, %edx            # imm = 0xD4E
xorl %edi, %edi
movq %r15, %rsi
callq 0xddaf
movq %rax, 0x2bbf6(%rip)     # 0x35500
movl $0xd4f, %edx            # imm = 0xD4F
xorl %edi, %edi
movq %r15, %rsi
callq 0xddaf
movq %rax, 0x2bbe8(%rip)     # 0x35508
leaq 0x2434(%rip), %rdi      # 0xbd5b
movl $0xd50, %ecx            # imm = 0xD50
xorl %esi, %esi
movq %r15, %rdx
callq 0xe100
movq %rax, 0x2bbb3(%rip)     # 0x354f0
leaq 0x25de(%rip), %rdi      # 0xbf22
movl $0xd51, %ecx            # imm = 0xD51
xorl %esi, %esi
movq %r15, %rdx
callq 0xe100
movq %rax, 0x2bb9e(%rip)     # 0x354f8
movq 0x2bba7(%rip), %rdi     # 0x35508
leaq 0xb998(%rip), %r15      # 0x15300
movl $0xd55, %edx            # imm = 0xD55
movq %r15, %rsi
callq 0xdf23
movq 0x2bb8c(%rip), %rdi     # 0x35508
movl $0xd56, %r8d            # imm = 0xD56
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0xdfde
movq 0x2bb6b(%rip), %rdi     # 0x35500
movl $0xd57, %edx            # imm = 0xD57
movq %r15, %rsi
callq 0xdf23
movq 0x2bb57(%rip), %rdi     # 0x35500
movl $0xd58, %r8d            # imm = 0xD58
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0xdfde
movl %ebx, %edx
movq %rdx, 0x2bb4c(%rip)     # 0x35510
testl %ebx, %ebx
je 0x99de
addq %rdx, 0x1bab9(%rip)     # 0x25488
leaq 0x2bb4a(%rip), %rdi     # 0x35520
movq %r14, %rsi
callq 0x3360
movq 0x2bb1b(%rip), %rdi     # 0x35500
leaq 0xb914(%rip), %r14      # 0x15300
movl $0x1, %edx
movl $0xd60, %r8d            # imm = 0xD60
xorl %esi, %esi
movq %r14, %rcx
callq 0xdf81
movq 0x2bb00(%rip), %rdi     # 0x35508
movl $0x1, %edx
movl $0xd61, %r8d            # imm = 0xD61
xorl %esi, %esi
movq %r14, %rcx
callq 0xdf81
testl %ebx, %ebx
jne 0x9aea
cmpq $0x0, 0x2bad3(%rip)     # 0x35500
je 0x9aea
movq 0x2babe(%rip), %rdi     # 0x354f8
leaq 0xb8bf(%rip), %rbx      # 0x15300
movl $0xd66, %edx            # imm = 0xD66
movq %rbx, %rsi
callq 0xe280
movq 0x2ba9b(%rip), %rdi     # 0x354f0
movl $0xd67, %edx            # imm = 0xD67
movq %rbx, %rsi
callq 0xe280
movq 0x2ba9f(%rip), %rdi     # 0x35508
movl $0xd68, %edx            # imm = 0xD68
movq %rbx, %rsi
callq 0xe0a3
movq 0x2ba83(%rip), %rdi     # 0x35500
movl $0xd69, %edx            # imm = 0xD69
movq %rbx, %rsi
callq 0xe0a3
movq $0x0, 0x2ba6b(%rip) # 0x35500
jmp 0x9aea
testl %ebx, %ebx
je 0x9aea
cmpl $0x1, 0x13926(%rip)     # 0x1d3c8
movl %ebx, %r15d
jne 0x9ab8
movl 0x138a7(%rip), %edi     # 0x1d354
movq %r14, %rsi
movq %r15, %rdx
callq 0xbcde
cmpl $0x1, 0x138c9(%rip)     # 0x1d388
movq 0x1b9ca(%rip), %rdi     # 0x25490
movq %r14, %rsi
jne 0x9ad4
movl %ebx, %edx
callq 0x3390
jmp 0x9adc
movq %r15, %rdx
callq 0xbaff
movq %rax, 0x1b9ad(%rip)     # 0x25490
addq %r15, 0x1b99e(%rip)     # 0x25488
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq