// File: zeeev[P]DASVC/bamtools/src/api/internal/bam/BamHeader_p.cpp
// Function: BamTools::Internal::BamHeader::ReadHeaderText(BamTools::Internal::BgzfStream*, unsigned int const&)
void BamHeader::ReadHeaderText(BgzfStream* stream, const uint32_t& length) {

    // read header text
    char* headerText = (char*)calloc(length + 1, 1);
    const size_t bytesRead = stream->Read(headerText, length);

    // if error reading, clean up buffer & throw
    if ( bytesRead != length ) {
        free(headerText);
        throw BamException("BamHeader::ReadHeaderText", "could not read header text");
    }

    // otherwise, text was read OK
    // store & cleanup
    m_header.SetHeaderText( (string)((const char*)headerText) );
    free(headerText);
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xd0(%rsp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x748b0
movq %rax, 0xc8(%rsp)
movq 0xd8(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rax
movl (%rax), %eax
movl %eax, %edx
callq 0x79a30
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq 0xd0(%rsp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
je 0x9d7f1
movq 0xc8(%rsp), %rdi
callq 0x77c20
movb $0x1, 0x66(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x20(%rsp)
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x7b5f0
movq 0x28(%rsp), %rdx
leaq 0x4cefe(%rip), %rsi     # 0xea5f0
leaq 0xa0(%rsp), %rdi
callq 0x78e70
jmp 0x9d701
leaq 0x67(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x4ceee(%rip), %rsi     # 0xea60a
leaq 0x68(%rsp), %rdi
callq 0x78e70
jmp 0x9d728
movq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0x79cd0
jmp 0x9d741
movq 0x20(%rsp), %rdi
movb $0x0, 0x66(%rsp)
movq 0x747be(%rip), %rsi     # 0x111f10
movq 0x74807(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0x9d8be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x9d7cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x9d7b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0x9d7af
jmp 0x9d7b1
leaq 0x67(%rsp), %rdi
callq 0x76f80
leaq 0xa0(%rsp), %rdi
callq 0x7cce8
jmp 0x9d7ca
jmp 0x9d7cc
leaq 0x9f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x66(%rsp)
jne 0x9d7e2
jmp 0x9d7ec
movq 0x20(%rsp), %rdi
callq 0x74e00
jmp 0x9d8a9
movq 0x30(%rsp), %rax
movq %rax, (%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x3f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rdi
callq 0x78e70
jmp 0x9d82c
movq (%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x79d80
jmp 0x9d83c
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0x9d848
leaq 0x3f(%rsp), %rdi
callq 0x76f80
movq 0xc8(%rsp), %rdi
callq 0x77c20
addq $0xe8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x9d89f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0x9d89d
jmp 0x9d89f
leaq 0x3f(%rsp), %rdi
callq 0x76f80
movq 0x90(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nop