// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
andl $0x0, 0xc(%rsp)
movq %rdi, %rbx
andl $0x0, 0x30(%rdi)
andl $0x0, 0x8848(%rdi)
leaq 0x18(%rsp), %rdi
movl $0x250, %edx            # imm = 0x250
xorl %esi, %esi
callq 0x63b0
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%rbx), %eax
leaq 0x18(%rsp), %rsi
cmpl $0x100, %eax            # imm = 0x100
jne 0x50d23
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c72b
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x50d4f
xorl %r14d, %r14d
cmpl $0x1, 0x8858(%rbx)
movl $0x0, %eax
adcl $0x1, %eax
movl %eax, 0x8848(%rbx)
jmp 0x50e11
movq %rbx, %rdi
callq 0x4d834
cmpl $-0x1, %eax
je 0x50dee
movl %eax, %ebp
movl 0x18(%rsp), %eax
leaq 0x14(%rsp), %rsi
movl %eax, (%rsi)
pushq $0x4
popq %rdx
xorl %edi, %edi
callq 0x64b0
movl %eax, 0xc(%rsp)
leaq 0x1c(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c72b
cmpl $-0x1, %eax
je 0x50e0e
movl %eax, %r14d
leaq 0x20(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c72b
cmpl $-0x1, %eax
je 0x50e0e
movl %eax, %r15d
leaq 0x24(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c72b
cmpl $-0x1, %eax
je 0x50e0e
movl %eax, %r12d
leaq 0x38(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c72b
cmpl $-0x1, %eax
je 0x50e0e
movl %ebp, %ecx
movl %r14d, %edx
addq %rcx, %rdx
movl %r15d, %ecx
movl %r12d, %esi
addq %rcx, %rsi
addq %rdx, %rsi
movl %eax, %r12d
addq %rsi, %r12
movl 0xc(%rbx), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x50e26
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rsp)
jmp 0x50e7d
cmpl $0x200, 0xc(%rbx)       # imm = 0x200
jne 0x50dfc
pushq $0x1
popq %rax
jmp 0x50e08
xorl %eax, %eax
cmpl $0x1, 0x8858(%rbx)
adcl $0x1, %eax
movl %eax, 0x8848(%rbx)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %eax
jl 0x50e3f
leaq 0x28(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4d192
jmp 0x50e60
leaq 0x14(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c72b
cmpl $-0x1, %eax
je 0x50e0e
movslq 0x14(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movl %eax, %r14d
leaq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4d192
movl %eax, %eax
addq %r14, %rax
addq %rax, %r12
leaq 0x3c(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c72b
cmpl $-0x1, %eax
je 0x50e0e
movl %eax, %ebp
leaq 0x40(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c72b
cmpl $-0x1, %eax
je 0x50e0e
movl %eax, %r15d
pushq $0x1
popq %rdi
movl $0x250, %esi            # imm = 0x250
callq 0x6470
testq %rax, %rax
je 0x50e0e
movq %rax, %r14
leaq 0x18(%rsp), %rsi
movl $0x250, %edx            # imm = 0x250
movq %rax, %rdi
callq 0x6570
movslq 0x28(%r14), %r13
testq %r13, %r13
setne 0x13(%rsp)
leaq (,%r13,4), %rdi
callq 0x69d0
movq %rax, 0x30(%r14)
testq %rax, %rax
sete %al
testb %al, 0x13(%rsp)
jne 0x50f4f
movl %ebp, %eax
movl %r15d, %ecx
addq %rax, %rcx
addq %rcx, %r12
xorl %ebp, %ebp
xorl %r15d, %r15d
movslq %r13d, %rax
cmpq %rax, %r15
jge 0x50f66
movq 0x30(%r14), %rsi
addq %rbp, %rsi
movq %rbx, %rdi
leaq 0xc(%rsp), %rdx
callq 0x4c72b
cmpl $-0x1, %eax
je 0x50f59
movl %eax, %eax
addq %rax, %r12
incq %r15
movl 0x28(%r14), %r13d
addq $0x4, %rbp
jmp 0x50f1c
callq 0x6060
movl (%rax), %eax
movl %eax, 0x30(%rbx)
movq %r14, %rdi
callq 0x5093a
jmp 0x50e0e
cmpl $0x300, 0xc(%rbx)       # imm = 0x300
jl 0x50f9e
movq %r14, %r15
addq $0x248, %r15            # imm = 0x248
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4d834
cmpl $-0x1, %eax
je 0x50e0e
movl 0xc(%rsp), %eax
cmpl (%r15), %eax
jne 0x50ffd
addq $0x4, %r12
movl 0x28(%r14), %r13d
movq %r12, 0x38(%r14)
andq $0x0, 0x78(%r14)
andl $0x0, 0x54(%r14)
movl %r13d, 0x50(%r14)
andl $0x0, 0x68(%r14)
andq $0x0, 0x58(%r14)
movl 0x4(%r14), %ecx
cmpl $-0x2, %ecx
jne 0x50fd7
pushq $0x1
popq %rax
movl %eax, 0x94(%r14)
movl %eax, 0x8850(%rbx)
xorl %eax, %eax
jmp 0x50ff2
xorl %eax, %eax
cmpl $-0x1, %ecx
jne 0x50ff2
cmpl $0x0, 0x20(%r14)
jne 0x50ff2
xorl %eax, %eax
cmpl $0x454f46, 0x8(%r14)    # imm = 0x454F46
sete %al
movl %eax, 0x8858(%rbx)
jmp 0x50e11
movq 0x61fd4(%rip), %rax     # 0xb2fd8
movq (%rax), %rcx
leaq 0x36ed5(%rip), %rdi     # 0x87ee3
pushq $0x1f
popq %rsi
pushq $0x1
popq %rdx
callq 0x6e70
jmp 0x50f59