// File: zeeev[P]DASVC/bamtools/src/api/internal/io/BgzfStream_p.cpp
// Function: BamTools::Internal::BgzfStream::InflateBlock(unsigned long const&)
size_t BgzfStream::InflateBlock(const size_t& blockLength) {

    // setup zlib stream object
    z_stream zs;
    zs.zalloc    = NULL;
    zs.zfree     = NULL;
    zs.next_in   = (Bytef*)m_compressedBlock.Buffer + 18;
    zs.avail_in  = blockLength - 16;
    zs.next_out  = (Bytef*)m_uncompressedBlock.Buffer;
    zs.avail_out = Constants::BGZF_DEFAULT_BLOCK_SIZE;

    // initialize
    int status = inflateInit2(&zs, Constants::GZIP_WINDOW_BITS);
    if ( status != Z_OK )
        throw BamException("BgzfStream::InflateBlock", "zlib inflateInit failed");

    // decompress
    status = inflate(&zs, Z_FINISH);
    if ( status != Z_STREAM_END ) {
        inflateEnd(&zs);
        throw BamException("BgzfStream::InflateBlock", "zlib inflate failed");
    }

    // finalize
    status = inflateEnd(&zs);
    if ( status != Z_OK ) {
        inflateEnd(&zs);
        throw BamException("BgzfStream::InflateBlock", "zlib inflateEnd failed");
    }

    // return result
    return zs.total_out;
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movq 0x1d0(%rsp), %rax
movq $0x0, 0x198(%rsp)
movq $0x0, 0x1a0(%rsp)
movq 0x30(%rax), %rcx
addq $0x12, %rcx
movq %rcx, 0x158(%rsp)
movq 0x1c8(%rsp), %rcx
movq (%rcx), %rcx
subq $0x10, %rcx
movl %ecx, 0x160(%rsp)
movq 0x20(%rax), %rax
movq %rax, 0x170(%rsp)
movl $0x10000, 0x178(%rsp) # imm = 0x10000
leaq 0x158(%rsp), %rdi
movl $0xfffffff1, %esi       # imm = 0xFFFFFFF1
leaq 0x1dc11(%rip), %rdx     # 0xebf89
movl $0x70, %ecx
callq 0x75ca0
movl %eax, 0x154(%rsp)
cmpl $0x0, 0x154(%rsp)
je 0xce4e0
movb $0x1, 0xf6(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x40(%rsp)
leaq 0x12f(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x7b5f0
movq 0x48(%rsp), %rdx
leaq 0x1dcc8(%rip), %rsi     # 0xec094
leaq 0x130(%rsp), %rdi
callq 0x78e70
jmp 0xce3db
leaq 0xf7(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x7b5f0
movq 0x38(%rsp), %rdx
leaq 0x1dcb4(%rip), %rsi     # 0xec0ad
leaq 0xf8(%rsp), %rdi
callq 0x78e70
jmp 0xce408
movq 0x40(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x79cd0
jmp 0xce424
movq 0x40(%rsp), %rdi
movb $0x0, 0xf6(%rsp)
movq 0x43ad8(%rip), %rsi     # 0x111f10
movq 0x43b21(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xce7d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0xce4b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0xce49a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x7cce8
jmp 0xce498
jmp 0xce49a
leaq 0xf7(%rsp), %rdi
callq 0x76f80
leaq 0x130(%rsp), %rdi
callq 0x7cce8
jmp 0xce4b6
jmp 0xce4b8
leaq 0x12f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0xf6(%rsp)
jne 0xce4d1
jmp 0xce4db
movq 0x40(%rsp), %rdi
callq 0x74e00
jmp 0xce7c4
leaq 0x158(%rsp), %rdi
movl $0x4, %esi
callq 0x75460
movl %eax, 0x154(%rsp)
cmpl $0x1, 0x154(%rsp)
je 0xce65d
leaq 0x158(%rsp), %rdi
callq 0x76d60
movb $0x1, 0xa6(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x28(%rsp)
leaq 0xcf(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x7b5f0
movq 0x30(%rsp), %rdx
leaq 0x1db4b(%rip), %rsi     # 0xec094
leaq 0xd0(%rsp), %rdi
callq 0x78e70
jmp 0xce558
leaq 0xa7(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x20(%rsp), %rdx
leaq 0x1db4f(%rip), %rsi     # 0xec0c5
leaq 0xa8(%rsp), %rdi
callq 0x78e70
jmp 0xce585
movq 0x28(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x79cd0
jmp 0xce5a1
movq 0x28(%rsp), %rdi
movb $0x0, 0xa6(%rsp)
movq 0x4395b(%rip), %rsi     # 0x111f10
movq 0x439a4(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xce7d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0xce635
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0xce617
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x7cce8
jmp 0xce615
jmp 0xce617
leaq 0xa7(%rsp), %rdi
callq 0x76f80
leaq 0xd0(%rsp), %rdi
callq 0x7cce8
jmp 0xce633
jmp 0xce635
leaq 0xcf(%rsp), %rdi
callq 0x76f80
testb $0x1, 0xa6(%rsp)
jne 0xce64e
jmp 0xce658
movq 0x28(%rsp), %rdi
callq 0x74e00
jmp 0xce7c4
leaq 0x158(%rsp), %rdi
callq 0x76d60
movl %eax, 0x154(%rsp)
cmpl $0x0, 0x154(%rsp)
je 0xce7b4
leaq 0x158(%rsp), %rdi
callq 0x76d60
movb $0x1, 0x56(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x10(%rsp)
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x1d9d9(%rip), %rsi     # 0xec094
leaq 0x80(%rsp), %rdi
callq 0x78e70
jmp 0xce6ca
leaq 0x57(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x1d9f4(%rip), %rsi     # 0xec0d9
leaq 0x58(%rsp), %rdi
callq 0x78e70
jmp 0xce6f1
movq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x79cd0
jmp 0xce70a
movq 0x10(%rsp), %rdi
movb $0x0, 0x56(%rsp)
movq 0x437f5(%rip), %rsi     # 0x111f10
movq 0x4383e(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xce7d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0xce795
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0xce77a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xce778
jmp 0xce77a
leaq 0x57(%rsp), %rdi
callq 0x76f80
leaq 0x80(%rsp), %rdi
callq 0x7cce8
jmp 0xce793
jmp 0xce795
leaq 0x7f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x56(%rsp)
jne 0xce7a8
jmp 0xce7b2
movq 0x10(%rsp), %rdi
callq 0x74e00
jmp 0xce7c4
movq 0x180(%rsp), %rax
addq $0x1d8, %rsp            # imm = 0x1D8
retq
movq 0x120(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax)