// File: maramire[P]SP_PSO/parallel_main.cpp
// Function: RecursePacking(Strip&, std::vector<int, std::allocator<int>>&, std::vector<Item, std::allocator<Item>>&)
void RecursePacking(Strip &s2, vector<int> &permutation, Item_vector &items)
{

    for (int i = 0; i < permutation.size(); i++)
    {
        int item_id = permutation[i]-1;

        if (s2.height >= items[item_id].height && s2.width >= items[item_id].width)
        {
            /* Place item */
            items[item_id].x_position = s2.x_position;
            items[item_id].y_position = s2.y_position;

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

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

            /* Erase */
            permutation.erase(permutation.begin() + i);
            
            if (s3.width*s3.height>s4.height*s4.width)
            {
                s2=s3; RecursePacking(s2,permutation,items);
                s2=s4; RecursePacking(s2,permutation,items);
                
            }
            else
            {
                s2=s4; RecursePacking(s2,permutation,items);
                s2=s3; RecursePacking(s2,permutation,items);
        
            }   

        }
        else{
            continue;
        }
        
    }
    return;   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movslq -0x1c(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0x55e0
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jae 0x30a9
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x5600
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0x6c(%rbp), %eax
cmpl 0x4(%rcx), %eax
jl 0x3097
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0x70(%rbp), %eax
cmpl 0x8(%rcx), %eax
jl 0x3097
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movl -0x90(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movl -0x8c(%rbp), %ecx
movl %ecx, 0x14(%rax)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x20e0
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0x88(%rbp), %eax
addl 0x4(%rcx), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0x84(%rbp), %eax
subl 0x4(%rcx), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x20e0
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x80(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0x80(%rbp), %eax
addl 0x8(%rcx), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0x4a30
movq %rax, %rcx
movl -0x7c(%rbp), %eax
subl 0x8(%rcx), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0x56d0
movq %rax, -0x58(%rbp)
movslq -0x1c(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x5700
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x5740
movq -0x78(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x5660
movq %rax, -0x60(%rbp)
movl -0x2c(%rbp), %eax
imull -0x30(%rbp), %eax
movl -0x40(%rbp), %ecx
imull -0x3c(%rbp), %ecx
cmpl %ecx, %eax
jle 0x304d
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2de0
movq -0x8(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2de0
jmp 0x3095
movq -0x8(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2de0
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2de0
jmp 0x3099
jmp 0x309b
jmp 0x309b
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2dfe
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)