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

///////////////////////////////
// Parse command line arguments
///////////////////////////////
    if (argc != 9)
    {
        std::cerr << "wrong number of Command line arguments" << std::endl;
        std::cerr << "./ip_analyzing_gm\n[inFileName] \n[outFolderName] \n[nx] [ny] [nz] [erosiondepth] [sigma_g] [sigma_p]";
        return 0;
    }

    std::string inFileName = argv[1];
    std::string outFolderName = argv[2];

    CreateFolders(outFolderName);

    // the size of the tomogram
    unsigned long  nx = atoi(argv[3]);
    unsigned long  ny = atoi(argv[4]);
    unsigned long  nz = atoi(argv[5]);

    // erosion depth for watershed segmentation of the particles
    int erosiondepth = atoi(argv[6]);


    // bilateral filter parameters
    double bf_sigma_Pos = atof(argv[7]);
    double bf_sigma_Col = atof(argv[8]);
    //double bf_sigma_Pos = 1.75;
    //double bf_sigma_Col = 2000;
    // cutoff for spatial gauss
    unsigned bf_size = static_cast<unsigned>(bf_sigma_Pos * 2.5);

///////////////////////////////
// Load Tomogram
///////////////////////////////
    std::cout << "loading tomogram from " << inFileName << std::endl;

    tomogram3d<uint16_t> original;
    original.read_raw(inFileName, "uint16_t", nx, ny, nz);

    std::cout << "tomogram successfully loaded" << std::endl;
    
    // write some images of the original tomogram
    WriteImages(original, outFolderName + "/images/", "0_original", nz);
    
///////////////////////////////
// Apply bilateral filter
///////////////////////////////
    {
    std::cout << "applying filter" << std::endl;
    // create filter object
    bilateralFilter B (bf_size, bf_sigma_Pos, bf_sigma_Col);
    tomogram3d<uint16_t> filtered;
    // apply filter
    B.Process(original, filtered);
    // original data is no longer needed, so swap it with filtered and dismiss filtered.
    std::swap(original, filtered);
    filtered.clear();
    original.write_raw(outFolderName + "/bilateral.raw", "uint16_t");
    // write some slices of the bilateral tomogram
    WriteImages(original, outFolderName + "/images/", "1_bilateral", nz);
    }

///////////////////////////////
// Create Homogenized Tomogram
///////////////////////////////
    tomogram3d<uint16_t> hom;
    // class for homogenization
    homogenator H;
    H.Process(original, hom, outFolderName);    
    
    //original is no longer needed
    original.clear();
    // write some slices of the homogenized tomogram
    hom.write_raw(outFolderName + "/homogenized.raw", "uint16_t");
    WriteImages(hom, outFolderName + "/images/", "2_homogenized", nz);

///////////////////////////////
// Apply selected Area Histogram
///////////////////////////////
    std::cout << "calculate histogram" << std::endl;
    // this will calculate a histogram of the whole tomogram 
    selectedAreaHistogram sah(nx,ny, nz);

    // selected area histogram will fill two vectors: bins will contain the bin information (list of the bins, identified by the first grey value in each bin.), 
    std::vector<double> bins;
    // hist will include the corresponding greyvalue counts
    std::vector<double> hist;
    sah.Process(hom, bins, hist, outFolderName, 150);

    // the black outside region should not get counted so just remove that from the histogram
    hist[0] = 0;
///////////////////////////////
// Calculate threshold with Otsu's method
///////////////////////////////
    std::cout << "calculate Threshold" << std::endl;
    cSegmentationByOtsu::NormalizeHisto(hist);
    double T = cSegmentationByOtsu::CalculateSegmentationThreshold(hist);
    std::cout << "binthresh from otsu: " << T << std::endl; 
    // since otsu doesn't need to know anything about the bins it is acting on, it will just return the bin ID (this is T). 
    // To get the greyvalue threshold (t1_gv) the next line is needed.
    uint16_t t1_gv = static_cast<uint16_t>(bins.at(T));

    std::cout << "threshol from otsu: " << static_cast<int>(t1_gv) << std::endl;
    
    // this writes a gnuplot script for visualizing otsu thresholding and histogram calculation
    {
    std::cout << "write gnuplot script for histogram" << std::endl;
    std::ofstream out(outFolderName + "/plot_selectedAreaHistogram.gpl");
    out << "#!/usr/bin/gnuplot -persist"<< std::endl;
    out << "t_low = " << static_cast<int>(t1_gv)<< std::endl;
    out << "set xlabel 'greyvalue'" << std::endl;
    out << "set ylabel 'occurrence'" << std::endl;
    out << "set xr [1:]" << std::endl;
    out << "set arrow from t_low, 0 to t_low, graph(0, 1) nohead" << std::endl;
    out << "pl 'selectedAreaHist.dat' w l" << std::endl;
    out.close();
    }
