// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/test/test_mod.c
// Function: main
int main(int argc, char **argv) {
    int extended = 0;
    uint32_t flags = 0;

    if (argc > 1 && strcmp(argv[1], "-x") == 0) {
        extended = 1;
        argv++;
        argc--;
    }

    if (argc > 2 && strcmp(argv[1], "-f") == 0) {
        flags = atoi(argv[2]);
        argv+=2;
        argc-=2;
    }

    if (argc < 2)
        return 1;

    samFile *in = sam_open(argv[1], "r");
    if (!in)
        return 1;

    bam1_t *b = bam_init1();
    sam_hdr_t *h = sam_hdr_read(in);
    hts_base_mod_state *m = hts_base_mod_state_alloc();
    if (!h || !b || !m)
        goto err;

    int r;
    while ((r = sam_read1(in, h, b)) >= 0) {
        if (bam_parse_basemod2(b, m, flags) < 0) {
            fprintf(stderr, "Failed to parse MM/ML aux tags\n");
            goto err;
        }

        // per-base iterator
        int i, j, n;
        hts_base_mod mods[5];
        for (i = 0; i < b->core.l_qseq; i++) {
            char sp = '\t';
            n = bam_mods_at_next_pos(b, m, mods, 5);
            printf("%d\t%c", i, seq_nt16_str[bam_seqi(bam_get_seq(b), i)]);
            for (j = 0; j < n && j < 5; j++) {
                char qstr[10];
                if (mods[j].qual == HTS_MOD_UNCHECKED)
                    qstr[0] = '#', qstr[1] = 0;
                else if (mods[j].qual == HTS_MOD_UNKNOWN)
                    qstr[0] = '.', qstr[1] = 0;
                else
                    snprintf(qstr, 10, "%d", mods[j].qual);

                if (extended) {
                    int m_strand, m_implicit;
                    char m_canonical;
                    int ret = bam_mods_query_type(m, mods[j].modified_base,
                                                  &m_strand, &m_implicit,
                                                  &m_canonical);
                    if (ret < 0 ||
                        m_canonical != mods[j].canonical_base ||
                        m_strand    != mods[j].strand)
                        goto err;
                    printf("%c%c%c%s%c%s",
                           sp, mods[j].canonical_base,
                           "+-"[mods[j].strand],
                           code(mods[j].modified_base),
                           "?."[m_implicit],
                           qstr);
                } else {
                    printf("%c%c%c%s%s",
                           sp, mods[j].canonical_base,
                           "+-"[mods[j].strand],
                           code(mods[j].modified_base),
                           qstr);
                }
                sp = ' ';
            }
            putchar('\n');
        }

        puts("---");

        bam_parse_basemod2(b, m, flags);

        // List possible mod choices.
        int *all_mods;
        int all_mods_n = 0;
        all_mods = bam_mods_recorded(m, &all_mods_n);
        printf("Present:");
        for (i = 0; i < all_mods_n; i++) {
            int m_strand, m_implicit;
            char m_canonical;
            bam_mods_queryi(m, i, &m_strand, &m_implicit, &m_canonical);
            printf(all_mods[i] > 0 ? " %c" : " #%d", all_mods[i]);
            putchar("?."[m_implicit]);
        }
        putchar('\n');

        int pos;
        while ((n=bam_next_basemod(b, m, mods, 5, &pos)) > 0) {
            char sp = '\t';
            printf("%d\t%c", pos,
                   seq_nt16_str[bam_seqi(bam_get_seq(b), pos)]);
            for (j = 0; j < n && j < 5; j++) {
                char qstr[10];
                if (mods[j].qual == HTS_MOD_UNCHECKED)
                    qstr[0] = '#', qstr[1] = 0;
                else if (mods[j].qual == HTS_MOD_UNKNOWN)
                    qstr[0] = '.', qstr[1] = 0;
                else
                    snprintf(qstr, 10, "%d", mods[j].qual);

                printf("%c%c%c%s%s",
                       sp, mods[j].canonical_base,
                       "+-"[mods[j].strand],
                       code(mods[j].modified_base),
                       qstr);
                sp = ' ';
            }
            putchar('\n');
        }

        if (n < 0)
            goto err;

        puts("\n===\n");
    }
    fflush(stdout);
    int ret = 0;
    if (sam_close(in) != 0 || r < -1)
        ret = 1;

    bam_destroy1(b);
    sam_hdr_destroy(h);
    hts_base_mod_state_free(m);
    return ret;

 err:
    bam_destroy1(b);
    sam_hdr_destroy(h);
    hts_base_mod_state_free(m);
    return sam_close(in) != 0 ? 1 : 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x1, -0x8(%rbp)
jle 0x5b22
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xe0508(%rip), %rsi     # 0xe6004
callq 0x46a0
cmpl $0x0, %eax
jne 0x5b22
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x2, -0x8(%rbp)
jle 0x5b66
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xe04d0(%rip), %rsi     # 0xe6007
callq 0x46a0
cmpl $0x0, %eax
jne 0x5b66
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x47e0
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x8(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x5b78
movl $0x1, -0x4(%rbp)
jmp 0x630f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xe35ea(%rip), %rsi     # 0xe9171
callq 0xa130
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x5ba3
movl $0x1, -0x4(%rbp)
jmp 0x630f
callq 0x1ecf0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x23810
movq %rax, -0x30(%rbp)
callq 0x353e0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5bd7
cmpq $0x0, -0x28(%rbp)
je 0x5bd7
cmpq $0x0, -0x38(%rbp)
jne 0x5bdc
jmp 0x62d6
jmp 0x5bde
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x28950
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jl 0x6279
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x18(%rbp), %edx
callq 0x35420
cmpl $0x0, %eax
jge 0x5c2d
movq 0xfe3c9(%rip), %rax     # 0x103fe0
movq (%rax), %rdi
leaq 0xe03e9(%rip), %rsi     # 0xe600a
movb $0x0, %al
callq 0x46e0
jmp 0x62d6
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x5f74
movb $0x9, -0xa1(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
movl $0x5, %ecx
callq 0x360c0
movl %eax, -0x48(%rbp)
movl -0x40(%rbp), %esi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x28(%rbp), %rcx
movl 0x14(%rcx), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl -0x40(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0x40(%rbp), %ecx
xorl $-0x1, %ecx
andl $0x1, %ecx
shll $0x2, %ecx
sarl %cl, %eax
andl $0xf, %eax
movslq %eax, %rcx
leaq 0xe071a(%rip), %rax     # 0xe63d0
movsbl (%rax,%rcx), %edx
leaq 0xe0369(%rip), %rdi     # 0xe602a
movb $0x0, %al
callq 0x4060
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %ecx
xorl %eax, %eax
cmpl -0x48(%rbp), %ecx
movb %al, -0xed(%rbp)
jge 0x5cec
cmpl $0x5, -0x44(%rbp)
setl %al
movb %al, -0xed(%rbp)
movb -0xed(%rbp), %al
testb $0x1, %al
jne 0x5cfb
jmp 0x5f5c
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x2, 0xc(%rax)
jne 0x5d23
movb $0x23, -0xab(%rbp)
movb $0x0, -0xaa(%rbp)
jmp 0x5d7c
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
jne 0x5d4b
movb $0x2e, -0xab(%rbp)
movb $0x0, -0xaa(%rbp)
jmp 0x5d7a
leaq -0xab(%rbp), %rdi
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movl $0xa, %esi
leaq 0xe9ece(%rip), %rdx     # 0xefc41
movb $0x0, %al
callq 0x4800
jmp 0x5d7c
cmpl $0x0, -0x14(%rbp)
je 0x5eb5
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %esi
leaq -0xb0(%rbp), %rdx
leaq -0xb4(%rbp), %rcx
leaq -0xb5(%rbp), %r8
callq 0x36d00
movl %eax, -0xbc(%rbp)
cmpl $0x0, -0xbc(%rbp)
jl 0x5e02
movsbl -0xb5(%rbp), %eax
movslq -0x44(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0x5e02
movl -0xb0(%rbp), %eax
movslq -0x44(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
je 0x5e07
jmp 0x62d6
movsbl -0xa1(%rbp), %eax
movl %eax, -0xfc(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0xf8(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rcx
leaq 0xe01f1(%rip), %rax     # 0xe603d
movsbl (%rax,%rcx), %eax
movl %eax, -0xf4(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %edi
callq 0x6320
movl -0xfc(%rbp), %esi
movl -0xf8(%rbp), %edx
movl -0xf4(%rbp), %ecx
movq %rax, %r8
movslq -0xb4(%rbp), %rdi
leaq 0xe01ae(%rip), %rax     # 0xe6040
movsbl (%rax,%rdi), %r9d
leaq -0xab(%rbp), %rax
leaq 0xe018b(%rip), %rdi     # 0xe6030
movq %rax, (%rsp)
movb $0x0, %al
callq 0x4060
jmp 0x5f47
movsbl -0xa1(%rbp), %eax
movl %eax, -0x108(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x104(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rcx
leaq 0xe0143(%rip), %rax     # 0xe603d
movsbl (%rax,%rcx), %eax
movl %eax, -0x100(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %edi
callq 0x6320
movl -0x108(%rbp), %esi
movl -0x104(%rbp), %edx
movl -0x100(%rbp), %ecx
movq %rax, %r8
leaq -0xab(%rbp), %r9
leaq 0xe0103(%rip), %rdi     # 0xe6043
movb $0x0, %al
callq 0x4060
movb $0x20, -0xa1(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x5ccf
movl $0xa, %edi
callq 0x4690
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x5c34
leaq 0xe00d3(%rip), %rdi     # 0xe604e
callq 0x47c0
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x18(%rbp), %edx
callq 0x35420
movl $0x0, -0xcc(%rbp)
movq -0x38(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x36cd0
movq %rax, -0xc8(%rbp)
leaq 0xe009a(%rip), %rdi     # 0xe6052
movb $0x0, %al
callq 0x4060
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0xcc(%rbp), %eax
jge 0x604f
movq -0x38(%rbp), %rdi
movl -0x40(%rbp), %esi
leaq -0xd0(%rbp), %rdx
leaq -0xd4(%rbp), %rcx
leaq -0xd5(%rbp), %r8
callq 0x36dd0
movq -0xc8(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
leaq 0xe49f8(%rip), %rdi     # 0xea9ff
leaq 0xe4dab(%rip), %rax     # 0xeadb9
cmpl $0x0, %ecx
cmovgq %rax, %rdi
movq -0xc8(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movb $0x0, %al
callq 0x4060
movslq -0xd4(%rbp), %rcx
leaq 0xe0008(%rip), %rax     # 0xe6040
movsbl (%rax,%rcx), %edi
callq 0x4690
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x5fc6
movl $0xa, %edi
callq 0x4690
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
movl $0x5, %ecx
leaq -0xdc(%rbp), %r8
callq 0x36740
movl %eax, -0x48(%rbp)
cmpl $0x0, %eax
jle 0x6260
movb $0x9, -0xdd(%rbp)
movl -0xdc(%rbp), %esi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x28(%rbp), %rcx
movl 0x14(%rcx), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl -0xdc(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0xdc(%rbp), %ecx
xorl $-0x1, %ecx
andl $0x1, %ecx
shll $0x2, %ecx
sarl %cl, %eax
andl $0xf, %eax
movslq %eax, %rcx
leaq 0xe02ec(%rip), %rax     # 0xe63d0
movsbl (%rax,%rcx), %edx
leaq 0xdff3b(%rip), %rdi     # 0xe602a
movb $0x0, %al
callq 0x4060
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %ecx
xorl %eax, %eax
cmpl -0x48(%rbp), %ecx
movb %al, -0x109(%rbp)
jge 0x611a
cmpl $0x5, -0x44(%rbp)
setl %al
movb %al, -0x109(%rbp)
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0x6129
jmp 0x6251
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x2, 0xc(%rax)
jne 0x6151
movb $0x23, -0xe7(%rbp)
movb $0x0, -0xe6(%rbp)
jmp 0x61aa
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
jne 0x6179
movb $0x2e, -0xe7(%rbp)
movb $0x0, -0xe6(%rbp)
jmp 0x61a8
leaq -0xe7(%rbp), %rdi
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movl $0xa, %esi
leaq 0xe9aa0(%rip), %rdx     # 0xefc41
movb $0x0, %al
callq 0x4800
jmp 0x61aa
movsbl -0xdd(%rbp), %eax
movl %eax, -0x118(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x114(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rcx
leaq 0xdfe4e(%rip), %rax     # 0xe603d
movsbl (%rax,%rcx), %eax
movl %eax, -0x110(%rbp)
movslq -0x44(%rbp), %rcx
leaq -0xa0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %edi
callq 0x6320
movl -0x118(%rbp), %esi
movl -0x114(%rbp), %edx
movl -0x110(%rbp), %ecx
movq %rax, %r8
leaq -0xe7(%rbp), %r9
leaq 0xdfe0e(%rip), %rdi     # 0xe6043
movb $0x0, %al
callq 0x4060
movb $0x20, -0xdd(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x60fd
movl $0xa, %edi
callq 0x4690
jmp 0x6059
cmpl $0x0, -0x48(%rbp)
jge 0x6268
jmp 0x62d6
leaq 0xdfdec(%rip), %rdi     # 0xe605b
callq 0x47c0
jmp 0x5bde
movq 0xfdd40(%rip), %rax     # 0x103fc0
movq (%rax), %rdi
callq 0x4580
movl $0x0, -0xec(%rbp)
movq -0x20(%rbp), %rdi
callq 0xc250
cmpl $0x0, %eax
jne 0x62a6
cmpl $-0x1, -0x3c(%rbp)
jge 0x62b0
movl $0x1, -0xec(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1ef30
movq -0x30(%rbp), %rdi
callq 0x1ddb0
movq -0x38(%rbp), %rdi
callq 0x35400
movl -0xec(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x630f
movq -0x28(%rbp), %rdi
callq 0x1ef30
movq -0x30(%rbp), %rdi
callq 0x1ddb0
movq -0x38(%rbp), %rdi
callq 0x35400
movq -0x20(%rbp), %rdi
callq 0xc250
movl %eax, %edx
movl $0x2, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax,%rax)