// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xc3268
movl $0x1, %edi
movl $0x20, %esi
callq 0x16060
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xc3246
movq $0x0, -0x8(%rbp)
jmp 0xc348c
callq 0xc34a0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xc3266
jmp 0xc3471
jmp 0xc3268
movq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xc34c0
leaq -0x38(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0xc3500
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0xc3467
movq -0x40(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x16770
movl $0x0, -0x58(%rbp)
cmpl $0x2, -0x58(%rbp)
jge 0xc3462
movslq -0x58(%rbp), %rax
cmpl $-0x2, -0x4c(%rbp,%rax,4)
jle 0xc3452
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x58(%rbp), %rax
movl -0x4c(%rbp,%rax,4), %esi
leaq -0x54(%rbp), %rdx
callq 0xc36a0
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x54(%rbp)
jge 0xc32e4
jmp 0xc3471
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jl 0xc3340
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x64, %ecx
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
shll %ecx
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movslq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x164b0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0xc3335
jmp 0xc3471
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x54(%rbp)
jne 0xc33fc
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jl 0xc338f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movslq -0x64(%rbp), %rcx
movl (%rax,%rcx,8), %eax
cmpl -0x44(%rbp), %eax
jne 0xc337b
jmp 0xc338f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movslq -0x64(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %eax
movl %eax, -0x64(%rbp)
jmp 0xc3360
cmpl $-0x1, -0x64(%rbp)
jne 0xc33fa
movl -0x44(%rbp), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq 0xc(%rcx), %rcx
movl %edx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq 0xc(%rcx), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movq -0x20(%rbp), %rax
movslq 0xc(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movl -0x50(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
jmp 0xc3450
movl -0x44(%rbp), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq 0xc(%rcx), %rcx
movl %edx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movslq 0xc(%rcx), %rcx
movl $0xffffffff, 0x4(%rax,%rcx,8) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movslq 0xc(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movl -0x50(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
jmp 0xc3452
jmp 0xc3454
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xc32a4
jmp 0xc3275
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc348c
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0xc3484
movq -0x20(%rbp), %rdi
callq 0x15540
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)