// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, -0x48(%rbp)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
cmpq %rax, %rdx
je 0x2d5e
movq $-0x4, %r12
movl $0x4, %r13d
xorl %ebx, %ebx
movq %rsi, -0x40(%rbp)
movq %rdi, -0x30(%rbp)
movslq (%rax,%rbx,4), %r10
movl (%rdi), %r14d
movq -0x48(%rbp), %rcx
movq (%rcx), %rcx
leaq (%r10,%r10,8), %r9
leaq (%r9,%r9,2), %r9
addq %r10, %r9
movl -0x18(%rcx,%r9), %r15d
subl %r15d, %r14d
jl 0x2d39
addq %r9, %rcx
movl 0x4(%rdi), %r9d
movl -0x14(%rcx), %r10d
movl %r9d, %r8d
subl %r10d, %r8d
jl 0x2d39
movl %r8d, -0x4c(%rbp)
movl 0x8(%rdi), %r11d
movl %r11d, -0x50(%rbp)
movl %r11d, -0xc(%rcx)
movl 0xc(%rdi), %r11d
movl %r11d, -0x8(%rcx)
leaq (%rax,%r13), %rcx
cmpq %rdx, %rcx
je 0x2c93
leaq (%rax,%rbx,4), %rdi
leaq (%rax,%rbx,4), %rsi
addq $0x4, %rsi
subq %rax, %rdx
addq %r12, %rdx
movl %r9d, -0x38(%rbp)
movl %r10d, -0x34(%rbp)
movq %r11, -0x58(%rbp)
callq 0x22a0
movq -0x58(%rbp), %r11
movl -0x34(%rbp), %r10d
movl -0x38(%rbp), %r9d
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x50(%rbp), %r8d
addl %r8d, %r10d
addq $-0x4, 0x8(%rsi)
movl %r9d, %eax
imull %r14d, %eax
movl -0x4c(%rbp), %edx
movl %edx, %ecx
imull %r15d, %ecx
cmpl %ecx, %eax
movl %r15d, %eax
cmovgl %r14d, %eax
movl %edx, %ecx
cmovgl %r9d, %ecx
cmovgl %edx, %r9d
movl %r9d, -0x38(%rbp)
movl %r10d, %edx
cmovgl %r8d, %edx
cmovgl %r15d, %r14d
leal (%r11,%r15), %r15d
cmovlel %r8d, %r10d
movl %r10d, -0x34(%rbp)
movl %r11d, %r9d
cmovgl %r15d, %r9d
cmovgl %r11d, %r15d
movl %eax, (%rdi)
movl %ecx, 0x4(%rdi)
movl %edx, 0x8(%rdi)
movl %r9d, 0xc(%rdi)
movq -0x48(%rbp), %rdx
callq 0x2bc1
movq -0x30(%rbp), %rax
movl %r14d, (%rax)
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl %r15d, 0xc(%rax)
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x2bc1
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
incq %rbx
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x2, %rcx
addq $-0x4, %r12
addq $0x4, %r13
cmpq %rbx, %rcx
ja 0x2bfd
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq