// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/region.c
// Function: hts_reglist_create
hts_reglist_t *hts_reglist_create(char **argv, int argc, int *r_count, void *hdr,  hts_name2id_f getid) {

    if (!argv || argc < 1)
        return NULL;

    reghash_t *h = NULL;
    reglist_t *p;
    hts_reglist_t *h_reglist = NULL;

    khint_t k;
    int i, l_count = 0, tid;
    const char *q;
    hts_pos_t beg, end;

    /* First, transform the char array into a hash table */
    h = kh_init(reg);
    if (!h) {
        hts_log_error("Error when creating the region hash table");
        return NULL;
    }

    for (i=0; i<argc; i++) {
        if (!strcmp(argv[i], ".")) {
            q = argv[i] + 1;
            tid = HTS_IDX_START; beg = 0; end = INT64_MAX;
        } else if (!strcmp(argv[i], "*")) {
            q = argv[i] + 1;
            tid = HTS_IDX_NOCOOR; beg = 0; end = INT64_MAX;
        } else {
            q = hts_parse_region(argv[i], &tid, &beg, &end, getid, hdr,
                                 HTS_PARSE_THOUSANDS_SEP);
        }
        if (!q) {
            if (tid < -1) {
                hts_log_error("Failed to parse header");
                goto fail;
            } else {
                // not parsable as a region
                hts_log_warning("Region '%s' specifies an unknown reference name. Continue anyway", argv[i]);
                continue;
            }
        }

        if (reg_insert(h, tid, beg, end) != 0) {
            hts_log_error("Error when inserting region='%s' in the bed hash table at address=%p", argv[i], (void *) h);
            goto fail;
        }
    }

    *r_count = reg_compact(h);
    if (!*r_count)
        goto fail;

    /* Transform the hash table into a list */
    h_reglist = (hts_reglist_t *)calloc(*r_count, sizeof(hts_reglist_t));
    if (!h_reglist)
        goto fail;

    for (k = kh_begin(h); k < kh_end(h) && l_count < *r_count; k++) {
        if (!kh_exist(h,k) || !(p = &kh_val(h,k)))
            continue;

        h_reglist[l_count].tid = p->tid;
        h_reglist[l_count].intervals = p->a;
        h_reglist[l_count].count = p->n;
        p->a = NULL; // As we stole it.

        // After reg_compact(), list is ordered and non-overlapping, so...
        if (p->n > 0) {
            h_reglist[l_count].min_beg = h_reglist[l_count].intervals[0].beg;
            h_reglist[l_count].max_end = h_reglist[l_count].intervals[p->n - 1].end;
        } else {
            h_reglist[l_count].min_beg = 0;
            h_reglist[l_count].max_end = 0;
        }

        l_count++;
    }
    reg_destroy(h);

    return h_reglist;

fail:
    reg_destroy(h);
    if(h_reglist) hts_reglist_free(h_reglist, l_count);

    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdi, 0x20(%rsp)
testq %rdi, %rdi
sete %al
testl %esi, %esi
setle %cl
orb %al, %cl
jne 0x22695
movq %rdx, %r14
movl %esi, %ebp
movl $0x1, %edi
movl $0x28, %esi
callq 0x4300
testq %rax, %rax
je 0x2253a
movq %rax, %rbx
movq %r14, 0x38(%rsp)
testl %ebp, %ebp
jle 0x22433
movl %ebp, %eax
movq %rax, 0x50(%rsp)
xorl %r15d, %r15d
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %r14
movq %r14, %rdi
leaq 0x75f32(%rip), %rsi     # 0x9805c
callq 0x46c0
testl %eax, %eax
je 0x221a6
movq %r14, %rdi
leaq 0x79653(%rip), %rsi     # 0x9b790
callq 0x46c0
testl %eax, %eax
je 0x221b0
movl $0x1, (%rsp)
movq %r14, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x28(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x40(%rsp), %r9
callq 0x1a16d
testq %rax, %rax
jne 0x221d0
cmpl $-0x2, 0x14(%rsp)
jle 0x22673
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rcx
movl $0x3, %edi
leaq 0x77e4c(%rip), %rsi     # 0x99fdf
leaq 0x775a4(%rip), %rdx     # 0x9973e
xorl %eax, %eax
callq 0x14378
jmp 0x22425
movl $0xfffffffd, 0x14(%rsp) # imm = 0xFFFFFFFD
jmp 0x221b8
movl $0xfffffffe, 0x14(%rsp) # imm = 0xFFFFFFFE
movq $0x0, 0x30(%rsp)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, 0x28(%rsp)
movl 0x14(%rsp), %ebp
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %r14
movl (%rbx), %esi
testl %esi, %esi
je 0x22241
leal -0x1(%rsi), %edx
movl %edx, %edi
andl %ebp, %edi
movq 0x10(%rbx), %r8
movl $0x1, %r9d
movl %edi, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl (%r8,%rcx,4), %r10d
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %r10d, %r11d
shrl %cl, %r11d
testb $0x2, %r11b
jne 0x22235
testb $0x1, %r11b
jne 0x22225
movq 0x18(%rbx), %r11
movl %eax, %r13d
cmpl %ebp, (%r11,%r13,4)
je 0x22235
addl %r9d, %eax
andl %edx, %eax
incl %r9d
cmpl %edi, %eax
jne 0x221f7
movl %esi, %eax
jmp 0x22243
shrl %cl, %r10d
testb $0x3, %r10b
cmovnel %esi, %eax
jmp 0x22243
xorl %eax, %eax
cmpl %esi, %eax
jne 0x223bc
movl 0x8(%rbx), %eax
cmpl 0xc(%rbx), %eax
jb 0x22272
movl 0x4(%rbx), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x22260
decl %esi
jmp 0x22262
incl %esi
movq %rbx, %rdi
callq 0x22770
testl %eax, %eax
js 0x222ff
movl (%rbx), %esi
leal -0x1(%rsi), %r9d
movl %r9d, %eax
andl %ebp, %eax
movq 0x10(%rbx), %rdx
movl %eax, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %edi
leal (%rax,%rax), %ecx
shrl %cl, %edi
testb $0x2, %dil
jne 0x22337
movl $0x1, %r10d
movl %eax, %r8d
movq %rsi, 0x18(%rsp)
movl %esi, %edi
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %r11d
leal (%r8,%r8), %ecx
andl $0x1e, %ecx
movl %r11d, %r13d
shrl %cl, %r13d
testb $0x2, %r13b
jne 0x22308
testb $0x1, %r13b
jne 0x222e5
movq 0x18(%rbx), %r13
movq %r12, %rsi
movq %r14, %r12
movl %r8d, %r14d
cmpl %ebp, (%r13,%r14,4)
movq %r12, %r14
movq %rsi, %r12
je 0x22308
btl %ecx, %r11d
cmovbl %r8d, %edi
addl %r10d, %r8d
andl %r9d, %r8d
incl %r10d
movl %edi, %ecx
cmpl %eax, %r8d
jne 0x222a8
jmp 0x2230f
movl (%rbx), %eax
movb $0x1, %cl
jmp 0x2238e
movq 0x18(%rsp), %rax
movl %eax, %ecx
movl %ecx, %eax
movq 0x18(%rsp), %rsi
cmpl %esi, %ecx
jne 0x22337
movl %r8d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %eax
leal (%r8,%r8), %ecx
shrl %cl, %eax
cmpl %esi, %edi
cmovel %r8d, %edi
testb $0x2, %al
cmovel %r8d, %edi
movl %edi, %eax
movl %eax, %esi
shrl $0x4, %esi
movl (%rdx,%rsi,4), %edi
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
shrl %cl, %edi
testb $0x2, %dil
jne 0x2236f
testb $0x1, %dil
je 0x2238c
movq 0x18(%rbx), %rdi
movl %eax, %r8d
movl %ebp, (%rdi,%r8,4)
movl $0x3, %edi
shll %cl, %edi
notl %edi
andl %edi, (%rdx,%rsi,4)
incl 0x4(%rbx)
jmp 0x2238c
movq 0x18(%rbx), %rdi
movl %eax, %r8d
movl %ebp, (%rdi,%r8,4)
movl $0x3, %edi
shll %cl, %edi
notl %edi
andl %edi, (%rdx,%rsi,4)
incl 0x4(%rbx)
incl 0x8(%rbx)
xorl %ecx, %ecx
testb %cl, %cl
jne 0x2255c
movq 0x20(%rbx), %rcx
movl %eax, %edx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
xorps %xmm0, %xmm0
movups %xmm0, (%rcx,%rdx)
movq $0x0, 0x10(%rcx,%rdx)
movq 0x20(%rbx), %rcx
movl %ebp, 0x10(%rcx,%rdx)
movq 0x20(%rbx), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rbp
movl 0x4(%rbp), %eax
cmpl %eax, (%rbp)
jne 0x2240b
leal (%rax,%rax), %r13d
testl %eax, %eax
movl $0x4, %eax
cmovel %eax, %r13d
testl %r13d, %r13d
je 0x2255c
movq 0x8(%rbp), %rdi
movl %r13d, %esi
shlq $0x4, %rsi
callq 0x4840
testq %rax, %rax
je 0x2255c
movl %r13d, 0x4(%rbp)
movq %rax, 0x8(%rbp)
movq 0x8(%rbp), %rax
movl (%rbp), %ecx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq %r12, (%rax,%rcx)
movl %edx, (%rbp)
movq %r14, 0x8(%rax,%rcx)
incq %r15
cmpq 0x50(%rsp), %r15
jne 0x22117
cmpl $0x0, (%rbx)
je 0x22587
xorl %r15d, %r15d
leaq 0x641(%rip), %r14       # 0x22a87
xorl %ebp, %ebp
movq 0x10(%rbx), %rax
movl %r15d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
leal (%r15,%r15), %ecx
shrl %cl, %eax
testb $0x3, %al
je 0x2246e
incq %r15
movl (%rbx), %eax
cmpq %rax, %r15
jb 0x22448
jmp 0x22589
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x2245f
leaq (%r15,%r15,2), %rcx
leaq (%rax,%rcx,8), %r12
movl (%r12), %esi
testq %rsi, %rsi
je 0x2245f
movq 0x8(%r12), %rdi
movl $0x10, %edx
movq %r14, %rcx
callq 0x4990
movl (%r12), %eax
movl $0x1, %r13d
cmpq $0x2, %rax
jb 0x2250f
movq 0x8(%r12), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
addq $-0x10, %rdx
xorl %esi, %esi
xorl %r13d, %r13d
movl %r13d, %edi
shlq $0x4, %rdi
movq 0x8(%rcx,%rdi), %r9
movq 0x10(%rcx,%rsi), %r8
cmpq %r8, %r9
jge 0x224ef
incl %r13d
movq %r13, %rdi
shlq $0x4, %rdi
movq %r8, (%rcx,%rdi)
movq 0x18(%rcx,%rsi), %r8
movq %r8, 0x8(%rcx,%rdi)
jmp 0x22503
movq 0x18(%rcx,%rsi), %r8
cmpq %r8, %r9
jge 0x22503
addq %rcx, %rdi
addq $0x8, %rdi
movq %r8, (%rdi)
addq $0x10, %rsi
cmpq %rsi, %rdx
jne 0x224bf
incl %r13d
cmpl %r13d, %eax
jbe 0x2252f
movq 0x8(%r12), %rdi
movl %r13d, %esi
shlq $0x4, %rsi
callq 0x4840
testq %rax, %rax
je 0x2252f
movq %rax, 0x8(%r12)
movl %r13d, (%r12)
incl %ebp
jmp 0x2245f
leaq 0x77a9e(%rip), %rsi     # 0x99fdf
leaq 0x77aaa(%rip), %rdx     # 0x99ff2
xorl %r14d, %r14d
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x22698
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rcx
leaq 0x77a73(%rip), %rsi     # 0x99fdf
leaq 0x77aa9(%rip), %rdx     # 0x9a01c
movl $0x1, %edi
movq %rbx, %r8
xorl %eax, %eax
callq 0x14378
jmp 0x2268d
xorl %ebp, %ebp
movq 0x38(%rsp), %rax
movl %ebp, (%rax)
testl %ebp, %ebp
je 0x2268d
movslq %ebp, %rdi
movl $0x28, %esi
callq 0x4300
testq %rax, %rax
je 0x2268d
movq %rax, %r14
movl (%rbx), %eax
testq %rax, %rax
sete %cl
testl %ebp, %ebp
setle %dl
orb %cl, %dl
jne 0x22669
movq 0x10(%rbx), %rdx
movl $0x8, %esi
xorl %edi, %edi
xorps %xmm0, %xmm0
xorl %r8d, %r8d
xorl %r9d, %r9d
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %r10d
movl %edi, %ecx
andb $0x1e, %cl
shrl %cl, %r10d
testb $0x3, %r10b
jne 0x22651
movq 0x20(%rbx), %r15
testq %r15, %r15
je 0x22651
movl (%r15,%rsi,2), %r10d
movslq %r9d, %rcx
leaq (%rcx,%rcx,4), %r12
leaq (%r14,%r12,8), %rcx
movl %r10d, 0x10(%r14,%r12,8)
movq -0x8(%r15,%rsi,2), %r10
movq %r10, 0x8(%r14,%r12,8)
movl -0x10(%r15,%rsi,2), %r11d
movl %r11d, 0x14(%r14,%r12,8)
movq $0x0, -0x8(%r15,%rsi,2)
testl %r11d, %r11d
je 0x2264a
movq (%r10), %r15
movq %r15, 0x18(%rcx)
decl %r11d
shlq $0x4, %r11
movq 0x8(%r10,%r11), %r10
movq %r10, 0x20(%rcx)
jmp 0x2264e
movups %xmm0, 0x18(%rcx)
incl %r9d
incq %r8
cmpq %rax, %r8
jae 0x22669
addq $0xc, %rsi
addl $0x2, %edi
cmpl %ebp, %r9d
jl 0x225da
movq %rbx, %rdi
callq 0x226aa
jmp 0x22698
leaq 0x77965(%rip), %rsi     # 0x99fdf
leaq 0x770a6(%rip), %rdx     # 0x99727
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
movq %rbx, %rdi
callq 0x226aa
xorl %r14d, %r14d
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq