// File: joncampbell123[P]floppytools/kryoflux7.cpp
// Function: main
int main(int argc,char **argv) {
    struct flux_bits fb;
    struct kryoflux_event ev;
    std::vector<std::string> cappaths;
    std::string path;
    FILE *dsk_fp;
    int c;

    if (argc < 2) {
        fprintf(stderr,"%s <raw capture directory> [dir...]\n",argv[0]);
        return 1;
    }

    for (int i=1;i < argc;i++) {
        char *a = argv[i];

        if (*a == '-') {
            do { a++; } while (*a == '-');

            if (!strcmp(a,"1.4mb")) {
                sectors = 18;
                heads = 2;
                tracks = 80;
                sector_size = 512;
            }
            else if (!strcmp(a,"720k")) {
                sectors = 9;
                heads = 2;
                tracks = 80;
                sector_size = 512;
            }
            else {
                fprintf(stderr,"Unknown switch %s\n",a);
                return 1;
            }
        }
        else {
            cappaths.push_back(argv[i]);
        }
    }

    dsk_fp = fopen("disk.img","wb");
    if (dsk_fp == NULL) return 1;

    captured.resize(heads * sectors * tracks);

    for (size_t capidx=0;capidx < cappaths.size();capidx++) {
        for (unsigned int track=0;track < tracks;track++) {
            for (unsigned int head=0;head < heads;head++) {
                {
                    char tmp[128];

                    sprintf(tmp,"track%02u.%u.raw",track,head);
                    path = cappaths[capidx] + "/" + tmp;
                }

                printf("%s...\n",path.c_str());

                FILE *fp = fopen(path.c_str(),"rb");
                if (fp == NULL) {
                    printf("Failed to open\n");
                    continue;
                }

                if (!autodetect_flux_bits_mfm(fb,ev,fp)) {
                    fprintf(stderr,"Autodetect failure\n");
                    fclose(fp);
                    continue;
                }

                flux_bits ofb = fb;

                int adj_span = 8;
                int dadj_span = 8;

                for (int adj_c = 0;adj_c <= (adj_span*2);adj_c++) {
                    for (int dadj_c = 0;dadj_c <= (dadj_span*2);dadj_c++) {
                        unsigned int capcount = 0;

                        int adj = adj_c;
                        int dadj = dadj_c;

                        if (adj >= (adj_span+1)) adj -= adj_span*2;
                        if (dadj >= (dadj_span+1)) dadj -= dadj_span*2;

                        if ((int)ofb.shortest+(int)adj <= 0)
                            continue;
                        fb.shortest = ofb.shortest + adj;

                        if ((int)ofb.dist+(int)dadj <= 0)
                            continue;
                        fb.dist = ofb.dist + dadj;

                        unsigned long snum = ((track * heads) + head) * sectors;

                        for (size_t i=0;i < sectors;i++)
                            capcount += captured[i+snum];

                        if (capcount >= sectors) {
                            printf("Track %u head %u already captured\n",track,head);
                            adj_c = 99;
                            dadj_c = 99;
                            break;
                        }
                        else {
                            printf("Track %u head %u capture progress: %u/%u adj=%d dadj=%d ",track,head,capcount,sectors,adj,dadj);
                            for (size_t i=0;i < sectors;i++) printf("%u",captured[i+snum]?1:0);
                            printf("\n");
                        }

                        fseek(fp,0,SEEK_SET);
                        fb.clear();

                        do {
                            kryoflux_bits_refill(fb,ev,fp);

                            /*                                                      *            */
                            /*                                            1 0 1 0 0 0 0 1   (A1) */
                            /* look for A1 sync (100010010001). Look for '0100010010001001' */
                            /*                                            ................  16 bits */
                            /*                                            4-->4-->8-->9-->  */
                            /*                                            3210321032103210  */
                            while (fb.avail() >= MFM_A1_SYNC_LENGTH) {
                                if (fb.peek(MFM_A1_SYNC_LENGTH) == MFM_A1_SYNC) {
                                    process_sync(dsk_fp,fb,ev,fp);
                                }
                                else {
                                    fb.get(1);
                                }
                            }

                            if (!kryoflux_bits_refill(fb,ev,fp))
                                break;
                        } while (fb.avail() > 0);
                    }
                }

                {
                    unsigned int capcount = 0;
                    {
                        unsigned long snum = ((track * heads) + head) * sectors;
                        for (size_t i=0;i < sectors;i++)
                            capcount += captured[i+snum];
                    }

                    if (capcount < sectors) {
                        printf("Track %u head %u not captured fully (%u < %u)\n",track,head,capcount,sectors);
                    }
                }

                fclose(fp);
            }
        }
    }

    {
        size_t count = 0;

        for (size_t i=0;i < captured.size();i++) {
            if (captured[i]) count++;
        }

        printf("Capture report: %zu captured / %zu total\n",count,captured.size());

        if (count < captured.size()) {
            printf("Missing sectors:\n");
            for (size_t i=0;i < captured.size();i++) {
                if (!captured[i])
                    printf(" %zu (C/H/S %u/%u/%u)\n",
                        i,
                        i / heads / sectors,
                        (i / sectors) % heads,
                        (i % sectors) + 1);
            }
        }
    }

    fclose(dsk_fp);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x3ab0
leaq -0x60(%rbp), %rdi
callq 0x3ad0
leaq -0x80(%rbp), %rdi
callq 0x2200
cmpl $0x2, -0x8(%rbp)
jge 0x2c5f
movq 0xb3af(%rip), %rax      # 0xdfe0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x6553(%rip), %rsi      # 0x9195
movb $0x0, %al
callq 0x2220
movl $0x1, -0x4(%rbp)
movl $0x1, -0x90(%rbp)
jmp 0x38ba
movl $0x1, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x2e4e
movq -0x10(%rbp), %rax
movslq -0x94(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x2d84
jmp 0x2ca3
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x2ca3
movq -0xa0(%rbp), %rdi
leaq 0x64e8(%rip), %rsi      # 0x91ba
callq 0x2210
cmpl $0x0, %eax
jne 0x2d06
movl $0x12, 0xb482(%rip)     # 0xe168
movl $0x2, 0xb47c(%rip)      # 0xe16c
movl $0x50, 0xb476(%rip)     # 0xe170
movl $0x200, 0xb470(%rip)    # imm = 0x200
jmp 0x2d7f
movq -0xa0(%rbp), %rdi
leaq 0x64ac(%rip), %rsi      # 0x91c0
callq 0x2210
cmpl $0x0, %eax
jne 0x2d48
movl $0x9, 0xb440(%rip)      # 0xe168
movl $0x2, 0xb43a(%rip)      # 0xe16c
movl $0x50, 0xb434(%rip)     # 0xe170
movl $0x200, 0xb42e(%rip)    # imm = 0x200
jmp 0x2d7d
movq 0xb291(%rip), %rax      # 0xdfe0
movq (%rax), %rdi
movq -0xa0(%rbp), %rdx
leaq 0x6465(%rip), %rsi      # 0x91c5
movb $0x0, %al
callq 0x2220
movl $0x1, -0x4(%rbp)
movl $0x1, -0x90(%rbp)
jmp 0x38ba
jmp 0x2d7f
jmp 0x2e38
movq -0x10(%rbp), %rax
movslq -0x94(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x290(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x2280
movq -0x290(%rbp), %rsi
movq -0x288(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x21f0
jmp 0x2dc9
leaq -0x60(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3af0
jmp 0x2ddb
leaq -0xc0(%rbp), %rdi
callq 0x2100
leaq -0xc1(%rbp), %rdi
callq 0x2190
jmp 0x2e38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x2e27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x2100
leaq -0xc1(%rbp), %rdi
callq 0x2190
jmp 0x38e1
jmp 0x2e3a
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x2c69
leaq 0x6383(%rip), %rdi      # 0x91d8
leaq 0x6385(%rip), %rsi      # 0x91e1
callq 0x21b0
movq %rax, -0x298(%rbp)
jmp 0x2e6a
movq -0x298(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jne 0x2eaf
movl $0x1, -0x4(%rbp)
movl $0x1, -0x90(%rbp)
jmp 0x38ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x38e1
movl 0xb2b7(%rip), %eax      # 0xe16c
movl 0xb2ad(%rip), %ecx      # 0xe168
imull %ecx, %eax
movl 0xb2ac(%rip), %ecx      # 0xe170
imull %ecx, %eax
movl %eax, %esi
leaq 0xf2d0(%rip), %rdi      # 0x121a0
xorl %edx, %edx
callq 0x3b20
jmp 0x2ed9
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3c40
movq %rax, %rcx
movq -0x2a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x364f
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
cmpl 0xb24c(%rip), %eax      # 0xe170
jae 0x3636
movl $0x0, -0xe8(%rbp)
movl -0xe8(%rbp), %eax
cmpl 0xb22c(%rip), %eax      # 0xe16c
jae 0x3620
movl -0xe4(%rbp), %edx
movl -0xe8(%rbp), %ecx
leaq 0x628b(%rip), %rsi      # 0x91e4
xorl %eax, %eax
leaq -0x170(%rbp), %rdi
callq 0x2060
movq -0xe0(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3d30
movq %rax, %rsi
leaq 0x6274(%rip), %rdx      # 0x91f5
leaq -0x1b0(%rbp), %rdi
callq 0x3cb0
jmp 0x2f8f
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0x170(%rbp), %rdx
callq 0x3c60
jmp 0x2fab
leaq -0x80(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
leaq -0x190(%rbp), %rsi
movq %rsi, -0x2b0(%rbp)
callq 0x21c0
movq -0x2b0(%rbp), %rdi
callq 0x2100
leaq -0x1b0(%rbp), %rdi
callq 0x2100
movq -0x2a8(%rbp), %rdi
callq 0x20b0
movq %rax, %rsi
leaq 0x6200(%rip), %rdi      # 0x91f7
xorl %eax, %eax
callq 0x2050
jmp 0x3000
leaq -0x80(%rbp), %rdi
callq 0x20b0
movq %rax, %rdi
leaq 0x61eb(%rip), %rsi      # 0x91fe
callq 0x21b0
movq %rax, -0x2b8(%rbp)
jmp 0x3021
movq -0x2b8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, -0x1b8(%rbp)
jne 0x3071
leaq 0x61c1(%rip), %rdi      # 0x9201
xorl %eax, %eax
callq 0x2050
jmp 0x3049
jmp 0x360c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x2100
jmp 0x38e1
movq -0x1b8(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x72f0
movb %al, -0x2b9(%rbp)
jmp 0x308d
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x30c4
jmp 0x3099
movq 0xaf40(%rip), %rax      # 0xdfe0
movq (%rax), %rdi
leaq 0x6167(%rip), %rsi      # 0x9211
xorl %eax, %eax
callq 0x2220
movq -0x1b8(%rbp), %rdi
callq 0x2170
jmp 0x30bf
jmp 0x360c
movq -0x20(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movl $0x8, -0x1cc(%rbp)
movl $0x8, -0x1d0(%rbp)
movl $0x0, -0x1d4(%rbp)
movl -0x1d4(%rbp), %eax
movl -0x1cc(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0x34fc
movl $0x0, -0x1d8(%rbp)
movl -0x1d8(%rbp), %eax
movl -0x1d0(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0x34e6
movl $0x0, -0x1dc(%rbp)
movl -0x1d4(%rbp), %eax
movl %eax, -0x1e0(%rbp)
movl -0x1d8(%rbp), %eax
movl %eax, -0x1e4(%rbp)
movl -0x1e0(%rbp), %eax
movl -0x1cc(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jl 0x3179
movl -0x1cc(%rbp), %ecx
shll %ecx
movl -0x1e0(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1e0(%rbp)
movl -0x1e4(%rbp), %eax
movl -0x1d0(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jl 0x31a2
movl -0x1d0(%rbp), %ecx
shll %ecx
movl -0x1e4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1e4(%rbp)
movl -0x1c0(%rbp), %eax
addl -0x1e0(%rbp), %eax
cmpl $0x0, %eax
jg 0x31b8
jmp 0x34d2
movl -0x1c0(%rbp), %eax
addl -0x1e0(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x1bc(%rbp), %eax
addl -0x1e4(%rbp), %eax
cmpl $0x0, %eax
jg 0x31dd
jmp 0x34d2
movl -0x1bc(%rbp), %eax
addl -0x1e4(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0xe4(%rbp), %eax
imull 0xaf73(%rip), %eax      # 0xe16c
addl -0xe8(%rbp), %eax
imull 0xaf62(%rip), %eax      # 0xe168
movl %eax, %eax
movq %rax, -0x1f0(%rbp)
movq $0x0, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rax
movl 0xaf41(%rip), %ecx      # 0xe168
cmpq %rcx, %rax
jae 0x32a9
movq -0x1f8(%rbp), %rsi
movq -0x1f0(%rbp), %rax
addq %rax, %rsi
leaq 0xef5c(%rip), %rdi      # 0x121a0
callq 0x39d0
movq %rdx, -0x2d0(%rbp)
movq %rax, -0x2c8(%rbp)
jmp 0x3259
movq -0x2d0(%rbp), %rax
movq -0x2c8(%rbp), %rcx
movq %rcx, -0x208(%rbp)
movq %rax, -0x200(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x3a30
andb $0x1, %al
movzbl %al, %eax
addl -0x1dc(%rbp), %eax
movl %eax, -0x1dc(%rbp)
movq -0x1f8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1f8(%rbp)
jmp 0x321a
movl -0x1dc(%rbp), %eax
cmpl 0xaeb3(%rip), %eax      # 0xe168
jb 0x32ec
movl -0xe4(%rbp), %esi
movl -0xe8(%rbp), %edx
leaq 0x5f5b(%rip), %rdi      # 0x9225
xorl %eax, %eax
callq 0x2050
jmp 0x32d3
movl $0x63, -0x1d4(%rbp)
movl $0x63, -0x1d8(%rbp)
jmp 0x34e6
movl -0xe4(%rbp), %esi
movl -0xe8(%rbp), %edx
movl -0x1dc(%rbp), %ecx
movl 0xae63(%rip), %r8d      # 0xe168
movl -0x1e0(%rbp), %r9d
movl -0x1e4(%rbp), %edi
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x5f2a(%rip), %rdi      # 0x9248
xorl %eax, %eax
callq 0x2050
jmp 0x3327
movq $0x0, -0x210(%rbp)
movq -0x210(%rbp), %rax
movl 0xae29(%rip), %ecx      # 0xe168
cmpq %rcx, %rax
jae 0x33c9
movq -0x210(%rbp), %rsi
movq -0x1f0(%rbp), %rax
addq %rax, %rsi
leaq 0xee40(%rip), %rdi      # 0x121a0
callq 0x39d0
movq %rdx, -0x2e0(%rbp)
movq %rax, -0x2d8(%rbp)
jmp 0x3375
movq -0x2e0(%rbp), %rax
movq -0x2d8(%rbp), %rcx
movq %rcx, -0x220(%rbp)
movq %rax, -0x218(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3a30
movzbl %al, %esi
leaq 0x5eda(%rip), %rdi      # 0x9281
xorl %eax, %eax
callq 0x2050
jmp 0x33b0
jmp 0x33b2
movq -0x210(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x210(%rbp)
jmp 0x3332
leaq 0x5ee1(%rip), %rdi      # 0x92b1
xorl %eax, %eax
callq 0x2050
jmp 0x33d9
jmp 0x33db
movq -0x1b8(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x21a0
jmp 0x33ed
leaq -0x20(%rbp), %rdi
callq 0x71f0
jmp 0x33f8
jmp 0x33fa
movq -0x1b8(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x7070
jmp 0x3410
jmp 0x3412
leaq -0x20(%rbp), %rdi
callq 0x7150
movl %eax, -0x2e4(%rbp)
jmp 0x3423
movl -0x2e4(%rbp), %eax
cmpl $0x10, %eax
jb 0x3484
leaq -0x20(%rbp), %rdi
movl $0x10, %esi
callq 0x7210
movl %eax, -0x2e8(%rbp)
jmp 0x3444
movl -0x2e8(%rbp), %eax
cmpl $0x4489, %eax           # imm = 0x4489
jne 0x3470
movq -0x88(%rbp), %rdi
movq -0x1b8(%rbp), %rcx
leaq -0x20(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x23f0
jmp 0x346e
jmp 0x3482
leaq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x7280
jmp 0x3480
jmp 0x3482
jmp 0x3412
movq -0x1b8(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x7070
movb %al, -0x2e9(%rbp)
jmp 0x34a0
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0x34ae
jmp 0x34ac
jmp 0x34d0
jmp 0x34b0
leaq -0x20(%rbp), %rdi
callq 0x7150
movl %eax, -0x2f0(%rbp)
jmp 0x34c1
movl -0x2f0(%rbp), %eax
cmpl $0x0, %eax
ja 0x33fa
jmp 0x34d2
movl -0x1d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d8(%rbp)
jmp 0x3118
jmp 0x34e8
movl -0x1d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d4(%rbp)
jmp 0x30f8
movl $0x0, -0x224(%rbp)
movl -0xe4(%rbp), %eax
imull 0xac59(%rip), %eax      # 0xe16c
addl -0xe8(%rbp), %eax
imull 0xac48(%rip), %eax      # 0xe168
movl %eax, %eax
movq %rax, -0x230(%rbp)
movq $0x0, -0x238(%rbp)
movq -0x238(%rbp), %rax
movl 0xac27(%rip), %ecx      # 0xe168
cmpq %rcx, %rax
jae 0x35c3
movq -0x238(%rbp), %rsi
movq -0x230(%rbp), %rax
addq %rax, %rsi
leaq 0xec42(%rip), %rdi      # 0x121a0
callq 0x39d0
movq %rdx, -0x300(%rbp)
movq %rax, -0x2f8(%rbp)
jmp 0x3573
movq -0x300(%rbp), %rax
movq -0x2f8(%rbp), %rcx
movq %rcx, -0x248(%rbp)
movq %rax, -0x240(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x3a30
andb $0x1, %al
movzbl %al, %eax
addl -0x224(%rbp), %eax
movl %eax, -0x224(%rbp)
movq -0x238(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x238(%rbp)
jmp 0x3534
movl -0x224(%rbp), %eax
cmpl 0xab99(%rip), %eax      # 0xe168
jae 0x35fc
movl -0xe4(%rbp), %esi
movl -0xe8(%rbp), %edx
movl -0x224(%rbp), %ecx
movl 0xab7e(%rip), %r8d      # 0xe168
leaq 0x5c93(%rip), %rdi      # 0x9284
xorl %eax, %eax
callq 0x2050
jmp 0x35fa
jmp 0x35fc
movq -0x1b8(%rbp), %rdi
callq 0x2170
jmp 0x360a
jmp 0x360c
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x2f34
jmp 0x3622
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x2f18
jmp 0x3638
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x2ee4
movq $0x0, -0x250(%rbp)
movq $0x0, -0x258(%rbp)
movq -0x258(%rbp), %rax
movq %rax, -0x308(%rbp)
leaq 0xeb26(%rip), %rdi      # 0x121a0
callq 0x3950
movq %rax, %rcx
movq -0x308(%rbp), %rax
cmpq %rcx, %rax
jae 0x370a
movq -0x258(%rbp), %rsi
leaq 0xeb04(%rip), %rdi      # 0x121a0
callq 0x39d0
movq %rdx, -0x318(%rbp)
movq %rax, -0x310(%rbp)
jmp 0x36b1
movq -0x318(%rbp), %rax
movq -0x310(%rbp), %rcx
movq %rcx, -0x268(%rbp)
movq %rax, -0x260(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x3a30
testb $0x1, %al
jne 0x36df
jmp 0x36f1
movq -0x250(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x250(%rbp)
jmp 0x36f3
movq -0x258(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x258(%rbp)
jmp 0x3665
movq -0x250(%rbp), %rax
movq %rax, -0x320(%rbp)
leaq 0xea81(%rip), %rdi      # 0x121a0
callq 0x3950
movq -0x320(%rbp), %rsi
movq %rax, %rdx
leaq 0x5b7e(%rip), %rdi      # 0x92b3
xorl %eax, %eax
callq 0x2050
jmp 0x373e
movq -0x250(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq 0xea4d(%rip), %rdi      # 0x121a0
callq 0x3950
movq %rax, %rcx
movq -0x328(%rbp), %rax
cmpq %rcx, %rax
jae 0x389b
leaq 0x5b6b(%rip), %rdi      # 0x92dd
xorl %eax, %eax
callq 0x2050
jmp 0x377b
movq $0x0, -0x270(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x330(%rbp)
leaq 0xea05(%rip), %rdi      # 0x121a0
callq 0x3950
movq %rax, %rcx
movq -0x330(%rbp), %rax
cmpq %rcx, %rax
jae 0x3899
movq -0x270(%rbp), %rsi
leaq 0xe9df(%rip), %rdi      # 0x121a0
callq 0x39d0
movq %rdx, -0x340(%rbp)
movq %rax, -0x338(%rbp)
jmp 0x37d6
movq -0x340(%rbp), %rax
movq -0x338(%rbp), %rcx
movq %rcx, -0x280(%rbp)
movq %rax, -0x278(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x3a30
xorb $-0x1, %al
testb $0x1, %al
jne 0x3806
jmp 0x3880
movq -0x270(%rbp), %rsi
movl 0xa959(%rip), %eax      # 0xe16c
movl %eax, %ecx
xorl %eax, %eax
movl %eax, -0x34c(%rbp)
movl %eax, %edx
movq %rdx, -0x358(%rbp)
movq %rsi, %rax
divq %rcx
movq -0x358(%rbp), %rdx
movl 0xa92f(%rip), %edi      # 0xe168
divq %rdi
movq -0x358(%rbp), %rdx
movq %rax, -0x348(%rbp)
movq %rsi, %rax
divq %rdi
movq %rdx, %r8
movq -0x358(%rbp), %rdx
divq %rcx
movl -0x34c(%rbp), %eax
movq %rdx, %rcx
movq -0x348(%rbp), %rdx
incq %r8
leaq 0x5a78(%rip), %rdi      # 0x92ef
callq 0x2050
jmp 0x387e
jmp 0x3880
jmp 0x3882
movq -0x270(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x270(%rbp)
jmp 0x3786
jmp 0x389b
movq -0x88(%rbp), %rdi
callq 0x2170
jmp 0x38a9
movl $0x0, -0x4(%rbp)
movl $0x1, -0x90(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x2100
leaq -0x60(%rbp), %rdi
callq 0x3d50
leaq -0x48(%rbp), %rdi
callq 0x3db0
movl -0x4(%rbp), %eax
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
leaq -0x80(%rbp), %rdi
callq 0x2100
leaq -0x60(%rbp), %rdi
callq 0x3d50
leaq -0x48(%rbp), %rdi
callq 0x3db0
movq -0xd0(%rbp), %rdi
callq 0x2270
nopl (%rax,%rax)