// File: /workspace/github_cpp_makefile_star2_O3/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, -0x50(%rbp)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
cmpq %rax, %rdx
je 0x2d6f
movq $-0x4, %r12
movl $0x4, %r13d
xorl %ebx, %ebx
movq %rsi, -0x48(%rbp)
movq %rdi, -0x30(%rbp)
movslq (%rax,%rbx,4), %r10
movl (%rdi), %r14d
movq -0x50(%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 0x2d4a
addq %r9, %rcx
movl 0x4(%rdi), %r9d
movl -0x14(%rcx), %r10d
movl %r9d, %r8d
subl %r10d, %r8d
jl 0x2d4a
movl %r8d, -0x54(%rbp)
movl 0x8(%rdi), %r11d
movl %r11d, -0x3c(%rbp)
movl %r11d, -0xc(%rcx)
movl 0xc(%rdi), %r8d
movl %r8d, -0x8(%rcx)
leaq (%rax,%r13), %rcx
cmpq %rdx, %rcx
je 0x2c9d
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 %r8, -0x60(%rbp)
callq 0x22a0
movq -0x60(%rbp), %r8
movl -0x34(%rbp), %r10d
movl -0x38(%rbp), %r9d
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq 0x8(%rsi), %rdx
addl -0x3c(%rbp), %r10d
addq $-0x4, %rdx
movl %r9d, %eax
imull %r14d, %eax
movl -0x54(%rbp), %r11d
movl %r11d, %ecx
imull %r15d, %ecx
cmpl %ecx, %eax
movl %r15d, %eax
cmovgl %r14d, %eax
movl %r11d, %ecx
cmovgl %r9d, %ecx
movq %rdx, 0x8(%rsi)
cmovgl %r11d, %r9d
movl %r9d, -0x38(%rbp)
movl %r10d, %edx
movl -0x3c(%rbp), %r11d
cmovgl %r11d, %edx
cmovgl %r15d, %r14d
leal (%r8,%r15), %r15d
cmovlel %r11d, %r10d
movl %r10d, -0x34(%rbp)
movl %r8d, %r9d
cmovgl %r15d, %r9d
cmovgl %r8d, %r15d
movl %eax, (%rdi)
movl %ecx, 0x4(%rdi)
movl %edx, 0x8(%rdi)
movl %r9d, 0xc(%rdi)
movq -0x50(%rbp), %rdx
callq 0x2bc7
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 -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x2bc7
movq -0x30(%rbp), %rdi
movq -0x48(%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 0x2c03
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq