// File: /workspace/github_c_makefile_star2_O2/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)
testq %rdi, %rdi
sete %al
testl %esi, %esi
setle %cl
orb %al, %cl
jne 0x1d24a
movq %rdx, %r15
movl %esi, %r14d
movq %rdi, %r12
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
callq 0x4300
testq %rax, %rax
je 0x1d001
movq %rax, %rbx
movq %r15, 0x48(%rsp)
movl %r14d, %eax
movq %rax, 0x60(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x0, 0x18(%rsp)
xorl %r14d, %r14d
movq %r12, 0x40(%rsp)
cmpq 0x60(%rsp), %r14
je 0x1d021
movq (%r12,%r14,8), %rdi
movzbl (%rdi), %eax
cmpl $0x2a, %eax
movq %r14, 0x28(%rsp)
je 0x1cd0f
cmpl $0x2e, %eax
jne 0x1cd15
cmpb $0x0, 0x1(%rdi)
jne 0x1cd15
movl $0xfffffffd, 0x14(%rsp) # imm = 0xFFFFFFFD
andq $0x0, 0x38(%rsp)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, 0x30(%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
pushq $-0x3
jmp 0x1cdb7
cmpb $0x0, 0x1(%rdi)
je 0x1cd8a
movl $0x1, (%rsp)
leaq 0x14(%rsp), %rsi
leaq 0x38(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq 0x58(%rsp), %r8
movq 0x50(%rsp), %r9
callq 0x15efd
movl 0x14(%rsp), %r14d
testq %rax, %rax
je 0x1cd5a
movq 0x38(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0x1cdb9
cmpl $-0x2, %r14d
jle 0x1d22a
movq 0x28(%rsp), %r14
movq (%r12,%r14,8), %rcx
pushq $0x3
popq %rdi
leaq 0x5c2f9(%rip), %rsi     # 0x79070
leaq 0x5ba51(%rip), %rdx     # 0x787cf
xorl %eax, %eax
callq 0x110c6
jmp 0x1cff9
movl $0xfffffffe, 0x14(%rsp) # imm = 0xFFFFFFFE
andq $0x0, 0x38(%rsp)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, 0x30(%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
pushq $-0x2
popq %r14
testl %r15d, %r15d
je 0x1ce19
leal -0x1(%r15), %edx
movl %edx, %esi
andl %r14d, %esi
pushq $0x1
popq %rdi
movl %esi, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl (%r13,%rcx,4), %r8d
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %r8d, %r9d
shrl %cl, %r9d
testb $0x2, %r9b
jne 0x1ce07
testb $0x1, %r9b
jne 0x1cdfb
movq 0x18(%rbx), %r9
movl %eax, %r10d
cmpl %r14d, (%r9,%r10,4)
je 0x1ce07
addl %edi, %eax
andl %edx, %eax
incl %edi
cmpl %esi, %eax
jne 0x1cdcc
jmp 0x1ce20
shrl %cl, %r8d
testb $0x3, %r8b
cmovnel %r15d, %eax
movq %r13, 0x20(%rsp)
jmp 0x1ce1b
xorl %eax, %eax
cmpl %r15d, %eax
jne 0x1ce37
movl 0x8(%rbx), %eax
cmpl 0xc(%rbx), %eax
jb 0x1ce5c
movl 0x4(%rbx), %eax
addl %eax, %eax
cmpl %eax, %r15d
jbe 0x1ce46
decl %r15d
jmp 0x1ce49
movl %eax, %eax
imulq $0x18, %rax, %rcx
movl (%rbp,%rcx), %ecx
jmp 0x1cf79
incl %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1d31a
testl %eax, %eax
js 0x1d1f5
movl (%rbx), %r15d
leal -0x1(%r15), %esi
movl %esi, %eax
andl %r14d, %eax
movq 0x10(%rbx), %r13
movl %eax, %ecx
shrl $0x4, %ecx
movl (%r13,%rcx,4), %edx
leal (%rax,%rax), %ecx
shrl %cl, %edx
testb $0x2, %dl
je 0x1ce84
movl %eax, %edx
jmp 0x1cef6
pushq $0x1
popq %r8
movl %eax, %edi
movl %r15d, %edx
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r13,%rcx,4), %r9d
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %r9d, %r10d
shrl %cl, %r10d
testb $0x2, %r10b
jne 0x1cedb
testb $0x1, %r10b
jne 0x1cebc
movq 0x18(%rbx), %r10
movl %edi, %r11d
cmpl %r14d, (%r10,%r11,4)
je 0x1cedb
btl %ecx, %r9d
cmovbl %edi, %edx
addl %r8d, %edi
andl %esi, %edi
incl %r8d
cmpl %eax, %edi
jne 0x1ce8d
movb $0x1, %cl
movl %r15d, %esi
cmpl %r15d, %edx
je 0x1cee9
jmp 0x1cef6
shrl %cl, %r9d
testb $0x2, %r9b
sete %cl
movl %edx, %esi
movl %edi, %eax
cmpl %r15d, %esi
cmovel %eax, %esi
testb %cl, %cl
cmovnel %eax, %esi
movl %esi, %edx
movl %edx, %esi
shrl $0x4, %esi
movl (%r13,%rsi,4), %edi
leal (%rdx,%rdx), %ecx
andl $0x1e, %ecx
shrl %cl, %edi
movl %edx, %eax
testb $0x2, %dil
jne 0x1cf2f
testb $0x1, %dil
je 0x1cf55
movq 0x18(%rbx), %rdx
movl %r14d, (%rdx,%rax,4)
pushq $0x3
popq %rdx
shll %cl, %edx
notl %edx
andl %edx, (%r13,%rsi,4)
incl 0x4(%rbx)
jmp 0x1cf55
movq 0x18(%rbx), %rdx
movl %r14d, (%rdx,%rax,4)
pushq $0x3
popq %rdx
shll %cl, %edx
notl %edx
andl %edx, (%r13,%rsi,4)
movq 0x4(%rbx), %xmm0
psubd 0x5c110(%rip), %xmm0    # 0x79060
movq %xmm0, 0x4(%rbx)
movq 0x20(%rbx), %rbp
imulq $0x18, %rax, %rcx
andq $0x0, 0x10(%rbp,%rcx)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rbp,%rcx)
movl %r14d, 0x10(%rbp,%rcx)
xorl %ecx, %ecx
movq %r13, 0x20(%rsp)
imulq $0x18, %rax, %rax
leaq (%rax,%rbp), %r14
cmpl 0x4(%rbp,%rax), %ecx
jne 0x1cfc3
leal (%rcx,%rcx), %r12d
testl %ecx, %ecx
pushq $0x4
popq %rax
cmovel %eax, %r12d
testl %r12d, %r12d
je 0x1d1f5
movq 0x8(%r14), %rdi
movl %r12d, %esi
shlq $0x4, %rsi
callq 0x4840
testq %rax, %rax
je 0x1d1f5
movl %r12d, 0x4(%r14)
movq %rax, 0x8(%r14)
movl (%r14), %ecx
jmp 0x1cfc7
movq 0x8(%r14), %rax
movl %ecx, %edx
shlq $0x4, %rdx
movq 0x18(%rsp), %rsi
movq %rsi, (%rax,%rdx)
incl %ecx
movl %ecx, (%r14)
movq 0x8(%rsp), %rcx
movq %rcx, 0x8(%rax,%rdx)
movq %rbp, 0x8(%rsp)
movl %r15d, 0x18(%rsp)
movq 0x40(%rsp), %r12
movq 0x28(%rsp), %r14
incq %r14
jmp 0x1ccb6
leaq 0x5c068(%rip), %rsi     # 0x79070
leaq 0x5c074(%rip), %rdx     # 0x79083
xorl %r14d, %r14d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x1d24d
movl 0x18(%rsp), %r12d
xorl %r13d, %r13d
movq 0x8(%rsp), %rdi
movq %rdi, %r15
xorl %ebp, %ebp
movq 0x20(%rsp), %rdx
cmpq %r12, %r13
jae 0x1d135
movq %r13, %rax
shrq $0x4, %rax
movl (%rdx,%rax,4), %eax
leal (,%r13,2), %ecx
shrl %cl, %eax
testb $0x3, %al
je 0x1d05e
incq %r13
jmp 0x1d038
testq %rdi, %rdi
je 0x1d125
imulq $0x18, %r13, %r15
addq %rdi, %r15
movl (%r15), %esi
testq %rsi, %rsi
je 0x1d12d
movq 0x8(%r15), %rdi
pushq $0x10
popq %rdx
leaq 0x545(%rip), %rcx       # 0x1d5cd
callq 0x4990
movl (%r15), %eax
xorl %r14d, %r14d
pushq $0x18
popq %rcx
pushq $0x1
popq %rdx
cmpq %rax, %rdx
jae 0x1d0ed
movq 0x8(%r15), %rsi
movl %r14d, %edi
shlq $0x4, %rdi
movq 0x8(%rsi,%rdi), %r9
movq -0x8(%rsi,%rcx), %r8
cmpq %r8, %r9
jge 0x1d0d1
incl %r14d
movq %r14, %rdi
shlq $0x4, %rdi
movq %r8, (%rsi,%rdi)
movq (%rsi,%rcx), %r8
movq %r8, 0x8(%rsi,%rdi)
jmp 0x1d0e4
movq (%rsi,%rcx), %r8
cmpq %r8, %r9
jge 0x1d0e4
addq %rdi, %rsi
addq $0x8, %rsi
movq %r8, (%rsi)
incq %rdx
addq $0x10, %rcx
jmp 0x1d099
incl %r14d
cmpl %r14d, %eax
jbe 0x1d10e
movq 0x8(%r15), %rdi
movl %r14d, %esi
shlq $0x4, %rsi
callq 0x4840
testq %rax, %rax
je 0x1d10e
movq %rax, 0x8(%r15)
movl %r14d, (%r15)
incl %ebp
movq 0x8(%rsp), %rdi
movq %rdi, %r15
movq 0x20(%rsp), %rdx
jmp 0x1d059
xorl %r15d, %r15d
jmp 0x1d059
movq %rdi, %r15
jmp 0x1d059
movq 0x48(%rsp), %rax
movl %ebp, (%rax)
testl %ebp, %ebp
je 0x1d242
movslq %ebp, %rdi
pushq $0x28
popq %rsi
callq 0x4300
testq %rax, %rax
je 0x1d242
movq %rax, %r14
leaq 0x10(%r15), %rax
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
cmpq %r12, %rsi
jae 0x1d220
cmpl %ebp, %edi
jge 0x1d220
movl %esi, %ecx
shrl $0x4, %ecx
movq 0x20(%rsp), %r8
movl (%r8,%rcx,4), %r8d
movl %edx, %ecx
andb $0x1e, %cl
shrl %cl, %r8d
testb $0x3, %r8b
jne 0x1d1e6
testq %r15, %r15
je 0x1d1e6
movl (%rax), %r8d
movslq %edi, %rcx
imulq $0x28, %rcx, %rcx
movl %r8d, 0x10(%r14,%rcx)
movq -0x8(%rax), %r9
movq %r9, 0x8(%r14,%rcx)
movl -0x10(%rax), %r10d
movl %r10d, 0x14(%r14,%rcx)
andq $0x0, -0x8(%rax)
testl %r10d, %r10d
je 0x1d1d3
movq (%r9), %r8
decl %r10d
shlq $0x4, %r10
movq 0x8(%r9,%r10), %r9
jmp 0x1d1d9
xorl %r8d, %r8d
xorl %r9d, %r9d
addq %r14, %rcx
movq %r8, 0x18(%rcx)
movq %r9, 0x20(%rcx)
incl %edi
incq %rsi
addl $0x2, %edx
addq $0x18, %rax
jmp 0x1d165
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x5be66(%rip), %rsi     # 0x79070
leaq 0x5be9c(%rip), %rdx     # 0x790ad
pushq $0x1
popq %rdi
movq %rbx, %r8
xorl %eax, %eax
callq 0x110c6
jmp 0x1d242
movq %rbx, %rdi
callq 0x1d25f
jmp 0x1d24d
leaq 0x5be3f(%rip), %rsi     # 0x79070
leaq 0x5b580(%rip), %rdx     # 0x787b8
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
movq %rbx, %rdi
callq 0x1d25f
xorl %r14d, %r14d
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq