// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/bgzf.c
// Function: bgzf_write
ssize_t bgzf_write(BGZF *fp, const void *data, size_t length)
{
    if ( !fp->is_compressed ) {
        size_t push = length + (size_t) fp->block_offset;
        fp->block_offset = push % BGZF_MAX_BLOCK_SIZE;
        fp->block_address += (push - fp->block_offset);
        return hwrite(fp->fp, data, length);
    }

    const uint8_t *input = (const uint8_t*)data;
    ssize_t remaining = length;
    assert(fp->is_write);
    while (remaining > 0) {
        uint8_t* buffer = (uint8_t*)fp->uncompressed_block;
        int copy_length = BGZF_BLOCK_SIZE - fp->block_offset;
        if (copy_length > remaining) copy_length = remaining;
        memcpy(buffer + fp->block_offset, input, copy_length);
        fp->block_offset += copy_length;
        input += copy_length;
        remaining -= copy_length;
        if (fp->block_offset == BGZF_BLOCK_SIZE) {
            if (lazy_flush(fp) != 0) return -1;
        }
    }
    return length - remaining;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x10034
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rax
subq %rax, %rcx
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xfdc0
movq %rax, -0x8(%rbp)
jmp 0x10130
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x11, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x10057
jmp 0x10076
leaq 0xdeeb2(%rip), %rdi     # 0xeef10
leaq 0xded80(%rip), %rsi     # 0xeede5
movl $0x7d8, %edx            # imm = 0x7D8
leaq 0xdeeac(%rip), %rcx     # 0xeef1d
callq 0x42e0
jmp 0x10078
cmpq $0x0, -0x38(%rbp)
jle 0x10124
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movl $0xff00, %eax           # imm = 0xFF00
subl 0x10(%rcx), %eax
movl %eax, -0x44(%rbp)
movslq -0x44(%rbp), %rax
cmpq -0x38(%rbp), %rax
jle 0x100af
movq -0x38(%rbp), %rax
movl %eax, -0x44(%rbp)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rax
addq %rax, %rdi
movq -0x30(%rbp), %rsi
movslq -0x44(%rbp), %rdx
callq 0x43b0
movl -0x44(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movl -0x44(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movslq -0x44(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0xff00, 0x10(%rax)     # imm = 0xFF00
jne 0x1011f
movq -0x10(%rbp), %rdi
callq 0xff50
cmpl $0x0, %eax
je 0x1011d
movq $-0x1, -0x8(%rbp)
jmp 0x10130
jmp 0x1011f
jmp 0x10078
movq -0x20(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)