// File: maramire[P]SP_PSO/main.cpp
// Function: main
int main(int argc, const char *argv[]) 
{


    /* Taking algorithm time performance! */
    auto t1 = chrono::high_resolution_clock::now(); 

    cout << "Start!"<<endl;
    
    /* Save items data */
    Item_vector items;

    /* Open Instance File */

    /* Define number of items to pack */
    int n_items = 0; 
    int strip_width = 0;
    int max_height = 0;

    string filepath = argv[1];
    cout << "-> Opening instances!"<<endl;
    openInstance(filepath, items, strip_width, max_height, n_items);

    
    unsigned int a = filepath.rfind('.');
    unsigned int b = filepath.rfind('/',a-1);
    string name = filepath.substr(b+1,a-b-1);
    
    

    cout << "-> Number of items: " << n_items << endl;
    cout << "-> Strip width: " << strip_width << endl;
    cout << "-> Upper bound computed: "  << max_height << endl;

    /* Swarm of particles */
    Swarm swarm;

    /* Initialize particles */
    for(int i=0; i<N_PARTICLES; i++){
        //unsigned seed = i+1;
        particle_init(n_items, swarm);

        /* Initialize strip */
        Strip s = {};
        s.height = max_height;
        s.width = strip_width;

        s.x_position = 0;
        s.y_position = 0;
    
        /* Evaluate each particle */
        HR(items,s,n_items,swarm[i]); 

        swarm[i].pbest = swarm[i].permutation;
        swarm[i].pbest_fitness = swarm[i].fitness;

    } 

    //showSwarm(swarm);

    /* Declare global best particle */

    Particle gbest;
    gbest.fitness = max_height;


    /* Select best position */
    sort(swarm.begin(), swarm.end(), compareByFitness);
    
    if (swarm[0].fitness < gbest.fitness)
    {
        gbest.fitness = swarm[0].fitness;
        gbest.permutation = swarm[0].permutation;
    }

    int iter = 0;
    float omega = 1.2;
    float c1 = 2.05;
    float c2 = 2.05;
    float omega_max = 1.2;
    float omega_min = 0.7;

    float velocity_max = (n_items)/2;
    float velocity_min = -(n_items)/2;
    float current_velocity = 0;


    random_device rd;
    mt19937 gen(rd());
    uniform_real_distribution<> dis(0, 1);//uniform distribution between 0 and 1

    while (iter<MAX_ITER)
    {

        iter++;
        //cout << gbest.fitness << endl;
        
        /* Update velocity and position with results */
        for (int p = 0; p < N_PARTICLES; p++)
        {
            vector<float> new_permutation(n_items);
            iota(begin(new_permutation), end(new_permutation), 1);

            for (int i = 0; i < swarm[p].permutation.size(); i++)
            {
            
                float r1 = dis(gen);
                float r2 = dis(gen);

                float pfactor = swarm[p].pbest[i] - swarm[p].permutation[i];
                float gfactor = gbest.permutation[i] - swarm[p].permutation[i];                

                current_velocity = omega*swarm[p].permutation[i] + r1*c1*pfactor + r2*c2*gfactor;

                if (current_velocity < velocity_min)
                {
                    current_velocity = velocity_min;

                }else if(current_velocity > velocity_max)
                {
                    current_velocity = velocity_max;
                }

                swarm[p].velocity[i] = current_velocity;
            
                new_permutation[i] = swarm[p].permutation[i] + swarm[p].velocity[i];
                
            }

            /* Discretize position */
            vector<float> assignments = new_permutation;
            sort(assignments.begin(),assignments.end());

            for (int i = 0; i < new_permutation.size(); i++)
            {
                for (int j = 0; j < assignments.size(); j++)
                {
                    if (new_permutation[j]==assignments[i])
                    {
                        swarm[p].permutation[i] = j+1;
                    }   
                }
            }

            /* Initialize strip */
            Strip s = {};
            s.height = max_height;
            s.width = strip_width;

            s.x_position = 0;
            s.y_position = 0;
        
            /* Evaluate particle */
            HR(items,s,n_items,swarm[p]); 

            if (swarm[p].fitness < swarm[p].pbest_fitness)
            {
                swarm[p].pbest = swarm[p].permutation;
                swarm[p].pbest_fitness = swarm[p].fitness;
            }
            
            if (swarm[p].pbest_fitness < gbest.fitness)
            {
                gbest.fitness = swarm[p].pbest_fitness;
                gbest.permutation = swarm[p].pbest;
            }

        }
        
        omega = (omega_max)-((omega_max-omega_min)/MAX_ITER)*iter;
    } 
    

    //showSwarm(swarm);
    //showRectangles(items);

    //showPermutation(gbest);

    Strip s = {};
    s.height = max_height;
    s.width = strip_width;

    s.x_position = 0;
    s.y_position = 0;

    HR(items,s,n_items,gbest); 
    cout << "-> Fitness of best solution: " << gbest.fitness << endl;
    
    //showRectangles(items);


    //cout << "-> End!" << endl;

    auto t2 = chrono::high_resolution_clock::now(); 
    chrono::duration<double> time_span = (t2 - t1);
    cout << "-> It took me " << time_span.count() << " seconds.";
    cout << endl;

/*     ofstream myfile;
    myfile.open ("Results/"+name+".csv", fstream::app);
    myfile << gbest.fitness << "," << time_span.count() << endl;
    myfile.close(); */


    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2ab0, %rsp           # imm = 0x2AB0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x2030
movq %rax, -0x18(%rbp)
movq 0x129ff(%rip), %rdi     # 0x15fd8
leaq 0xbb3c(%rip), %rsi      # 0xf11c
callq 0x21a0
movq %rax, %rdi
movq 0x129d9(%rip), %rsi     # 0x15fc8
callq 0x21e0
leaq -0x30(%rbp), %rdi
callq 0x55c0
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x2968(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0x2960(%rbp)
callq 0x2310
movq -0x2968(%rbp), %rsi
movq -0x2960(%rbp), %rdx
leaq -0x60(%rbp), %rdi
callq 0x55e0
jmp 0x364a
leaq -0x61(%rbp), %rdi
callq 0x2200
movq 0x1297e(%rip), %rdi     # 0x15fd8
leaq 0xbac2(%rip), %rsi      # 0xf123
callq 0x21a0
movq %rax, -0x2970(%rbp)
jmp 0x366f
movq -0x2970(%rbp), %rdi
movq 0x1294b(%rip), %rsi     # 0x15fc8
callq 0x21e0
jmp 0x3684
leaq -0x98(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x20a0
jmp 0x3696
leaq -0x98(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x38(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
leaq -0x34(%rbp), %r8
callq 0x2500
jmp 0x36b4
leaq -0x98(%rbp), %rdi
callq 0x2100
leaq -0x60(%rbp), %rdi
movq %rdi, -0x2978(%rbp)
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x2340
movq -0x2978(%rbp), %rdi
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
decl %eax
movl %eax, %edx
movl $0x2f, %esi
callq 0x2340
movq -0x2978(%rbp), %rsi
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, %ecx
incl %ecx
movl %ecx, %edx
movl -0x9c(%rbp), %ecx
notl %eax
addl %ecx, %eax
movl %eax, %ecx
leaq -0xc0(%rbp), %rdi
callq 0x21d0
jmp 0x3730
movq 0x128a1(%rip), %rdi     # 0x15fd8
leaq 0xb9fb(%rip), %rsi      # 0xf139
callq 0x21a0
movq %rax, -0x2980(%rbp)
jmp 0x374c
movq -0x2980(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x22f0
movq %rax, -0x2988(%rbp)
jmp 0x3764
movq -0x2988(%rbp), %rdi
movq 0x12856(%rip), %rsi     # 0x15fc8
callq 0x21e0
jmp 0x3779
movq 0x12858(%rip), %rdi     # 0x15fd8
leaq 0xb9c7(%rip), %rsi      # 0xf14e
callq 0x21a0
movq %rax, -0x2990(%rbp)
jmp 0x3795
movq -0x2990(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x22f0
movq %rax, -0x2998(%rbp)
jmp 0x37ad
movq -0x2998(%rbp), %rdi
movq 0x1280d(%rip), %rsi     # 0x15fc8
callq 0x21e0
jmp 0x37c2
movq 0x1280f(%rip), %rdi     # 0x15fd8
leaq 0xb98f(%rip), %rsi      # 0xf15f
callq 0x21a0
movq %rax, -0x29a0(%rbp)
jmp 0x37de
movq -0x29a0(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x22f0
movq %rax, -0x29a8(%rbp)
jmp 0x37f6
movq -0x29a8(%rbp), %rdi
movq 0x127c4(%rip), %rsi     # 0x15fc8
callq 0x21e0
jmp 0x380b
leaq -0xd8(%rbp), %rdi
callq 0x5690
movl $0x0, -0xdc(%rbp)
cmpl $0x1e, -0xdc(%rbp)
jge 0x39a5
movl -0x34(%rbp), %edi
leaq -0xd8(%rbp), %rsi
callq 0x27b0
jmp 0x383f
xorps %xmm0, %xmm0
movaps %xmm0, -0xf0(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0xf0(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0xec(%rbp)
movl $0x0, -0xe8(%rbp)
movl $0x0, -0xe4(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x29ac(%rbp)
movslq -0xdc(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movl -0x29ac(%rbp), %edx
movq %rax, %rcx
leaq -0x30(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x2f80
jmp 0x38a6
movslq -0xdc(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x29c0(%rbp)
callq 0x55a0
movq -0x29c0(%rbp), %rdi
movq %rax, -0x29b8(%rbp)
movslq -0xdc(%rbp), %rsi
callq 0x55a0
movq -0x29b8(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rdi
callq 0x4ba0
jmp 0x38ef
movslq -0xdc(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movl 0x18(%rax), %eax
movl %eax, -0x29c4(%rbp)
movslq -0xdc(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movl -0x29c4(%rbp), %ecx
movl %ecx, 0x38(%rax)
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x3821
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x2200
jmp 0x4504
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x44fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x2100
jmp 0x44fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x44ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x44e3
leaq -0x148(%rbp), %rdi
callq 0x4690
movl -0x3c(%rbp), %eax
movl %eax, -0x130(%rbp)
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x29d0(%rbp)
callq 0x5700
movq -0x29d0(%rbp), %rdi
movq %rax, -0x150(%rbp)
callq 0x5730
movq %rax, -0x158(%rbp)
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %rsi
leaq -0x152c(%rip), %rdx     # 0x24d0
callq 0x56b0
jmp 0x3a03
leaq -0xd8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x55a0
movl 0x18(%rax), %eax
cmpl -0x130(%rbp), %eax
jge 0x3a7c
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x29d8(%rbp)
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x29e0(%rbp)
callq 0x55a0
movq -0x29e0(%rbp), %rdi
movq -0x29d8(%rbp), %rsi
movl 0x18(%rax), %eax
movl %eax, -0x130(%rbp)
callq 0x55a0
movq %rax, %rsi
leaq -0x148(%rbp), %rdi
callq 0x4ba0
jmp 0x3a69
jmp 0x3a7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x44d7
movl $0x0, -0x15c(%rbp)
movl $0x3f99999a, -0x160(%rbp) # imm = 0x3F99999A
movl $0x40033333, -0x164(%rbp) # imm = 0x40033333
movl $0x40033333, -0x168(%rbp) # imm = 0x40033333
movl $0x3f99999a, -0x16c(%rbp) # imm = 0x3F99999A
movl $0x3f333333, -0x170(%rbp) # imm = 0x3F333333
movl -0x34(%rbp), %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %ecx, %eax
sarl %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x174(%rbp)
movl -0x34(%rbp), %ecx
movl %ecx, %eax
negl %eax
shrl $0x1f, %eax
subl %ecx, %eax
sarl %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x178(%rbp)
movl $0x0, -0x17c(%rbp)
leaq -0x1508(%rbp), %rdi
callq 0x46d0
jmp 0x3b02
leaq -0x1508(%rbp), %rdi
callq 0x4770
movl %eax, -0x29e4(%rbp)
jmp 0x3b16
movl -0x29e4(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x2890(%rbp), %rdi
callq 0x4790
jmp 0x3b2e
leaq -0x28a0(%rbp), %rdi
xorps %xmm0, %xmm0
movsd 0xb4c8(%rip), %xmm1     # 0xf008
callq 0x5760
jmp 0x3b47
jmp 0x3b49
cmpl $0x2bc, -0x15c(%rbp)    # imm = 0x2BC
jge 0x431d
movl -0x15c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x15c(%rbp)
movl $0x0, -0x28a4(%rbp)
cmpl $0x1e, -0x28a4(%rbp)
jge 0x42cf
movslq -0x34(%rbp), %rax
movq %rax, -0x29f8(%rbp)
leaq -0x28c1(%rbp), %rdi
movq %rdi, -0x29f0(%rbp)
callq 0x4df0
movq -0x29f8(%rbp), %rsi
movq -0x29f0(%rbp), %rdx
leaq -0x28c0(%rbp), %rdi
callq 0x5790
jmp 0x3bb9
leaq -0x28c1(%rbp), %rdi
callq 0x4e90
leaq -0x28c0(%rbp), %rdi
callq 0x5860
movq %rax, -0x2a00(%rbp)
jmp 0x3bda
movq -0x2a00(%rbp), %rax
movq %rax, -0x28d0(%rbp)
leaq -0x28c0(%rbp), %rdi
callq 0x5890
movq %rax, -0x2a08(%rbp)
jmp 0x3bfd
movq -0x2a08(%rbp), %rax
movq %rax, -0x28d8(%rbp)
movq -0x28d0(%rbp), %rdi
movq -0x28d8(%rbp), %rsi
movl $0x1, %edx
callq 0x5800
jmp 0x3c25
movl $0x0, -0x28dc(%rbp)
movslq -0x28dc(%rbp), %rax
movq %rax, -0x2a10(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
callq 0x52a0
movq %rax, %rcx
movq -0x2a10(%rbp), %rax
cmpq %rcx, %rax
jae 0x3f74
leaq -0x28a0(%rbp), %rdi
leaq -0x2890(%rbp), %rsi
callq 0x58c0
movsd %xmm0, -0x2a18(%rbp)
jmp 0x3c88
movsd -0x2a18(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x28e0(%rbp)
leaq -0x28a0(%rbp), %rdi
leaq -0x2890(%rbp), %rsi
callq 0x58c0
movsd %xmm0, -0x2a20(%rbp)
jmp 0x3cb9
movsd -0x2a20(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x28e4(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
addq $0x20, %rdi
movslq -0x28dc(%rbp), %rsi
callq 0x52c0
movl (%rax), %eax
movl %eax, -0x2a2c(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
movslq -0x28dc(%rbp), %rsi
callq 0x52c0
movq %rax, %rcx
movl -0x2a2c(%rbp), %eax
subl (%rcx), %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x28e8(%rbp)
leaq -0x148(%rbp), %rdi
movslq -0x28dc(%rbp), %rsi
callq 0x52c0
movl (%rax), %eax
movl %eax, -0x2a28(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
movslq -0x28dc(%rbp), %rsi
callq 0x52c0
movq %rax, %rcx
movl -0x2a28(%rbp), %eax
subl (%rcx), %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x28ec(%rbp)
movss -0x160(%rbp), %xmm0
movss %xmm0, -0x2a24(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
movslq -0x28dc(%rbp), %rsi
callq 0x52c0
movss -0x2a24(%rbp), %xmm1
cvtsi2ssl (%rax), %xmm2
movss -0x28e0(%rbp), %xmm0
mulss -0x164(%rbp), %xmm0
mulss -0x28e8(%rbp), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss -0x28e4(%rbp), %xmm0
mulss -0x168(%rbp), %xmm0
movss -0x28ec(%rbp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x17c(%rbp)
movss -0x17c(%rbp), %xmm1
movss -0x178(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3e74
movss -0x178(%rbp), %xmm0
movss %xmm0, -0x17c(%rbp)
jmp 0x3e97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x44cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x28c1(%rbp), %rdi
callq 0x4e90
jmp 0x44cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x42be
movss -0x17c(%rbp), %xmm0
ucomiss -0x174(%rbp), %xmm0
jbe 0x3e95
movss -0x174(%rbp), %xmm0
movss %xmm0, -0x17c(%rbp)
jmp 0x3e97
movss -0x17c(%rbp), %xmm0
movss %xmm0, -0x2a38(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
addq $0x40, %rdi
movslq -0x28dc(%rbp), %rsi
callq 0x5300
movss -0x2a38(%rbp), %xmm0
movss %xmm0, (%rax)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
movslq -0x28dc(%rbp), %rsi
callq 0x52c0
cvtsi2ssl (%rax), %xmm0
movss %xmm0, -0x2a34(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
addq $0x40, %rdi
movslq -0x28dc(%rbp), %rsi
callq 0x5300
movss -0x2a34(%rbp), %xmm0
addss (%rax), %xmm0
movss %xmm0, -0x2a30(%rbp)
movslq -0x28dc(%rbp), %rsi
leaq -0x28c0(%rbp), %rdi
callq 0x5300
movss -0x2a30(%rbp), %xmm0
movss %xmm0, (%rax)
movl -0x28dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28dc(%rbp)
jmp 0x3c2f
leaq -0x2908(%rbp), %rdi
leaq -0x28c0(%rbp), %rsi
callq 0x58f0
jmp 0x3f89
leaq -0x2908(%rbp), %rdi
movq %rdi, -0x2a40(%rbp)
callq 0x5a20
movq -0x2a40(%rbp), %rdi
movq %rax, -0x2910(%rbp)
callq 0x5a50
movq %rax, -0x2918(%rbp)
movq -0x2910(%rbp), %rdi
movq -0x2918(%rbp), %rsi
callq 0x59e0
jmp 0x3fcb
movl $0x0, -0x291c(%rbp)
movslq -0x291c(%rbp), %rax
movq %rax, -0x2a48(%rbp)
leaq -0x28c0(%rbp), %rdi
callq 0x52e0
movq %rax, %rcx
movq -0x2a48(%rbp), %rax
cmpq %rcx, %rax
jae 0x40fe
movl $0x0, -0x2920(%rbp)
movslq -0x2920(%rbp), %rax
movq %rax, -0x2a50(%rbp)
leaq -0x2908(%rbp), %rdi
callq 0x52e0
movq %rax, %rcx
movq -0x2a50(%rbp), %rax
cmpq %rcx, %rax
jae 0x40e8
movslq -0x2920(%rbp), %rsi
leaq -0x28c0(%rbp), %rdi
callq 0x5300
movss (%rax), %xmm0
movss %xmm0, -0x2a54(%rbp)
movslq -0x291c(%rbp), %rsi
leaq -0x2908(%rbp), %rdi
callq 0x5300
movss -0x2a54(%rbp), %xmm0
ucomiss (%rax), %xmm0
jne 0x40d2
jp 0x40d2
movl -0x2920(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a58(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rdi
movslq -0x291c(%rbp), %rsi
callq 0x52c0
movl -0x2a58(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x40d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x2908(%rbp), %rdi
callq 0x5170
jmp 0x42be
jmp 0x40d4
movl -0x2920(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2920(%rbp)
jmp 0x400c
jmp 0x40ea
movl -0x291c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x291c(%rbp)
jmp 0x3fd5
xorps %xmm0, %xmm0
movaps %xmm0, -0x2930(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x2930(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x292c(%rbp)
movl $0x0, -0x2928(%rbp)
movl $0x0, -0x2924(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x2a5c(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movl -0x2a5c(%rbp), %edx
movq %rax, %rcx
leaq -0x30(%rbp), %rdi
leaq -0x2930(%rbp), %rsi
callq 0x2f80
jmp 0x4165
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movl 0x18(%rax), %eax
movl %eax, -0x2a60(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movq %rax, %rcx
movl -0x2a60(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x4227
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x2a70(%rbp)
callq 0x55a0
movq -0x2a70(%rbp), %rdi
movq %rax, -0x2a68(%rbp)
movslq -0x28a4(%rbp), %rsi
callq 0x55a0
movq -0x2a68(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rdi
callq 0x4ba0
jmp 0x41ef
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movl 0x18(%rax), %eax
movl %eax, -0x2a74(%rbp)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movl -0x2a74(%rbp), %ecx
movl %ecx, 0x38(%rax)
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x55a0
movl 0x38(%rax), %eax
cmpl -0x130(%rbp), %eax
jge 0x4292
movslq -0x28a4(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x2a80(%rbp)
callq 0x55a0
movq -0x2a80(%rbp), %rdi
movl 0x38(%rax), %eax
movl %eax, -0x130(%rbp)
movslq -0x28a4(%rbp), %rsi
callq 0x55a0
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x148(%rbp), %rdi
callq 0x4ba0
jmp 0x4290
jmp 0x4292
leaq -0x2908(%rbp), %rdi
callq 0x5170
leaq -0x28c0(%rbp), %rdi
callq 0x5170
movl -0x28a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28a4(%rbp)
jmp 0x3b72
leaq -0x28c0(%rbp), %rdi
callq 0x5170
jmp 0x44cb
movss -0x16c(%rbp), %xmm1
movss -0x16c(%rbp), %xmm0
subss -0x170(%rbp), %xmm0
movss 0xad31(%rip), %xmm2     # 0xf020
divss %xmm2, %xmm0
cvtsi2ssl -0x15c(%rbp), %xmm2
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x160(%rbp)
jmp 0x3b49
xorps %xmm0, %xmm0
movaps %xmm0, -0x2940(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x2940(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x293c(%rbp)
movl $0x0, -0x2938(%rbp)
movl $0x0, -0x2934(%rbp)
movl -0x34(%rbp), %edx
leaq -0x30(%rbp), %rdi
leaq -0x2940(%rbp), %rsi
leaq -0x148(%rbp), %rcx
callq 0x2f80
jmp 0x4369
movq 0x11c68(%rip), %rdi     # 0x15fd8
leaq 0xae02(%rip), %rsi      # 0xf179
callq 0x21a0
movq %rax, -0x2a88(%rbp)
jmp 0x4385
movq -0x2a88(%rbp), %rdi
movl -0x130(%rbp), %esi
callq 0x22f0
movq %rax, -0x2a90(%rbp)
jmp 0x43a0
movq -0x2a90(%rbp), %rdi
movq 0x11c1a(%rip), %rsi     # 0x15fc8
callq 0x21e0
jmp 0x43b5
callq 0x2030
movq %rax, -0x2948(%rbp)
leaq -0x2948(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x5a80
movq %rax, -0x2a98(%rbp)
jmp 0x43da
movq -0x2a98(%rbp), %rax
movq %rax, -0x2958(%rbp)
leaq -0x2950(%rbp), %rdi
leaq -0x2958(%rbp), %rsi
callq 0x5ad0
jmp 0x43fd
movq 0x11bd4(%rip), %rdi     # 0x15fd8
leaq 0xad8c(%rip), %rsi      # 0xf197
callq 0x21a0
movq %rax, -0x2aa0(%rbp)
jmp 0x4419
leaq -0x2950(%rbp), %rdi
callq 0x5b10
movsd %xmm0, -0x2aa8(%rbp)
jmp 0x442f
movsd -0x2aa8(%rbp), %xmm0
movq -0x2aa0(%rbp), %rdi
callq 0x2330
movq %rax, -0x2ab0(%rbp)
jmp 0x444c
movq -0x2ab0(%rbp), %rdi
leaq 0xad4c(%rip), %rsi      # 0xf1a6
callq 0x21a0
jmp 0x4461
movq 0x11b70(%rip), %rdi     # 0x15fd8
movq 0x11b59(%rip), %rsi     # 0x15fc8
callq 0x21e0
jmp 0x4476
movl $0x0, -0x4(%rbp)
leaq -0x1508(%rbp), %rdi
callq 0x5230
leaq -0x148(%rbp), %rdi
callq 0x5260
leaq -0xd8(%rbp), %rdi
callq 0x5b30
leaq -0xc0(%rbp), %rdi
callq 0x2100
leaq -0x60(%rbp), %rdi
callq 0x2100
leaq -0x30(%rbp), %rdi
callq 0x5b90
movl -0x4(%rbp), %eax
addq $0x2ab0, %rsp           # imm = 0x2AB0
popq %rbp
retq
leaq -0x1508(%rbp), %rdi
callq 0x5230
leaq -0x148(%rbp), %rdi
callq 0x5260
leaq -0xd8(%rbp), %rdi
callq 0x5b30
leaq -0xc0(%rbp), %rdi
callq 0x2100
leaq -0x60(%rbp), %rdi
callq 0x2100
leaq -0x30(%rbp), %rdi
callq 0x5b90
movq -0x70(%rbp), %rdi
callq 0x2300
nopw %cs:(%rax,%rax)