// File: /workspace/github_c_makefile_star2_O2/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, 0x1284c(%rip)     # 0x1c3f0
jl 0x9d5b
cmpq $0x0, 0x2a94e(%rip)     # 0x34500
jne 0x9c21
leaq 0xa745(%rip), %r15      # 0x14300
movl $0xd4e, %edx            # imm = 0xD4E
xorl %edi, %edi
movq %r15, %rsi
callq 0xd5df
movq %rax, 0x2a92f(%rip)     # 0x34500
movl $0xd4f, %edx            # imm = 0xD4F
xorl %edi, %edi
movq %r15, %rsi
callq 0xd5df
movq %rax, 0x2a921(%rip)     # 0x34508
leaq 0x1a1c(%rip), %rdi      # 0xb60a
movl $0xd50, %ecx            # imm = 0xD50
xorl %esi, %esi
movq %r15, %rdx
callq 0xd940
movq %rax, 0x2a8ec(%rip)     # 0x344f0
leaq 0x1bc1(%rip), %rdi      # 0xb7cc
movl $0xd51, %ecx            # imm = 0xD51
xorl %esi, %esi
movq %r15, %rdx
callq 0xd940
movq %rax, 0x2a8d7(%rip)     # 0x344f8
movq 0x2a8e0(%rip), %rdi     # 0x34508
leaq 0xa6d1(%rip), %r15      # 0x14300
movl $0xd55, %edx            # imm = 0xD55
movq %r15, %rsi
callq 0xd763
movq 0x2a8c5(%rip), %rdi     # 0x34508
movl $0xd56, %r8d            # imm = 0xD56
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0xd81e
movq 0x2a8a4(%rip), %rdi     # 0x34500
movl $0xd57, %edx            # imm = 0xD57
movq %r15, %rsi
callq 0xd763
movq 0x2a890(%rip), %rdi     # 0x34500
movl $0xd58, %r8d            # imm = 0xD58
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0xd81e
movl %ebx, %edx
movq %rdx, 0x2a885(%rip)     # 0x34510
testl %ebx, %ebx
je 0x9ca5
addq %rdx, 0x1a7f2(%rip)     # 0x24488
leaq 0x2a883(%rip), %rdi     # 0x34520
movq %r14, %rsi
callq 0x3360
movq 0x2a854(%rip), %rdi     # 0x34500
leaq 0xa64d(%rip), %r14      # 0x14300
pushq $0x1
popq %r15
movl $0xd60, %r8d            # imm = 0xD60
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0xd7c1
movq 0x2a837(%rip), %rdi     # 0x34508
movl $0xd61, %r8d            # imm = 0xD61
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0xd7c1
testl %ebx, %ebx
jne 0x9dae
cmpq $0x0, 0x2a80c(%rip)     # 0x34500
je 0x9dae
movq 0x2a7f7(%rip), %rdi     # 0x344f8
leaq 0xa5f8(%rip), %rbx      # 0x14300
movl $0xd66, %edx            # imm = 0xD66
movq %rbx, %rsi
callq 0xda9f
movq 0x2a7d4(%rip), %rdi     # 0x344f0
movl $0xd67, %edx            # imm = 0xD67
movq %rbx, %rsi
callq 0xda9f
movq 0x2a7d8(%rip), %rdi     # 0x34508
movl $0xd68, %edx            # imm = 0xD68
movq %rbx, %rsi
callq 0xd8e3
movq 0x2a7bc(%rip), %rdi     # 0x34500
movl $0xd69, %edx            # imm = 0xD69
movq %rbx, %rsi
callq 0xd8e3
andq $0x0, 0x2a7a7(%rip)     # 0x34500
jmp 0x9dae
testl %ebx, %ebx
je 0x9dae
cmpl $0x1, 0x12662(%rip)     # 0x1c3c8
movl %ebx, %r15d
jne 0x9d7c
movl 0x125e3(%rip), %edi     # 0x1c354
movq %r14, %rsi
movq %r15, %rdx
callq 0xb58d
cmpl $0x1, 0x12605(%rip)     # 0x1c388
movq 0x1a706(%rip), %rdi     # 0x24490
movq %r14, %rsi
jne 0x9d98
movl %ebx, %edx
callq 0x3390
jmp 0x9da0
movq %r15, %rdx
callq 0xb419
movq %rax, 0x1a6e9(%rip)     # 0x24490
addq %r15, 0x1a6da(%rip)     # 0x24488
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq