// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/cram_io.c
// Function: cram_read_SAM_hdr
SAM_hdr *cram_read_SAM_hdr(cram_fd *fd) {
    int32_t header_len;
    char *header;
    SAM_hdr *hdr;

    /* 1.1 onwards stores the header in the first block of a container */
    if (CRAM_MAJOR_VERS(fd->version) == 1) {
	/* Length */
	if (-1 == int32_decode(fd, &header_len))
	    return NULL;

	/* Alloc and read */
	if (header_len < 0 || NULL == (header = malloc((size_t) header_len+1)))
	    return NULL;

	if (header_len != hread(fd->fp, header, header_len))
	    return NULL;
	header[header_len] = '\0';

	fd->first_container += 4 + header_len;
    } else {
	cram_container *c = cram_read_container(fd);
	cram_block *b;
	int i, len;

	if (!c)
	    return NULL;

	if (c->num_blocks < 1) {
	    cram_free_container(c);
	    return NULL;
	}

	if (!(b = cram_read_block(fd))) {
	    cram_free_container(c);
	    return NULL;
	}
	if (cram_uncompress_block(b) != 0) {
	    cram_free_container(c);
	    return NULL;
	}

	len = b->comp_size + 2 + 4*(CRAM_MAJOR_VERS(fd->version) >= 3) +
	    itf8_size(b->content_id) + 
	    itf8_size(b->uncomp_size) + 
	    itf8_size(b->comp_size);

	/* Extract header from 1st block */
	if (-1 == int32_get_blk(b, &header_len) ||
            header_len < 0 || /* Spec. says signed...  why? */
	    b->uncomp_size - 4 < header_len) {
	    cram_free_container(c);
	    cram_free_block(b);
	    return NULL;
	}
	if (NULL == (header = malloc((size_t) header_len+1))) {
	    cram_free_container(c);
	    cram_free_block(b);
	    return NULL;
	}
	memcpy(header, BLOCK_END(b), header_len);
	header[header_len]='\0';
	cram_free_block(b);

	/* Consume any remaining blocks */
	for (i = 1; i < c->num_blocks; i++) {
	    if (!(b = cram_read_block(fd))) {
		cram_free_container(c);
		return NULL;
	    }
	    len += b->comp_size + 2 + 4*(CRAM_MAJOR_VERS(fd->version) >= 3) +
		itf8_size(b->content_id) + 
		itf8_size(b->uncomp_size) + 
		itf8_size(b->comp_size);
	    cram_free_block(b);
	}

	if (c->length > 0 && len > 0 && c->length > len) {
	    // Consume padding
	    char *pads = malloc(c->length - len);
	    if (!pads) {
		cram_free_container(c);
		return NULL;
	    }

	    if (c->length - len != hread(fd->fp, pads, c->length - len)) {
		cram_free_container(c);
		return NULL;
	    }
	    free(pads);
	}

	cram_free_container(c);
    }

    /* Parse */
    hdr = sam_hdr_parse_(header, header_len);
    free(header);

    return hdr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x884d6
movq -0x10(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x7db70
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x88447
movq $0x0, -0x8(%rbp)
jmp 0x88b58
cmpl $0x0, -0x14(%rbp)
jl 0x88468
movslq -0x14(%rbp), %rdi
addq $0x1, %rdi
callq 0x69c0
movq %rax, %rcx
movq %rcx, -0x20(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x88475
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movslq -0x14(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x7dbd0
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
je 0x884aa
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x4, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x8840(%rax), %rcx
movq %rcx, 0x8840(%rax)
jmp 0x88b37
movq -0x10(%rbp), %rdi
callq 0x841e0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x884f7
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x30(%rbp), %rax
cmpl $0x1, 0x24(%rax)
jge 0x88517
movq -0x30(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x10(%rbp), %rdi
callq 0x7e250
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x88540
movq -0x30(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x38(%rbp), %rdi
callq 0x7f790
cmpl $0x0, %eax
je 0x88564
movq -0x30(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x2, %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
sarl $0x8, %ecx
cmpl $0x3, %ecx
setge %cl
andb $0x1, %cl
movzbl %cl, %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x885a5
movl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x8860f
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x885c0
movl $0x2, %eax
movl %eax, -0x5c(%rbp)
jmp 0x88609
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x885db
movl $0x3, %eax
movl %eax, -0x60(%rbp)
jmp 0x88603
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
movl -0x58(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x64(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x88633
movl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x8869d
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x8864e
movl $0x2, %eax
movl %eax, -0x6c(%rbp)
jmp 0x88697
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x88669
movl $0x3, %eax
movl %eax, -0x70(%rbp)
jmp 0x88691
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
movl -0x68(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x74(%rbp)
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x886c1
movl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x8872b
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x886dc
movl $0x2, %eax
movl %eax, -0x7c(%rbp)
jmp 0x88725
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x886f7
movl $0x3, %eax
movl %eax, -0x80(%rbp)
jmp 0x8871f
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x74(%rbp), %eax
movl -0x78(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x7dcc0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
je 0x88763
cmpl $0x0, -0x14(%rbp)
jl 0x88763
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
subl $0x4, %eax
cmpl -0x14(%rbp), %eax
jge 0x88782
movq -0x30(%rbp), %rdi
callq 0x83b70
movq -0x38(%rbp), %rdi
callq 0x7f750
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movslq -0x14(%rbp), %rdi
addq $0x1, %rdi
callq 0x69c0
movq %rax, %rcx
movq %rcx, -0x20(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x887bc
movq -0x30(%rbp), %rdi
callq 0x83b70
movq -0x38(%rbp), %rdi
callq 0x7f750
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x38(%rbp), %rax
addq 0x30(%rax), %rsi
movslq -0x14(%rbp), %rdx
callq 0x6570
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
callq 0x7f750
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jge 0x88a7d
movq -0x10(%rbp), %rdi
callq 0x7e250
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x8882e
movq -0x30(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x2, %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
sarl $0x8, %ecx
cmpl $0x3, %ecx
setge %cl
andb $0x1, %cl
movzbl %cl, %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x84(%rbp)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x88875
movl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x888f4
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x88893
movl $0x2, %eax
movl %eax, -0x8c(%rbp)
jmp 0x888e8
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x888b1
movl $0x3, %eax
movl %eax, -0x90(%rbp)
jmp 0x888dc
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x84(%rbp), %eax
movl -0x88(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x94(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x88924
movl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x889a3
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x88942
movl $0x2, %eax
movl %eax, -0x9c(%rbp)
jmp 0x88997
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x88960
movl $0x3, %eax
movl %eax, -0xa0(%rbp)
jmp 0x8898b
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x94(%rbp), %eax
movl -0x98(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xa4(%rbp)
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x889d3
movl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x88a52
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x889f1
movl $0x2, %eax
movl %eax, -0xac(%rbp)
jmp 0x88a46
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x88a0f
movl $0x3, %eax
movl %eax, -0xb0(%rbp)
jmp 0x88a3a
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0xa4(%rbp), %eax
movl -0xa8(%rbp), %ecx
addl %ecx, %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x7f750
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x887f5
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x88b2e
cmpl $0x0, -0x40(%rbp)
jle 0x88b2e
movq -0x30(%rbp), %rax
movl (%rax), %eax
cmpl -0x40(%rbp), %eax
jle 0x88b2e
movq -0x30(%rbp), %rax
movl (%rax), %eax
subl -0x40(%rbp), %eax
movslq %eax, %rdi
callq 0x69c0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x88ad5
movq -0x30(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x30(%rbp), %rax
movl (%rax), %eax
subl -0x40(%rbp), %eax
cltq
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rsi
movq -0x30(%rbp), %rax
movl (%rax), %eax
subl -0x40(%rbp), %eax
movslq %eax, %rdx
callq 0x7dbd0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
je 0x88b25
movq -0x30(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x88b58
movq -0x48(%rbp), %rdi
callq 0x6880
movq -0x30(%rbp), %rdi
callq 0x83b70
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x96450
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x6880
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)