// File: karel-brinda[P]ococo/ext/htslib/hts.c
// Function: compress_binning
static void compress_binning(hts_idx_t *idx, int i)
{
    bidx_t *bidx = idx->bidx[i];
    khint_t k;
    int l, m;
    if (bidx == 0) return;
    // merge a bin to its parent if the bin is too small
    for (l = idx->n_lvls; l > 0; --l) {
        unsigned start = hts_bin_first(l);
        for (k = kh_begin(bidx); k != kh_end(bidx); ++k) {
            bins_t *p, *q;
            if (!kh_exist(bidx, k) || kh_key(bidx, k) >= idx->n_bins || kh_key(bidx, k) < start) continue;
            p = &kh_value(bidx, k);
            if (l < idx->n_lvls && p->n > 1) ks_introsort(_off, p->n, p->list);
            if ((p->list[p->n - 1].v>>16) - (p->list[0].u>>16) < HTS_MIN_MARKER_DIST) {
                khint_t kp;
                kp = kh_get(bin, bidx, hts_bin_parent(kh_key(bidx, k)));
                if (kp == kh_end(bidx)) continue;
                q = &kh_val(bidx, kp);
                if (q->n + p->n > q->m) {
                    q->m = q->n + p->n;
                    kroundup32(q->m);
                    q->list = (hts_pair64_t*)realloc(q->list, q->m * sizeof(hts_pair64_t));
                }
                memcpy(q->list + q->n, p->list, p->n * sizeof(hts_pair64_t));
                q->n += p->n;
                free(p->list);
                kh_del(bin, bidx, k);
            }
        }
    }
    k = kh_get(bin, bidx, 0);
    if (k != kh_end(bidx)) ks_introsort(_off, kh_val(bidx, k).n, kh_val(bidx, k).list);
    // merge adjacent chunks that start from the same BGZF block
    for (k = kh_begin(bidx); k != kh_end(bidx); ++k) {
        bins_t *p;
        if (!kh_exist(bidx, k) || kh_key(bidx, k) >= idx->n_bins) continue;
        p = &kh_value(bidx, k);
        for (l = 1, m = 0; l < p->n; ++l) {
            if (p->list[m].v>>16 >= p->list[l].u>>16) {
                if (p->list[m].v < p->list[l].v) p->list[m].v = p->list[l].v;
            } else p->list[++m] = p->list[l];
        }
        p->n = m + 1;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x165ef
jmp 0x16a5e
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x16888
movl -0x20(%rbp), %ecx
shll %ecx
addl -0x20(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl $0x7, %ecx
cltd
idivl %ecx
movl %eax, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x16878
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x1c(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x16685
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x16685
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x28(%rbp), %eax
jae 0x1668a
jmp 0x1686a
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x166cb
movq -0x30(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jle 0x166cb
movq -0x30(%rbp), %rax
movslq 0x4(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x156c0
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x10, %rax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rcx
shrq $0x10, %rcx
subq %rcx, %rax
cmpq $0x10000, %rax          # imm = 0x10000
jae 0x16868
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,4), %esi
subl $0x1, %esi
shrl $0x3, %esi
callq 0x17c30
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x1673d
jmp 0x1686a
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x30(%rbp), %rcx
addl 0x4(%rcx), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
jle 0x1680e
movq -0x38(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x30(%rbp), %rax
addl 0x4(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
sarl %ecx
movq -0x38(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
sarl $0x2, %ecx
movq -0x38(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
sarl $0x4, %ecx
movq -0x38(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
sarl $0x8, %ecx
movq -0x38(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
sarl $0x10, %ecx
movq -0x38(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
movslq (%rax), %rsi
shlq $0x4, %rsi
callq 0x4990
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
movslq 0x4(%rax), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
movslq 0x4(%rax), %rdx
shlq $0x4, %rdx
callq 0x4460
movq -0x30(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x38(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x46a0
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x1a330
jmp 0x1686a
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x16627
jmp 0x1687a
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x165f9
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x17c30
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x168d2
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
callq 0x156c0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x16a5e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x1c(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x16924
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jb 0x16929
jmp 0x16a50
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x1, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x20(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x16a43
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x10, %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x10, %rcx
cmpq %rcx, %rax
jb 0x169f7
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jae 0x169f5
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x16a33
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x24(%rbp)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x16a35
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1694d
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x168d9
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)