// File: /workspace/github_cpp_makefile_star2_O3/cmaureir[P]strip-packing/scattersearch.cpp
// Function: search_fit(int, int, int, int&, int&, int&, int**)
bool search_fit(int item, int item_w, int item_h, int &a, int &b, int &h, int **strip){
    //cout << "search_fit()" << endl;
    bool fit = true;

    for (int y = 0; y < strip_height; y++)
    {
        for (int x = 0; x < strip_width; x++)
        {
            if (strip[x][y]  == 0 && item_w + x - 1 < strip_width) // empty space
            {
                for (a = x; a < x + item_w; a++)
                {
                    if (strip[a][y] != 0 || strip[a][y+item_h-1] != 0)
                    {
                        fit = false;
                        break;
                    }
                }
                if(fit)
                {
                    for (b = y; b < y + item_h; b++)
                    {
                        if (strip[x][b] != 0 || strip[x+item_w-1][b] != 0)
                        {
                            fit = false;
                            break;
                        }
                    }
                }

                if (fit){
                    a = x;
                    b = y;
                    if (h < b + item_h){
                        h = b + item_h;
                    }
                    return fit;
                }
            }
            else
            {
                if (item_w + x >= strip_width)
                {
                    x = strip_width;
                }
                else
                {
                    x = x + bs[strip[x][y]-1].width - 1;
                }
            }
            fit = true;
        }
    }
    return false;
}

// Assembly:
movl 0xb41c(%rip), %r11d     # 0x12374
testl %r11d, %r11d
jle 0x7073
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x38(%rsp), %rdi
movslq %edx, %rbx
movl 0xb3f7(%rip), %ebp      # 0x12370
xorl %eax, %eax
movq %rbx, -0x8(%rsp)
testl %ebp, %ebp
jle 0x7043
leaq (%rax,%rbx), %r11
movq 0xb3c5(%rip), %rbx      # 0x12358
addq $-0x4, %rbx
xorl %r14d, %r14d
movslq %r14d, %r13
movq (%rdi,%r13,8), %r15
movslq (%r15,%rax,4), %r12
leal (%r14,%rsi), %r10d
testq %r12, %r12
jne 0x700a
cmpl %ebp, %r10d
jg 0x700a
movl %r14d, (%rcx)
movslq %r10d, %r12
testl %esi, %esi
jle 0x6fe0
leal 0x1(%r14), %ebp
movq (%rdi,%r13,8), %r10
cmpl $0x0, (%r10,%rax,4)
jne 0x701f
cmpl $0x0, -0x4(%r10,%r11,4)
jne 0x701f
incq %r13
movl %ebp, (%rcx)
incl %ebp
cmpq %r12, %r13
jl 0x6fc1
movl %eax, (%r8)
testl %edx, %edx
jle 0x7056
movq %rax, %r13
cmpl $0x0, (%r15,%r13,4)
jne 0x701f
movq -0x8(%rdi,%r12,8), %r10
cmpl $0x0, (%r10,%r13,4)
jne 0x701f
incq %r13
movl %r13d, (%r8)
cmpq %r11, %r13
jl 0x6fea
jmp 0x7056
cmpl %ebp, %r10d
jge 0x7022
leaq (%r12,%r12,2), %r10
movl (%rbx,%r10,4), %r10d
leal (%r14,%r10), %ebp
decl %ebp
jmp 0x7022
movl %r14d, %ebp
movl %ebp, %r14d
incl %r14d
movl 0xb342(%rip), %ebp      # 0x12370
cmpl %ebp, %r14d
jl 0x6f9a
movl 0xb336(%rip), %r11d     # 0x12374
movq -0x8(%rsp), %rbx
incq %rax
movslq %r11d, %r10
cmpq %r10, %rax
jl 0x6f80
xorl %eax, %eax
jmp 0x7068
movl %r14d, (%rcx)
movl %eax, (%r8)
addl %eax, %edx
movb $0x1, %al
cmpl %edx, (%r9)
jge 0x7068
movl %edx, (%r9)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq