// File: /workspace/github_c_makefile_star2_O1/samtools[P]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 = fd->vv.varint_decode32_crc(fd, &c2.length, &crc)) == -1) {
            fd->eof = fd->empty_container ? 1 : 2;
            return NULL;
        } else {
            rd+=s;
        }
    } else if (CRAM_MAJOR_VERS(fd->version) < 4) {
        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);
    } else {
        if ((s = fd->vv.varint_decode32_crc(fd, &c2.length, &crc))   == -1) {
            fd->eof = fd->empty_container ? 1 : 2;
            return NULL;
        } else {
            rd+=s;
        }
    }
    if ((s = fd->vv.varint_decode32s_crc(fd, &c2.ref_seq_id, &crc))   == -1) return NULL; else rd+=s;
    if (CRAM_MAJOR_VERS(fd->version) >= 4) {
        int64_t i64;
        if ((s = fd->vv.varint_decode64_crc(fd, &i64, &crc))== -1) return NULL; else rd+=s;
        c2.ref_seq_start = i64;
        if ((s = fd->vv.varint_decode64_crc(fd, &i64, &crc)) == -1) return NULL; else rd+=s;
        c2.ref_seq_span = i64;
    } else {
        int32_t i32;
        if ((s = fd->vv.varint_decode32_crc(fd, &i32, &crc))== -1) return NULL; else rd+=s;
        c2.ref_seq_start = i32;
        if ((s = fd->vv.varint_decode32_crc(fd, &i32, &crc)) == -1) return NULL; else rd+=s;
        c2.ref_seq_span = i32;
    }
    if ((s = fd->vv.varint_decode32_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 = fd->vv.varint_decode64_crc(fd, &c2.record_counter, &crc)) == -1)
                return NULL;
            else
                rd += s;
        } else {
            int32_t i32;
            if ((s = fd->vv.varint_decode32_crc(fd, &i32, &crc)) == -1)
                return NULL;
            else
                rd += s;
            c2.record_counter = i32;
        }

        if ((s = fd->vv.varint_decode64_crc(fd, &c2.num_bases, &crc))== -1)
            return NULL;
        else
            rd += s;
    }
    if ((s = fd->vv.varint_decode32_crc(fd, &c2.num_blocks, &crc))   == -1)
        return NULL;
    else
        rd+=s;
    if ((s = fd->vv.varint_decode32_crc(fd, &c2.num_landmarks, &crc))== -1)
        return NULL;
    else
        rd+=s;

    if (c2.num_landmarks < 0 || c2.num_landmarks >= SIZE_MAX / sizeof(int32_t))
        return NULL;

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

    *c = c2;
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    if (c->num_landmarks > FUZZ_ALLOC_LIMIT/sizeof(int32_t)) {
        fd->err = errno = ENOMEM;
        cram_free_container(c);
        return NULL;
    }
#endif
    if (c->num_landmarks && !(c->landmark = malloc(c->num_landmarks * sizeof(int32_t)))) {
        fd->err = errno;
        cram_free_container(c);
        return NULL;
    }
    for (i = 0; i < c->num_landmarks; i++) {
        if ((s = fd->vv.varint_decode32_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)) {
            cram_free_container(c);
            return NULL;
        } else {
            rd+=4;
        }

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
        // Pretend the CRC was OK so the fuzzer doesn't have to get it right
        crc = c->crc32;
#endif

        if (crc != c->crc32) {
            hts_log_error("Container header CRC32 failure");
            cram_free_container(c);
            return NULL;
        }
    }

    c->offset = rd;
    c->slices = NULL;
    c->slice = 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 $0x2b8, %rsp            # imm = 0x2B8
