// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/bgzf.c
// Function: bgzf_mt_read_block
int bgzf_mt_read_block(BGZF *fp, bgzf_job *j)
{
    uint8_t header[BLOCK_HEADER_LENGTH], *compressed_block;
    int count, block_length, remaining;

    // NOTE: Guaranteed to be compressed as we block multi-threading in
    // uncompressed mode.  However it may be gzip compression instead
    // of bgzf.

    // Reading compressed file
    int64_t block_address;
    block_address = htell(fp->fp);

    j->block_address = block_address;  // in case we exit with j->errcode

    if (fp->cache_size && load_block_from_cache(fp, block_address)) return 0;
    count = hpeek(fp->fp, header, sizeof(header));
    if (count == 0) // no data read
        return -1;
    int ret;
    if ( count != sizeof(header) || (ret=check_header(header))==-2 )
    {
        j->errcode |= BGZF_ERR_HEADER;
        return -1;
    }
    if (ret == -1) {
        j->errcode |= BGZF_ERR_MT;
        return -1;
    }

    count = hread(fp->fp, header, sizeof(header));
    if (count != sizeof(header)) // no data read
        return -1;

    block_length = unpackInt16((uint8_t*)&header[16]) + 1; // +1 because when writing this number, we used "-1"
    if (block_length < BLOCK_HEADER_LENGTH) {
        j->errcode |= BGZF_ERR_HEADER;
        return -1;
    }
    compressed_block = (uint8_t*)j->comp_data;
    memcpy(compressed_block, header, BLOCK_HEADER_LENGTH);
    remaining = block_length - BLOCK_HEADER_LENGTH;
    count = hread(fp->fp, &compressed_block[BLOCK_HEADER_LENGTH], remaining);
    if (count != remaining) {
        j->errcode |= BGZF_ERR_IO;
        return -1;
    }
    j->comp_len = block_length;
    j->uncomp_len = BGZF_MAX_BLOCK_SIZE;
    j->block_address = block_address;
    j->fp = fp;
    j->errcode = 0;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x28(%rax), %r15
addq 0x8(%rax), %r15
subq (%rax), %r15
movq %rsi, %r14
movq %r15, 0x20020(%rsi)
cmpl $0x0, 0x4(%rdi)
je 0xc20c
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbafc
xorl %ebp, %ebp
testl %eax, %eax
jne 0xc245
movq 0x40(%rbx), %rdi
movq %rsp, %rsi
movl $0x12, %edx
callq 0xf24d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0xc245
cmpl $0x12, %eax
jne 0xc23d
movq %rsp, %rdi
callq 0xbc0e
cmpl $-0x1, %eax
je 0xc256
cmpl $-0x2, %eax
jne 0xc260
orb $0x2, 0x20018(%r14)
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
orb $0x10, 0x20018(%r14)
jmp 0xc245
movq 0x40(%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rax), %rsi
movq 0x10(%rax), %r13
subq %rsi, %r13
cmpq $0x12, %r13
movl $0x12, %r12d
cmovbq %r13, %r12
movq %rsp, %rdi
movq %r12, %rdx
callq 0x43c0
movq 0x20(%rsp), %rdi
addq %r12, 0x8(%rdi)
cmpq $0x11, %r13
ja 0xc2b5
testb $0x2, 0x30(%rdi)
je 0xc2b5
movq %rsp, %rsi
movl $0x12, %edx
movq %r12, %rcx
callq 0xf2cd
movq %rax, %r12
cmpl $0x12, %r12d
jne 0xc245
movzwl 0x10(%rsp), %r13d
cmpl $0x10, %r13d
jbe 0xc23d
movzwl 0x10(%rsp), %eax
movw %ax, 0x18(%r14)
movaps (%rsp), %xmm0
movups %xmm0, 0x8(%r14)
leal -0x11(%r13), %r12d
movq 0x40(%rbx), %rdi
leaq 0x1a(%r14), %rsi
movq %r12, %rdx
callq 0xb85c
cmpl %eax, %r12d
jne 0xc32b
incl %r13d
movl %r13d, %eax
movq %rax, 0x10008(%r14)
movq $0x10000, 0x20010(%r14) # imm = 0x10000
movq %r15, 0x20020(%r14)
movq %rbx, (%r14)
movl $0x0, 0x20018(%r14)
xorl %ebp, %ebp
jmp 0xc245
orb $0x4, 0x20018(%r14)
jmp 0xc245