// File: maramire[P]SP_PSO/parallel_main.cpp
// Function: HR(std::vector<Item, std::allocator<Item>>&, Strip&, int, Particle&)
void HR(Item_vector &items, Strip &s, int n_items, Particle &particle)
{

    vector<int> permutation = particle.permutation;
    int fitness = 0;
    int i = 0;

    while(!permutation.empty())
    {
        
        int item_id = permutation[i]-1;
        int original_height;
        
        if (items[item_id].height > items[item_id].width)
        {
            original_height = items[item_id].height;
            items[item_id].height = items[item_id].width;
            items[item_id].width = original_height;
            items[item_id].rotated = 1;
        }           

        /* it is already defined, but convenience */
        items[item_id].x_position = s.x_position;
        items[item_id].y_position = s.y_position; 

        fitness += items[item_id].height;         

        /* Resize strip S1 */
        Strip s1 = {};
        s1.y_position = s.y_position + items[item_id].height;
        s1.x_position = s.x_position;
        s1.height = s.height - items[item_id].height;
        s1.width = s.width;

        /* Generate new strip S2 */
        Strip s2 = {};
        s2.x_position = s.x_position + items[item_id].width;
        s2.y_position = s.y_position;
        s2.height = items[item_id].height;
        s2.width = s.width - items[item_id].width;

        s = s1;

        /* Erase */
        permutation.erase(permutation.begin() + i);

        RecursePacking(s2,permutation,items);

    }      
            
    particle.fitness = fitness;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x5780
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5870
xorb $-0x1, %al
testb $0x1, %al
jne 0x3109
jmp 0x33b3
movslq -0x40(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x5600
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl 0x4(%rax), %eax
movl %eax, -0xa4(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0xa4(%rbp), %eax
cmpl 0x8(%rcx), %eax
jle 0x31c1
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl 0x4(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl 0x8(%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl -0xac(%rbp), %ecx
movl %ecx, 0x4(%rax)
movl -0x48(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl -0xa8(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl $0x1, 0x18(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xec(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl -0xec(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xe8(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl -0xe8(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl 0x4(%rax), %ecx
movl -0x3c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xe0(%rbp)
movaps %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xe4(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0xe4(%rbp), %eax
movl 0x4(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movaps -0xe0(%rbp), %xmm0
movq %rax, %rcx
movl -0xcc(%rbp), %eax
movl 0x4(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x5c(%rbp)
movaps %xmm0, -0x70(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0xc8(%rbp), %eax
movl 0x8(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movl 0x4(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0xc4(%rbp), %eax
movl 0x8(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movaps -0x60(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x56d0
movq %rax, -0x88(%rbp)
movslq -0x40(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x5700
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5740
movq -0xc0(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x5660
movq %rax, -0xb8(%rbp)
jmp 0x3370
movq -0xb8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rdx
leaq -0x70(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x2de0
jmp 0x3391
jmp 0x30f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5550
jmp 0x33cf
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
leaq -0x38(%rbp), %rdi
callq 0x5550
addq $0xf0, %rsp
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x2380
nopl (%rax,%rax)