// File: /workspace/github_c_makefile_star2_O1/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 %rdi, %r12
movq %rsi, %rbx
movq %rsi, 0x18(%rsp)
testq %rsi, %rsi
je 0x930b1
leaq 0x20(%rsp), %rax
movq %r12, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
leaq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x93107
testq %rax, %rax
je 0x930f5
movq %rax, %rdi
leaq 0x14(%rsp), %rsi
callq 0x15cb0
movl %eax, 0x10(%rsp)
movl 0xc(%rsp), %r9d
xorl %r12d, %r12d
movl %r9d, 0x8(%rsp)
movl 0x10(%rsp,%r12,4), %r15d
cmpl $-0x1, %r15d
jl 0x93088
movq 0x10(%rbx), %rbp
movl 0x8(%rbp), %eax
cmpl 0xc(%rbp), %eax
jb 0x92eb6
movl (%rbp), %esi
movl 0x4(%rbp), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x92ea4
decl %esi
jmp 0x92ea6
incl %esi
movq %rbp, %rdi
callq 0x93e6f
testl %eax, %eax
js 0x92f36
movl (%rbp), %edx
leal -0x1(%rdx), %r8d
movl %r8d, %r13d
andl %r15d, %r13d
movq 0x10(%rbp), %rax
movl %r13d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %esi
leal (,%r13,2), %ecx
shrl %cl, %esi
testb $0x2, %sil
jne 0x92f68
movl $0x1, %r9d
movl %r13d, %edi
movl %edx, %esi
movl %edi, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r10d
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %r10d, %r11d
shrl %cl, %r11d
testb $0x2, %r11b
jne 0x92f41
testb $0x1, %r11b
jne 0x92f1d
movq 0x18(%rbp), %r11
movl %edi, %r14d
cmpl %r15d, (%r11,%r14,4)
je 0x92f41
btl %ecx, %r10d
cmovbl %edi, %esi
addl %r9d, %edi
andl %r8d, %edi
incl %r9d
movl %esi, %ecx
cmpl %r13d, %edi
jne 0x92eef
jmp 0x92f43
movl (%rbp), %r13d
movb $0x1, %al
jmp 0x92fcc
movl %edx, %ecx
movl %ecx, %r13d
cmpl %edx, %ecx
jne 0x92f68
movl %edi, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r8d
leal (%rdi,%rdi), %ecx
shrl %cl, %r8d
cmpl %edx, %esi
cmovel %edi, %esi
testb $0x2, %r8b
cmovel %edi, %esi
movl %esi, %r13d
movl %r13d, %edx
shrl $0x4, %edx
movl (%rax,%rdx,4), %esi
leal (,%r13,2), %ecx
andl $0x1e, %ecx
shrl %cl, %esi
testb $0x2, %sil
jne 0x92f91
testb $0x1, %sil
jne 0x92fb0
movb $0x1, %bpl
xorl %eax, %eax
jmp 0x92fce
movq 0x18(%rbp), %rsi
movl %r13d, %edi
movl %r15d, (%rsi,%rdi,4)
movl $0x3, %esi
shll %cl, %esi
notl %esi
andl %esi, (%rax,%rdx,4)
incl 0x4(%rbp)
incl 0x8(%rbp)
jmp 0x92fca
movq 0x18(%rbp), %rsi
movl %r13d, %edi
movl %r15d, (%rsi,%rdi,4)
movl $0x3, %esi
shll %cl, %esi
notl %esi
andl %esi, (%rax,%rdx,4)
incl 0x4(%rbp)
xorl %eax, %eax
xorl %ebp, %ebp
testb %al, %al
jne 0x9309d
movl 0x8(%rbx), %eax
cmpl %eax, 0xc(%rbx)
jl 0x93011
leal 0xc8(,%rax,2), %eax
movl %eax, 0x8(%rbx)
movq (%rbx), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x162d0
testq %rax, %rax
je 0x93003
movq %rax, (%rbx)
xorl %ecx, %ecx
jmp 0x93008
movl $0x2, %ecx
testq %rax, %rax
je 0x930a2
testb %bpl, %bpl
je 0x9305c
movq 0x10(%rbx), %rax
movq 0x20(%rax), %rax
movl %r13d, %ecx
movl (%rax,%rcx,8), %edx
movl %edx, %esi
testl %edx, %edx
movl 0x8(%rsp), %r9d
js 0x93046
movq (%rbx), %rdi
movl %edx, %esi
movl %esi, %r8d
cmpl %r9d, (%rdi,%r8,8)
je 0x93046
movl 0x4(%rdi,%r8,8), %esi
testl %esi, %esi
jns 0x93034
cmpl $-0x1, %esi
jne 0x93088
movq (%rbx), %rdi
movslq 0xc(%rbx), %rsi
movl %r9d, (%rdi,%rsi,8)
movl %edx, 0x4(%rdi,%rsi,8)
jmp 0x9307f
movq (%rbx), %rax
movslq 0xc(%rbx), %rsi
movl 0x8(%rsp), %r9d
movl %r9d, (%rax,%rsi,8)
movl $0xffffffff, 0x4(%rax,%rsi,8) # imm = 0xFFFFFFFF
movq 0x10(%rbx), %rax
movq 0x20(%rax), %rax
movl %r13d, %ecx
movq %rsi, (%rax,%rcx,8)
incl %esi
movl %esi, 0xc(%rbx)
leaq 0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
je 0x92e79
xorl %ecx, %ecx
jmp 0x930a2
movl $0x2, %ecx
testl %ecx, %ecx
je 0x92e43
cmpl $0x2, %ecx
je 0x930e4
jmp 0x930f5
movl $0x1, %edi
movl $0x20, %esi
callq 0x15ea0
testq %rax, %rax
je 0x930f3
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x15ea0
movq %rax, 0x10(%rbx)
testq %rax, %rax
jne 0x92e34
cmpq 0x18(%rsp), %rbx
je 0x930f3
movq %rbx, %rdi
callq 0x153e0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq