// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movq %r8, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdi, 0x10(%rsp)
testq %rdi, %rdi
sete %al
testl %esi, %esi
setle %cl
orb %al, %cl
jne 0x21cf4
movq %rdx, %r15
movl %esi, %r14d
movl $0x1, %edi
movl $0x28, %esi
callq 0x4300
testq %rax, %rax
je 0x21ba3
movq %rax, %rbx
movq %r15, 0x48(%rsp)
movl %r14d, %eax
movq %rax, 0x60(%rsp)
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %rbx, 0x28(%rsp)
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rdi
movzbl (%rdi), %eax
cmpl $0x2a, %eax
je 0x2178d
cmpl $0x2e, %eax
jne 0x21793
cmpb $0x0, 0x1(%rdi)
jne 0x21793
movl $0xfffffffd, 0x1c(%rsp) # imm = 0xFFFFFFFD
movq $0x0, 0x40(%rsp)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, 0x38(%rsp)
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
jmp 0x2182d
cmpb $0x0, 0x1(%rdi)
je 0x21808
movl $0x1, (%rsp)
leaq 0x1c(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x38(%rsp), %rcx
movq 0x58(%rsp), %r8
movq 0x50(%rsp), %r9
callq 0x19c07
movl 0x1c(%rsp), %ebp
testq %rax, %rax
je 0x217d7
movq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x2183b
cmpl $-0x2, %ebp
jle 0x21cd2
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rcx
movl $0x3, %edi
leaq 0x758cb(%rip), %rsi     # 0x970c0
leaq 0x74fe2(%rip), %rdx     # 0x967de
xorl %eax, %eax
callq 0x13de5
jmp 0x21a82
movl $0xfffffffe, 0x1c(%rsp) # imm = 0xFFFFFFFE
movq $0x0, 0x40(%rsp)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, 0x38(%rsp)
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movq %rax, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testl %r15d, %r15d
je 0x21896
leal -0x1(%r15), %edx
movl %edx, %esi
andl %ebp, %esi
movl $0x1, %edi
movl %esi, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl (%r12,%rcx,4), %r8d
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %r8d, %r9d
shrl %cl, %r9d
testb $0x2, %r9b
jne 0x21889
testb $0x1, %r9b
jne 0x2187d
movq 0x18(%rbx), %r9
movl %eax, %r10d
cmpl %ebp, (%r9,%r10,4)
je 0x21889
addl %edi, %eax
andl %edx, %eax
incl %edi
cmpl %esi, %eax
jne 0x2184f
jmp 0x2189d
shrl %cl, %r8d
testb $0x3, %r8b
cmovnel %r15d, %eax
jmp 0x21898
xorl %eax, %eax
cmpl %r15d, %eax
jne 0x218ba
movl 0x8(%rbx), %eax
cmpl 0xc(%rbx), %eax
jb 0x218d9
movq 0x28(%rsp), %rdi
movl 0x4(%rdi), %eax
addl %eax, %eax
movq %r15, %rsi
cmpl %eax, %esi
jbe 0x218ca
decl %esi
jmp 0x218cc
movl %eax, %eax
leaq (%rax,%rax,2), %rcx
movl (%r13,%rcx,8), %ecx
jmp 0x219fd
incl %esi
callq 0x21dd4
testl %eax, %eax
js 0x21bc5
movq 0x28(%rsp), %rbx
movl (%rbx), %r15d
leal -0x1(%r15), %esi
movl %esi, %edx
andl %ebp, %edx
movq 0x10(%rbx), %r12
movl %edx, %eax
shrl $0x4, %eax
movl (%r12,%rax,4), %eax
leal (%rdx,%rdx), %ecx
shrl %cl, %eax
testb $0x2, %al
je 0x21903
movl %edx, %eax
jmp 0x21976
movl $0x1, %r8d
movl %edx, %edi
movl %r15d, %eax
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r12,%rcx,4), %r9d
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %r9d, %r10d
shrl %cl, %r10d
testb $0x2, %r10b
jne 0x2195b
testb $0x1, %r10b
jne 0x2193c
movq 0x18(%rbx), %r10
movl %edi, %r11d
cmpl %ebp, (%r10,%r11,4)
je 0x2195b
btl %ecx, %r9d
cmovbl %edi, %eax
addl %r8d, %edi
andl %esi, %edi
incl %r8d
cmpl %edx, %edi
jne 0x2190e
movb $0x1, %cl
movl %r15d, %esi
cmpl %r15d, %eax
je 0x21969
jmp 0x21976
shrl %cl, %r9d
testb $0x2, %r9b
sete %cl
movl %eax, %esi
movl %edi, %edx
cmpl %r15d, %esi
cmovel %edx, %esi
testb %cl, %cl
cmovnel %edx, %esi
movl %esi, %eax
movl %eax, %edx
shrl $0x4, %edx
movl (%r12,%rdx,4), %esi
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
shrl %cl, %esi
testb $0x2, %sil
jne 0x21997
testb $0x1, %sil
jne 0x219c1
movl %eax, %eax
jmp 0x219da
movq 0x18(%rbx), %rsi
movl %eax, %eax
movl %ebp, (%rsi,%rax,4)
movl $0x3, %esi
shll %cl, %esi
notl %esi
andl %esi, (%r12,%rdx,4)
movq 0x4(%rbx), %xmm0
psubd 0x756f6(%rip), %xmm0    # 0x970b0
movq %xmm0, 0x4(%rbx)
jmp 0x219da
movq 0x18(%rbx), %rsi
movl %eax, %eax
movl %ebp, (%rsi,%rax,4)
movl $0x3, %esi
shll %cl, %esi
notl %esi
andl %esi, (%r12,%rdx,4)
incl 0x4(%rbx)
movq 0x20(%rbx), %r13
leaq (%rax,%rax,2), %rcx
pxor %xmm0, %xmm0
movdqu %xmm0, (%r13,%rcx,8)
movq $0x0, 0x10(%r13,%rcx,8)
movl %ebp, 0x10(%r13,%rcx,8)
xorl %ecx, %ecx
leaq (%rax,%rax,2), %rax
leaq (,%rax,8), %rbp
addq %r13, %rbp
cmpl 0x4(%rbp), %ecx
jne 0x21a60
movq %r15, %rbx
movq %r13, %r15
leal (%rcx,%rcx), %r13d
testl %ecx, %ecx
movl $0x4, %eax
cmovel %eax, %r13d
testl %r13d, %r13d
je 0x21bc5
movq 0x8(%rbp), %rdi
movl %r13d, %esi
shlq $0x4, %rsi
callq 0x4840
testq %rax, %rax
je 0x21bc5
movl %r13d, 0x4(%rbp)
movq %rax, 0x8(%rbp)
movl (%rbp), %ecx
movq %r15, %r13
movq %rbx, %r15
movq 0x28(%rsp), %rbx
jmp 0x21a64
movq 0x8(%rbp), %rax
movl %ecx, %edx
shlq $0x4, %rdx
movq 0x30(%rsp), %rsi
movq %rsi, (%rax,%rdx)
incl %ecx
movl %ecx, (%rbp)
movq 0x20(%rsp), %rcx
movq %rcx, 0x8(%rax,%rdx)
incq %r14
cmpq 0x60(%rsp), %r14
jne 0x21747
testl %r15d, %r15d
je 0x21cc5
xorl %r14d, %r14d
xorl %ebp, %ebp
movq %r14, %rax
shrq $0x4, %rax
movl (%r12,%rax,4), %eax
leal (%r14,%r14), %ecx
shrl %cl, %eax
testb $0x3, %al
je 0x21ac3
incq %r14
movl %r15d, %eax
cmpq %rax, %r14
jb 0x21a9e
jmp 0x21bf5
testq %r13, %r13
je 0x21ab3
leaq (%r14,%r14,2), %rax
leaq (,%rax,8), %rax
addq %r13, %rax
movl (%rax), %esi
testq %rsi, %rsi
je 0x21ab3
movl %ebp, 0x20(%rsp)
movq 0x8(%rax), %rdi
movl $0x10, %edx
leaq 0x5bd(%rip), %rcx       # 0x220af
movq %rax, 0x10(%rsp)
callq 0x4990
movq 0x10(%rsp), %r10
movl (%r10), %eax
movl $0x1, %ebp
cmpq $0x2, %rax
jb 0x21b95
movq 0x8(%r10), %rdi
movq %rax, %rcx
shlq $0x4, %rcx
xorl %ebp, %ebp
movl $0x10, %edx
movl %ebp, %esi
shlq $0x4, %rsi
movq 0x8(%rdi,%rsi), %r9
movq (%rdi,%rdx), %r8
cmpq %r8, %r9
jge 0x21b52
incl %ebp
movq %rbp, %rsi
shlq $0x4, %rsi
movq %r8, (%rdi,%rsi)
movq 0x8(%rdi,%rdx), %r8
movq %r8, 0x8(%rdi,%rsi)
jmp 0x21b66
movq 0x8(%rdi,%rdx), %r8
cmpq %r8, %r9
jge 0x21b66
addq %rdi, %rsi
addq $0x8, %rsi
movq %r8, (%rsi)
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x21b25
incl %ebp
cmpl %ebp, %eax
jbe 0x21b95
movl %ebp, %esi
shlq $0x4, %rsi
callq 0x4840
testq %rax, %rax
je 0x21b90
movq 0x10(%rsp), %r10
movq %rax, 0x8(%r10)
jmp 0x21b95
movq 0x10(%rsp), %r10
movl %ebp, (%r10)
movl 0x20(%rsp), %ebp
incl %ebp
jmp 0x21ab3
leaq 0x75516(%rip), %rsi     # 0x970c0
leaq 0x75522(%rip), %rdx     # 0x970d3
xorl %r14d, %r14d
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x21cf7
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rcx
leaq 0x754eb(%rip), %rsi     # 0x970c0
leaq 0x75521(%rip), %rdx     # 0x970fd
movl $0x1, %edi
movq 0x28(%rsp), %rbx
movq %rbx, %r8
xorl %eax, %eax
callq 0x13de5
jmp 0x21cec
movq 0x48(%rsp), %rax
movl %ebp, (%rax)
testl %ebp, %ebp
je 0x21cec
movslq %ebp, %rdi
movl $0x28, %esi
callq 0x4300
testq %rax, %rax
je 0x21cec
movq %rax, %r14
testl %ebp, %ebp
jle 0x21cbb
movl %r15d, %eax
leaq 0x10(%r13), %rdx
xorl %esi, %esi
xorl %edi, %edi
xorl %r8d, %r8d
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r12,%rcx,4), %r9d
movl %esi, %ecx
andb $0x1e, %cl
shrl %cl, %r9d
testb $0x3, %r9b
jne 0x21ca3
testq %r13, %r13
je 0x21ca3
movl (%rdx), %r9d
movslq %r8d, %rcx
leaq (%rcx,%rcx,4), %rcx
movl %r9d, 0x10(%r14,%rcx,8)
movq -0x8(%rdx), %r10
movq %r10, 0x8(%r14,%rcx,8)
movl -0x10(%rdx), %r11d
movl %r11d, 0x14(%r14,%rcx,8)
movq $0x0, -0x8(%rdx)
testl %r11d, %r11d
je 0x21c8e
movq (%r10), %r9
decl %r11d
shlq $0x4, %r11
movq 0x8(%r10,%r11), %r10
jmp 0x21c94
xorl %r9d, %r9d
xorl %r10d, %r10d
leaq (%r14,%rcx,8), %rcx
movq %r9, 0x18(%rcx)
movq %r10, 0x20(%rcx)
incl %r8d
incq %rdi
cmpq %rax, %rdi
jae 0x21cbb
addq $0x18, %rdx
addl $0x2, %esi
cmpl %ebp, %r8d
jl 0x21c33
movq %rbx, %rdi
callq 0x21d09
jmp 0x21cf7
movq 0x48(%rsp), %rax
movl $0x0, (%rax)
jmp 0x21cec
leaq 0x753e7(%rip), %rsi     # 0x970c0
leaq 0x74ae7(%rip), %rdx     # 0x967c7
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movq %rbx, %rdi
callq 0x21d09
xorl %r14d, %r14d
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq