// File: zeeev[P]DASVC/bamtools/src/api/internal/bam/BamHeader_p.cpp
// Function: BamTools::Internal::BamHeader::CheckMagicNumber(BamTools::Internal::BgzfStream*)
void BamHeader::CheckMagicNumber(BgzfStream* stream) {

    // try to read magic number
    char buffer[Constants::BAM_HEADER_MAGIC_LENGTH];
    const size_t numBytesRead = stream->Read(buffer, Constants::BAM_HEADER_MAGIC_LENGTH);
    if ( numBytesRead != (int)Constants::BAM_HEADER_MAGIC_LENGTH )
        throw BamException("BamHeader::CheckMagicNumber", "could not read magic number");

    // validate magic number
    if ( !isValidMagicNumber(buffer) )
        throw BamException("BamHeader::CheckMagicNumber", "invalid magic number");
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq 0xf8(%rsp), %rdi
leaq 0xf4(%rsp), %rsi
movl $0x4, %edx
callq 0x79a30
movq %rax, 0xe8(%rsp)
cmpq $0x4, 0xe8(%rsp)
je 0x9d251
movb $0x1, 0x8e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x28(%rsp)
leaq 0xc7(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x7b5f0
movq 0x30(%rsp), %rdx
leaq 0x4d42d(%rip), %rsi     # 0xea56a
leaq 0xc8(%rsp), %rdi
callq 0x78e70
jmp 0x9d14c
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x20(%rsp), %rdx
leaq 0x4d41c(%rip), %rsi     # 0xea586
leaq 0x90(%rsp), %rdi
callq 0x78e70
jmp 0x9d179
movq 0x28(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x79cd0
jmp 0x9d195
movq 0x28(%rsp), %rdi
movb $0x0, 0x8e(%rsp)
movq 0x74d67(%rip), %rsi     # 0x111f10
movq 0x74db0(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0x9d3a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x9d229
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x9d20b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x7cce8
jmp 0x9d209
jmp 0x9d20b
leaq 0x8f(%rsp), %rdi
callq 0x76f80
leaq 0xc8(%rsp), %rdi
callq 0x7cce8
jmp 0x9d227
jmp 0x9d229
leaq 0xc7(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x8e(%rsp)
jne 0x9d242
jmp 0x9d24c
movq 0x28(%rsp), %rdi
callq 0x74e00
jmp 0x9d38d
leaq 0xf4(%rsp), %rdi
callq 0x9d3b0
testb $0x1, %al
jne 0x9d385
movb $0x1, 0x3e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x10(%rsp)
leaq 0x67(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x4d2d5(%rip), %rsi     # 0xea56a
leaq 0x68(%rsp), %rdi
callq 0x78e70
jmp 0x9d2a1
leaq 0x3f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x4d2e6(%rip), %rsi     # 0xea5a2
leaq 0x40(%rsp), %rdi
callq 0x78e70
jmp 0x9d2c8
movq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x79cd0
jmp 0x9d2de
movq 0x10(%rsp), %rdi
movb $0x0, 0x3e(%rsp)
movq 0x74c21(%rip), %rsi     # 0x111f10
movq 0x74c6a(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0x9d3a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x9d366
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x9d34e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0x9d34c
jmp 0x9d34e
leaq 0x3f(%rsp), %rdi
callq 0x76f80
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0x9d364
jmp 0x9d366
leaq 0x67(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x3e(%rsp)
jne 0x9d379
jmp 0x9d383
movq 0x10(%rsp), %rdi
callq 0x74e00
jmp 0x9d38d
addq $0x108, %rsp            # imm = 0x108
retq
movq 0xb8(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)