// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $0x0, 0xb3e6(%rip)      # 0x12374
setg -0x15(%rsp)
jle 0x70dc
movq %r9, -0x10(%rsp)
movq 0x38(%rsp), %rdi
movl %edx, -0x14(%rsp)
movslq %edx, %r10
movb $0x1, %bl
xorl %r11d, %r11d
movl 0xb3ba(%rip), %r15d     # 0x12370
testl %r15d, %r15d
setg %bpl
jle 0x70a4
leaq (%r11,%r10), %r14
movq 0xb38a(%rip), %rax      # 0x12358
addq $-0x4, %rax
movq %rax, -0x8(%rsp)
xorl %r12d, %r12d
movslq %r12d, %r9
movq (%rdi,%r9,8), %r13
movslq (%r13,%r11,4), %rdx
testq %rdx, %rdx
jne 0x6ff4
leal (%r12,%rsi), %eax
cmpl %r15d, %eax
jle 0x7016
leal (%r12,%rsi), %eax
cmpl %r15d, %eax
jge 0x7088
leaq (%rdx,%rdx,2), %rax
movq -0x8(%rsp), %rdx
movl (%rdx,%rax,4), %eax
leal (%r12,%rax), %r15d
decl %r15d
jmp 0x7088
movl %r12d, (%rcx)
movslq %eax, %r15
testl %esi, %esi
jle 0x704c
leal 0x1(%r12), %edx
movq (%rdi,%r9,8), %rax
cmpl $0x0, (%rax,%r11,4)
jne 0x704a
leaq (%rax,%r11,4), %rax
cmpl $0x0, -0x4(%rax,%r10,4)
jne 0x704a
incq %r9
movl %edx, (%rcx)
incl %edx
cmpq %r15, %r9
jl 0x7025
jmp 0x704c
xorl %ebx, %ebx
testb $0x1, %bl
je 0x7080
movl %r11d, (%r8)
movq %r11, %rdx
cmpl $0x0, -0x14(%rsp)
jle 0x7080
cmpl $0x0, (%r13,%rdx,4)
jne 0x707e
movq -0x8(%rdi,%r15,8), %rax
cmpl $0x0, (%rax,%rdx,4)
jne 0x707e
incq %rdx
movl %edx, (%r8)
cmpq %r14, %rdx
jl 0x705e
jmp 0x7080
xorl %ebx, %ebx
testb $0x1, %bl
jne 0x70c4
movl %r12d, %r15d
movl %r15d, %r12d
incl %r12d
movl 0xb2db(%rip), %r15d     # 0x12370
movb $0x1, %bl
cmpl %r15d, %r12d
setl %bpl
jl 0x6fda
testb $0x1, %bpl
jne 0x70dc
incq %r11
movslq 0xb2c0(%rip), %rax      # 0x12374
cmpq %rax, %r11
setl -0x15(%rsp)
jl 0x6faf
jmp 0x70dc
movl %r12d, (%rcx)
movl %r11d, (%r8)
movq -0x10(%rsp), %rdx
movslq (%rdx), %rax
cmpq %rax, %r14
jle 0x70a4
movl %r14d, (%rdx)
jmp 0x70a4
movb -0x15(%rsp), %al
andb $0x1, %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq