// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xebf0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20020(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0xea38
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0xe160
cmpl $0x0, %eax
je 0xea38
movl $0x0, -0x4(%rbp)
jmp 0xebe6
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0x30(%rbp), %rsi
movl $0x12, %edx
callq 0x140b0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0xea63
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebe6
movslq -0x3c(%rbp), %rax
cmpq $0x12, %rax
jne 0xea7e
leaq -0x30(%rbp), %rdi
callq 0xe270
movl %eax, -0x54(%rbp)
cmpl $-0x2, %eax
jne 0xea9d
movq -0x18(%rbp), %rax
movl 0x20018(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x20018(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebe6
cmpl $-0x1, -0x54(%rbp)
jne 0xeac2
movq -0x18(%rbp), %rax
movl 0x20018(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x20018(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebe6
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0x30(%rbp), %rsi
movl $0x12, %edx
callq 0xde00
movl %eax, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
cmpq $0x12, %rax
je 0xeaf1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebe6
leaq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0xe340
addl $0x1, %eax
movl %eax, -0x40(%rbp)
cmpl $0x12, -0x40(%rbp)
jge 0xeb29
movq -0x18(%rbp), %rax
movl 0x20018(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x20018(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebe6
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movw -0x20(%rbp), %cx
movw %cx, 0x10(%rax)
movl -0x40(%rbp), %eax
subl $0x12, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0x12, %rsi
movslq -0x44(%rbp), %rdx
callq 0xde00
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
je 0xeb99
movq -0x18(%rbp), %rax
movl 0x20018(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x20018(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xebe6
movslq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10008(%rax)
movq -0x18(%rbp), %rax
movq $0x10000, 0x20010(%rax) # imm = 0x10000
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20020(%rax)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x20018(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop