// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_decode.c
// Function: cram_decode_aux_1_0
static int cram_decode_aux_1_0(cram_container *c, cram_slice *s,
                               cram_block *blk, cram_record *cr) {
    int i, r = 0, out_sz = 1;
    unsigned char ntags;

    if (!c->comp_hdr->codecs[DS_TC]) return -1;
    r |= c->comp_hdr->codecs[DS_TC]->decode(s, c->comp_hdr->codecs[DS_TC], blk,
                                            (char *)&ntags, &out_sz);
    cr->ntags = ntags;

    //printf("TC=%d\n", cr->ntags);
    cr->aux_size = 0;
    cr->aux = BLOCK_SIZE(s->aux_blk);

    for (i = 0; i < cr->ntags; i++) {
        int32_t id, out_sz = 1;
        unsigned char tag_data[3];
        cram_map *m;

        //printf("Tag %d/%d\n", i+1, cr->ntags);
        if (!c->comp_hdr->codecs[DS_TN]) return -1;
        r |= c->comp_hdr->codecs[DS_TN]->decode(s, c->comp_hdr->codecs[DS_TN],
                                                blk, (char *)&id, &out_sz);
        if (out_sz == 3) {
            // Tag name stored as 3 chars instead of an int?
            memcpy(tag_data, &id, 3);
        } else {
            tag_data[0] = (id>>16) & 0xff;
            tag_data[1] = (id>>8)  & 0xff;
            tag_data[2] = id       & 0xff;
        }

        m = map_find(c->comp_hdr->tag_encoding_map, tag_data, id);
        if (!m)
            return -1;
        BLOCK_APPEND(s->aux_blk, (char *)tag_data, 3);

        if (!m->codec) return -1;
        r |= m->codec->decode(s, m->codec, blk, (char *)s->aux_blk, &out_sz);

        cr->aux_size += out_sz + 3;
    }

    return r;

 block_err:
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movl $0x1, 0x34(%rsp)
movq 0x48(%rdi), %rax
movq 0x3e0(%rax), %rsi
testq %rsi, %rsi
je 0x3c280
movq %rcx, %r12
movq %rdi, %rbp
leaq 0xf(%rsp), %r13
leaq 0x34(%rsp), %r8
movq %rbx, %rdi
movq %rdx, 0x18(%rsp)
movq %r13, %rcx
callq *0x28(%rsi)
movl %eax, (%rsp)
movzbl (%r13), %eax
movl %eax, 0x50(%r12)
movl $0x0, 0x58(%r12)
movq 0x90(%rbx), %rcx
movl 0x30(%rcx), %ecx
movl %ecx, 0x54(%r12)
testl %eax, %eax
jle 0x3c287
xorl %r14d, %r14d
movq 0x18(%rsp), %r13
movq %r12, 0x28(%rsp)
movq %rbx, 0x10(%rsp)
movq %rbp, 0x20(%rsp)
movl $0x1, 0x8(%rsp)
movq 0x48(%rbp), %rax
movq 0x3b8(%rax), %rsi
testq %rsi, %rsi
je 0x3c13b
movq %rbx, %rdi
movq %r13, %rdx
leaq 0x4(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq *0x28(%rsi)
cmpl $0x3, 0x8(%rsp)
jne 0x3c142
movb 0x4(%rsp), %r15b
movb 0x5(%rsp), %bl
movb 0x6(%rsp), %dil
jmp 0x3c152
xorl %eax, %eax
jmp 0x3c26c
movl 0x4(%rsp), %edi
movl %edi, %r15d
shrl $0x10, %r15d
movl %edi, %ebx
shrl $0x8, %ebx
movq 0x48(%rbp), %rcx
movzbl %r15b, %edx
leal (%rdx,%rdx,2), %edx
movzbl %bl, %esi
addl %edx, %esi
andl $0x1f, %esi
movq 0x180(%rcx,%rsi,8), %rbp
testq %rbp, %rbp
je 0x3c184
movl 0x4(%rsp), %ecx
cmpl %ecx, (%rbp)
je 0x3c184
movq 0x18(%rbp), %rbp
testq %rbp, %rbp
jne 0x3c176
orl %eax, (%rsp)
testq %rbp, %rbp
je 0x3c252
movq 0x10(%rsp), %rax
movq 0x90(%rax), %r12
movq 0x28(%r12), %rax
movq 0x30(%r12), %r13
addq $0x3, %r13
cmpq %r13, %rax
ja 0x3c1ee
movl %edi, 0x30(%rsp)
leaq 0x320(%rax), %rcx
shrq $0x2, %rcx
addq %rcx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %r13, %rax
cmovaq %rax, %r13
movq 0x20(%r12), %rdi
movq %r13, %rsi
callq 0x4840
testq %rax, %rax
je 0x3c256
movq %r13, 0x28(%r12)
movq %rax, 0x20(%r12)
movl 0x30(%rsp), %edi
movq 0x20(%r12), %rax
movq 0x30(%r12), %rcx
movb %r15b, (%rax,%rcx)
movb %bl, 0x1(%rax,%rcx)
movb %dil, 0x2(%rax,%rcx)
addq $0x3, 0x30(%r12)
movq 0x10(%rbp), %rsi
testq %rsi, %rsi
je 0x3c256
movq 0x10(%rsp), %rbx
movq 0x90(%rbx), %rcx
movq %rbx, %rdi
movq 0x18(%rsp), %r13
movq %r13, %rdx
leaq 0x8(%rsp), %r8
callq *0x28(%rsi)
orl %eax, (%rsp)
movl 0x8(%rsp), %eax
movq 0x28(%rsp), %r12
movl 0x58(%r12), %ecx
addl %ecx, %eax
addl $0x3, %eax
movl %eax, 0x58(%r12)
movb $0x1, %al
jmp 0x3c267
xorl %eax, %eax
jmp 0x3c262
xorl %eax, %eax
movq 0x28(%rsp), %r12
movq 0x18(%rsp), %r13
movq 0x10(%rsp), %rbx
movq 0x20(%rsp), %rbp
testb %al, %al
je 0x3c280
incl %r14d
cmpl 0x50(%r12), %r14d
jl 0x3c0f9
jmp 0x3c287
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movl (%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq