// File: /workspace/github_c_makefile_star2_O3/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, 0x13826(%rip)     # 0x1d400
jl 0x9d94
cmpq $0x0, 0x2b928(%rip)     # 0x35510
jne 0x9c57
leaq 0xb70f(%rip), %r15      # 0x15300
movl $0xd4e, %edx            # imm = 0xD4E
xorl %edi, %edi
movq %r15, %rsi
callq 0xe13f
movq %rax, 0x2b909(%rip)     # 0x35510
movl $0xd4f, %edx            # imm = 0xD4F
xorl %edi, %edi
movq %r15, %rsi
callq 0xe13f
movq %rax, 0x2b8fb(%rip)     # 0x35518
leaq 0x2518(%rip), %rdi      # 0xc13c
movl $0xd50, %ecx            # imm = 0xD50
xorl %esi, %esi
movq %r15, %rdx
callq 0xe490
movq %rax, 0x2b8c6(%rip)     # 0x35500
leaq 0x26c2(%rip), %rdi      # 0xc303
movl $0xd51, %ecx            # imm = 0xD51
xorl %esi, %esi
movq %r15, %rdx
callq 0xe490
movq %rax, 0x2b8b1(%rip)     # 0x35508
movq 0x2b8ba(%rip), %rdi     # 0x35518
leaq 0xb69b(%rip), %r15      # 0x15300
movl $0xd55, %edx            # imm = 0xD55
movq %r15, %rsi
callq 0xe2b3
movq 0x2b89f(%rip), %rdi     # 0x35518
movl $0xd56, %r8d            # imm = 0xD56
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0xe36e
movq 0x2b87e(%rip), %rdi     # 0x35510
movl $0xd57, %edx            # imm = 0xD57
movq %r15, %rsi
callq 0xe2b3
movq 0x2b86a(%rip), %rdi     # 0x35510
movl $0xd58, %r8d            # imm = 0xD58
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0xe36e
movl %ebx, %edx
movq %rdx, 0x2b85f(%rip)     # 0x35520
testl %ebx, %ebx
je 0x9cdb
addq %rdx, 0x1b7cc(%rip)     # 0x25498
leaq 0x2b85d(%rip), %rdi     # 0x35530
movq %r14, %rsi
callq 0x3370
movq 0x2b82e(%rip), %rdi     # 0x35510
leaq 0xb617(%rip), %r14      # 0x15300
movl $0x1, %edx
movl $0xd60, %r8d            # imm = 0xD60
xorl %esi, %esi
movq %r14, %rcx
callq 0xe311
movq 0x2b813(%rip), %rdi     # 0x35518
movl $0x1, %edx
movl $0xd61, %r8d            # imm = 0xD61
xorl %esi, %esi
movq %r14, %rcx
callq 0xe311
testl %ebx, %ebx
jne 0x9de7
cmpq $0x0, 0x2b7e6(%rip)     # 0x35510
je 0x9de7
movq 0x2b7d1(%rip), %rdi     # 0x35508
leaq 0xb5c2(%rip), %rbx      # 0x15300
movl $0xd66, %edx            # imm = 0xD66
movq %rbx, %rsi
callq 0xe610
movq 0x2b7ae(%rip), %rdi     # 0x35500
movl $0xd67, %edx            # imm = 0xD67
movq %rbx, %rsi
callq 0xe610
movq 0x2b7b2(%rip), %rdi     # 0x35518
movl $0xd68, %edx            # imm = 0xD68
movq %rbx, %rsi
callq 0xe433
movq 0x2b796(%rip), %rdi     # 0x35510
movl $0xd69, %edx            # imm = 0xD69
movq %rbx, %rsi
callq 0xe433
movq $0x0, 0x2b77e(%rip) # 0x35510
jmp 0x9de7
testl %ebx, %ebx
je 0x9de7
cmpl $0x1, 0x13639(%rip)     # 0x1d3d8
movl %ebx, %r15d
jne 0x9db5
movl 0x135ba(%rip), %edi     # 0x1d364
movq %r14, %rsi
movq %r15, %rdx
callq 0xc0bf
cmpl $0x1, 0x135dc(%rip)     # 0x1d398
movq 0x1b6dd(%rip), %rdi     # 0x254a0
movq %r14, %rsi
jne 0x9dd1
movl %ebx, %edx
callq 0x33a0
jmp 0x9dd9
movq %r15, %rdx
callq 0xbee2
movq %rax, 0x1b6c0(%rip)     # 0x254a0
addq %r15, 0x1b6b1(%rip)     # 0x25498
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq