// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/regidx.c
// Function: reglist_build_index_
static int reglist_build_index_(regidx_t *regidx, reglist_t *list)
{
    int i;
    if ( list->unsorted ) {
        if ( !regidx->payload_size ) {
            qsort(list->reg,list->nreg,sizeof(reg_t),cmp_reg_ptrs);
        } else {
            reg_t **ptr = malloc(sizeof(*ptr)*list->nreg);
            if (!ptr) return -1;
            for (i=0; i<list->nreg; i++) ptr[i] = list->reg + i;
            qsort(ptr,list->nreg,sizeof(*ptr),cmp_reg_ptrs2);

            uint8_t *tmp_dat = malloc(regidx->payload_size*list->nreg);
            if (!tmp_dat) { free(ptr); return -1; }
            for (i=0; i<list->nreg; i++) {
                size_t iori = ptr[i] - list->reg;
                memcpy(tmp_dat+i*regidx->payload_size,
                       list->dat+iori*regidx->payload_size,
                       regidx->payload_size);
            }
            free(list->dat);
            list->dat = tmp_dat;

            reg_t *tmp_reg = (reg_t*) malloc(sizeof(reg_t)*list->nreg);
            if (!tmp_reg) { free(ptr); return -1; }
            for (i=0; i<list->nreg; i++) {
                size_t iori = ptr[i] - list->reg;
                tmp_reg[i] = list->reg[iori];
            }
            free(ptr);
            free(list->reg);
            list->reg  = tmp_reg;
            list->mreg = list->nreg;
        }
        list->unsorted = 0;
    }

    list->nidx = 0;
    uint32_t j,k, midx = 0;
    // Find highest index bin.  It's possible that we could just look at
    // the last region, but go through the list in case some entries overlap.
    for (j=0; j<list->nreg; j++) {
        int iend = iBIN(list->reg[j].end);
        if (midx <= iend) midx = iend;
    }
    midx++;
    uint32_t *new_idx = calloc(midx, sizeof(uint32_t));
    if (!new_idx) return -1;
    free(list->idx); // Should be NULL on entry, but just in case...
    list->idx = new_idx;
    list->nidx = midx;

    for (j=0; j<list->nreg; j++) {
        int ibeg = iBIN(list->reg[j].beg);
        int iend = iBIN(list->reg[j].end);
        if ( ibeg==iend ) {
            if ( !list->idx[ibeg] ) list->idx[ibeg] = j + 1;
        } else {
            for (k=ibeg; k<=iend; k++)
                if ( !list->idx[k] ) list->idx[k] = j + 1;
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x2f547
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x2f31f
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
movl $0x10, %edx
leaq 0x168b(%rip), %rcx      # 0x309a0
callq 0x4990
jmp 0x2f53c
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x4650
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2f348
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2f6ca
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x2f385
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
movslq -0x1c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2f34f
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %esi
movl $0x8, %edx
leaq 0x1632(%rip), %rcx      # 0x309d0
callq 0x4990
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x18(%rbp), %rcx
imull 0xc(%rcx), %eax
movl %eax, %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2f3db
movq -0x28(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2f6ca
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x2f454
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
sarq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
imull 0x38(%rcx), %eax
cltq
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x38(%rcx), %rcx
imulq %rcx, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movslq 0x38(%rax), %rdx
callq 0x43b0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2f3e2
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x45a0
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
shlq $0x4, %rdi
callq 0x4650
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2f49f
movq -0x28(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2f6ca
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x2f50c
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
sarq $0x4, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x48(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2f4a6
movq -0x28(%rbp), %rdi
callq 0x45a0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x45a0
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x8(%rax)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x2f5a4
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
sarq $0xd, %rax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x58(%rbp), %eax
ja 0x2f597
movl -0x58(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x2f599
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2f560
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x42f0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x2f5d3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2f6ca
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x45a0
movq -0x60(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x54(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x2f6c3
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
sarq $0xd, %rax
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
sarq $0xd, %rax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
jne 0x2f673
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x64(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x2f671
movl -0x4c(%rbp), %edx
addl $0x1, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x64(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x2f6b3
movl -0x64(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x68(%rbp), %eax
ja 0x2f6b1
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x50(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
jne 0x2f6a4
movl -0x4c(%rbp), %edx
addl $0x1, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x50(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x2f6a6
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2f679
jmp 0x2f6b3
jmp 0x2f6b5
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2f5fb
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)