// File: /workspace/github_c_makefile_star2_O0/madler[P]pigz/pigz.c
// Function: write_thread
local void write_thread(void *dummy) {
    long seq;                       // next sequence number looking for
    struct job *job;                // job pulled and working on
    size_t len;                     // input length
    int more;                       // true if more chunks to write
    length_t head;                  // header length
    length_t ulen;                  // total uncompressed size (overflow ok)
    length_t clen;                  // total compressed size (overflow ok)
    unsigned long check;            // check value of uncompressed data
    ball_t err;                     // error information from throw()

    (void)dummy;

    try {
        // build and write header
        Trace(("-- write thread running"));
        head = put_header();

        // process output of compress threads until end of input
        ulen = clen = 0;
        check = CHECK(0L, Z_NULL, 0);
        seq = 0;
        do {
            // get next write job in order
            possess(write_first);
            wait_for(write_first, TO_BE, seq);
            job = write_head;
            write_head = job->next;
            twist(write_first, TO, write_head == NULL ? -1 : write_head->seq);

            // update lengths, save uncompressed length for COMB
            more = job->more;
            len = job->in->len;
            drop_space(job->in);
            ulen += len;
            clen += job->out->len;

            // write the compressed data and drop the output buffer
            Trace(("-- writing #%ld", seq));
            writen(g.outd, job->out->buf, job->out->len);
            drop_space(job->out);
            Trace(("-- wrote #%ld%s", seq, more ? "" : " (last)"));

            // wait for check calculation to complete, then combine, once the
            // compress thread is done with the input, release it
            possess(job->calc);
            wait_for(job->calc, TO_BE, 1);
            release(job->calc);
            check = COMB(check, job->check, len);
            Trace(("-- combined #%ld%s", seq, more ? "" : " (last)"));

            // free the job
            free_lock(job->calc);
            FREE(job);

            // get the next buffer in sequence
            seq++;
        } while (more);

        // write trailer
        put_trailer(ulen, clen, check, head);

        // verify no more jobs, prepare for next use
        possess(compress_have);
        assert(compress_head == NULL && peek_lock(compress_have) == 0);
        release(compress_have);
        possess(write_first);
        assert(write_head == NULL);
        twist(write_first, TO, -1);
    }
    catch (err) {
        THREADABORT(err);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movl $0x1, -0x14c(%rbp)
movl $0x0, -0x80(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
callq 0x12220
leaq 0x35142(%rip), %rax     # 0x43ab4
movl (%rax), %edi
callq 0x3110
movq %rax, -0x68(%rbp)
leaq 0x35130(%rip), %rax     # 0x43ab4
movl (%rax), %edi
leaq -0x148(%rbp), %rsi
callq 0x35f0
movl %eax, -0x150(%rbp)
cmpl $0x0, -0x150(%rbp)
jne 0xe9ab
movb $0x1, %al
testb $0x1, %al
jne 0xe9a9
jmp 0xe9ab
jmp 0xe9ca
leaq 0xd868(%rip), %rdi      # 0x1c21a
leaq 0xd891(%rip), %rsi      # 0x1c24a
movl $0x7b8, %edx            # imm = 0x7B8
leaq 0xee2d(%rip), %rcx      # 0x1d7f2
callq 0x3220
jmp 0xe9cc
leaq -0x148(%rbp), %rdi
callq 0x32f0
cmpl $0x0, %eax
jne 0xed2b
jmp 0xe9e3
callq 0x102d0
movq %rax, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
cmpl $0x1, 0x14dc5(%rip)     # 0x237c8
jne 0xea1d
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rdi
movq %rdx, %rsi
callq 0xe030
movq %rax, -0x160(%rbp)
jmp 0xea33
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rdi
movq %rdx, %rsi
callq 0xdf70
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x10(%rbp)
movq 0x34f7b(%rip), %rdi     # 0x439c8
leaq 0xd7f6(%rip), %rsi      # 0x1c24a
movl $0x7c3, %edx            # imm = 0x7C3
callq 0x11900
movq 0x34f63(%rip), %rdi     # 0x439c8
movq -0x10(%rbp), %rdx
xorl %esi, %esi
leaq 0xd7d8(%rip), %rcx      # 0x1c24a
movl $0x7c4, %r8d            # imm = 0x7C4
callq 0x11a50
movq 0x34f4c(%rip), %rax     # 0x439d0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x34f39(%rip)     # 0x439d0
movq 0x34f2a(%rip), %rax     # 0x439c8
movq %rax, -0x168(%rbp)
cmpq $0x0, 0x34f23(%rip)     # 0x439d0
jne 0xeabf
movq $-0x1, %rax
movq %rax, -0x170(%rbp)
jmp 0xead0
movq 0x34f0a(%rip), %rax     # 0x439d0
movq (%rax), %rax
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rdi
movq -0x170(%rbp), %rdx
xorl %esi, %esi
leaq 0xd763(%rip), %rcx      # 0x1c24a
movl $0x7c7, %r8d            # imm = 0x7C7
callq 0x119a0
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x10160
movq -0x20(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl 0x14c55(%rip), %edi     # 0x23794
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
callq 0xe2c0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x10160
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
leaq 0xd6d2(%rip), %rsi      # 0x1c24a
movl $0x7d8, %edx            # imm = 0x7D8
callq 0x11900
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
xorl %esi, %esi
movl $0x1, %edx
leaq 0xd6b2(%rip), %rcx      # 0x1c24a
movl $0x7d9, %r8d            # imm = 0x7D9
callq 0x11a50
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
leaq 0xd698(%rip), %rsi      # 0x1c24a
movl $0x7da, %edx            # imm = 0x7DA
callq 0x11950
cmpl $0x1, 0x14c05(%rip)     # 0x237c8
jne 0xebe3
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0xe150
movq %rax, -0x178(%rbp)
jmp 0xebff
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0xe260
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
leaq 0xd631(%rip), %rsi      # 0x1c24a
movl $0x7df, %edx            # imm = 0x7DF
callq 0x11c00
movq -0x18(%rbp), %rdi
callq 0x3050
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xea46
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x10750
movq 0x34d52(%rip), %rdi     # 0x439b0
leaq 0xd5e5(%rip), %rsi      # 0x1c24a
movl $0x7ea, %edx            # imm = 0x7EA
callq 0x11900
cmpq $0x0, 0x34d49(%rip)     # 0x439c0
jne 0xec8d
movq 0x34d30(%rip), %rdi     # 0x439b0
callq 0x11be0
cmpq $0x0, %rax
jne 0xec8d
jmp 0xecac
leaq 0xeb78(%rip), %rdi      # 0x1d80c
leaq 0xd5af(%rip), %rsi      # 0x1c24a
movl $0x7eb, %edx            # imm = 0x7EB
leaq 0xeb4b(%rip), %rcx      # 0x1d7f2
callq 0x3220
movq 0x34cfd(%rip), %rdi     # 0x439b0
leaq 0xd590(%rip), %rsi      # 0x1c24a
movl $0x7ec, %edx            # imm = 0x7EC
callq 0x11950
movq 0x34cfd(%rip), %rdi     # 0x439c8
leaq 0xd578(%rip), %rsi      # 0x1c24a
movl $0x7ed, %edx            # imm = 0x7ED
callq 0x11900
cmpq $0x0, 0x34cec(%rip)     # 0x439d0
jne 0xece8
jmp 0xed07
leaq 0xeb54(%rip), %rdi      # 0x1d843
leaq 0xd554(%rip), %rsi      # 0x1c24a
movl $0x7ee, %edx            # imm = 0x7EE
leaq 0xeaf0(%rip), %rcx      # 0x1d7f2
callq 0x3220
movq 0x34cba(%rip), %rdi     # 0x439c8
xorl %esi, %esi
movq $-0x1, %rdx
leaq 0xd52c(%rip), %rcx      # 0x1c24a
movl $0x7ef, %r8d            # imm = 0x7EF
callq 0x119a0
jmp 0xed2b
movl -0x14c(%rbp), %eax
cmpl $0x0, %eax
je 0xed8e
jmp 0xed38
leaq 0x34d75(%rip), %rax     # 0x43ab4
movl (%rax), %edi
movq -0x68(%rbp), %rsi
callq 0x35f0
movl %eax, -0x154(%rbp)
cmpl $0x0, -0x154(%rbp)
jne 0xed63
movb $0x1, %al
testb $0x1, %al
jne 0xed61
jmp 0xed63
jmp 0xed82
leaq 0xd4b0(%rip), %rdi      # 0x1c21a
leaq 0xd4d9(%rip), %rsi      # 0x1c24a
movl $0x7f1, %edx            # imm = 0x7F1
leaq 0xea75(%rip), %rcx      # 0x1d7f2
callq 0x3220
jmp 0xed84
movl $0x0, -0x14c(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0xedf4
jmp 0xedae
cmpl $0x20, -0x5c(%rbp)
je 0xedc6
movq -0x50(%rbp), %rsi
leaq 0xd597(%rip), %rdi      # 0x1c356
movb $0x0, %al
callq 0x49e0
jmp 0xedc8
cmpl $0x0, -0x58(%rbp)
je 0xede6
movq -0x50(%rbp), %rdi
callq 0x3050
movl $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
jmp 0xede8
xorl %edi, %edi
subl -0x5c(%rbp), %edi
callq 0x3f20
jmp 0xedf4
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
nopl (%rax)