///////////////////////////////
// Create Particle binray image
///////////////////////////////
    std::cout << std::endl << "make binarized versions" << std::endl;
    tomogram3d<uint8_t> binary_particles;
    binary_particles.initialise(nx,ny,nz,0);

    // loop over all voxels and compare with calculated threshold
    for (unsigned long k = 0; k != nz; ++k)
    for (unsigned long j = 0; j != ny; ++j)
    for (unsigned long i = 0; i != nx; ++i)
    {
        uint16_t v = hom.get(i,j,k);
        if (v >= t1_gv)
        { 
            binary_particles.set(i,j,k,1); 
        }
    }
   
    WriteImages(binary_particles,  outFolderName+"images/", "3_binary", nz);

///////////////////////////////
// Remove inside holes from particle image
///////////////////////////////
    tomogram3d<uint8_t> binary_water;
    binary_water.initialise(nx,ny,nz,0);
    removeInsideHoles::Process(binary_particles);
    WriteImages(binary_particles, outFolderName+"images/", "4_binary_woHolesInside", nz); 
    binary_particles.write_raw(outFolderName + "/particles_binary.raw", "uint8_t");

///////////////////////////////
// Create labeled image
///////////////////////////////
    tomogram3d<int> out;
    try
    {
        // this calculates the segmented tomogram
        watershedSegmentation::Process(binary_particles, out, erosiondepth, outFolderName + "/images/", 100);

        // remove all clusters that touch the border
        out.cleanBorder(0.075);

        // write some images 
        WriteImages(out,outFolderName+"images/","7_labeled" , nz);
        WriteImages(out,outFolderName+"images/","8_labeled_color" , nz, true);

    }
    catch (std::string& e)
    {
        std::cerr << e << std::endl;
        return 1;
    }

