// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x30a2b
cmpl $0x1, -0x14(%rbp)
jge 0x30a38
movq $0x0, -0x8(%rbp)
jmp 0x30e16
movq $0x0, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x54(%rbp)
callq 0x30e30
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x30a86
movl $0x1, %edi
leaq 0xc07b4(%rip), %rsi     # 0xf121f
leaq 0xc07c0(%rip), %rdx     # 0xf1232
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x30e16
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x30c1a
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xbe7ba(%rip), %rsi     # 0xef266
callq 0x4690
cmpl $0x0, %eax
jne 0x30aec
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movl $0xfffffffd, -0x58(%rbp) # imm = 0xFFFFFFFD
movq $0x0, -0x68(%rbp)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, -0x70(%rbp)
jmp 0x30b6e
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xc21c4(%rip), %rsi     # 0xf2cc3
callq 0x4690
cmpl $0x0, %eax
jne 0x30b3c
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movl $0xfffffffe, -0x58(%rbp) # imm = 0xFFFFFFFE
movq $0x0, -0x68(%rbp)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, -0x70(%rbp)
jmp 0x30b6c
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x30(%rbp), %r8
movq -0x28(%rbp), %r9
leaq -0x58(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0x70(%rbp), %rcx
movl $0x1, (%rsp)
callq 0x234d0
movq %rax, -0x60(%rbp)
jmp 0x30b6e
cmpq $0x0, -0x60(%rbp)
jne 0x30bc2
cmpl $-0x1, -0x58(%rbp)
jge 0x30b9a
movl $0x1, %edi
leaq 0xc0698(%rip), %rsi     # 0xf121f
leaq 0xbfe71(%rip), %rdx     # 0xf09ff
movb $0x0, %al
callq 0x1b030
jmp 0x30df2
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl $0x3, %edi
leaq 0xc066d(%rip), %rsi     # 0xf121f
leaq 0xbfe5d(%rip), %rdx     # 0xf0a16
movb $0x0, %al
callq 0x1b030
jmp 0x30c0c
movq -0x38(%rbp), %rdi
movl -0x58(%rbp), %esi
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
callq 0x30e50
cmpl $0x0, %eax
je 0x30c0a
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x38(%rbp), %r8
movl $0x1, %edi
leaq 0xc0628(%rip), %rsi     # 0xf121f
leaq 0xc065e(%rip), %rdx     # 0xf125c
movb $0x0, %al
callq 0x1b030
jmp 0x30df2
jmp 0x30c0c
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x30a8d
movq -0x38(%rbp), %rdi
callq 0x30ff0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x30c39
jmp 0x30df2
movq -0x20(%rbp), %rax
movslq (%rax), %rdi
movl $0x28, %esi
callq 0x42f0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x30c5a
jmp 0x30df2
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x38(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x71(%rbp)
jae 0x30c80
movl -0x54(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
setl %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x30c8c
jmp 0x30ddf
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x4c(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x30ccd
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x30cd2
jmp 0x30dd1
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movl (%rax), %ecx
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, (%rax)
jbe 0x30d9a
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x20(%rax)
jmp 0x30dc8
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x18(%rax)
movq -0x48(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x30c61
movq -0x38(%rbp), %rdi
callq 0x31230
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x30e16
movq -0x38(%rbp), %rdi
callq 0x31230
cmpq $0x0, -0x48(%rbp)
je 0x30e0e
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x312c0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)