// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq 0xe6c2a(%rip), %rax     # 0xec72a
movq %rax, -0x28(%rbp)
leaq 0xe6c1f(%rip), %rax     # 0xec72a
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq 0xe3655(%rip), %rax     # 0xe917b
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0xffffffff, -0x6c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xe3502(%rip), %rdx     # 0xe907c
callq 0x40c0
movl %eax, -0x64(%rbp)
cmpl $0x0, %eax
jl 0x5c36
movl -0x64(%rbp), %eax
addl $-0x61, %eax
movl %eax, %ecx
movq %rcx, -0x88(%rbp)
subl $0x11, %eax
ja 0x5c19
movq -0x88(%rbp), %rax
leaq 0xe3457(%rip), %rcx     # 0xe9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, -0x74(%rbp)
jmp 0x5c31
movl $0x1, -0x78(%rbp)
jmp 0x5c31
movq 0x1013f9(%rip), %rax    # 0x106fc8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x5c31
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5aa0
movl $0x0, -0x4(%rbp)
jmp 0x60b5
movq 0x1013d1(%rip), %rax    # 0x106fc8
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x5c31
movq 0x1013c1(%rip), %rax    # 0x106fc8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x5c31
movl $0x1, -0x7c(%rbp)
jmp 0x5c31
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5aa0
movl $0x1, -0x4(%rbp)
jmp 0x60b5
jmp 0x5b6c
cmpq $0x0, -0x38(%rbp)
jne 0x5c55
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x5aa0
movl $0x1, -0x4(%rbp)
jmp 0x60b5
movl -0x74(%rbp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl -0x78(%rbp), %esi
xorl %ecx, %ecx
movl $0x2, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
orl %ecx, %eax
movl -0x7c(%rbp), %esi
xorl %ecx, %ecx
movl $0x4, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
orl %ecx, %eax
movl %eax, -0x80(%rbp)
movq -0x38(%rbp), %rdi
callq 0x6c10
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x5cc1
movq 0x101339(%rip), %rax    # 0x106fe0
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0xe33d2(%rip), %rsi     # 0xe9087
movb $0x0, %al
callq 0x46d0
jmp 0x605c
callq 0x27650
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x5cdf
xorl %eax, %eax
movl %eax, %edi
callq 0x43c0
jmp 0x605c
movq -0x28(%rbp), %rdi
leaq 0xe339b(%rip), %rsi     # 0xe9085
callq 0x112b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x5d46
movq 0x1012df(%rip), %rax    # 0x106fe0
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rdx
movq %rax, %rcx
leaq 0xe3369(%rip), %rsi     # 0xe90a3
movb $0x0, %al
callq 0x46d0
jmp 0x605c
movq -0x18(%rbp), %rdi
callq 0x2c170
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x5d7b
movq 0x10127f(%rip), %rax    # 0x106fe0
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0xe334b(%rip), %rsi     # 0xe90ba
movb $0x0, %al
callq 0x46d0
jmp 0x605c
movq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x112b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x5ddf
movq 0x101246(%rip), %rax    # 0x106fe0
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xa0(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
movq %rax, %rcx
leaq 0xe32d0(%rip), %rsi     # 0xe90a3
movb $0x0, %al
callq 0x46d0
jmp 0x605c
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x2d180
cmpl $0x0, %eax
jge 0x5e3d
movq 0x1011e8(%rip), %rax    # 0x106fe0
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xb0(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movq %rax, %rcx
leaq 0xe32a6(%rip), %rsi     # 0xe90d7
movb $0x0, %al
callq 0x46d0
jmp 0x605c
jmp 0x5e3f
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x312b0
movl %eax, -0x68(%rbp)
cmpl $0x0, %eax
jl 0x5fbf
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
jl 0x5e8f
movq 0x10116e(%rip), %rax    # 0x106fe0
movq (%rax), %rdi
movq -0x60(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0xe3276(%rip), %rsi     # 0xe90f9
movb $0x0, %al
callq 0x46d0
jmp 0x605c
movl -0x6c(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x5f20
movq -0x60(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0x5f20
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
movslq 0x8(%rcx), %rcx
movq (%rax,%rcx,8), %rsi
xorl %edx, %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq -0x70(%rbp), %r8
callq 0x78f0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5f16
movq 0x1010f4(%rip), %rax    # 0x106fe0
movq (%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
movslq 0x8(%rcx), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xe320c(%rip), %rsi     # 0xe9116
movb $0x0, %al
callq 0x46d0
jmp 0x605c
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0x5f83
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0x70(%rbp), %rdx
movl -0x80(%rbp), %ecx
callq 0x23fb0
movl %eax, -0x68(%rbp)
cmpl $-0x4, -0x68(%rbp)
jg 0x5f81
movq 0x101092(%rip), %rax    # 0x106fe0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
leaq 0xe31bc(%rip), %rsi     # 0xe9131
movb $0x0, %al
callq 0x46d0
jmp 0x605c
jmp 0x5f83
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x34070
cmpl $0x0, %eax
jge 0x5fba
movq 0x101040(%rip), %rax    # 0x106fe0
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
leaq 0xe31a6(%rip), %rsi     # 0xe9154
movb $0x0, %al
callq 0x46d0
jmp 0x605c
jmp 0x5e3f
movq -0x18(%rbp), %rdi
callq 0x133d0
movl %eax, -0x68(%rbp)
movq $0x0, -0x18(%rbp)
cmpl $0x0, -0x68(%rbp)
jge 0x5ff7
movq 0x101000(%rip), %rax    # 0x106fe0
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0xe317b(%rip), %rsi     # 0xe9169
movb $0x0, %al
callq 0x46d0
jmp 0x605c
movq -0x20(%rbp), %rdi
callq 0x133d0
movl %eax, -0x68(%rbp)
movq $0x0, -0x20(%rbp)
cmpl $0x0, -0x68(%rbp)
jge 0x602f
movq 0x100fc8(%rip), %rax    # 0x106fe0
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
leaq 0xe3143(%rip), %rsi     # 0xe9169
movb $0x0, %al
callq 0x46d0
jmp 0x605c
movq -0x58(%rbp), %rdi
callq 0x26710
movq -0x60(%rbp), %rdi
callq 0x27890
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x50(%rbp), %rdi
callq 0x60d0
movl $0x0, -0x4(%rbp)
jmp 0x60b5
cmpq $0x0, -0x58(%rbp)
je 0x606c
movq -0x58(%rbp), %rdi
callq 0x26710
cmpq $0x0, -0x60(%rbp)
je 0x607c
movq -0x60(%rbp), %rdi
callq 0x27890
cmpq $0x0, -0x18(%rbp)
je 0x608c
movq -0x18(%rbp), %rdi
callq 0x133d0
cmpq $0x0, -0x20(%rbp)
je 0x609c
movq -0x20(%rbp), %rdi
callq 0x133d0
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x50(%rbp), %rdi
callq 0x60d0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)