// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hts.c
// Function: hts_parse_region
const char *hts_parse_region(const char *s, int *tid, hts_pos_t *beg,
                             hts_pos_t *end, hts_name2id_f getid, void *hdr,
                             int flags)
{
    if (!s || !tid || !beg || !end || !getid)
        return NULL;

    size_t s_len = strlen(s);
    kstring_t ks = { 0, 0, NULL };

    const char *colon = NULL, *comma = NULL;
    int quoted = 0;

    if (flags & HTS_PARSE_LIST)
        flags &= ~HTS_PARSE_THOUSANDS_SEP;
    else
        flags |= HTS_PARSE_THOUSANDS_SEP;

    const char *s_end = s + s_len;

    // Braced quoting of references is permitted to resolve ambiguities.
    if (*s == '{') {
        const char *close = memchr(s, '}', s_len);
        if (!close) {
            hts_log_error("Mismatching braces in \"%s\"", s);
            *tid = -1;
            return NULL;
        }
        s++;
        s_len--;
        if (close[1] == ':')
            colon = close+1;
        quoted = 1; // number of trailing characters to trim

        // Truncate to this item only, if appropriate.
        if (flags & HTS_PARSE_LIST) {
            comma = strchr(close, ',');
            if (comma) {
                s_len = comma-s;
                s_end = comma+1;
            }
        }
    } else {
        // Truncate to this item only, if appropriate.
        if (flags & HTS_PARSE_LIST) {
            comma = strchr(s, ',');
            if (comma) {
                s_len = comma-s;
                s_end = comma+1;
            }
        }

        colon = hts_memrchr(s, ':', s_len);
    }

    // No colon is simplest case; just check and return.
    if (colon == NULL) {
        *beg = 0; *end = HTS_POS_MAX;
        kputsn(s, s_len-quoted, &ks); // convert to nul terminated string
        if (!ks.s) {
            *tid = -2;
            return NULL;
        }

        *tid = getid(hdr, ks.s);
        free(ks.s);

        return *tid >= 0 ? s_end : NULL;
    }

    // Has a colon, but check whole name first.
    if (!quoted) {
        *beg = 0; *end = HTS_POS_MAX;
        kputsn(s, s_len, &ks); // convert to nul terminated string
        if (!ks.s) {
            *tid = -2;
            return NULL;
        }
        if ((*tid = getid(hdr, ks.s)) >= 0) {
            // Entire name matches, but also check this isn't
            // ambiguous.  eg we have ref chr1 and ref chr1:100-200
            // both present.
            ks.l = 0;
            kputsn(s, colon-s, &ks); // convert to nul terminated string
            if (!ks.s) {
                *tid = -2;
                return NULL;
            }
            if (getid(hdr, ks.s) >= 0) {
                free(ks.s);
                *tid = -1;
                hts_log_error("Range is ambiguous. "
                              "Use {%s} or {%.*s}%s instead",
                              s, (int)(colon-s), s, colon);
                return NULL;
            }
            free(ks.s);

            return s_end;
        }
        if (*tid < -1) // Failed to parse header
            return NULL;
    }

    // Quoted, or unquoted and whole string isn't a name.
    // Check the pre-colon part is valid.
    ks.l = 0;
    kputsn(s, colon-s-quoted, &ks); // convert to nul terminated string
    if (!ks.s) {
        *tid = -2;
        return NULL;
    }
    *tid = getid(hdr, ks.s);
    free(ks.s);
    if (*tid < 0)
        return NULL;

    // Finally parse the post-colon coordinates
    char *hyphen;
    *beg = hts_parse_decimal(colon+1, &hyphen, flags) - 1;
    if (*beg < 0) {
        if (*beg != -1 && *hyphen == '-' && colon[1] != '\0') {
            // User specified zero, but we're 1-based.
            hts_log_error("Coordinates must be > 0");
            return NULL;
        }
        if (isdigit_c(*hyphen) || *hyphen == '\0' || *hyphen == ',') {
            // interpret chr:-100 as chr:1-100
            *end = *beg==-1 ? HTS_POS_MAX : -(*beg+1);
            *beg = 0;
            return s_end;
        } else if (*beg < -1) {
            hts_log_error("Unexpected string \"%s\" after region", hyphen);
            return NULL;
        }
    }

    if (*hyphen == '\0' || ((flags & HTS_PARSE_LIST) && *hyphen == ',')) {
        *end = flags & HTS_PARSE_ONE_COORD ? *beg+1 : HTS_POS_MAX;
    } else if (*hyphen == '-') {
        *end = hts_parse_decimal(hyphen+1, &hyphen, flags);
        if (*hyphen != '\0' && *hyphen != ',') {
            hts_log_error("Unexpected string \"%s\" after region", hyphen);
            return NULL;
        }
    } else {
        hts_log_error("Unexpected string \"%s\" after region", hyphen);
        return NULL;
    }

    if (*end == 0)
        *end = HTS_POS_MAX; // interpret chr:100- as chr:100-<end>

    if (*beg >= *end) return NULL;

    return s_end;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x23519
cmpq $0x0, -0x18(%rbp)
je 0x23519
cmpq $0x0, -0x20(%rbp)
je 0x23519
cmpq $0x0, -0x28(%rbp)
je 0x23519
cmpq $0x0, -0x30(%rbp)
jne 0x23526
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x10(%rbp), %rdi
callq 0x41b0
movq %rax, -0x40(%rbp)
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4250
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl 0x10(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x23570
movl 0x10(%rbp), %eax
andl $-0x2, %eax
movl %eax, 0x10(%rbp)
jmp 0x23579
movl 0x10(%rbp), %eax
orl $0x1, %eax
movl %eax, 0x10(%rbp)
movq -0x10(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0x23662
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rdx
movl $0x7d, %esi
callq 0x4530
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x235e7
movq -0x10(%rbp), %rcx
movl $0x1, %edi
leaq 0xcd36f(%rip), %rsi     # 0xf0931
leaq 0xcd379(%rip), %rdx     # 0xf0942
movb $0x0, %al
callq 0x1b030
movq -0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x80(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3a, %eax
jne 0x23618
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movl $0x1, -0x6c(%rbp)
movl 0x10(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x23660
movq -0x80(%rbp), %rdi
movl $0x2c, %esi
callq 0x4170
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x2365e
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x23660
jmp 0x236b9
movl 0x10(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x236a3
movq -0x10(%rbp), %rdi
movl $0x2c, %esi
callq 0x4170
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x236a1
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x236a3
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rdx
movl $0x3a, %esi
callq 0x23be0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x23766
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rax
movabsq $0x7fffffff7fffffff, %rcx # imm = 0x7FFFFFFF7FFFFFFF
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0x6c(%rbp), %rax
subq %rax, %rsi
leaq -0x58(%rbp), %rdx
callq 0x23c50
cmpq $0x0, -0x48(%rbp)
jne 0x23716
movq -0x18(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq *%rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rdi
callq 0x45a0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jl 0x2374b
movq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x23756
xorl %eax, %eax
movq %rax, -0x90(%rbp)
jmp 0x23756
movq -0x90(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x23bc7
cmpl $0x0, -0x6c(%rbp)
jne 0x238af
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rax
movabsq $0x7fffffff7fffffff, %rcx # imm = 0x7FFFFFFF7FFFFFFF
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x23c50
cmpq $0x0, -0x48(%rbp)
jne 0x237bb
movq -0x18(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq *%rax
movq -0x18(%rbp), %rcx
movl %eax, (%rcx)
cmpl $0x0, %eax
jl 0x23897
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
leaq -0x58(%rbp), %rdx
callq 0x23c50
cmpq $0x0, -0x48(%rbp)
jne 0x23816
movq -0x18(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
jl 0x23881
movq -0x48(%rbp), %rdi
callq 0x45a0
movq -0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rcx
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rdx
subq %rdx, %rax
movl %eax, %r8d
movq -0x10(%rbp), %r9
movq -0x60(%rbp), %rax
movl $0x1, %edi
leaq 0xcd0cf(%rip), %rsi     # 0xf0931
leaq 0xcd0f4(%rip), %rdx     # 0xf095d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x48(%rbp), %rdi
callq 0x45a0
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x23bc7
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jge 0x238ad
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
jmp 0x238af
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
movslq -0x6c(%rbp), %rax
subq %rax, %rsi
leaq -0x58(%rbp), %rdx
callq 0x23c50
cmpq $0x0, -0x48(%rbp)
jne 0x238f4
movq -0x18(%rbp), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq *%rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rdi
callq 0x45a0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x23929
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x60(%rbp), %rdi
addq $0x1, %rdi
movl 0x10(%rbp), %edx
leaq -0x88(%rbp), %rsi
callq 0x23070
movq %rax, %rcx
subq $0x1, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x23a71
movq -0x20(%rbp), %rax
cmpq $-0x1, (%rax)
je 0x239a9
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x239a9
movq -0x60(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x239a9
movl $0x1, %edi
leaq 0xccfa3(%rip), %rsi     # 0xf0931
leaq 0xccff9(%rip), %rdx     # 0xf098e
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x88(%rbp), %rax
movsbl (%rax), %edi
callq 0x23470
cmpl $0x0, %eax
jne 0x239db
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x239db
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x23a35
movq -0x20(%rbp), %rax
cmpq $-0x1, (%rax)
jne 0x239f8
movabsq $0x7fffffff7fffffff, %rax # imm = 0x7FFFFFFF7FFFFFFF
movq %rax, -0x98(%rbp)
jmp 0x23a0f
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
xorl %eax, %eax
subq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x23bc7
movq -0x20(%rbp), %rax
cmpq $-0x1, (%rax)
jge 0x23a6d
movq -0x88(%rbp), %rcx
movl $0x1, %edi
leaq 0xccedf(%rip), %rsi     # 0xf0931
leaq 0xccf4d(%rip), %rdx     # 0xf09a6
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
jmp 0x23a6f
jmp 0x23a71
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x23a9a
movl 0x10(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x23adf
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x23adf
movl 0x10(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x23ab9
movq -0x20(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x23acc
movabsq $0x7fffffff7fffffff, %rax # imm = 0x7FFFFFFF7FFFFFFF
movq %rax, -0xa0(%rbp)
jmp 0x23acc
movq -0xa0(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0x23b8a
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x23b5d
movq -0x88(%rbp), %rdi
addq $0x1, %rdi
movl 0x10(%rbp), %edx
leaq -0x88(%rbp), %rsi
callq 0x23070
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x23b5b
movq -0x88(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
je 0x23b5b
movq -0x88(%rbp), %rcx
movl $0x1, %edi
leaq 0xccdee(%rip), %rsi     # 0xf0931
leaq 0xcce5c(%rip), %rdx     # 0xf09a6
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
jmp 0x23b88
movq -0x88(%rbp), %rcx
movl $0x1, %edi
leaq 0xccdc1(%rip), %rsi     # 0xf0931
leaq 0xcce2f(%rip), %rdx     # 0xf09a6
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
jmp 0x23b8a
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x23ba5
movq -0x28(%rbp), %rax
movabsq $0x7fffffff7fffffff, %rcx # imm = 0x7FFFFFFF7FFFFFFF
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jl 0x23bbf
movq $0x0, -0x8(%rbp)
jmp 0x23bc7
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)