// File: /workspace/github_c_makefile_star2_O1/skoren[P]bacValidation/samToErrorRate.C
// Function: main
int
main (int argc, char **argv) {
    map<string, string> reference;
    // loadFasta
    FILE *in = fopen(argv[2], "r");
    gzFile f = gzdopen(fileno(in), "r");
    kseq_t *seq = kseq_init(f);
    int l = 0;
    while ((l=kseq_read(seq)) >= 0) {
       reference[seq->name.s] = seq->seq.s;
       string name = seq->name.s;
       name.append("rc");
       reference[name] = rc(seq->seq.s, strlen(seq->seq.s));
    }
    kseq_destroy(seq);
    gzclose(f);
    fclose(in);

    bam1_t *b = bam_init1();
    samfile_t * fp = open_alignment_file(argv[1]);
    if (fp == NULL) {
        exit(1);
    }
    bam_header_t* head = fp->header; // sam header
    while (samread(fp, b) >= 0) {
        //Get bam core.
        const bam1_core_t *core = &b->core;
        if (core == NULL) {
            printf("Input file is corrupt!");
            exit(1);
        }
        if (!is_mapped(core)) {
            continue;
        }

        string id = bam1_qname(b);
        string ref = head->target_name[core->tid];
        uint32_t* cigar = bam1_cigar(b);
        uint32_t refLen = head->target_len[core->tid];
        uint32_t refLo = core->pos + 1;
        uint32_t refHigh = bam_calend(core, cigar);
        uint32_t seqLow = 0;
        uint32_t seqHi = core->l_qseq; 
        uint32_t seqLen = core->l_qseq;
        bool isFwd = !(core->flag & BAM_FREVERSE);

        // now parse, we need both sequecnes for this
        if (strlen(reference[ref].c_str()) <= 0) { 
           fprintf(stderr, "Error: unknown reference sequence %s", ref.c_str());
           exit(1);
        }
        char *refSeq = (char*)reference[ref].c_str()+refLo-1;
        char *qrySeq = new char[core->l_qseq+1];
        char *orig = qrySeq;
        for (int i = 0; i < core->l_qseq; i++) {
          qrySeq[i] = bam_nt16_rev_table[bam1_seqi(bam1_seq(b), i)];
        }
        qrySeq[core->l_qseq]='\0';
        int errors = 0;
        int matches = 0;
        int indels = 0;
        uint32_t len = 0;
        for (int k = 0; k < core->n_cigar; ++k) {
            int cop = cigar[k] & BAM_CIGAR_MASK; // operation
            int cl = cigar[k] >> BAM_CIGAR_SHIFT; // length
            switch (cop) {
            // we don't care about clipping, not part of length
            case BAM_CSOFT_CLIP:
                 if (k == 0) seqLow+=cl;
                 else seqHi-=cl;
                 qrySeq+=cl;
                 break;
            case BAM_CHARD_CLIP:
                 if (k == 0) seqLow+=cl;
                 else seqHi-=cl;
                 seqLen+=cl;
                 seqHi+=cl;
                 break;
            // we don't care about matches either, not an error
            case BAM_CMATCH:
            case BAM_CEQUAL:
            case BAM_CDIFF: 
              for (int i = 0; i < cl; i++) {
                 if (toupper(*refSeq) == toupper(*qrySeq)) {
                    matches++;
                 } else {
                    errors++;
                 }
                 refSeq++;
                 qrySeq++;
             }
             len+=cl;
             break;
            case BAM_CINS:
               errors+=cl;
               indels+=cl;
               qrySeq+=cl;
               len+=cl;
               break;
            case BAM_CREF_SKIP:
               refSeq+=cl;
               len+=cl;
               break;
            case BAM_CDEL:
               errors+=cl;
               indels+=cl;
               refSeq+=cl;
               len+=cl;
               break;
            default:
                cerr << "Error: unknown base " << cop << " of len " << cl << endl;
                exit(1);
                break;
            }
        }

        double idy = (1-((double) errors / len /*(seqHi-seqLow)*/ /*(refHigh - refLo + 1)*/)) * 100;
        double idyMismatches =  (1-((double) (errors-indels) / len /*(seqHi-seqLow)*/ /*(refHigh - refLo + 1)*/)) * 100;
        cout << id << "\t" << ref << "\t" << int(ceil(-1*idy/100*len)) << "\t" << idy << "\t0\t" << (isFwd == true ? seqLow : seqLen-seqHi) << "\t" << (isFwd == true ? seqHi : seqLen-seqLow) << "\t" << seqLen << "\t" <<  (isFwd == true ? 0 : 1) << "\t" << (isFwd == true ? refLo : refLen-refHigh) << "\t" << (isFwd == true ? refHigh : refLen-refLo) << "\t" << refLen << "\t" << len << "\t" << (seqHi-seqLow) << "\t" << (refHigh-refLo) << "\t" << matches << "\t" << errors << "\t" << idyMismatches << "\t" << indels << endl;
        delete[] orig;
    }
    samclose(fp);
return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rsi, %r14
leaq -0x150(%rbp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq 0x10(%rsi), %rdi
leaq 0x2c21(%rip), %rbx      # 0xd406
movq %rbx, %rsi
callq 0x33a0
movq %rax, %r15
movq %rax, %rdi
callq 0x3330
movl %eax, %edi
movq %rbx, %rsi
callq 0x35b0
movq %rax, %r13
movq %r15, -0x30(%rbp)
movq %r14, -0x90(%rbp)
movl $0x1, %edi
movl $0x70, %esi
callq 0x31b0
movq %rax, %r12
movl $0x1, %edi
movl $0x20, %esi
callq 0x31b0
movq %rax, %rbx
movq %r13, -0x48(%rbp)
movq %r13, 0x18(%rax)
movl $0x1000, %edi           # imm = 0x1000
callq 0x3440
movq %rax, (%rbx)
movq %rbx, 0x68(%r12)
leaq 0x18(%r12), %rax
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %r15
movq 0x68(%r12), %r13
cmpl $0x0, 0x60(%r12)
jne 0xa8f4
jmp 0xa875
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xa8d9
cmpl $0x0, 0x10(%r13)
je 0xa88b
movl 0x8(%r13), %eax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl 0xc(%r13), %eax
jge 0xa8d9
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
jl 0xa8c6
movl $0x0, 0x8(%r13)
movq (%r13), %rsi
movq 0x18(%r13), %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x35f0
movl %eax, 0xc(%r13)
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0xa8c2
movl $0x1, 0x10(%r13)
testl %eax, %eax
je 0xa86e
movq (%r13), %rax
movslq 0x8(%r13), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%r13)
movsbl (%rax,%rcx), %ebx
movl %ebx, -0x70(%rbp)
cmpl $-0x1, %ebx
je 0xabd6
cmpl $0x40, %ebx
je 0xa8ef
cmpl $0x3e, %ebx
jne 0xa875
movl %ebx, 0x60(%r12)
xorl %eax, %eax
movq %rax, 0x48(%r12)
movq %rax, 0x30(%r12)
movq %rax, 0x18(%r12)
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0xb62b
testl %eax, %eax
js 0xaa4f
cmpl $0xa, -0x70(%rbp)
je 0xa936
movq %r13, %rdi
movl $0xa, %esi
movq -0x78(%rbp), %rdx
xorl %ecx, %ecx
callq 0xb62b
cmpl $0x0, 0x10(%r13)
je 0xa94c
movl 0x8(%r13), %eax
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpl 0xc(%r13), %eax
jge 0xa99e
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
jl 0xa98b
movl $0x0, 0x8(%r13)
movq (%r13), %rsi
movq 0x18(%r13), %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x35f0
movl %eax, 0xc(%r13)
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0xa983
movl $0x1, 0x10(%r13)
testl %eax, %eax
je 0xaa45
movq (%r13), %rax
movslq 0x8(%r13), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%r13)
movsbl (%rax,%rcx), %edi
movl %edi, -0x70(%rbp)
cmpl $0x3d, %edi
jg 0xa9b9
cmpl $-0x1, %edi
je 0xaa5e
cmpl $0x2b, %edi
jne 0xa9cb
jmp 0xaa5e
cmpl $0x3e, %edi
je 0xaa59
cmpl $0x40, %edi
je 0xaa59
callq 0x3290
testl %eax, %eax
je 0xa936
movq 0x30(%r12), %rbx
leaq 0x1(%rbx), %r14
cmpq 0x38(%r12), %r14
jb 0xaa30
movq %r14, %rax
shrq %rax
orq %r14, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x38(%r12)
movq 0x40(%r12), %rdi
callq 0x3560
movq %rax, 0x40(%r12)
movb -0x70(%rbp), %al
movq 0x40(%r12), %rcx
movq %r14, 0x30(%r12)
movb %al, (%rcx,%rbx)
jmp 0xa936
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
jmp 0xa99e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xabd6
movl %edi, 0x60(%r12)
movq 0x30(%r12), %rbx
movq 0x40(%r12), %rax
movb $0x0, (%rax,%rbx)
cmpl $0x2b, -0x70(%rbp)
jne 0xabd6
movq 0x38(%r12), %rsi
cmpq %rsi, 0x50(%r12)
jae 0xaa96
movq %rsi, 0x50(%r12)
movq 0x58(%r12), %rdi
callq 0x3560
movq %rax, 0x58(%r12)
cmpl $0x0, 0x10(%r13)
je 0xaaac
movl 0x8(%r13), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0xc(%r13), %ecx
jge 0xaafa
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
jl 0xaae7
movl $0x0, 0x8(%r13)
movq (%r13), %rsi
movq 0x18(%r13), %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x35f0
movl %eax, 0xc(%r13)
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0xaae3
movl $0x1, 0x10(%r13)
testl %eax, %eax
je 0xab0d
movq (%r13), %rax
movslq 0x8(%r13), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%r13)
movsbl (%rax,%rcx), %eax
movl %eax, -0x70(%rbp)
cmpl $-0x1, %eax
je 0xabd1
cmpl $0xa, %eax
jne 0xaa96
jmp 0xab33
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xaafa
cmpl $0x21, %eax
jl 0xab33
movq 0x58(%r12), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x48(%r12)
movb %al, (%rdx,%rcx)
jmp 0xab33
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xab97
cmpl $0x0, 0x10(%r13)
je 0xab49
movl 0x8(%r13), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0xc(%r13), %ecx
jge 0xab97
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
jl 0xab84
movl $0x0, 0x8(%r13)
movq (%r13), %rsi
movq 0x18(%r13), %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x35f0
movl %eax, 0xc(%r13)
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0xab80
movl $0x1, 0x10(%r13)
testl %eax, %eax
je 0xab2c
movq (%r13), %rax
movslq 0x8(%r13), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%r13)
movsbl (%rax,%rcx), %eax
movl %eax, -0x70(%rbp)
cmpl $-0x1, %eax
je 0xabad
movq 0x48(%r12), %rcx
cmpq %rbx, %rcx
jb 0xab14
movq 0x48(%r12), %rax
movq 0x58(%r12), %rcx
movb $0x0, (%rcx,%rax)
movl $0x0, 0x60(%r12)
cmpq %rax, %rbx
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmovnel %eax, %ebx
jmp 0xabd6
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
testl %ebx, %ebx
js 0xacfe
movq 0x40(%r12), %r13
movq 0x10(%r12), %rbx
movq %r15, %rdi
movq %rbx, %rsi
leaq -0xc8(%rbp), %rdx
callq 0xb854
leaq -0x158(%rbp), %rdi
movq %r15, %rsi
callq 0xb892
movq %rax, %r15
movq 0x8(%rax), %r14
movq %r13, %rdi
callq 0x3120
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x3500
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xac44
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x32e0
leaq -0x70(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq -0xc8(%rbp), %rdx
callq 0xb854
movq %r14, %rdi
leaq 0x2e82(%rip), %rsi      # 0xdae6
callq 0x3600
movq %r13, %rdi
callq 0x3120
movq %rax, %r15
incl %eax
movslq %eax, %rdi
callq 0x3030
movq %rax, %rbx
testl %r15d, %r15d
leaq 0x2d35(%rip), %rdx      # 0xd9c0
jle 0xacaa
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq %rbx, %rax
movsbq -0x1(%r13,%r15), %rcx
movb (%rcx,%rdx), %cl
movb %cl, (%rax)
incq %rax
decq %r15
jne 0xac97
leaq -0x158(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xb912
movq %rax, %r15
movq 0x8(%rax), %r14
movq %rbx, %rdi
callq 0x3120
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x3500
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xa857
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x32e0
jmp 0xa857
testq %r12, %r12
movq -0x90(%rbp), %r14
movq -0x30(%rbp), %r15
movq -0x48(%rbp), %r13
je 0xad5c
movq 0x10(%r12), %rdi
callq 0x33b0
movq 0x28(%r12), %rdi
callq 0x33b0
movq 0x40(%r12), %rdi
callq 0x33b0
movq 0x58(%r12), %rdi
callq 0x33b0
movq 0x68(%r12), %rbx
testq %rbx, %rbx
je 0xad54
movq (%rbx), %rdi
callq 0x33b0
movq %rbx, %rdi
callq 0x33b0
movq %r12, %rdi
callq 0x33b0
movq %r13, %rdi
callq 0x3570
movq %r15, %rdi
callq 0x32c0
movl $0x1, %edi
movl $0x38, %esi
callq 0x31b0
movq %rax, %r12
movq 0x8(%r14), %rsi
leaq -0x128(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0xb854
leaq -0x128(%rbp), %rdi
callq 0xa6ad
movq %rax, -0x98(%rbp)
leaq -0x118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xadc4
movq -0x118(%rbp), %rsi
incq %rsi
callq 0x32e0
movq -0x98(%rbp), %rax
testq %rax, %rax
je 0xb523
movq 0x10(%rax), %rax
movq %rax, -0xe0(%rbp)
movq %r12, -0xe8(%rbp)
movq -0x98(%rbp), %rdi
movq %r12, %rsi
callq 0x4a8f
testl %eax, %eax
js 0xb4e9
testq %r12, %r12
je 0xb515
movzwl 0xc(%r12), %eax
testl $0x104, %eax            # imm = 0x104
jne 0xade6
movq 0x30(%r12), %rsi
leaq -0x70(%rbp), %rdi
leaq -0xc8(%rbp), %r14
movq %r14, %rdx
callq 0xb854
movq -0xe0(%rbp), %rbx
movq 0x8(%rbx), %rax
movslq (%r12), %rcx
movq (%rax,%rcx,8), %rsi
movq %r14, %rdi
leaq -0x7d(%rbp), %rdx
callq 0xb854
movzbl 0xb(%r12), %esi
addq 0x30(%r12), %rsi
movq 0x10(%rbx), %rax
movslq (%r12), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0xa8(%rbp)
movl 0x4(%r12), %r13d
movq %r12, %rdi
movq %rsi, -0xd8(%rbp)
callq 0x5c72
movq %rax, -0xa0(%rbp)
movl 0x14(%r12), %eax
movq %rax, -0x40(%rbp)
movq 0x8(%r12), %rcx
movabsq $0x1000000000, %rax     # imm = 0x1000000000
andq %rax, %rcx
movq %rcx, -0x88(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xb912
movq (%rax), %rax
cmpb $0x0, (%rax)
je 0xb581
leaq -0x158(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xb912
movq (%rax), %rbx
movl 0x14(%r12), %r15d
movslq %r15d, %r14
leaq 0x1(%r14), %rdi
callq 0x3030
movq %rax, -0xd0(%rbp)
testl %r15d, %r15d
movq -0xd0(%rbp), %r9
jle 0xaf4b
leaq 0x673c(%rip), %rax      # 0x11640
movq (%rax), %rax
movl 0x10(%r12), %ecx
shll $0x2, %ecx
addq 0x30(%r12), %rcx
movzbl 0xb(%r12), %edx
addq %rcx, %rdx
xorl %esi, %esi
xorl %edi, %edi
movl %edi, %ecx
shrl %ecx
movzbl (%rdx,%rcx), %r8d
movl %esi, %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %r8d
andl $0xf, %r8d
movb (%rax,%r8), %cl
movb %cl, (%r9,%rdi)
incq %rdi
addl $0x4, %esi
cmpq %rdi, %r15
jne 0xaf21
incl %r13d
movb $0x0, (%r9,%r14)
movl 0x10(%r12), %r10d
testq %r10, %r10
movl %r13d, -0x7c(%rbp)
je 0xb11a
movl %r13d, %eax
leaq (%rbx,%rax), %r11
decq %r11
xorl %ebx, %ebx
movl $0x0, -0x48(%rbp)
xorl %esi, %esi
xorl %r14d, %r14d
xorl %edi, %edi
movq %r9, %r13
xorl %r8d, %r8d
movq -0x40(%rbp), %rax
movl %eax, -0x34(%rbp)
movq -0xd8(%rbp), %r9
movq %r10, -0xf0(%rbp)
movl (%r9,%rbx,4), %edx
movl %edx, %r15d
andl $0xf, %r15d
movl %edx, %eax
shrl $0x4, %eax
movq %rax, -0x30(%rbp)
cmpl $0x8, %r15d
ja 0xb52d
leaq 0x29d1(%rip), %rcx      # 0xd990
movslq (%rcx,%r15,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x10, %edx
jb 0xb090
movq %rbx, -0x108(%rbp)
movl %r8d, -0x38(%rbp)
movl %esi, -0x4c(%rbp)
movq -0x30(%rbp), %rax
decl %eax
movq %rax, -0x100(%rbp)
leaq 0x1(%r13), %rax
movq %rax, -0xf8(%rbp)
shrl $0x4, %edx
xorl %r12d, %r12d
movq %r13, -0x90(%rbp)
movq %rdx, -0x78(%rbp)
movl %r14d, %ebx
movl %edi, %r14d
movsbl (%r11,%r12), %edi
movq %r11, %r13
callq 0x35e0
movl %eax, %r15d
movq -0x90(%rbp), %rax
movsbl (%rax,%r12), %edi
callq 0x35e0
movq %r13, %r11
movl %r14d, %edi
movl %ebx, %r14d
xorl %ecx, %ecx
xorl %edx, %edx
cmpl %eax, %r15d
sete %cl
setne %dl
addl %edx, %edi
movq -0x78(%rbp), %rdx
addl %ecx, %r14d
incq %r12
cmpl %r12d, %edx
jne 0xb008
movq -0x100(%rbp), %rax
addq %rax, %r11
incq %r11
movq -0xf8(%rbp), %r13
addq %rax, %r13
movq -0xe8(%rbp), %r12
movl -0x4c(%rbp), %esi
movl -0x38(%rbp), %r8d
movq -0xd8(%rbp), %r9
movq -0xf0(%rbp), %r10
movq -0x108(%rbp), %rbx
movq -0x30(%rbp), %rax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0xb10c
movq -0x30(%rbp), %rcx
addl %ecx, %edi
addl %ecx, %esi
jmp 0xb0aa
movq -0x30(%rbp), %rcx
movl %ecx, %eax
addq %rax, %r11
jmp 0xb0df
testq %rbx, %rbx
movl $0x0, %eax
movq -0x30(%rbp), %rcx
cmovel %ecx, %eax
addl %eax, %r8d
addl %ecx, -0x34(%rbp)
movq -0x40(%rbp), %rcx
addl %eax, %ecx
movq %rcx, -0x40(%rbp)
jmp 0xb10c
movq -0x30(%rbp), %rcx
addl %ecx, %edi
addl %ecx, %esi
movl %ecx, %eax
addq %rax, %r13
addl %ecx, -0x48(%rbp)
jmp 0xb10c
testq %rbx, %rbx
movq -0x30(%rbp), %r15
movl %r15d, %eax
movl $0x0, %edx
cmovel %edx, %eax
movl %r15d, %ecx
cmovnel %edx, %ecx
movq -0x40(%rbp), %rdx
subl %eax, %edx
movq %rdx, -0x40(%rbp)
addl %ecx, %r8d
addq %r15, %r13
incq %rbx
cmpq %r10, %rbx
jne 0xaf9a
jmp 0xb132
xorl %r8d, %r8d
movq -0x40(%rbp), %rax
movl %eax, -0x34(%rbp)
xorl %edi, %edi
xorl %r14d, %r14d
xorl %esi, %esi
movl $0x0, -0x48(%rbp)
movl %r8d, -0x38(%rbp)
movl %edi, -0x78(%rbp)
movl %esi, -0x4c(%rbp)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq 0x5e7d(%rip), %rdi      # 0x10fc8
callq 0x3370
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x29e3(%rip), %rsi      # 0xdb45
callq 0x3370
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movq %rbx, %rdi
callq 0x3370
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x29b6(%rip), %rsi      # 0xdb45
callq 0x3370
cvtsi2sdl -0x78(%rbp), %xmm0
movl -0x48(%rbp), %ebx
cvtsi2sd %rbx, %xmm2
divsd %xmm2, %xmm0
movsd 0x27cb(%rip), %xmm1     # 0xd978
subsd %xmm0, %xmm1
mulsd 0x27c7(%rip), %xmm1     # 0xd980
movsd %xmm1, -0x90(%rbp)
movapd %xmm1, %xmm0
divsd 0x27bb(%rip), %xmm0     # 0xd988
movsd %xmm2, -0x30(%rbp)
mulsd %xmm2, %xmm0
callq 0x30b0
cvttsd2si %xmm0, %esi
movq %r13, %rdi
callq 0x3580
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x294c(%rip), %rsi      # 0xdb45
callq 0x3370
movq %r15, %rdi
movsd -0x90(%rbp), %xmm0
callq 0x3530
movq %rax, %r15
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2923(%rip), %rsi      # 0xdb43
callq 0x3370
movl -0x34(%rbp), %eax
movl %eax, %esi
subl -0x40(%rbp), %esi
cmpq $0x0, -0x88(%rbp)
cmovel -0x38(%rbp), %esi
movq %r15, %rdi
callq 0x31c0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x28f2(%rip), %rsi      # 0xdb45
callq 0x3370
movl -0x34(%rbp), %eax
movl %eax, %esi
subl -0x38(%rbp), %esi
cmpq $0x0, -0x88(%rbp)
cmovel -0x40(%rbp), %esi
movq %r15, %rdi
callq 0x31c0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x28bf(%rip), %rsi      # 0xdb45
callq 0x3370
movl -0x34(%rbp), %esi
movq %r15, %rdi
callq 0x31c0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x289d(%rip), %rsi      # 0xdb45
callq 0x3370
movq -0x88(%rbp), %rsi
shrq $0x24, %rsi
movq %r15, %rdi
callq 0x3580
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2873(%rip), %rsi      # 0xdb45
callq 0x3370
movq -0xa8(%rbp), %rsi
subl -0xa0(%rbp), %esi
cmpq $0x0, -0x88(%rbp)
cmovel -0x7c(%rbp), %esi
movq %r15, %rdi
callq 0x31c0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x283b(%rip), %rsi      # 0xdb45
callq 0x3370
movq -0xa8(%rbp), %rsi
subl -0x7c(%rbp), %esi
cmpq $0x0, -0x88(%rbp)
cmovel -0xa0(%rbp), %esi
movq %r15, %rdi
callq 0x31c0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2803(%rip), %rsi      # 0xdb45
callq 0x3370
movq %r15, %rdi
movq -0xa8(%rbp), %rsi
callq 0x31c0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x27dd(%rip), %rsi      # 0xdb45
callq 0x3370
movq %r15, %rdi
movq %rbx, %rsi
callq 0x31c0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x27bb(%rip), %rsi      # 0xdb45
callq 0x3370
movq -0x40(%rbp), %rsi
subl -0x38(%rbp), %esi
movq %rbx, %rdi
callq 0x31c0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2795(%rip), %rsi      # 0xdb45
callq 0x3370
movq -0xa0(%rbp), %rsi
subl -0x7c(%rbp), %esi
movq %rbx, %rdi
callq 0x31c0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x276c(%rip), %rsi      # 0xdb45
callq 0x3370
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3580
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x274a(%rip), %rsi      # 0xdb45
callq 0x3370
movq %rbx, %rdi
movl -0x78(%rbp), %esi
callq 0x3580
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2728(%rip), %rsi      # 0xdb45
callq 0x3370
movl -0x78(%rbp), %eax
subl -0x4c(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd -0x30(%rbp), %xmm1
movsd 0x253f(%rip), %xmm0     # 0xd978
subsd %xmm1, %xmm0
mulsd 0x253b(%rip), %xmm0     # 0xd980
movq %rbx, %rdi
callq 0x3530
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x26e6(%rip), %rsi      # 0xdb45
callq 0x3370
movq %rbx, %rdi
movl -0x4c(%rbp), %esi
callq 0x3580
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq -0xd0(%rbp), %rdi
callq 0x3420
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xb4c7
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x32e0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xade6
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x32e0
jmp 0xade6
movq -0x98(%rbp), %rdi
callq 0x4845
leaq -0x158(%rbp), %rdi
callq 0xb9a0
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25cd(%rip), %rdi      # 0xdae9
xorl %eax, %eax
callq 0x3060
movl $0x1, %edi
callq 0x33d0
movq 0x5abc(%rip), %rdi      # 0x10ff0
leaq 0x25ea(%rip), %rsi      # 0xdb25
movl $0x14, %edx
callq 0x3370
movq 0x5aa4(%rip), %rdi      # 0x10ff0
movl %r15d, %esi
callq 0x3580
movq %rax, %r14
leaq 0x25dc(%rip), %rsi      # 0xdb3a
movl $0x8, %edx
movq %rax, %rdi
callq 0x3370
movq %r14, %rdi
movq -0x30(%rbp), %rsi
callq 0x3580
movq %rax, %rdi
callq 0x3140
jmp 0xb523
leaq -0xc8(%rbp), %rdi
callq 0x3d96
jmp 0xb5cd
movq %rax, %rbx
leaq -0x118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb617
movq -0x118(%rbp), %rsi
jmp 0xb60f
jmp 0xb5cd
jmp 0xb5cd
jmp 0xb5cd
jmp 0xb5d9
jmp 0xb5d9
jmp 0xb5cd
jmp 0xb5d9
jmp 0xb5d4
jmp 0xb5d9
jmp 0xb5cd
jmp 0xb5d9
jmp 0xb5cd
jmp 0xb5cd
jmp 0xb5cd
jmp 0xb5cd
jmp 0xb5cd
jmp 0xb5cd
movq %rax, %rbx
jmp 0xb617
jmp 0xb5d4
movq %rax, %rbx
jmp 0xb5fe
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xb5fe
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x32e0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xb617
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x32e0
leaq -0x158(%rbp), %rdi
callq 0xb9a0
movq %rbx, %rdi
callq 0x3590