// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/test/test_realn.c
// Function: main
int main(int argc, char **argv) {
    htsFile *in = NULL;
    htsFile *out = NULL;
    char *in_name = "-";
    char *out_name = "-";
    char *ref_name = NULL;
    char *ref_seq = NULL;
    char modew[8] = "w";
    faidx_t *fai = NULL;
    sam_hdr_t *hdr = NULL;
    bam1_t *rec = NULL;
    int c, res, last_ref = -1, ref_len = 0;
    int adjust = 0, extended = 0, recalc = 0, flags = 0;

    while ((c = getopt(argc, argv, "aef:hi:o:r")) >= 0) {
        switch (c) {
        case 'a': adjust = 1; break;
        case 'e': extended = 1; break;
        case 'f': ref_name = optarg; break;
        case 'h': usage(argv[0]); return EXIT_SUCCESS;
        case 'i': in_name = optarg; break;
        case 'o': out_name = optarg; break;
        case 'r': recalc = 1; break;
        default: usage(argv[0]); return EXIT_FAILURE;
        }
    }

    if (!ref_name) {
        usage(argv[0]);
        return EXIT_FAILURE;
    }

    flags = (adjust ? 1 : 0) | (extended ? 2 : 0) | (recalc ? 4 : 0);

    fai = fai_load(ref_name);
    if (!fai) {
        fprintf(stderr, "Couldn't load reference %s\n", ref_name);
        goto fail;
    }

    rec = bam_init1();
    if (!rec) {
        perror(NULL);
        goto fail;
    }

    in = hts_open(in_name, "r");
    if (!in) {
        fprintf(stderr, "Couldn't open %s : %s\n", in_name, strerror(errno));
        goto fail;
    }

    hdr = sam_hdr_read(in);
    if (!hdr) {
        fprintf(stderr, "Couldn't read header for %s\n", in_name);
        goto fail;
    }

    out = hts_open(out_name, modew);
    if (!out) {
        fprintf(stderr, "Couldn't open %s : %s\n", out_name, strerror(errno));
        goto fail;
    }

    if (sam_hdr_write(out, hdr) < 0) {
        fprintf(stderr, "Couldn't write header to %s : %s\n",
                out_name, strerror(errno));
        goto fail;
    }

    while ((res = sam_read1(in, hdr, rec)) >= 0) {
        if (rec->core.tid >= hdr->n_targets) {
            fprintf(stderr, "Invalid BAM reference id %d\n", rec->core.tid);
            goto fail;
        }
        if (last_ref != rec->core.tid && rec->core.tid >= 0) {
            free(ref_seq);
            ref_seq = faidx_fetch_seq(fai, hdr->target_name[rec->core.tid],
                                      0, INT_MAX, &ref_len);
            if (!ref_seq) {
                fprintf(stderr, "Couldn't get reference %s\n",
                        hdr->target_name[rec->core.tid]);
                goto fail;
            }
            last_ref = rec->core.tid;
        }
        if (rec->core.tid >= 0) {
            res = sam_prob_realn(rec, ref_seq, ref_len, flags);
            if (res <= -4) {
                fprintf(stderr, "Error running sam_prob_realn : %s\n",
                        strerror(errno));
                goto fail;
            }
        }
        if (sam_write1(out, hdr, rec) < 0) {
            fprintf(stderr, "Error writing to %s\n", out_name);
            goto fail;
        }
    }
    res = hts_close(in);
    in = NULL;
    if (res < 0) {
        fprintf(stderr, "Error closing %s\n", in_name);
        goto fail;
    }

    res = hts_close(out);
    out = NULL;
    if (res < 0) {
        fprintf(stderr, "Error closing %s\n", out_name);
        goto fail;
    }

    sam_hdr_destroy(hdr);
    bam_destroy1(rec);
    free(ref_seq);
    fai_destroy(fai);

    return EXIT_SUCCESS;

 fail:
    if (hdr) sam_hdr_destroy(hdr);
    if (rec) bam_destroy1(rec);
    if (in) hts_close(in);
    if (out) hts_close(out);
    free(ref_seq);
    fai_destroy(fai);
    return EXIT_FAILURE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
andl $0x0, 0x2c(%rsp)
movl %edi, %r15d
movq $0x77, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x7099e(%rip), %rax     # 0x76487
leaq 0x6d57c(%rip), %r12     # 0x7306c
pushq $0x1
popq %rbp
leaq 0x6d50a(%rip), %r14     # 0x73004
movq %rax, 0x20(%rsp)
movq %rax, 0x10(%rsp)
movl $0x0, 0x28(%rsp)
movl $0x0, 0x18(%rsp)
xorl %r13d, %r13d
movl %r13d, %eax
movl %eax, %r13d
movl %r15d, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x40e0
testl %eax, %eax
js 0x5b8a
leal -0x65(%rax), %ecx
cmpl $0xd, %ecx
ja 0x5b48
movslq (%r14,%rcx,4), %rcx
addq %r14, %rcx
movl %ebp, %eax
jmpq *%rcx
movl %ebp, 0x18(%rsp)
jmp 0x5b17
cmpl $0x61, %eax
jne 0x5d15
movl %ebp, 0x28(%rsp)
jmp 0x5b17
movq 0x94462(%rip), %rax     # 0x99fc0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x5b17
movq 0x94451(%rip), %rax     # 0x99fc0
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x5b17
movq 0x94440(%rip), %rax     # 0x99fc0
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x5b17
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x5d15
xorl %ebx, %ebx
cmpl $0x0, 0x18(%rsp)
setne %r12b
xorl %ebp, %ebp
testl %r13d, %r13d
setne %r15b
movq %r14, %rdi
callq 0x70e1
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x5d81
callq 0x182c4
testq %rax, %rax
je 0x5da3
movq %rax, %r14
leaq 0x6d49b(%rip), %rsi     # 0x73075
movq 0x20(%rsp), %rdi
callq 0xc29f
testq %rax, %rax
je 0x5db1
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x1aa4e
testq %rax, %rax
je 0x5ded
movq %rax, %r13
movb %r12b, 0x7(%rsp)
leaq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0xc29f
testq %rax, %rax
je 0x5e14
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
callq 0x1b54d
testl %eax, %eax
js 0x5e4d
movb %r15b, %bpl
shll $0x2, %ebp
movb 0x7(%rsp), %al
movb %al, %bl
leal (%rbp,%rbx,2), %ebp
orl 0x28(%rsp), %ebp
pushq $-0x1
popq %r15
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x1d7e2
testl %eax, %eax
js 0x5d2c
movl 0x8(%r14), %edx
cmpl (%r13), %edx
jge 0x5e83
cmpl %edx, %r15d
sete %al
testl %edx, %edx
sets %cl
orb %al, %cl
jne 0x5cc5
movq %rbx, %rdi
callq 0x45c0
movq 0x20(%r13), %rax
movslq 0x8(%r14), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x18(%rsp), %rdi
xorl %edx, %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq 0x2c(%rsp), %r8
callq 0x785e
testq %rax, %rax
je 0x5f11
movq %rax, %rbx
movl 0x8(%r14), %edx
movl %edx, %r15d
testl %edx, %edx
js 0x5ce4
movslq 0x2c(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x166a4
cmpl $-0x4, %eax
jle 0x5eec
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x1f169
testl %eax, %eax
jns 0x5c53
movq 0x942d7(%rip), %rax     # 0x99fd8
movq (%rax), %rdi
leaq 0x6d439(%rip), %rsi     # 0x73144
movq 0x10(%rsp), %rdx
jmp 0x5f30
movq (%rbx), %rdi
callq 0x5a9c
pushq $0x1
popq %rax
jmp 0x5d72
movq (%rbx), %rdi
callq 0x5a9c
jmp 0x5d70
movq 0x8(%rsp), %rdi
callq 0xd475
testl %eax, %eax
js 0x5ea0
movq %r12, %rdi
callq 0xd475
testl %eax, %eax
js 0x5ec1
movq %r13, %rdi
callq 0x17a1e
movq %r14, %rdi
callq 0x18392
movq %rbx, %rdi
callq 0x45c0
movq 0x18(%rsp), %rdi
callq 0x5f80
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x94250(%rip), %rax     # 0x99fd8
movq (%rax), %rdi
leaq 0x6d2e5(%rip), %rsi     # 0x73077
xorl %ebx, %ebx
movq %r14, %rdx
xorl %eax, %eax
callq 0x4700
jmp 0x5f66
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x43d0
jmp 0x5f66
movq 0x94220(%rip), %rax     # 0x99fd8
movq (%rax), %rbx
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x6d2c5(%rip), %rsi     # 0x73093
xorl %r15d, %r15d
movq %rbx, %rdi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4700
xorl %r12d, %r12d
xorl %ebx, %ebx
jmp 0x5f44
movq 0x941e4(%rip), %rax     # 0x99fd8
movq (%rax), %rdi
leaq 0x6d2ac(%rip), %rsi     # 0x730aa
xorl %r12d, %r12d
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x4700
xorl %ebx, %ebx
jmp 0x5f3f
movq 0x941bd(%rip), %rax     # 0x99fd8
movq (%rax), %r12
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x6d262(%rip), %rsi     # 0x73093
xorl %ebx, %ebx
movq %r12, %rdi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4700
xorl %r12d, %r12d
jmp 0x5f37
movq 0x94184(%rip), %rax     # 0x99fd8
movq (%rax), %rbp
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x6d25d(%rip), %rsi     # 0x730c7
xorl %ebx, %ebx
movq %rbp, %rdi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4700
jmp 0x5f37
movq 0x9414e(%rip), %rax     # 0x99fd8
movq (%rax), %rdi
leaq 0x6d255(%rip), %rsi     # 0x730e9
xorl %eax, %eax
callq 0x4700
jmp 0x5f37
movq 0x94131(%rip), %rax     # 0x99fd8
movq (%rax), %rdi
leaq 0x6d2a8(%rip), %rsi     # 0x73159
movq $0x0, 0x8(%rsp)
movq 0x20(%rsp), %rdx
jmp 0x5f30
movq 0x94110(%rip), %rax     # 0x99fd8
movq (%rax), %rdi
leaq 0x6d287(%rip), %rsi     # 0x73159
xorl %r12d, %r12d
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x4700
movq $0x0, 0x8(%rsp)
jmp 0x5f37
movq 0x940e5(%rip), %rax     # 0x99fd8
movq (%rax), %rbp
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x6d218(%rip), %rsi     # 0x73121
movq %rbp, %rdi
movq %rax, %rdx
jmp 0x5f30
movq 0x940c0(%rip), %rax     # 0x99fd8
movq (%rax), %rdi
movq 0x20(%r13), %rax
movslq 0x8(%r14), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x6d1d8(%rip), %rsi     # 0x73106
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4700
movq %r13, %rdi
callq 0x17a1e
movq 0x8(%rsp), %r15
movq %r14, %rdi
callq 0x18392
testq %r15, %r15
je 0x5f59
movq %r15, %rdi
callq 0xd475
testq %r12, %r12
je 0x5f66
movq %r12, %rdi
callq 0xd475
movq %rbx, %rdi
callq 0x45c0
movq 0x18(%rsp), %rdi
callq 0x5f80
jmp 0x5d1d
nopl (%rax)