// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_external.c
// Function: cram_update_cid2ds_map
cram_cid2ds_t *cram_update_cid2ds_map(cram_block_compression_hdr *hdr,
                                      cram_cid2ds_t *cid2ds) {
    cram_cid2ds_t *c2d = cid2ds;
    if (!c2d) {
        c2d = calloc(1, sizeof(*c2d));
        if (!c2d)
            return NULL;

        c2d->hash = kh_init(cid);
        if (!c2d->hash)
            goto err;
    }

    // Iterate through codecs.  Initially primary two-left ones in
    // rec_encoding_map, and then the three letter in tag_encoding_map.
    cram_codec_iter citer;
    cram_codec_iter_init(hdr, &citer);
    cram_codec *codec;
    int key;

    while ((codec = cram_codec_iter_next(&citer, &key))) {
        // Having got a codec, we can then use cram_codec_to_id to get
        // the block IDs utilised by that codec.  This is then our
        // map for allocating data blocks to data series, but for shared
        // blocks we can't separate out how much is used by each DS.
        int bnum[2];
        cram_codec_get_content_ids(codec, bnum);

        khiter_t k;
        int ret, i;
        for (i = 0; i < 2; i++) {
            if (bnum[i] > -2) {
                k = kh_put(cid, c2d->hash, bnum[i], &ret);
                if (ret < 0)
                    goto err;

                if (c2d->ds_idx >= c2d->ds_size) {
                    c2d->ds_size += 100;
                    c2d->ds_size *= 2;
                    ds_list *ds_new = realloc(c2d->ds,
                                              c2d->ds_size * sizeof(*ds_new));
                    if (!ds_new)
                        goto err;
                    c2d->ds = ds_new;
                }

                if (ret == 0) {
                    // Shared content_id, so add to list of DS

                    // Maybe data-series should be part of the hash key?
                    //
                    // So top-32 bit is content-id, bot-32 bit is key.
                    // Sort hash by key and then can group all the data-series
                    // known together. ??
                    //
                    // Brute force for now, scan to see if recorded.
                    // Typically this is minimal effort as we almost always
                    // have 1 data-series per block content-id, so the list to
                    // search is of size 1.
                    int dsi = kh_value(c2d->hash, k);
                    while (dsi >= 0) {
                        if (c2d->ds[dsi].data_series == key)
                            break;
                        dsi = c2d->ds[dsi].next;
                    }

                    if (dsi == -1) {
                        // Block content_id seen before, but not with this DS
                        c2d->ds[c2d->ds_idx].data_series = key;
                        c2d->ds[c2d->ds_idx].next = kh_value(c2d->hash, k);
                        kh_value(c2d->hash, k) = c2d->ds_idx;
                        c2d->ds_idx++;
                    }
                } else {
                    // First time this content id has been used
                    c2d->ds[c2d->ds_idx].data_series = key;
                    c2d->ds[c2d->ds_idx].next = -1;
                    kh_value(c2d->hash, k) = c2d->ds_idx;
                    c2d->ds_idx++;
                }
            }
        }
    }

    return c2d;

 err:
    if (c2d != cid2ds)
        cram_cid2ds_free(c2d);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq %rsi, %rbx
testq %rsi, %rsi
je 0x90274
leaq 0x20(%rsp), %rdi
movq %r15, (%rdi)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x8(%rdi)
leaq 0x10(%rsp), %rsi
callq 0x902bd
testq %rax, %rax
je 0x902ab
movq %r14, 0x18(%rsp)
leaq 0xc(%rsp), %r15
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %r14
movq %rax, %rdi
callq 0x15ca0
movl %eax, 0x8(%rsp)
movb $0x1, %r13b
movl 0x10(%rsp), %r8d
movq %r14, %rax
movl %r8d, 0x14(%rsp)
movl (%rax), %r14d
cmpl $-0x1, %r14d
jl 0x90229
movq 0x10(%rbx), %rbp
movl 0x8(%rbp), %eax
cmpl 0xc(%rbp), %eax
jb 0x90072
movl (%rbp), %esi
movl 0x4(%rbp), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x90060
decl %esi
jmp 0x90062
incl %esi
movq %rbp, %rdi
callq 0x90f93
testl %eax, %eax
js 0x90260
movl (%rbp), %edx
leal -0x1(%rdx), %edi
movl %edi, %esi
andl %r14d, %esi
movq 0x10(%rbp), %rax
movl %esi, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r8d
leal (%rsi,%rsi), %ecx
shrl %cl, %r8d
testb $0x2, %r8b
je 0x9009b
movl %esi, %r12d
jmp 0x90115
movl $0x1, %r9d
movl %esi, %r8d
movl %edx, %r12d
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r10d
leal (%r8,%r8), %ecx
andl $0x1e, %ecx
movl %r10d, %r11d
shrl %cl, %r11d
testb $0x2, %r11b
jne 0x900f8
testb $0x1, %r11b
jne 0x900d7
movq 0x18(%rbp), %r11
movl %r8d, %r15d
cmpl %r14d, (%r11,%r15,4)
je 0x900f8
btl %ecx, %r10d
cmovbl %r8d, %r12d
addl %r9d, %r8d
andl %edi, %r8d
incl %r9d
cmpl %esi, %r8d
jne 0x900a7
movb $0x1, %cl
movl %edx, %edi
cmpl %edx, %r12d
je 0x90108
jmp 0x90115
shrl %cl, %r10d
testb $0x2, %r10b
sete %cl
movl %r12d, %edi
movl %r8d, %esi
cmpl %edx, %edi
cmovel %esi, %edi
testb %cl, %cl
cmovnel %esi, %edi
movl %edi, %r12d
movl %r12d, %edx
shrl $0x4, %edx
movl (%rax,%rdx,4), %esi
leal (%r12,%r12), %ecx
andl $0x1e, %ecx
shrl %cl, %esi
testb $0x2, %sil
jne 0x90152
movb $0x1, %r15b
testb $0x1, %sil
je 0x9017e
movq 0x18(%rbp), %rsi
movl %r12d, %edi
movl %r14d, (%rsi,%rdi,4)
movl $0x3, %esi
shll %cl, %esi
notl %esi
andl %esi, (%rax,%rdx,4)
incl 0x4(%rbp)
jmp 0x9017b
movq 0x18(%rbp), %rsi
movl %r12d, %edi
movl %r14d, (%rsi,%rdi,4)
movl $0x3, %esi
shll %cl, %esi
notl %esi
andl %esi, (%rax,%rdx,4)
movq 0x4(%rbp), %xmm0
psubd 0x3e0fa(%rip), %xmm0    # 0xce270
movq %xmm0, 0x4(%rbp)
xorl %r15d, %r15d
movl 0x8(%rbx), %eax
cmpl %eax, 0xc(%rbx)
jl 0x901ab
leal 0xc8(,%rax,2), %eax
movl %eax, 0x8(%rbx)
movq (%rbx), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x162c0
testq %rax, %rax
je 0x90260
movq %rax, (%rbx)
testb %r15b, %r15b
movl 0x14(%rsp), %r8d
je 0x901fd
movq 0x10(%rbx), %rax
movq 0x20(%rax), %rax
movl %r12d, %ecx
movl (%rax,%rcx,8), %edx
movl %edx, %edi
testl %edx, %edx
leaq 0xc(%rsp), %r15
js 0x901e3
movq (%rbx), %rsi
movl %edx, %edi
movl %edi, %edi
cmpl %r8d, (%rsi,%rdi,8)
je 0x90229
movl 0x4(%rsi,%rdi,8), %edi
testl %edi, %edi
jns 0x901d3
cmpl $-0x1, %edi
jne 0x90229
movq (%rbx), %rdi
movslq 0xc(%rbx), %rsi
movl %r8d, (%rdi,%rsi,8)
movl %edx, 0x4(%rdi,%rsi,8)
movq %rsi, (%rax,%rcx,8)
jmp 0x90224
movq (%rbx), %rax
movslq 0xc(%rbx), %rsi
movl %r8d, (%rax,%rsi,8)
movl $0xffffffff, 0x4(%rax,%rsi,8) # imm = 0xFFFFFFFF
movq 0x10(%rbx), %rax
movq 0x20(%rax), %rax
movl %r12d, %ecx
movq %rsi, (%rax,%rcx,8)
leaq 0xc(%rsp), %r15
incl %esi
movl %esi, 0xc(%rbx)
movq %r15, %rax
testb $0x1, %r13b
movl $0x0, %r13d
jne 0x90037
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x902bd
testq %rax, %rax
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %r14
jne 0x9001b
jmp 0x902ab
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x902a9
movq %rbx, %rdi
callq 0x153e0
jmp 0x902a9
movl $0x1, %edi
movl $0x20, %esi
callq 0x15e90
testq %rax, %rax
je 0x902a9
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x15e90
movq %rax, 0x10(%rbx)
testq %rax, %rax
jne 0x8ffe3
jmp 0x90265
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq