// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/sdict.c
// Function: asm_index
void asm_index(asm_dict_t *d)
{
    int32_t i, s, c;
    uint64_t *a, last;
    sd_seg_t seg;

    s = d->u;
    if (s == 0) return;

    c_pair_t *c_pairs;
    c_pairs = (c_pair_t *) malloc(s * sizeof(c_pair_t));
    for(i = 0; i < s; ++i) {
        seg = d->seg[i];
        c_pairs[i].x = (uint64_t) seg.c >> 1 << 32 | (seg.x + seg.y);
        c_pairs[i].y = (uint64_t) (seg.x + seg.y) << 32 | i;
    }

    radix_sort_pair(c_pairs, c_pairs + s);
    
    if (d->index)
        free(d->index);
    d->index = (uint64_t *) malloc(s * sizeof(uint64_t));
    a = d->a;
    memset(a, 0, sizeof(uint64_t) * d->sdict->n);
    d->index[0] = c_pairs[0].y;
    c = c_pairs[0].x >> 32;
    for (i = 1, last = 0; i < s; ++i) {
        d->index[i] = c_pairs[i].y;
        if (c != c_pairs[i].x >> 32) {
            a[c] = last << 32 | (i - last);
            last = i;
            c = c_pairs[i].x >> 32;
        }
    }
    a[c] = last << 32 | (i - last);

    free(c_pairs);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x6f31
jmp 0x713a
movslq -0x10(%rbp), %rdi
shlq $0x4, %rdi
callq 0x2260
movq %rax, -0x60(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x6fd5
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movslq -0xc(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rsi
leaq -0x58(%rbp), %rdi
movl $0x30, %edx
callq 0x2220
movl -0x40(%rbp), %eax
movl %eax, %ecx
shrq %rcx
shlq $0x20, %rcx
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, %eax
orq %rax, %rcx
movq -0x60(%rbp), %rax
movslq -0xc(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
shlq $0x20, %rcx
movslq -0xc(%rbp), %rax
orq %rax, %rcx
movq -0x60(%rbp), %rax
movslq -0xc(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x6f49
movq -0x60(%rbp), %rdi
movq -0x60(%rbp), %rsi
movslq -0x10(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x6eb0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x7005
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2050
movslq -0x10(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2260
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl (%rax), %eax
movl %eax, %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x2170
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x14(%rbp)
movl $0x1, -0xc(%rbp)
movq $0x0, -0x28(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x7112
movq -0x60(%rbp), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0x14(%rbp), %rax
movq -0x60(%rbp), %rcx
movslq -0xc(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x7102
movq -0x28(%rbp), %rdx
shlq $0x20, %rdx
movslq -0xc(%rbp), %rax
subq -0x28(%rbp), %rax
orq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0xc(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x60(%rbp), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x14(%rbp)
jmp 0x7104
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x7074
movq -0x28(%rbp), %rdx
shlq $0x20, %rdx
movslq -0xc(%rbp), %rax
subq -0x28(%rbp), %rax
orq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x60(%rbp), %rdi
callq 0x2050
addq $0x60, %rsp
popq %rbp
retq