// File: Slexis-Works[P]texture-packing/algoFF.cpp
// Function: algoFF(std::vector<Rectangle, std::allocator<Rectangle>> const&, std::vector<Bin, std::allocator<Bin>>&, unsigned int, unsigned int)
void algoFF(const std::vector<Rectangle> &rects, std::vector<Bin> &bins, coord bw, coord by) {
	// Création de tous les étages
	std::vector<Shelf> shelves;
	for (const Rectangle &rect : rects) {
		bool inserted = false;
		for (auto & shelf : shelves) {
			if (shelf.putRect(rect)) {
				inserted = true;
				break;
			}
		}
		if (inserted) {
			continue;
		}
		shelves.push_back(Shelf(bw, 0, rect));
	}

	// Insertion de tous les étages de manière naïve
	coord curY = by;
	for (auto & shelf : shelves) {
		if (curY + shelf.getHeight() > by) {
			bins.push_back(Bin(bw, by));
			curY = 0;
		}
		shelf.setY(curY);
		curY += shelf.getHeight();
		bins.back().importShelf(shelf);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5390
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x43f0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4420
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x4450
testb $0x1, %al
jne 0x50ea
jmp 0x51f0
leaq -0x40(%rbp), %rdi
callq 0x4490
movq %rax, -0x50(%rbp)
movb $0x0, -0x51(%rbp)
leaq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x53b0
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
callq 0x53e0
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5410
testb $0x1, %al
jne 0x5130
jmp 0x5185
leaq -0x68(%rbp), %rdi
callq 0x5450
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3fc0
movb %al, -0xf9(%rbp)
jmp 0x5152
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x515e
jmp 0x5178
movb $0x1, -0x51(%rbp)
jmp 0x5185
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x5370
jmp 0x517a
leaq -0x68(%rbp), %rdi
callq 0x5470
jmp 0x511d
testb $0x1, -0x51(%rbp)
je 0x518d
jmp 0x51c2
movl -0x14(%rbp), %esi
movq -0x50(%rbp), %rcx
leaq -0xb0(%rbp), %rdi
xorl %edx, %edx
callq 0x3f10
jmp 0x51a4
leaq -0x30(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5490
jmp 0x51b6
leaq -0xb0(%rbp), %rdi
callq 0x2ca0
leaq -0x40(%rbp), %rdi
callq 0x44b0
jmp 0x50d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x2ca0
jmp 0x5370
movl -0x18(%rbp), %eax
movl %eax, -0xb4(%rbp)
leaq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x53b0
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x53e0
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x5410
testb $0x1, %al
jne 0x5246
jmp 0x535e
leaq -0xc8(%rbp), %rdi
callq 0x5450
movq %rax, -0xd8(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, -0x104(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x54c0
movl %eax, -0x100(%rbp)
jmp 0x5279
movl -0x100(%rbp), %ecx
movl -0x104(%rbp), %eax
addl %ecx, %eax
cmpl -0x18(%rbp), %eax
jbe 0x52f5
movq -0x10(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
leaq -0xf8(%rbp), %rdi
callq 0x4e40
jmp 0x52ab
movq -0x110(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x54d0
jmp 0x52c0
leaq -0xf8(%rbp), %rdi
callq 0x5500
movl $0x0, -0xb4(%rbp)
jmp 0x52f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x5500
jmp 0x5370
movq -0xd8(%rbp), %rdi
movl -0xb4(%rbp), %esi
callq 0x40e0
jmp 0x5309
movq -0xd8(%rbp), %rdi
callq 0x54c0
movl %eax, -0x114(%rbp)
jmp 0x531d
movl -0x114(%rbp), %ecx
movl -0xb4(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xb4(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5520
movq %rax, %rdi
movq -0xd8(%rbp), %rsi
callq 0x4ec0
jmp 0x534b
jmp 0x534d
leaq -0xc8(%rbp), %rdi
callq 0x5470
jmp 0x522a
leaq -0x30(%rbp), %rdi
callq 0x5560
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x5560
movq -0x80(%rbp), %rdi
callq 0x2290
nopw %cs:(%rax,%rax)
nopl (%rax)