// File: /workspace/github_cpp_makefile_star2_O2/pgrouchy[P]NoiseWorld/master.cpp
// Function: main
int main(int argc, char* argv[]) {

    if (argc != 2) {
        cout << "Usage: EMM_SymComm [runID]" << endl;
        exit(-1);
    }

    signal(SIGTERM, term_trap);

    list<Genome*>::iterator curGenome, curGenome2;
    list<Population*>::iterator curPop;

    string myFilename;

    Population *initPop;

    int i, j, fd, intStat, bestIsl, numInSync, counter1 = 0, counter2 = 0, zipCounter = 0, bestFit = 0, era_counter = 0;
    int myInt[6], myBestInt[6];
    double myDouble[2], myBestDouble[2];
    double densityTotal = 0.0;

    int run_id = atoi(argv[1]);

    FILE *dataFile;
    struct stat stFileInfo;
    ofstream myFile;
    struct flock fl = {F_WRLCK, SEEK_SET,   0,      0,     0 };
    fl.l_pid = getpid();

    string tempString, tempString2;

    // Initialize randomizer so that different runs produce different results
    srand( (unsigned)(run_id*100000) );
    //srand ( time(NULL) );

    // make necessary directories
    for (i = 0; i < NUM_ISLANDS; i++) {
        stringstream isl_sync_dir;
        isl_sync_dir << "mkdir /dev/shm/sync_dir_" << i;
        system(isl_sync_dir.str().c_str());

        stringstream isl_sync_file;
        isl_sync_file << "touch /dev/shm/sync_dir_" << i << "/folderSync.txt";
        system(isl_sync_file.str().c_str());
    }
    stringstream data_dir_ss;
    data_dir_ss << "mkdir dataDir_" << run_id;
    system(data_dir_ss.str().c_str());

    // Start islands
    for (i = 0; i < NUM_ISLANDS; i++) {
        // Generate initial population
        initPop = new Population(i);
        stringstream isl_pop_ss;
        isl_pop_ss << "/dev/shm/initPop_" << i << ".pop";
        initPop->savePop(isl_pop_ss.str().c_str());
        delete initPop;
    }
    for (i = 0; i < NUM_SLAVES; i++) {
        // Run slaves
        stringstream isl_ss;
        isl_ss << "nice ./EMM_island " << i << " " << run_id << " &";
        system(isl_ss.str().c_str());
    }

    // we run the simulation until it is killed by the system or user
    while (true) {
        numInSync = 0;
        for (i = 0; i < NUM_SLAVES; i++) {
            stringstream ss;
            ss << "/dev/shm/fitFlag_" << i << ".txt";
            intStat = stat(ss.str().c_str(),&stFileInfo);
            if (intStat == 0) {
                numInSync++;
            } else {
                break;
            }
        }

        if (numInSync == NUM_SLAVES) {

            era_counter++;

            ofstream myFile;
            stringstream ss_gen_file;
            ss_gen_file << "dataDir_" << run_id << "/genOutput.csv";
            myFile.open(ss_gen_file.str().c_str(), ios::out | ios::app);

            myBestInt[3] = -1;

            for (i = 0; i < NUM_ISLANDS; i++) {

                stringstream sync_ss1;
                sync_ss1 << "/dev/shm/sync_dir_" << i << "/folderSync.txt";
                // set file lock
                fl.l_type = F_WRLCK;
                fd = open(sync_ss1.str().c_str(), O_RDWR);
                fcntl(fd, F_SETLKW, &fl);

                stringstream ss2;
                ss2 << "/dev/shm/currentStatus_" << i << ".txt";
                dataFile = fopen(ss2.str().c_str(), "r");
                fscanf(dataFile, "%d,%d,%d,%d,%d,%lf,%lf,%d\n", &myInt[0], &myInt[1], &myInt[2], &myInt[3], &myInt[4], &myDouble[0], &myDouble[1], &myInt[5]);
                fclose(dataFile);

                myFile << "Isl " << i << " t-step " << myInt[1] << " numBirths: " << myInt[3] << " NumMigIn: " << myInt[4] << " avgAge: " << myDouble[0] << " beta: " << myDouble[1] << " hitWall: " << myBestInt[5] << endl;

                cout << "Isl " << i << " t-step " << myInt[1] << " numBirths: " << myInt[3] << " NumMigIn: " << myInt[4] << " avgAge: " << myDouble[0] << " beta: " << myDouble[1] << " hitWall: " << myBestInt[5] << endl;

                if (myInt[3] > myBestInt[3]) {
                    bestIsl = i;
                    for (j = 0; j < 6; j++) {
                        if (j < 2) {
                            myBestDouble[j] = myDouble[j];
                        }
                        myBestInt[j] = myInt[j];
                    }
                }

                // release lock file
                fl.l_type = F_UNLCK;
                fcntl(fd, F_SETLK, &fl);
                close(fd);
                
                counter1 += myInt[3];
                counter2++;
                densityTotal += myDouble[1];
            }
            myFile.close();

            stringstream copy_best_pop;
            copy_best_pop << "cp /dev/shm/popSnapshot-" << (era_counter * ERA) << "_" << bestIsl << ".pop dataDir_" << run_id << "/curBestPop.pop";
            system(copy_best_pop.str().c_str());

            if (myBestInt[3] > bestFit) {
                bestFit = myBestInt[3];
                stringstream copy_best_pop_2;
                copy_best_pop_2 << "cp /dev/shm/popSnapshot-" << (era_counter * ERA) << "_" << bestIsl << ".pop dataDir_" << run_id << "/overallBestPop.pop";
                system(copy_best_pop_2.str().c_str());
            }

            stringstream ss_avg_file;
            ss_avg_file << "dataDir_" << run_id << "/avgPopSize.csv";
            myFile.open(ss_avg_file.str().c_str(), ios::out | ios::app);
            myFile << ((double)counter1 / (double)counter2) << "  " << (densityTotal / (double)counter2) << endl;
            myFile.close();
            counter1 = 0;
            counter2 = 0;
            densityTotal = 0.0;

            stringstream do_zip;
            do_zip << "/dev/shm/zip_time_flag.txt";
            intStat = stat(do_zip.str().c_str(),&stFileInfo);
            if (intStat == 0) {
                stringstream zip_ss;
                if (zipCounter == 0) {
                    zip_ss << "zip -q -j dataDir_" << run_id << "/popSnapshots_" << zipCounter << ".zip /dev/shm/initPop_* /dev/shm/popSnapshot* /dev/shm/mig*.pop";
                } else {
                    zip_ss << "zip -q -j dataDir_" << run_id << "/popSnapshots_" << zipCounter << ".zip /dev/shm/popSnapshot* /dev/shm/mig*.pop";
                }
                system(zip_ss.str().c_str());

                stringstream zip_rm;
                zip_rm << "rm /dev/shm/popSnapshot*";
                system(zip_rm.str().c_str());

                if (zipCounter == 0) {
                    stringstream del_ss;
                    del_ss << "rm /dev/shm/initPop_*";
                    system(del_ss.str().c_str());
                }

                zipCounter++;
                stringstream rm_zip;
                rm_zip << "rm /dev/shm/zip_time_flag.txt";
                system(rm_zip.str().c_str());
            }


            for (i = 0; i < NUM_SLAVES; i++) {
                stringstream ss;
                ss << "rm /dev/shm/fitFlag_" << i << ".txt";
                system(ss.str().c_str());
            }
        }
        numInSync = 0;
        for (i = 0; i < NUM_SLAVES; i++) {
            stringstream ss;
            ss << "/dev/shm/syncFlag_" << i << ".txt";
            intStat = stat(ss.str().c_str(),&stFileInfo);
            if (intStat == 0) {
                numInSync++;
            } else {
                break;
            }
        }
        if (numInSync == NUM_SLAVES) {
            for (i = 0; i < NUM_SLAVES; i++) {
                stringstream ss;
                ss << "rm /dev/shm/syncFlag_" << i << ".txt";
                system(ss.str().c_str());
            }
        }
        usleep(100000);
    }

    return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x11f8, %rsp           # imm = 0x11F8
cmpl $0x2, %edi
jne 0x277f
movq %rsi, %rbx
leaq -0x12a(%rip), %rsi      # 0x24dc
pushq $0xf
popq %rdi
callq 0x2220
leaq 0x118(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x8(%rbx), %rdi
callq 0x22d0
movl %eax, %ebx
leaq 0xff8(%rsp), %rdi
callq 0x2310
movups 0x6d67(%rip), %xmm0     # 0x93a8
movaps %xmm0, 0x80(%rsp)
movupd 0x6d47(%rip), %xmm0     # 0x9398
movapd %xmm0, 0x70(%rsp)
callq 0x22a0
movl %eax, 0x88(%rsp)
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0xd8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %ebp, %ebp
movb %bpl, (%rax)
movb %bpl, (%rcx)
movl %ebx, 0xc(%rsp)
imull $0x186a0, %ebx, %edi    # imm = 0x186A0
callq 0x21c0
leaq 0x438(%rsp), %rbx
leaq 0xc58(%rsp), %r15
leaq 0x6a69(%rip), %r12      # 0x911c
leaq 0x6a7b(%rip), %r13      # 0x9135
leaq 0x128(%rsp), %r14
cmpl $0x64, %ebp
je 0x27a2
movq %rbx, %rdi
callq 0x20f0
leaq 0x448(%rsp), %rdi
leaq 0x6a21(%rip), %rsi      # 0x9103
callq 0x21d0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2320
movq %r15, %rdi
leaq 0x450(%rsp), %rsi
callq 0x22e0
movq 0xc58(%rsp), %rdi
callq 0x2180
movq %r15, %rdi
callq 0x20b0
movq %r15, %rdi
callq 0x20f0
leaq 0xc68(%rsp), %rdi
movq %r12, %rsi
callq 0x21d0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2320
movq %rax, %rdi
movq %r13, %rsi
callq 0x21d0
movq %r14, %rdi
leaq 0xc70(%rsp), %rsi
callq 0x22e0
movq 0x128(%rsp), %rdi
callq 0x2180
movq %r14, %rdi
callq 0x20b0
movq %r15, %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x2120
incl %ebp
jmp 0x26c2
movq 0xa852(%rip), %rdi      # 0xcfd8
leaq 0x695b(%rip), %rsi      # 0x90e8
callq 0x21d0
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rdi
callq 0x2230
leaq 0xc58(%rsp), %rdi
callq 0x20f0
leaq 0xc68(%rsp), %rdi
leaq 0x6987(%rip), %rsi      # 0x9145
callq 0x21d0
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2320
leaq 0xc70(%rsp), %rsi
leaq 0x438(%rsp), %rdi
callq 0x22e0
movq 0x438(%rsp), %rdi
callq 0x2180
leaq 0x438(%rsp), %rbx
movq %rbx, %rdi
callq 0x20b0
xorl %ebp, %ebp
pushq $0x50
popq %r12
leaq 0x128(%rsp), %r15
leaq 0xa8(%rsp), %r13
cmpl $0x64, %ebp
je 0x28cf
movq %r12, %rdi
callq 0x21f0
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
callq 0x3748
movq %rbx, %rdi
callq 0x20f0
leaq 0x448(%rsp), %rdi
leaq 0x6908(%rip), %rsi      # 0x9154
callq 0x21d0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x6a5a(%rip), %rsi      # 0x92bf
callq 0x21d0
movq %r15, %rdi
leaq 0x450(%rsp), %rsi
callq 0x22e0
movq 0x128(%rsp), %rsi
movq %r13, %rdi
leaq 0x7c0(%rsp), %rdx
callq 0x38a4
movq %r14, %rdi
movq %r13, %rsi
callq 0x4c02
movq %r13, %rdi
callq 0x20b0
movq %r15, %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x38e0
movq %r14, %rdi
movq %r12, %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2120
incl %ebp
jmp 0x2817
xorl %ebp, %ebp
leaq 0x438(%rsp), %r15
leaq 0x6886(%rip), %r12      # 0x9166
leaq 0x6979(%rip), %r13      # 0x9260
leaq 0x688b(%rip), %rbx      # 0x9179
leaq 0x128(%rsp), %r14
cmpl $0x14, %ebp
je 0x2970
movq %r15, %rdi
callq 0x20f0
leaq 0x448(%rsp), %rdi
movq %r12, %rsi
callq 0x21d0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2320
movq %rax, %rdi
movq %r13, %rsi
callq 0x21d0
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2320
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21d0
movq %r14, %rdi
leaq 0x450(%rsp), %rsi
callq 0x22e0
movq 0x128(%rsp), %rdi
callq 0x2180
movq %r14, %rdi
callq 0x20b0
movq %r15, %rdi
callq 0x2120
incl %ebp
jmp 0x28f6
leaq 0x438(%rsp), %r14
movl $0x0, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x18(%rsp)
xorl %ebx, %ebx
cmpl $0x14, %ebx
je 0x2a16
movq %r14, %rdi
callq 0x20f0
leaq 0x448(%rsp), %rdi
leaq 0x6993(%rip), %rsi      # 0x9341
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x6779(%rip), %rsi      # 0x9140
callq 0x21d0
leaq 0x128(%rsp), %r15
movq %r15, %rdi
leaq 0x450(%rsp), %rsi
callq 0x22e0
movq 0x128(%rsp), %rdi
leaq 0xf68(%rsp), %rsi
callq 0x21b0
movl %eax, %ebp
movq %r15, %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x2120
incl %ebx
testl %ebp, %ebp
je 0x2992
jmp 0x332d
movq %r14, %rdi
callq 0x2310
leaq 0x128(%rsp), %rdi
callq 0x20f0
leaq 0x138(%rsp), %rdi
leaq 0x6832(%rip), %rsi      # 0x926c
callq 0x21d0
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x6727(%rip), %rsi      # 0x917c
callq 0x21d0
leaq 0x7c0(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x22e0
movq 0x7c0(%rsp), %rsi
movq %r14, %rdi
pushq $0x11
popq %rdx
callq 0x2040
incl 0x18(%rsp)
leaq 0x7c0(%rsp), %rdi
callq 0x20b0
orl $-0x1, 0x9c(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpl $0x64, %r13d
je 0x2e1a
leaq 0x7c0(%rsp), %rdi
callq 0x20f0
leaq 0x7d0(%rsp), %rdi
leaq 0x6651(%rip), %rsi      # 0x9122
callq 0x21d0
movq %rax, %rdi
movl %r13d, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x664a(%rip), %rsi      # 0x9135
callq 0x21d0
movw $0x1, 0x70(%rsp)
leaq 0x2b0(%rsp), %rdi
leaq 0x7d8(%rsp), %rsi
callq 0x22e0
movq 0x2b0(%rsp), %rdi
pushq $0x2
popq %rsi
xorl %eax, %eax
callq 0x2110
movl %eax, %r12d
leaq 0x2b0(%rsp), %rdi
callq 0x20b0
movl %r12d, %edi
pushq $0x7
popq %rsi
leaq 0x70(%rsp), %rdx
xorl %eax, %eax
callq 0x20e0
leaq 0x2b0(%rsp), %rdi
callq 0x20f0
leaq 0x2c0(%rsp), %rdi
leaq 0x662f(%rip), %rsi      # 0x918b
callq 0x21d0
movq %rax, %rdi
movl %r13d, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x65ca(%rip), %rsi      # 0x9140
callq 0x21d0
leaq 0x638(%rsp), %rbp
movq %rbp, %rdi
leaq 0x2c8(%rsp), %rsi
callq 0x22e0
movq 0x638(%rsp), %rdi
leaq 0x6601(%rip), %rsi      # 0x91a3
callq 0x2210
movq %rax, %rbx
movq %rbp, %rdi
callq 0x20b0
movq %rbx, %rdi
leaq 0x65e9(%rip), %rsi      # 0x91a5
leaq 0x20(%rsp), %rdx
leaq 0x24(%rsp), %rcx
leaq 0x28(%rsp), %r8
leaq 0x2c(%rsp), %r9
xorl %eax, %eax
leaq 0x34(%rsp), %r10
pushq %r10
leaq 0x50(%rsp), %r10
pushq %r10
leaq 0x50(%rsp), %r10
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
callq 0x2350
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x21e0
movq %r14, %rdi
leaq 0x65b7(%rip), %rsi      # 0x91c0
callq 0x21d0
movq %rax, %rdi
movl %r13d, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x65a2(%rip), %rsi      # 0x91c5
callq 0x21d0
movl 0x24(%rsp), %esi
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
leaq 0x6590(%rip), %rsi      # 0x91ce
callq 0x21d0
movl 0x2c(%rsp), %esi
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
leaq 0x6582(%rip), %rsi      # 0x91db
callq 0x21d0
movl 0x30(%rsp), %esi
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
leaq 0x6573(%rip), %rsi      # 0x91e7
callq 0x21d0
movsd 0x40(%rsp), %xmm0
movq %rax, %rdi
callq 0x22f0
movq %rax, %rdi
leaq 0x6560(%rip), %rsi      # 0x91f1
callq 0x21d0
movsd 0x48(%rsp), %xmm0
movq %rax, %rdi
callq 0x22f0
movq %rax, %rdi
leaq 0x654b(%rip), %rsi      # 0x91f9
callq 0x21d0
movl 0xa4(%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x2320
movq %rax, %rdi
callq 0x20c0
movq 0xa305(%rip), %rdi      # 0xcfd8
leaq 0x64e6(%rip), %rsi      # 0x91c0
callq 0x21d0
movq %rax, %rdi
movl %r13d, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x64d1(%rip), %rsi      # 0x91c5
callq 0x21d0
movl 0x24(%rsp), %esi
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
leaq 0x64bf(%rip), %rsi      # 0x91ce
callq 0x21d0
movl 0x2c(%rsp), %esi
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
leaq 0x64b1(%rip), %rsi      # 0x91db
callq 0x21d0
movl 0x30(%rsp), %esi
movq %rax, %rdi
callq 0x2320
movq %rax, %rdi
leaq 0x64a2(%rip), %rsi      # 0x91e7
callq 0x21d0
movsd 0x40(%rsp), %xmm0
movq %rax, %rdi
callq 0x22f0
movq %rax, %rdi
leaq 0x648f(%rip), %rsi      # 0x91f1
callq 0x21d0
movsd 0x48(%rsp), %xmm0
movq %rax, %rdi
callq 0x22f0
movq %rax, %rdi
leaq 0x647a(%rip), %rsi      # 0x91f9
callq 0x21d0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2320
movq %rax, %rdi
callq 0x20c0
movl 0x2c(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jle 0x2dc0
xorl %eax, %eax
cmpq $0x6, %rax
je 0x2dbb
movl 0x20(%rsp,%rax,4), %ecx
movl %ecx, 0x90(%rsp,%rax,4)
incq %rax
jmp 0x2da5
movl %r13d, 0x1c(%rsp)
movw $0x2, 0x70(%rsp)
movl %r12d, %edi
pushq $0x6
popq %rsi
leaq 0x70(%rsp), %rdx
xorl %eax, %eax
callq 0x20e0
movl %r12d, %edi
callq 0x2380
addl 0x2c(%rsp), %r15d
incl %r13d
movsd 0x38(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x2b0(%rsp), %rdi
callq 0x2120
leaq 0x7c0(%rsp), %rdi
callq 0x2120
jmp 0x2aab
movq %r14, %rdi
callq 0x2290
leaq 0x7c0(%rsp), %rdi
callq 0x20f0
leaq 0x7d0(%rsp), %rdi
leaq 0x63c6(%rip), %rsi      # 0x9204
callq 0x21d0
imull $0x186a0, 0x18(%rsp), %ebx # imm = 0x186A0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x6508(%rip), %rsi      # 0x9367
callq 0x21d0
movq %rax, %rdi
movl 0x1c(%rsp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x63a3(%rip), %rsi      # 0x921d
callq 0x21d0
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x6396(%rip), %rsi      # 0x922b
callq 0x21d0
leaq 0x2b0(%rsp), %rdi
leaq 0x7d8(%rsp), %rsi
callq 0x22e0
movq 0x2b0(%rsp), %rdi
callq 0x2180
leaq 0x2b0(%rsp), %r12
movq %r12, %rdi
callq 0x20b0
movl 0x9c(%rsp), %ebp
cmpl 0x14(%rsp), %ebp
jle 0x2f8b
movq %r12, %rdi
callq 0x20f0
leaq 0x2c0(%rsp), %rdi
leaq 0x6310(%rip), %rsi      # 0x9204
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x645a(%rip), %rsi      # 0x9367
callq 0x21d0
movq %rax, %rdi
movl 0x1c(%rsp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x62f5(%rip), %rsi      # 0x921d
callq 0x21d0
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x62f8(%rip), %rsi      # 0x923b
callq 0x21d0
leaq 0x638(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
callq 0x22e0
movq 0x638(%rsp), %rdi
callq 0x2180
leaq 0x638(%rsp), %rdi
callq 0x20b0
leaq 0x2b0(%rsp), %r12
movq %r12, %rdi
callq 0x2120
movl %ebp, 0x14(%rsp)
movq %r12, %rdi
callq 0x20f0
leaq 0x2c0(%rsp), %rdi
leaq 0x62ca(%rip), %rsi      # 0x926c
callq 0x21d0
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x6292(%rip), %rsi      # 0x924f
callq 0x21d0
leaq 0x638(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
callq 0x22e0
movq 0x638(%rsp), %rsi
movq %r14, %rdi
pushq $0x11
popq %rdx
callq 0x2040
leaq 0x638(%rsp), %rdi
callq 0x20b0
cvtsi2sd %r15d, %xmm0
divsd 0x6004(%rip), %xmm0     # 0x9008
movq %r14, %rdi
callq 0x22f0
movq %rax, %rdi
leaq 0x6249(%rip), %rsi      # 0x925f
callq 0x21d0
movsd 0x38(%rsp), %xmm0
divsd 0x5fdf(%rip), %xmm0     # 0x9008
movq %rax, %rdi
callq 0x22f0
movq %rax, %rdi
callq 0x20c0
movq %r14, %rdi
callq 0x2290
leaq 0x638(%rsp), %rdi
callq 0x20f0
leaq 0x648(%rsp), %rdi
leaq 0x62c6(%rip), %rsi      # 0x9323
callq 0x21d0
leaq 0xad0(%rsp), %r15
movq %r15, %rdi
leaq 0x650(%rsp), %rsi
callq 0x22e0
movq 0xad0(%rsp), %rdi
leaq 0xf68(%rsp), %rsi
callq 0x21b0
movl %eax, %ebx
movq %r15, %rdi
callq 0x20b0
testl %ebx, %ebx
jne 0x3270
movq %r15, %rdi
callq 0x20f0
cmpl $0x0, 0x10(%rsp)
je 0x30f4
leaq 0xae0(%rsp), %rdi
leaq 0x61a3(%rip), %rsi      # 0x9262
callq 0x21d0
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x619b(%rip), %rsi      # 0x9275
callq 0x21d0
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x2320
leaq 0x61d2(%rip), %rsi      # 0x92c4
jmp 0x3134
leaq 0xae0(%rsp), %rdi
leaq 0x615f(%rip), %rsi      # 0x9262
callq 0x21d0
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x6157(%rip), %rsi      # 0x9275
callq 0x21d0
movq %rax, %rdi
xorl %esi, %esi
callq 0x2320
leaq 0x6150(%rip), %rsi      # 0x9284
movq %rax, %rdi
callq 0x21d0
leaq 0x948(%rsp), %rdi
leaq 0xae8(%rsp), %rsi
callq 0x22e0
movq 0x948(%rsp), %rdi
callq 0x2180
leaq 0x948(%rsp), %rbx
movq %rbx, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x20f0
leaq 0x958(%rsp), %rdi
leaq 0x616c(%rip), %rsi      # 0x92f1
callq 0x21d0
leaq 0xde0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x960(%rsp), %rsi
callq 0x22e0
movq 0xde0(%rsp), %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x20b0
cmpl $0x0, 0x10(%rsp)
jne 0x3208
movq %rbx, %rdi
callq 0x20f0
leaq 0xdf0(%rsp), %rdi
leaq 0x6135(%rip), %rsi      # 0x930a
callq 0x21d0
leaq 0x50(%rsp), %rdi
leaq 0xdf8(%rsp), %rsi
callq 0x22e0
movq 0x50(%rsp), %rdi
callq 0x2180
leaq 0x50(%rsp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x20f0
leaq 0xdf0(%rsp), %rdi
leaq 0x6101(%rip), %rsi      # 0x9320
callq 0x21d0
leaq 0x50(%rsp), %rdi
leaq 0xdf8(%rsp), %rsi
callq 0x22e0
movq 0x50(%rsp), %rdi
callq 0x2180
incl 0x10(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2120
leaq 0x948(%rsp), %rdi
callq 0x2120
leaq 0xad0(%rsp), %rdi
callq 0x2120
xorl %ebx, %ebx
cmpl $0x14, %ebx
je 0x32f1
leaq 0xad0(%rsp), %rdi
callq 0x20f0
leaq 0xae0(%rsp), %rdi
leaq 0x60ab(%rip), %rsi      # 0x933e
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x5e94(%rip), %rsi      # 0x9140
callq 0x21d0
leaq 0x948(%rsp), %rdi
leaq 0xae8(%rsp), %rsi
callq 0x22e0
movq 0x948(%rsp), %rdi
callq 0x2180
leaq 0x948(%rsp), %rdi
callq 0x20b0
leaq 0xad0(%rsp), %rdi
callq 0x2120
incl %ebx
jmp 0x3272
leaq 0x638(%rsp), %rdi
callq 0x2120
leaq 0x2b0(%rsp), %rdi
callq 0x2120
leaq 0x7c0(%rsp), %rdi
callq 0x2120
leaq 0x128(%rsp), %rdi
callq 0x2120
movq %r14, %rdi
callq 0x22b0
xorl %ebx, %ebx
cmpl $0x14, %ebx
je 0x33c5
movq %r14, %rdi
callq 0x20f0
leaq 0x448(%rsp), %rdi
leaq 0x6007(%rip), %rsi      # 0x9356
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x5dd8(%rip), %rsi      # 0x9140
callq 0x21d0
leaq 0x128(%rsp), %r15
movq %r15, %rdi
leaq 0x450(%rsp), %rsi
callq 0x22e0
movq 0x128(%rsp), %rdi
leaq 0xf68(%rsp), %rsi
callq 0x21b0
movl %eax, %ebp
movq %r15, %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x2120
incl %ebx
testl %ebp, %ebp
je 0x332f
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x2280
jmp 0x2990
xorl %ebx, %ebx
cmpl $0x14, %ebx
je 0x33b6
movq %r14, %rdi
callq 0x20f0
leaq 0x448(%rsp), %rdi
leaq 0x5f70(%rip), %rsi      # 0x9353
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x5d44(%rip), %rsi      # 0x9140
callq 0x21d0
leaq 0x128(%rsp), %rdi
leaq 0x450(%rsp), %rsi
callq 0x22e0
movq 0x128(%rsp), %rdi
callq 0x2180
leaq 0x128(%rsp), %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x2120
incl %ebx
jmp 0x33c7
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x20b0
jmp 0x3468
jmp 0x344d
movq %rax, %rbx
jmp 0x3468
jmp 0x348d
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x20b0
jmp 0x3468
jmp 0x3465
movq %rax, %rbx
leaq 0xde0(%rsp), %rdi
callq 0x2120
jmp 0x3490
jmp 0x348d
movq %rax, %rbx
leaq 0xde0(%rsp), %rdi
callq 0x20b0
jmp 0x3490
jmp 0x348d
movq %rax, %rbx
leaq 0x948(%rsp), %rdi
callq 0x2120
jmp 0x3544
jmp 0x3541
movq %rax, %rbx
leaq 0x948(%rsp), %rdi
callq 0x20b0
jmp 0x3544
jmp 0x3541
jmp 0x3576
movq %rax, %rbx
leaq 0x638(%rsp), %rdi
callq 0x20b0
jmp 0x35d8
jmp 0x354b
jmp 0x3555
jmp 0x3576
jmp 0x3576
jmp 0x355d
movq %rax, %rbx
leaq 0x638(%rsp), %rdi
callq 0x20b0
jmp 0x35d8
jmp 0x355d
jmp 0x3555
movq %rax, %rbx
leaq 0x2b0(%rsp), %rdi
callq 0x20b0
jmp 0x35e5
jmp 0x3555
jmp 0x3593
movq %rax, %rbx
leaq 0x7c0(%rsp), %rdi
callq 0x20b0
jmp 0x360f
jmp 0x3593
movq %rax, %rbx
jmp 0x361c
jmp 0x36a6
movq %rax, %rbx
jmp 0x35be
jmp 0x36a6
movq %rax, %rbx
jmp 0x35d8
jmp 0x3593
movq %rax, %rbx
jmp 0x35e5
movq %rax, %rbx
jmp 0x35d8
jmp 0x35bb
movq %rax, %rbx
leaq 0x948(%rsp), %rdi
callq 0x20b0
jmp 0x35be
movq %rax, %rbx
jmp 0x35cb
movq %rax, %rbx
leaq 0x2b0(%rsp), %rdi
callq 0x20b0
jmp 0x3602
jmp 0x35f2
jmp 0x35ed
jmp 0x35ed
movq %rax, %rbx
jmp 0x360f
jmp 0x362b
jmp 0x3641
jmp 0x36a6
jmp 0x3641
jmp 0x36a6
jmp 0x3641
jmp 0x36a6
movq %rax, %rbx
leaq 0xad0(%rsp), %rdi
callq 0x2120
leaq 0x638(%rsp), %rdi
callq 0x2120
leaq 0x2b0(%rsp), %rdi
callq 0x2120
jmp 0x3602
jmp 0x3641
jmp 0x3641
jmp 0x3641
movq %rax, %rbx
jmp 0x3602
movq %rax, %rbx
leaq 0x2b0(%rsp), %rdi
callq 0x2120
leaq 0x7c0(%rsp), %rdi
callq 0x2120
leaq 0x128(%rsp), %rdi
callq 0x2120
leaq 0x438(%rsp), %rdi
callq 0x22b0
jmp 0x36a9
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x20b0
jmp 0x3683
jmp 0x3641
jmp 0x36a6
movq %rax, %rbx
jmp 0x3683
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x20b0
jmp 0x365b
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x20b0
jmp 0x3683
jmp 0x3680
jmp 0x36a6
movq %rax, %rbx
pushq $0x50
popq %rsi
movq %r14, %rdi
callq 0x2200
jmp 0x36a9
jmp 0x36a6
movq %rax, %rbx
leaq 0x438(%rsp), %rdi
callq 0x2120
jmp 0x36a9
movq %rax, %rbx
leaq 0x438(%rsp), %rdi
callq 0x20b0
jmp 0x36a9
jmp 0x36a6
movq %rax, %rbx
leaq 0xc58(%rsp), %rdi
jmp 0x3701
jmp 0x36df
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x20b0
jmp 0x36ec
jmp 0x36e9
jmp 0x36e4
movq %rax, %rbx
leaq 0xc58(%rsp), %rdi
callq 0x20b0
jmp 0x36f9
jmp 0x36e4
movq %rax, %rbx
jmp 0x3706
movq %rax, %rbx
jmp 0x36f9
movq %rax, %rbx
leaq 0xc58(%rsp), %rdi
callq 0x2120
leaq 0x438(%rsp), %rdi
callq 0x2120
leaq 0xc8(%rsp), %rdi
callq 0x20b0
leaq 0xe8(%rsp), %rdi
callq 0x20b0
leaq 0xff8(%rsp), %rdi
callq 0x22b0
jmp 0x3732
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2330
nop