// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/test/test-parse-reg.c
// Function: main
int main(int argc, char **argv) {
    sam_hdr_t *hdr;
    samFile *fp;
    int flags = 0;

    while (argc > 1) {
        if (strcmp(argv[1], "-m") == 0) {
            flags |= HTS_PARSE_LIST;
            argc--; argv++;
            continue;
        }

        if (strcmp(argv[1], "-c") == 0) {
            flags |= HTS_PARSE_ONE_COORD;
            argc--; argv++;
            continue;
        }

        // Automatic mode for test harness
        if (strcmp(argv[1], "-t") == 0)
            reg_test(argv[2]);

        break;
    }

    // Interactive mode for debugging
    if (argc != 3) {
        fprintf(stderr, "Usage: test-parse-reg [-m] [-c] region[,region]...\n");
        exit(1);
    }

    if (!(fp = sam_open(argv[1], "r"))) {
        perror(argv[1]);
        exit(1);
    }

    if (!(hdr = sam_hdr_read(fp))) {
        fprintf(stderr, "Couldn't read header\n");
        exit(1);
    }

    const char *reg = argv[2];
    while (*reg) {
        int tid;
        hts_pos_t beg, end;
        reg = sam_parse_region(hdr, reg, &tid, &beg, &end, flags);
        if (!reg) {
            fprintf(stderr, "Failed to parse region\n");
            exit(1);
        }
        printf("%-20s %12"PRIhts_pos" %12"PRIhts_pos"\n",
               tid == -1 ? "*" : hdr->target_name[tid],
               beg, end);
    }

    sam_hdr_destroy(hdr);
    sam_close(fp);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movl %edi, %r15d
xorl %ebx, %ebx
cmpl $0x2, %edi
jl 0x650b
xorl %ebx, %ebx
leaq 0x8ad32(%rip), %r12     # 0x911d1
leaq 0x8ad2e(%rip), %r13     # 0x911d4
movq 0x8(%r14), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x46c0
testl %eax, %eax
je 0x64cf
movq %rbp, %rdi
movq %r13, %rsi
callq 0x46c0
movl $0x2, %ecx
testl %eax, %eax
je 0x64d4
jmp 0x64ef
movl $0x4, %ecx
addq $0x8, %r14
orl %ecx, %ebx
leal -0x1(%r15), %eax
cmpl $0x2, %r15d
movl %eax, %r15d
jg 0x64a6
movl $0x1, %r15d
jmp 0x650b
leaq 0x8ace1(%rip), %rsi     # 0x911d7
movq %rbp, %rdi
callq 0x46c0
testl %eax, %eax
jne 0x650b
movq 0x10(%r14), %rdi
callq 0x6447
cmpl $0x3, %r15d
jne 0x65e0
movq 0x8(%r14), %rdi
leaq 0x8dbf5(%rip), %rsi     # 0x94115
callq 0x9a77
testq %rax, %rax
je 0x65e5
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x1991d
testq %rax, %rax
je 0x65f1
movq %rax, %r12
movq 0x10(%r14), %r15
cmpb $0x0, (%r15)
je 0x65b8
leaq 0x18(%rsp), %rbp
leaq 0x8dd84(%rip), %r13     # 0x942e1
leaq 0x8acd8(%rip), %r14     # 0x9123c
movq %r12, %rdi
movq %r15, %rsi
leaq 0xc(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %rbp, %r8
movl %ebx, %r9d
callq 0x16b3a
testq %rax, %rax
je 0x65db
movq %rax, %r15
movslq 0xc(%rsp), %rax
movq %r13, %rsi
cmpq $-0x1, %rax
je 0x659e
movq 0x20(%r12), %rcx
movq (%rcx,%rax,8), %rsi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x4060
cmpb $0x0, (%r15)
jne 0x6564
movq %r12, %rdi
callq 0x161e6
movq 0x10(%rsp), %rdi
callq 0xace1
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4ee2
callq 0x4ebd
addq $0x8, %r14
movq %r14, %rdi
callq 0x4f2c
callq 0x4f07
nop