///////////////////////////////
// Calculate centroids and save tomogram (converted to save disk space)
///////////////////////////////
    // calculate centroids and volumes, also
    // convert to uint16_t for writing
    std::cout << "convert and calculate" << std::endl;
    std::map<unsigned long, unsigned int> volumes;
    std::map<unsigned long, double> xPos;
    std::map<unsigned long, double> yPos;
    std::map<unsigned long, double> zPos;
    
    tomogram3d<uint16_t> safe;
    safe.initialise(nx, ny, nz, 0);
    std::cout << "counting voxels" << std::endl;

    
    for (unsigned int k = 0; k != nz; ++k)
    {
        std::cout << k << " ";
    for (unsigned int j = 0; j != ny; ++j)
    for (unsigned int i = 0; i != nx; ++i)
    {
        uint16_t v = static_cast<uint16_t>(out.get(i,j,k));
        safe.set(i,j,k, v);
        volumes[v] += 1;
        xPos[v] += i;    
        yPos[v] += j;    
        zPos[v] += k;    
    }
    }
    std::cout << "finished, writing centroids" << std::endl;
    // write centroids
    std::string filename = outFolderName +  "/particles_centroids_ed" + std::to_string(static_cast<int>(erosiondepth)) +  ".dat";
    std::cout << "filename: " << filename << std::endl;
    std::ofstream myOut(filename);
    if(!myOut.good())
    {
        std::cerr << "error: cannot write" << std::endl;
        return 1;
    }
    myOut << "#1_x #2_y #3_z #4_l #5_vol" << std::endl;
    myOut << "#boxsz=" << nz << ", boundary_condition= none " << std::endl;
    for(size_t i = 0; i != volumes.size(); ++i)
    {
        double v = static_cast<double>(volumes[i]);
        if(v == 0) continue;
        myOut << " " << xPos[i]/v << " " << yPos[i]/v << " " << zPos[i]/v << " " << i << " "  << volumes[i] << std::endl;
    }
    myOut.close();


    // save images, write tomogram
    WriteImages(safe, outFolderName+"images/", "5_particles_woInsideHoles", nz); 

    filename = outFolderName +  "particles_labelled_ed" + std::to_string(static_cast<int>(erosiondepth)) +  ".raw";
    safe.write_raw(filename, "uint16_t");

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x938, %rsp            # imm = 0x938
cmpl $0x9, %edi
jne 0x3f4a
movq %rsi, %r14
movq 0x8(%rsi), %rsi
leaq 0x1f0(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
movq 0x10(%r14), %rsi
leaq 0x30(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0x650(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x3320
leaq 0x650(%rsp), %rdi
callq 0x35ac
leaq 0x650(%rsp), %rdi
callq 0x3488
movq 0x18(%r14), %rdi
callq 0x3380
movl %eax, %ebx
movq 0x20(%r14), %rdi
callq 0x3380
movl %eax, %ebp
movq 0x28(%r14), %rdi
callq 0x3380
movl %eax, %r15d
movq 0x30(%r14), %rdi
callq 0x3380
movl %eax, 0x18(%rsp)
movq 0x38(%r14), %rdi
callq 0x32d0
movsd %xmm0, 0x50(%rsp)
movq 0x40(%r14), %rdi
callq 0x32d0
movsd %xmm0, 0x68(%rsp)
movq 0x1485c(%rip), %rdi     # 0x17fc8
leaq 0xdab2(%rip), %rsi      # 0x11225
callq 0x3260
leaq 0x1f0(%rsp), %rsi
movq %rax, %rdi
callq 0x3230
movq %rax, %rdi
callq 0x3110
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
andq $0x0, 0xa0(%rsp)
leaq 0x630(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x3320
leaq 0xda7a(%rip), %rsi      # 0x1123c
leaq 0x610(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
movslq %ebx, %rcx
movslq %ebp, %r8
movslq %r15d, %r9
leaq 0x90(%rsp), %rdi
leaq 0x630(%rsp), %rsi
leaq 0x610(%rsp), %rdx
movq %rcx, 0x10(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x8(%rsp)
callq 0x4f6c
leaq 0x610(%rsp), %rdi
callq 0x3488
leaq 0x630(%rsp), %rdi
callq 0x3488
movq 0x1479b(%rip), %rdi     # 0x17fc8
leaq 0xda11(%rip), %rsi      # 0x11245
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xda1a(%rip), %rdx      # 0x11262
leaq 0x5f0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xda0a(%rip), %rsi      # 0x1126b
leaq 0x5d0(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0x90(%rsp), %rdi
leaq 0x5f0(%rsp), %rsi
leaq 0x5d0(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x52db
leaq 0x5d0(%rsp), %rdi
callq 0x3488
leaq 0x5f0(%rsp), %rdi
callq 0x3488
movq 0x1470c(%rip), %rdi     # 0x17fc8
leaq 0xd9b3(%rip), %rsi      # 0x11276
callq 0x3260
movq %rax, %rdi
callq 0x3110
movsd 0x50(%rsp), %xmm0
movapd %xmm0, %xmm1
mulsd 0xd726(%rip), %xmm1     # 0x11008
cvttsd2si %xmm1, %rsi
leaq 0x700(%rsp), %rdi
movsd 0x68(%rsp), %xmm1
callq 0x577a
xorpd %xmm0, %xmm0
leaq 0x110(%rsp), %rdx
movapd %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x700(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x5a46
leaq 0x90(%rsp), %rdi
leaq 0x110(%rsp), %rbx
movq %rbx, %rsi
callq 0x5dc3
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x394d
movq %rax, 0x118(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x128(%rsp)
andq $0x0, 0x138(%rsp)
leaq 0xd91c(%rip), %rdx      # 0x11286
leaq 0x5b0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd8b9(%rip), %rsi      # 0x1123c
leaq 0x590(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x30d0
leaq 0x90(%rsp), %rdi
leaq 0x5b0(%rsp), %rsi
leaq 0x590(%rsp), %rdx
callq 0x5e1c
leaq 0x590(%rsp), %rdi
callq 0x3488
leaq 0x5b0(%rsp), %rdi
callq 0x3488
leaq 0xd88c(%rip), %rdx      # 0x11262
leaq 0x570(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd8a6(%rip), %rsi      # 0x11295
leaq 0x550(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x30d0
leaq 0x90(%rsp), %rdi
leaq 0x570(%rsp), %rsi
leaq 0x550(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x52db
leaq 0x550(%rsp), %rdi
callq 0x3488
leaq 0x570(%rsp), %rdi
callq 0x3488
leaq 0x110(%rsp), %rbx
movq %rbx, %rdi
callq 0xa518
leaq 0x700(%rsp), %rdi
callq 0x612e
xorpd %xmm0, %xmm0
movapd %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x530(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x3320
leaq 0x1f(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x110(%rsp), %rdx
leaq 0x530(%rsp), %rcx
movsd 0xd56c(%rip), %xmm0     # 0x11010
callq 0x6148
leaq 0x530(%rsp), %rdi
callq 0x3488
movq 0x90(%rsp), %rax
cmpq %rax, 0x98(%rsp)
je 0x3ad0
movq %rax, 0x98(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0xa8(%rsp)
andq $0x0, 0xb8(%rsp)
leaq 0xd7b4(%rip), %rdx      # 0x112a1
leaq 0x510(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd736(%rip), %rsi      # 0x1123c
leaq 0x4f0(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0x110(%rsp), %rdi
leaq 0x510(%rsp), %rsi
leaq 0x4f0(%rsp), %rdx
callq 0x5e1c
leaq 0x4f0(%rsp), %rdi
callq 0x3488
leaq 0x510(%rsp), %rdi
callq 0x3488
leaq 0xd709(%rip), %rdx      # 0x11262
leaq 0x4d0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd740(%rip), %rsi      # 0x112b2
leaq 0x4b0(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0x110(%rsp), %rdi
leaq 0x4d0(%rsp), %rsi
leaq 0x4b0(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x52db
leaq 0x4b0(%rsp), %rdi
callq 0x3488
leaq 0x4d0(%rsp), %rdi
callq 0x3488
movq 0x143fb(%rip), %rdi     # 0x17fc8
leaq 0xd6ec(%rip), %rsi      # 0x112c0
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0x1d8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rcx
callq 0x67e8
xorpd %xmm0, %xmm0
movapd %xmm0, 0x140(%rsp)
andq $0x0, 0x150(%rsp)
movapd %xmm0, 0xf0(%rsp)
andq $0x0, 0x100(%rsp)
leaq 0x490(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x3320
leaq 0x1d8(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0x140(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
leaq 0x490(%rsp), %r8
movl $0x96, %r9d
callq 0x6880
leaq 0x490(%rsp), %rdi
callq 0x3488
movq 0xf0(%rsp), %rax
andq $0x0, (%rax)
movq 0x1433e(%rip), %rdi     # 0x17fc8
leaq 0xd643(%rip), %rsi      # 0x112d4
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x6dac
movq %rbx, %rdi
callq 0x6dec
movapd %xmm0, 0x50(%rsp)
movq 0x14305(%rip), %rdi     # 0x17fc8
leaq 0xd61e(%rip), %rsi      # 0x112e8
callq 0x3260
movq %rax, %rdi
movapd 0x50(%rsp), %xmm0
callq 0x33a0
movq %rax, %rdi
callq 0x3110
movapd 0x50(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0xd319(%rip), %xmm0     # 0x11018
cvttsd2si %xmm0, %rsi
andq %rcx, %rsi
orq %rax, %rsi
leaq 0x140(%rsp), %rdi
callq 0x6fb8
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x142a0(%rip), %rdi     # 0x17fc8
leaq 0xd5cf(%rip), %rsi      # 0x112fe
callq 0x3260
cvttsd2si 0x50(%rsp), %ebp
movzwl %bp, %ebx
movq %rax, %rdi
movl %ebx, %esi
callq 0x3410
movq %rax, %rdi
callq 0x3110
movq 0x14272(%rip), %rdi     # 0x17fc8
leaq 0xd5b6(%rip), %rsi      # 0x11313
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xd5c5(%rip), %rdx      # 0x11336
leaq 0xc0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0x700(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x3460
leaq 0xc0(%rsp), %rdi
callq 0x3488
leaq 0xd5a7(%rip), %rsi      # 0x11356
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xd5a7(%rip), %rsi      # 0x11372
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
movl %ebx, %esi
callq 0x3410
movq %rax, %rdi
callq 0x3110
leaq 0xd58a(%rip), %rsi      # 0x1137b
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xd585(%rip), %rsi      # 0x11392
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xd581(%rip), %rsi      # 0x113aa
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xd571(%rip), %rsi      # 0x113b6
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xd58a(%rip), %rsi      # 0x113eb
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0x700(%rsp), %rdi
callq 0x3330
leaq 0x700(%rsp), %rdi
callq 0x3350
movq 0x14131(%rip), %rdi     # 0x17fc8
callq 0x3110
leaq 0xd566(%rip), %rsi      # 0x11409
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
xorpd %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x6fda
xorl %ebx, %ebx
leaq 0x110(%rsp), %r14
leaq 0xc0(%rsp), %r15
cmpq 0x8(%rsp), %rbx
je 0x3f7e
xorl %r12d, %r12d
cmpq 0x20(%rsp), %r12
je 0x3f45
xorl %r13d, %r13d
cmpq %r13, 0x10(%rsp)
je 0x3f40
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x70ba
cmpw %bp, %ax
jb 0x3f3b
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbx, %rcx
pushq $0x1
popq %r8
callq 0x72fc
incq %r13
jmp 0x3f09
incq %r12
jmp 0x3eff
incq %rbx
jmp 0x3ef1
movq 0x14097(%rip), %rbx     # 0x17fe8
leaq 0xd243(%rip), %rsi      # 0x1119b
movq %rbx, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xd253(%rip), %rsi      # 0x111c2
movq %rbx, %rdi
callq 0x3260
xorl %ebx, %ebx
jmp 0x4993
leaq 0xd2de(%rip), %rdx      # 0x11263
leaq 0x470(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd483(%rip), %rsi      # 0x11421
leaq 0x450(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0xc0(%rsp), %rdi
leaq 0x470(%rsp), %rsi
leaq 0x450(%rsp), %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x7539
leaq 0x450(%rsp), %rdi
callq 0x3488
leaq 0x470(%rsp), %rdi
callq 0x3488
xorpd %xmm0, %xmm0
leaq 0x900(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x6fda
leaq 0xc0(%rsp), %rdi
callq 0x79d8
leaq 0xd230(%rip), %rdx      # 0x11263
leaq 0x430(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd3de(%rip), %rsi      # 0x1142a
leaq 0x410(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0xc0(%rsp), %rdi
leaq 0x430(%rsp), %rsi
leaq 0x410(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x7539
leaq 0x410(%rsp), %rdi
callq 0x3488
leaq 0x430(%rsp), %rdi
callq 0x3488
leaq 0xd39a(%rip), %rdx      # 0x11441
leaq 0x3f0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd397(%rip), %rsi      # 0x11457
leaq 0x3d0(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0xc0(%rsp), %rdi
leaq 0x3f0(%rsp), %rsi
leaq 0x3d0(%rsp), %rdx
callq 0x8042
leaq 0x3d0(%rsp), %rdi
callq 0x3488
leaq 0x3f0(%rsp), %rdi
callq 0x3488
xorpd %xmm0, %xmm0
movapd %xmm0, 0x180(%rsp)
andq $0x0, 0x190(%rsp)
leaq 0xd139(%rip), %rdx      # 0x11262
leaq 0x3b0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
cvtsi2ssl 0x18(%rsp), %xmm0
leaq 0xc0(%rsp), %rdi
leaq 0x180(%rsp), %rsi
leaq 0x3b0(%rsp), %rdx
pushq $0x64
popq %rcx
callq 0x8312
leaq 0x3b0(%rsp), %rdi
callq 0x3488
leaq 0x180(%rsp), %rdi
movsd 0xcea2(%rip), %xmm0     # 0x11020
callq 0x8f4e
leaq 0xd0d9(%rip), %rdx      # 0x11263
leaq 0x390(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd2bc(%rip), %rsi      # 0x1145f
leaq 0x370(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0x180(%rsp), %rdi
leaq 0x390(%rsp), %rsi
leaq 0x370(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x91bc
leaq 0x370(%rsp), %rdi
callq 0x3488
leaq 0x390(%rsp), %rdi
callq 0x3488
leaq 0xd065(%rip), %rdx      # 0x11263
leaq 0x350(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xd252(%rip), %rsi      # 0x11469
leaq 0x330(%rsp), %rdi
leaq 0x700(%rsp), %rdx
callq 0x30d0
leaq 0x180(%rsp), %rdi
leaq 0x350(%rsp), %rsi
leaq 0x330(%rsp), %rdx
pushq $0x1
popq %r8
movq 0x8(%rsp), %rcx
movl %r8d, 0x2c(%rsp)
callq 0x91bc
leaq 0x330(%rsp), %rdi
callq 0x3488
leaq 0x350(%rsp), %rdi
callq 0x3488
movq 0x13d50(%rip), %rdi     # 0x17fc8
leaq 0xd1fa(%rip), %rsi      # 0x11479
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0x308(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x6d8(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x6a8(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x678(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorpd %xmm0, %xmm0
leaq 0x210(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x9666
movq 0x13c95(%rip), %rdi     # 0x17fc8
leaq 0xd155(%rip), %rsi      # 0x1148f
callq 0x3260
movq %rax, %rdi
callq 0x3110
xorl %ebx, %ebx
leaq 0x700(%rsp), %r12
leaq 0x670(%rsp), %rbp
movl %ebx, %ebx
cmpq 0x8(%rsp), %rbx
je 0x4490
movq 0x13c5b(%rip), %rdi     # 0x17fc8
movq %rbx, %rsi
callq 0x31a0
movq %rax, %rdi
leaq 0xd8d3(%rip), %rsi      # 0x11c52
callq 0x3260
cvtsi2sd %rbx, %xmm0
movsd %xmm0, 0x68(%rsp)
xorl %r13d, %r13d
movl %r13d, %r13d
cmpq 0x20(%rsp), %r13
je 0x4489
cvtsi2sd %r13, %xmm0
movsd %xmm0, 0x50(%rsp)
xorl %r15d, %r15d
movl %r15d, %r15d
cmpq 0x10(%rsp), %r15
je 0x4481
leaq 0x180(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x9746
movl %eax, %r14d
movzwl %r14w, %r8d
leaq 0x210(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x9988
movzwl %r14w, %r14d
movq %r14, 0x700(%rsp)
leaq 0x300(%rsp), %rdi
movq %r12, %rsi
callq 0x9bca
incl (%rax)
movq %r14, 0x700(%rsp)
leaq 0x6d0(%rsp), %rdi
movq %r12, %rsi
callq 0x9c1a
cvtsi2sd %r15, %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq %r14, 0x700(%rsp)
leaq 0x6a0(%rsp), %rdi
movq %r12, %rsi
callq 0x9c1a
movsd (%rax), %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r14, 0x700(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x9c1a
movsd (%rax), %xmm0
addsd 0x68(%rsp), %xmm0
movsd %xmm0, (%rax)
incl %r15d
jmp 0x43ae
incl %r13d
jmp 0x4392
incl %ebx
jmp 0x4359
movq 0x13b31(%rip), %rdi     # 0x17fc8
leaq 0xd001(%rip), %rsi      # 0x1149f
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xd009(%rip), %rdx      # 0x114bb
leaq 0x70(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0x160(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x9cef
leaq 0x700(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x160(%rsp), %rdx
callq 0x9c88
leaq 0xd709(%rip), %rdx      # 0x11bfc
leaq 0x1b8(%rsp), %rdi
leaq 0x700(%rsp), %rsi
callq 0x9c69
leaq 0x700(%rsp), %rdi
callq 0x3488
leaq 0x160(%rsp), %rdi
callq 0x3488
leaq 0x70(%rsp), %rdi
callq 0x3488
movq 0x13a95(%rip), %rdi     # 0x17fc8
leaq 0xcf99(%rip), %rsi      # 0x114d3
callq 0x3260
leaq 0x1b8(%rsp), %rsi
movq %rax, %rdi
callq 0x3230
movq %rax, %rdi
callq 0x3110
leaq 0x700(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x3460
movq 0x700(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x720(%rsp,%rax)
je 0x45a5
movq 0x13a5c(%rip), %rdi     # 0x17fe8
leaq 0xcf4b(%rip), %rsi      # 0x114de
callq 0x3260
movq %rax, %rdi
callq 0x3110
jmp 0x48b5
leaq 0xcf46(%rip), %rsi      # 0x114f2
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0xcf45(%rip), %rsi      # 0x1150d
leaq 0x700(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x31a0
leaq 0xcf2c(%rip), %rsi      # 0x11515
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
xorl %eax, %eax
leaq 0x300(%rsp), %r15
leaq 0x70(%rsp), %r12
leaq 0xd643(%rip), %r13      # 0x11c52
leaq 0x670(%rsp), %rbx
movq %rax, 0x70(%rsp)
cmpq 0x328(%rsp), %rax
je 0x4728
movq %r15, %rdi
movq %r12, %rsi
callq 0x9d48
movl (%rax), %ebp
testl %ebp, %ebp
je 0x471b
leaq 0x700(%rsp), %rdi
movq %r13, %rsi
callq 0x3260
movq %rax, %r14
leaq 0x6d0(%rsp), %rdi
movq %r12, %rsi
callq 0x9d98
cvtsi2sd %rbp, %xmm1
movsd (%rax), %xmm0
movsd %xmm1, 0x10(%rsp)
divsd %xmm1, %xmm0
movq %r14, %rdi
callq 0x33a0
movq %rax, %rdi
movq %r13, %rsi
callq 0x3260
movq %rax, %r14
leaq 0x6a0(%rsp), %rdi
movq %r12, %rsi
callq 0x9d98
movsd (%rax), %xmm0
divsd 0x10(%rsp), %xmm0
movq %r14, %rdi
callq 0x33a0
movq %rax, %rdi
movq %r13, %rsi
callq 0x3260
movq %rax, %r14
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9d98
movsd (%rax), %xmm0
divsd 0x10(%rsp), %xmm0
movq %r14, %rdi
callq 0x33a0
movq %rax, %rdi
movq %r13, %rsi
callq 0x3260
movq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x31a0
movq %rax, %rdi
movq %r13, %rsi
callq 0x3260
movq %rax, %r14
movq %r15, %rdi
movq %r12, %rsi
callq 0x9d48
movl (%rax), %esi
movq %r14, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x3110
movq 0x70(%rsp), %rax
incq %rax
jmp 0x4617
leaq 0x700(%rsp), %rdi
callq 0x3330
leaq 0xcb27(%rip), %rdx      # 0x11263
leaq 0x2e0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0xcddc(%rip), %rsi      # 0x11531
leaq 0x2c0(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x30d0
leaq 0x210(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
leaq 0x2c0(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x52db
leaq 0x2c0(%rsp), %rdi
callq 0x3488
leaq 0x2e0(%rsp), %rdi
callq 0x3488
leaq 0xcd9e(%rip), %rdx      # 0x1154b
leaq 0x2a0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f34
leaq 0x280(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x9cef
leaq 0x160(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
leaq 0x280(%rsp), %rdx
callq 0x9c88
leaq 0xcab9(%rip), %rdx      # 0x112ad
leaq 0x70(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x9c69
leaq 0x1b8(%rsp), %rbx
leaq 0x70(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32c0
movq %r14, %rdi
callq 0x3488
leaq 0x160(%rsp), %rdi
callq 0x3488
leaq 0x280(%rsp), %rdi
callq 0x3488
leaq 0x2a0(%rsp), %rdi
callq 0x3488
leaq 0x260(%rsp), %rdi
movq %rbx, %rsi
callq 0x3320
leaq 0xc9d8(%rip), %rsi      # 0x1123c
leaq 0x240(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x30d0
leaq 0x210(%rsp), %rdi
leaq 0x260(%rsp), %rsi
leaq 0x240(%rsp), %rdx
callq 0x5e1c
leaq 0x240(%rsp), %rdi
callq 0x3488
leaq 0x260(%rsp), %rdi
callq 0x3488
movl $0x0, 0x2c(%rsp)
leaq 0x700(%rsp), %rdi
callq 0x3350
leaq 0x1b8(%rsp), %rdi
callq 0x3488
leaq 0x210(%rsp), %rdi
callq 0xa518
leaq 0x670(%rsp), %rdi
callq 0xe180
leaq 0x6a0(%rsp), %rdi
callq 0xe180
leaq 0x6d0(%rsp), %rdi
callq 0xe180
leaq 0x300(%rsp), %rdi
callq 0xe1c8
movl 0x2c(%rsp), %ebx
leaq 0x180(%rsp), %rdi
callq 0xb1c8
leaq 0x900(%rsp), %rdi
callq 0xb29a
leaq 0xc0(%rsp), %rdi
callq 0xb29a
leaq 0xf0(%rsp), %rdi
callq 0xe210
leaq 0x140(%rsp), %rdi
callq 0xe210
leaq 0x1d8(%rsp), %rdi
callq 0xa6a4
leaq 0x110(%rsp), %rdi
callq 0xa518
leaq 0x90(%rsp), %rdi
callq 0xa518
leaq 0x30(%rsp), %rdi
callq 0x3488
leaq 0x1f0(%rsp), %rdi
callq 0x3488
movl %ebx, %eax
addq $0x938, %rsp            # imm = 0x938
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x240(%rsp), %rdi
callq 0x3488
jmp 0x49bc
movq %rax, %rbx
leaq 0x260(%rsp), %rdi
jmp 0x4a19
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0x3488
jmp 0x49db
movq %rax, %rbx
leaq 0x280(%rsp), %rdi
callq 0x3488
jmp 0x49ed
movq %rax, %rbx
leaq 0x2a0(%rsp), %rdi
jmp 0x4a19
jmp 0x4d3e
movq %rax, %rbx
leaq 0x2c0(%rsp), %rdi
callq 0x3488
jmp 0x4a11
movq %rax, %rbx
leaq 0x2e0(%rsp), %rdi
callq 0x3488
jmp 0x4d41
jmp 0x4c71
movq %rax, %rbx
leaq 0x700(%rsp), %rdi
callq 0x3488
jmp 0x4a3d
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0x3488
jmp 0x4a4f
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x4d56
jmp 0x4d6a
movq %rdx, %r14
movq %rax, %rbx
leaq 0x330(%rsp), %rdi
callq 0x3488
jmp 0x4a79
movq %rdx, %r14
movq %rax, %rbx
leaq 0x350(%rsp), %rdi
jmp 0x4ab6
movq %rdx, %r14
movq %rax, %rbx
leaq 0x370(%rsp), %rdi
callq 0x3488
jmp 0x4a9e
movq %rdx, %r14
movq %rax, %rbx
leaq 0x390(%rsp), %rdi
jmp 0x4ab6
movq %rdx, %r14
movq %rax, %rbx
leaq 0x3b0(%rsp), %rdi
callq 0x3488
jmp 0x4cb3
movq %rax, %rbx
leaq 0x3d0(%rsp), %rdi
callq 0x3488
jmp 0x4ad5
movq %rax, %rbx
leaq 0x3f0(%rsp), %rdi
jmp 0x4afc
movq %rax, %rbx
leaq 0x410(%rsp), %rdi
callq 0x3488
jmp 0x4af4
movq %rax, %rbx
leaq 0x430(%rsp), %rdi
callq 0x3488
jmp 0x4dbb
movq %rax, %rbx
leaq 0x450(%rsp), %rdi
callq 0x3488
jmp 0x4b1b
movq %rax, %rbx
leaq 0x470(%rsp), %rdi
callq 0x3488
jmp 0x4dc8
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x4b4a
jmp 0x4d1f
movq %rax, %rbx
leaq 0x490(%rsp), %rdi
callq 0x3488
jmp 0x4dd5
jmp 0x4d0f
movq %rax, %rbx
leaq 0x4b0(%rsp), %rdi
callq 0x3488
jmp 0x4b6e
movq %rax, %rbx
leaq 0x4d0(%rsp), %rdi
jmp 0x4ba2
movq %rax, %rbx
leaq 0x4f0(%rsp), %rdi
callq 0x3488
jmp 0x4b8d
movq %rax, %rbx
leaq 0x510(%rsp), %rdi
jmp 0x4ba2
movq %rax, %rbx
leaq 0x530(%rsp), %rdi
callq 0x3488
jmp 0x4dfc
movq %rax, %rbx
leaq 0x550(%rsp), %rdi
callq 0x3488
jmp 0x4bc1
movq %rax, %rbx
leaq 0x570(%rsp), %rdi
jmp 0x4be8
movq %rax, %rbx
leaq 0x590(%rsp), %rdi
callq 0x3488
jmp 0x4be0
movq %rax, %rbx
leaq 0x5b0(%rsp), %rdi
callq 0x3488
jmp 0x4c81
jmp 0x4d17
movq %rax, %rbx
leaq 0x5d0(%rsp), %rdi
callq 0x3488
jmp 0x4c0c
movq %rax, %rbx
leaq 0x5f0(%rsp), %rdi
jmp 0x4c33
movq %rax, %rbx
leaq 0x610(%rsp), %rdi
callq 0x3488
jmp 0x4c2b
movq %rax, %rbx
leaq 0x630(%rsp), %rdi
callq 0x3488
jmp 0x4e09
movq %rax, %rbx
leaq 0x650(%rsp), %rdi
callq 0x3488
jmp 0x4e16
jmp 0x4ca0
movq %rax, %rbx
jmp 0x4e20
movq %rax, %rbx
jmp 0x4e2d
movq %rax, %rbx
jmp 0x4dae
jmp 0x4d65
movq %rax, %rbx
jmp 0x4d4e
jmp 0x4d1f
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xa518
leaq 0x700(%rsp), %rdi
callq 0x612e
jmp 0x4e09
movq %rax, %rbx
jmp 0x4e16
jmp 0x4d3e
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x4dae
movq %rbx, %rdi
callq 0x30e0
movq 0x1331c(%rip), %rdi     # 0x17fe8
movq %rax, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3110
callq 0x33c0
pushq $0x1
popq %rbx
jmp 0x4914
jmp 0x4c64
movq %rax, %rbx
callq 0x33c0
jmp 0x4dae
movq %rax, %rdi
callq 0x965b
movq %rax, %rbx
jmp 0x4dbb
jmp 0x4d1f
jmp 0x4d6a
movq %rax, %rbx
jmp 0x4dfc
movq %rax, %rbx
jmp 0x4e09
movq %rax, %rbx
jmp 0x4dd5
movq %rax, %rbx
leaq 0x700(%rsp), %rdi
callq 0x3350
jmp 0x4dd5
jmp 0x4d6a
movq %rax, %rbx
leaq 0x700(%rsp), %rdi
callq 0x3350
leaq 0x1b8(%rsp), %rdi
callq 0x3488
jmp 0x4d6d
jmp 0x4d6a
jmp 0x4d6a
jmp 0x4d6a
jmp 0x4d6a
movq %rax, %rbx
jmp 0x4dc8
movq %rax, %rbx
leaq 0x210(%rsp), %rdi
callq 0xa518
leaq 0x670(%rsp), %rdi
callq 0xe180
leaq 0x6a0(%rsp), %rdi
callq 0xe180
leaq 0x6d0(%rsp), %rdi
callq 0xe180
leaq 0x300(%rsp), %rdi
callq 0xe1c8
leaq 0x180(%rsp), %rdi
callq 0xb1c8
leaq 0x900(%rsp), %rdi
callq 0xb29a
leaq 0xc0(%rsp), %rdi
callq 0xb29a
leaq 0xf0(%rsp), %rdi
callq 0xe210
leaq 0x140(%rsp), %rdi
callq 0xe210
leaq 0x1d8(%rsp), %rdi
callq 0xa6a4
leaq 0x110(%rsp), %rdi
callq 0xa518
leaq 0x90(%rsp), %rdi
callq 0xa518
leaq 0x30(%rsp), %rdi
callq 0x3488
leaq 0x1f0(%rsp), %rdi
callq 0x3488
movq %rbx, %rdi
callq 0x3420