// File: karel-brinda[P]ococo/ext/htslib/bgzf.c
// Function: inflate_block
static int inflate_block(BGZF* fp, int block_length)
{
    z_stream zs;
    zs.zalloc = NULL;
    zs.zfree = NULL;
    zs.msg = NULL;
    zs.next_in = (Bytef*)fp->compressed_block + 18;
    zs.avail_in = block_length - 16;
    zs.next_out = (Bytef*)fp->uncompressed_block;
    zs.avail_out = BGZF_MAX_BLOCK_SIZE;

    int ret = inflateInit2(&zs, -15);
    if (ret != Z_OK) {
        if (hts_verbose >= 1) {
            fprintf(stderr, "[E::%s] inflateInit2 failed: %s\n",
                    __func__, bgzf_zerr(ret, &zs));
        }
        fp->errcode |= BGZF_ERR_ZLIB;
        return -1;
    }
    if ((ret = inflate(&zs, Z_FINISH)) != Z_STREAM_END) {
        if (hts_verbose >= 1) {
            fprintf(stderr, "[E::%s] inflate failed: %s\n",
                    __func__, bgzf_zerr(ret, ret == Z_DATA_ERROR ? &zs : NULL));
        }
        if ((ret = inflateEnd(&zs)) != Z_OK) {
            if (hts_verbose >= 2) {
                fprintf(stderr, "[E::%s] inflateEnd failed: %s\n",
                        __func__, bgzf_zerr(ret, NULL));
            }
        }
        fp->errcode |= BGZF_ERR_ZLIB;
        return -1;
    }
    if ((ret = inflateEnd(&zs)) != Z_OK) {
        if (hts_verbose >= 1) {
            fprintf(stderr, "[E::%s] inflateEnd failed: %s\n",
                    __func__, bgzf_zerr(ret, NULL));
        }
        fp->errcode |= BGZF_ERR_ZLIB;
        return -1;
    }
    return zs.total_out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
addq $0x12, %rax
movq %rax, -0x88(%rbp)
movl -0x14(%rbp), %eax
subl $0x10, %eax
movl %eax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x70(%rbp)
movl $0x10000, -0x68(%rbp)   # imm = 0x10000
leaq -0x88(%rbp), %rdi
movl $0xfffffff1, %esi       # imm = 0xFFFFFFF1
leaq 0x16b7e(%rip), %rdx     # 0x7b1aa
movl $0x70, %ecx
callq 0x44b0
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
je 0x646c0
leaq 0x25f94(%rip), %rax     # 0x8a5e0
cmpl $0x1, (%rax)
jl 0x64693
movq 0x25978(%rip), %rax     # 0x89fd0
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movl -0x8c(%rbp), %edi
leaq -0x88(%rbp), %rsi
callq 0x63940
movq -0x98(%rbp), %rdi
movq %rax, %rcx
leaq 0x19c8b(%rip), %rsi     # 0x7e310
leaq 0x19ca5(%rip), %rdx     # 0x7e331
movb $0x0, %al
callq 0x4830
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x64882
leaq -0x88(%rbp), %rdi
movl $0x4, %esi
callq 0x4450
movl %eax, -0x8c(%rbp)
cmpl $0x1, %eax
je 0x647ef
leaq 0x25ef9(%rip), %rax     # 0x8a5e0
cmpl $0x1, (%rax)
jl 0x6475e
movq 0x258dd(%rip), %rax     # 0x89fd0
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x9c(%rbp)
cmpl $-0x3, -0x8c(%rbp)
jne 0x64722
leaq -0x88(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x6472d
xorl %eax, %eax
movq %rax, -0xb0(%rbp)
jmp 0x6472d
movl -0x9c(%rbp), %edi
movq -0xb0(%rbp), %rsi
callq 0x63940
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
leaq 0x19b79(%rip), %rsi     # 0x7e2c9
leaq 0x19bda(%rip), %rdx     # 0x7e331
movb $0x0, %al
callq 0x4830
leaq -0x88(%rbp), %rdi
callq 0x45d0
movl %eax, -0x8c(%rbp)
cmpl $0x0, %eax
je 0x647c2
leaq 0x25e64(%rip), %rax     # 0x8a5e0
cmpl $0x2, (%rax)
jl 0x647c0
movq 0x25848(%rip), %rax     # 0x89fd0
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
movl -0x8c(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x63940
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
leaq 0x19b8d(%rip), %rsi     # 0x7e33f
leaq 0x19b78(%rip), %rdx     # 0x7e331
movb $0x0, %al
callq 0x4830
jmp 0x647c2
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x64882
leaq -0x88(%rbp), %rdi
callq 0x45d0
movl %eax, -0x8c(%rbp)
cmpl $0x0, %eax
je 0x6487b
leaq 0x25dd3(%rip), %rax     # 0x8a5e0
cmpl $0x1, (%rax)
jl 0x64851
movq 0x257b7(%rip), %rax     # 0x89fd0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movl -0x8c(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x63940
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
leaq 0x19afc(%rip), %rsi     # 0x7e33f
leaq 0x19ae7(%rip), %rdx     # 0x7e331
movb $0x0, %al
callq 0x4830
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x64882
movq -0x60(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nop