movq %rdi, %rbx
xorl %eax, %eax
movl %eax, 0xc(%rsp)
movl %eax, 0x30(%rdi)
movl %eax, 0x8890(%rdi)
leaq 0x18(%rsp), %rdi
movl $0x2a0, %edx            # imm = 0x2A0
xorl %esi, %esi
callq 0x4260
movl 0xc(%rbx), %eax
sarl $0x8, %eax
leaq 0x18(%rsp), %rsi
cmpl $0x1, %eax
je 0x52ede
cmpl $0x3, %eax
jg 0x52ede
movq %rbx, %rdi
callq 0x4f08a
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x52f13
movl %ebp, %r12d
movl 0x18(%rsp), %eax
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
xorl %edi, %edi
movl $0x4, %edx
callq 0x4320
movl %eax, 0xc(%rsp)
jmp 0x52f36
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x8990(%rbx)
cmpl $-0x1, %eax
je 0x52ef6
movslq %eax, %r12
jmp 0x52f3f
xorl %r14d, %r14d
cmpl $0x1, 0x88ac(%rbx)
movl $0x0, %eax
adcl $0x1, %eax
movl %eax, 0x8890(%rbx)
jmp 0x5326c
movl $0x1, %eax
cmpl $0x200, 0xc(%rbx)       # imm = 0x200
je 0x52f2d
xorl %eax, %eax
cmpl $0x1, 0x88ac(%rbx)
adcl $0x1, %eax
movl %eax, 0x8890(%rbx)
xorl %r12d, %r12d
cmpl $-0x1, %ebp
je 0x53269
leaq 0x1c(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x8998(%rbx)
cmpl $-0x1, %eax
je 0x53269
cltq
addq %rax, %r12
cmpl $0x400, 0xc(%rbx)       # imm = 0x400
jl 0x52fb6
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x89a0(%rbx)
cmpl $-0x1, %eax
je 0x53006
cltq
addq %rax, %r12
leaq 0x10(%rsp), %rsi
movq (%rsi), %rax
movq %rax, 0x20(%rsp)
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x89a0(%rbx)
cmpl $-0x1, %eax
je 0x53006
cltq
addq %rax, %r12
movq 0x10(%rsp), %rax
jmp 0x52ffd
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x8990(%rbx)
cmpl $-0x1, %eax
je 0x53006
cltq
addq %rax, %r12
leaq 0x10(%rsp), %rsi
movslq (%rsi), %rax
movq %rax, 0x20(%rsp)
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x8990(%rbx)
cmpl $-0x1, %eax
je 0x53006
cltq
addq %rax, %r12
movslq 0x10(%rsp), %rax
movq %rax, 0x28(%rsp)
movb $0x1, %al
jmp 0x53008
xorl %eax, %eax
testb %al, %al
je 0x53269
leaq 0x40(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x8990(%rbx)
cmpl $-0x1, %eax
je 0x53269
cltq
addq %rax, %r12
movl 0xc(%rbx), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x53046
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsp)
jmp 0x530c0
cmpl $0x3, %eax
jl 0x5306e
leaq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x89a0(%rbx)
cmpl $-0x1, %eax
je 0x53269
cltq
addq %rax, %r12
jmp 0x5309f
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x8990(%rbx)
cmpl $-0x1, %eax
je 0x53096
movslq %eax, %rcx
addq %rcx, %r12
movslq 0x10(%rsp), %rcx
movq %rcx, 0x30(%rsp)
cmpl $-0x1, %eax
je 0x53269
leaq 0x38(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x89a0(%rbx)
cmpl $-0x1, %eax
je 0x53269
cltq
addq %rax, %r12
leaq 0x44(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x8990(%rbx)
cmpl $-0x1, %eax
je 0x53269
movl %eax, %ebp
leaq 0x48(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq *0x8990(%rbx)
cmpl $-0x1, %eax
je 0x53269
cmpl $0x0, 0x48(%rsp)
js 0x53269
movl %eax, %r15d
movl $0x1, %edi
movl $0x2a0, %esi            # imm = 0x2A0
callq 0x4300
testq %rax, %rax
je 0x53269
movq %rax, %r14
leaq 0x18(%rsp), %rsi
movl $0x2a0, %edx            # imm = 0x2A0
movq %rax, %rdi
callq 0x43c0
movslq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x53154
shlq $0x2, %rdi
callq 0x4680
movq %rax, 0x38(%r14)
testq %rax, %rax
je 0x5323b
movslq %ebp, %rax
movslq %r15d, %rcx
addq %rax, %rcx
addq %rcx, %r12
cmpl $0x0, 0x30(%r14)
jle 0x531a2
xorl %r13d, %r13d
leaq 0xc(%rsp), %r15
xorl %ebp, %ebp
movq 0x38(%r14), %rsi
addq %r13, %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq *0x8990(%rbx)
cmpl $-0x1, %eax
je 0x53261
cltq
addq %rax, %r12
incq %rbp
movslq 0x30(%r14), %rax
addq $0x4, %r13
cmpq %rax, %rbp
jl 0x53171
cmpl $0x300, 0xc(%rbx)       # imm = 0x300
jl 0x531d6
movq %r14, %r15
addq $0x280, %r15            # imm = 0x280
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4f08a
cmpl $-0x1, %eax
je 0x53261
movl 0xc(%rsp), %eax
cmpl (%r15), %eax
jne 0x53247
addq $0x4, %r12
movq %r12, 0x40(%r14)
xorl %eax, %eax
movl %eax, 0x5c(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x88(%r14)
movl 0x4(%r14), %ecx
movl 0x30(%r14), %edx
movl %edx, 0x58(%r14)
movl %eax, 0x74(%r14)
movq $0x0, 0x64(%r14)
cmpl $-0x2, %ecx
jne 0x5321a
movl $0x1, %edx
movl %edx, 0xac(%r14)
movl %edx, 0x889c(%rbx)
cmpl $-0x1, %ecx
jne 0x53233
cmpl $0x0, 0x28(%r14)
jne 0x53233
xorl %eax, %eax
cmpq $0x454f46, 0x8(%r14)    # imm = 0x454F46
sete %al
movl %eax, 0x88ac(%rbx)
jmp 0x5326c
callq 0x4050
movl (%rax), %eax
movl %eax, 0x30(%rbx)
jmp 0x53261
leaq 0x4ad10(%rip), %rsi     # 0x9df5e
leaq 0x4ad1d(%rip), %rdx     # 0x9df72
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
movq %r14, %rdi
callq 0x5295e
xorl %r14d, %r14d
movq %r14, %rax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq