// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/cram_io.c
// Function: cram_read_container
cram_container *cram_read_container(cram_fd *fd) {
    cram_container c2, *c;
    int i, s;
    size_t rd = 0;
    uint32_t crc = 0;
    
    fd->err = 0;
    fd->eof = 0;

    memset(&c2, 0, sizeof(c2));
    if (CRAM_MAJOR_VERS(fd->version) == 1) {
	if ((s = itf8_decode_crc(fd, &c2.length, &crc)) == -1) {
	    fd->eof = fd->empty_container ? 1 : 2;
	    return NULL;
	} else {
	    rd+=s;
	}
    } else {
	uint32_t len;
	if ((s = int32_decode(fd, &c2.length)) == -1) {
	    if (CRAM_MAJOR_VERS(fd->version) == 2 &&
		CRAM_MINOR_VERS(fd->version) == 0)
		fd->eof = 1; // EOF blocks arrived in v2.1
	    else
		fd->eof = fd->empty_container ? 1 : 2;
	    return NULL;
	} else {
	    rd+=s;
	}
	len = le_int4(c2.length);
	crc = crc32(0L, (unsigned char *)&len, 4);
    }
    if ((s = itf8_decode_crc(fd, &c2.ref_seq_id, &crc))   == -1) return NULL; else rd+=s;
    if ((s = itf8_decode_crc(fd, &c2.ref_seq_start, &crc))== -1) return NULL; else rd+=s;
    if ((s = itf8_decode_crc(fd, &c2.ref_seq_span, &crc)) == -1) return NULL; else rd+=s;
    if ((s = itf8_decode_crc(fd, &c2.num_records, &crc))  == -1) return NULL; else rd+=s;

    if (CRAM_MAJOR_VERS(fd->version) == 1) {
	c2.record_counter = 0;
	c2.num_bases = 0;
    } else {
	if (CRAM_MAJOR_VERS(fd->version) >= 3) {
	    if ((s = ltf8_decode_crc(fd, &c2.record_counter, &crc)) == -1)
		return NULL;
	    else
		rd += s;
	} else {
	    int32_t i32;
	    if ((s = itf8_decode_crc(fd, &i32, &crc)) == -1)
		return NULL;
	    else
		rd += s;
	    c2.record_counter = i32;
	}

	if ((s = ltf8_decode_crc(fd, &c2.num_bases, &crc))== -1)
	    return NULL;
	else
	    rd += s;
    }
    if ((s = itf8_decode_crc(fd, &c2.num_blocks, &crc))   == -1) return NULL; else rd+=s;
    if ((s = itf8_decode_crc(fd, &c2.num_landmarks, &crc))== -1) return NULL; else rd+=s;

    if (!(c = calloc(1, sizeof(*c))))
	return NULL;

    *c = c2;

    if (!(c->landmark = malloc(c->num_landmarks * sizeof(int32_t))) &&
	c->num_landmarks) {
	fd->err = errno;
	cram_free_container(c);
	return NULL;
    }  
    for (i = 0; i < c->num_landmarks; i++) {
	if ((s = itf8_decode_crc(fd, &c->landmark[i], &crc)) == -1) {
	    cram_free_container(c);
	    return NULL;
	} else {
	    rd += s;
	}
    }

    if (CRAM_MAJOR_VERS(fd->version) >= 3) {
	if (-1 == int32_decode(fd, (int32_t *)&c->crc32))
	    return NULL;
	else
	    rd+=4;

	if (crc != c->crc32) {
	    fprintf(stderr, "Container header CRC32 failure\n");
	    cram_free_container(c);
	    return NULL;
	}
    }

    c->offset = rd;
    c->slices = NULL;
    c->curr_slice = 0;
    c->max_slice = c->num_landmarks;
    c->slice_rec = 0;
    c->curr_rec = 0;
    c->max_rec = 0;

    if (c->ref_seq_id == -2) {
	c->multi_seq = 1;
	fd->multi_seq = 1;
    }

    fd->empty_container =
	(c->num_records == 0 &&
	 c->ref_seq_id == -1 &&
	 c->ref_seq_start == 0x454f46 /* EOF */) ? 1 : 0;

    return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x10(%rbp)
movq $0x0, -0x278(%rbp)
movl $0x0, -0x27c(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8848(%rax)
leaq -0x260(%rbp), %rdi
xorl %esi, %esi
movl $0x250, %edx            # imm = 0x250
callq 0x63a0
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x842ac
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x84292
movq -0x10(%rbp), %rax
movl 0x8858(%rax), %edx
movl $0x2, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8848(%rax)
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
jmp 0x84364
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x7db70
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x84328
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x2, %eax
jne 0x842f7
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xff, %eax
cmpl $0x0, %eax
jne 0x842f7
movq -0x10(%rbp), %rax
movl $0x1, 0x8848(%rax)
jmp 0x8431b
movq -0x10(%rbp), %rax
movl 0x8858(%rax), %edx
movl $0x2, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8848(%rax)
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
movl -0x260(%rbp), %eax
movl %eax, -0x280(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq -0x280(%rbp), %rsi
movl $0x4, %edx
callq 0x64a0
movl %eax, -0x27c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
addq $0x4, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x84397
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
addq $0x8, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x843df
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
addq $0xc, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x84427
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
addq $0x20, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x8446f
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x844ae
movq $0x0, -0x250(%rbp)
movq $0x0, -0x248(%rbp)
jmp 0x845a3
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x3, %eax
jl 0x84507
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
addq $0x10, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7cf80
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x844f0
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
jmp 0x84559
movq -0x10(%rbp), %rdi
leaq -0x284(%rbp), %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x84536
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
movslq -0x284(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
addq $0x18, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7cf80
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x8458c
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
jmp 0x845a3
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
addq $0x24, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x845d6
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x260(%rbp), %rsi
addq $0x28, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x8461e
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
movl $0x1, %edi
movl $0x250, %esi            # imm = 0x250
callq 0x6460
movq %rax, -0x268(%rbp)
cmpq $0x0, %rax
jne 0x8465c
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movq -0x268(%rbp), %rdi
leaq -0x260(%rbp), %rsi
movl $0x250, %edx            # imm = 0x250
callq 0x6570
movq -0x268(%rbp), %rax
movslq 0x28(%rax), %rdi
shlq $0x2, %rdi
callq 0x69c0
movq -0x268(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0x846cd
movq -0x268(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x846cd
callq 0x6060
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x268(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movl $0x0, -0x26c(%rbp)
movl -0x26c(%rbp), %eax
movq -0x268(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x84761
movq -0x10(%rbp), %rdi
movq -0x268(%rbp), %rax
movq 0x30(%rax), %rsi
movslq -0x26c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
leaq -0x27c(%rbp), %rdx
callq 0x7b810
movl %eax, -0x270(%rbp)
cmpl $-0x1, %eax
jne 0x84736
movq -0x268(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movslq -0x270(%rbp), %rax
addq -0x278(%rbp), %rax
movq %rax, -0x278(%rbp)
jmp 0x8474d
movl -0x26c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x26c(%rbp)
jmp 0x846d7
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x3, %eax
jl 0x847fd
movq -0x10(%rbp), %rdi
movq -0x268(%rbp), %rsi
addq $0x248, %rsi            # imm = 0x248
callq 0x7db70
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x847a3
movq $0x0, -0x8(%rbp)
jmp 0x848ff
movq -0x278(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x278(%rbp)
movl -0x27c(%rbp), %eax
movq -0x268(%rbp), %rcx
cmpl 0x248(%rcx), %eax
je 0x847fb
movq 0x807ff(%rip), %rax     # 0x104fd0
movq (%rax), %rdi
leaq 0x5e708(%rip), %rsi     # 0xe2ee3
movb $0x0, %al
callq 0x6a80
movq -0x268(%rbp), %rdi
callq 0x83b70
movq $0x0, -0x8(%rbp)
jmp 0x848ff
jmp 0x847fd
movq -0x278(%rbp), %rcx
movq -0x268(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x268(%rbp), %rax
movq $0x0, 0x78(%rax)
movq -0x268(%rbp), %rax
movl $0x0, 0x54(%rax)
movq -0x268(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x268(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x268(%rbp), %rax
movl $0x0, 0x68(%rax)
movq -0x268(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x268(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x268(%rbp), %rax
cmpl $-0x2, 0x4(%rax)
jne 0x84896
movq -0x268(%rbp), %rax
movl $0x1, 0x94(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x8850(%rax)
movq -0x268(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x20(%rcx)
movb %al, -0x285(%rbp)
jne 0x848d7
movq -0x268(%rbp), %rcx
xorl %eax, %eax
cmpl $-0x1, 0x4(%rcx)
movb %al, -0x285(%rbp)
jne 0x848d7
movq -0x268(%rbp), %rax
cmpl $0x454f46, 0x8(%rax)    # imm = 0x454F46
sete %al
movb %al, -0x285(%rbp)
movb -0x285(%rbp), %dl
xorl %ecx, %ecx
movl $0x1, %eax
testb $0x1, %dl
cmovnel %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8858(%rax)
movq -0x268(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
nopl (%rax)