// File: /workspace/github_cpp_makefile_star2_O3/Doug0855[P]TigerZone/Board.cpp
// Function: Board::buildLake(Structure*, Tile*, std::vector<std::vector<Block, std::allocator<Block>>, std::allocator<std::vector<Block, std::allocator<Block>>>>&, std::pair<int, int>, std::vector<Tile*, std::allocator<Tile*>>&)
void Board::buildLake(Structure* struc, Tile *tile, std::vector< std::vector<Block> >& tileBlocks, std::pair<int,int> blockSpot, std::vector<Tile*> &visitedTiles) {
	// std::cout<<"in build lake"<<std::endl;
	int row = blockSpot.first;
	int col = blockSpot.second;
	tileBlocks[row][col].visit();
	// for(int i = 0; i < 3; i++) {
	// 	for(int j = 0; j < 3; j++) {
	// 		std::cout<<"Block at "<<i<<' '<<j<<" for tile "<<tile<<" has been visited? "<<tileBlocks[i][j].isVisited()<<std::endl;
	// 	}
	// }

	// Push the current block into the vector of blocks for this structure
	struc->structureBlocks.push_back(tileBlocks[row][col]);

	// check block for meeple and set the structure boolean accordingly
	if(tileBlocks[row][col].hasMeeple())
		struc->hasMeeple = true;

	// Check to see if you've already added this tiles animals to the structure
	bool addedTileAnimals;
	for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile)
			{
				addedTileAnimals = true;
				//debugging std::cout<<"Added animals already for this tile"<<std::endl;
			}
	}
	// If you havent already added the tiles animals to the structure, do so
	if(!addedTileAnimals) {
		struc->checkAnimals(tile);
		// if(tile->hasCrocodile())
		// 	struc->crocodileCount++;
		// if(tile->hasDeer())
		// 	struc->deerCount++;
		// if(tile->hasBoar())
		// 	struc->boarCount++;
		// if(tile->hasBuffalo())
		// 	struc->buffaloCount++;
	}

	// Check tiles above, below, left, and right of the current block to see if lake structure continues. 
	// Call this function with the new coordinates (of the direction you're going) again if it does
	if((row + 1) <= 2 && !(tileBlocks[row + 1][col].isVisited()) && tileBlocks[row+1][col].getType() == "lake") {
		buildLake(struc, tile, tileBlocks, std::pair<int,int>(row+1,col), visitedTiles);
	}
	else if(row + 1 > 2 && tile->getDownTile() != NULL) {
		bool visitedNeighborTile = false;
		for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile->getDownTile())
				visitedNeighborTile = true;
		}
		if(!visitedNeighborTile) {
			visitedTiles.push_back(tile->getDownTile());
			std::vector< std::vector<Block> > newBlocks = tile->getDownTile()->getInnerBlocks();
			buildLake(struc, tile->getDownTile(), newBlocks, std::pair<int,int>(row-2,col), visitedTiles);
		}
	}
	// std::cout<<"about to check row-1"<<std::endl;
	if((row - 1) >= 0 && !(tileBlocks[row - 1][col].isVisited()) && tileBlocks[row - 1][col].getType() == "lake") {
		buildLake(struc, tile, tileBlocks, std::pair<int,int>(row-1,col), visitedTiles);
	}
	else if(row-1 < 0 && tile->getUpTile() != NULL) {
		bool visitedNeighborTile = false;
		for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile->getUpTile())
				visitedNeighborTile = true;
		}
		if(!visitedNeighborTile) {
			visitedTiles.push_back(tile->getUpTile());
			std::vector< std::vector<Block> > newBlocks = tile->getUpTile()->getInnerBlocks();
			buildLake(struc, tile->getUpTile(), newBlocks, std::pair<int,int>(row+2,col), visitedTiles);
		}
	}
	// std::cout<<"about to check col+1"<<std::endl;
	if((col + 1) <= 2 && !(tileBlocks[row][col + 1].isVisited()) && tileBlocks[row][col + 1].getType() == "lake") {
		buildLake(struc, tile, tileBlocks, std::pair<int,int>(row,col+1), visitedTiles);
	}
	else if(col+1 > 2 && tile->getRightTile() != NULL) {
		bool visitedNeighborTile = false;
		for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile->getRightTile())
				visitedNeighborTile = true;
		}
		if(!visitedNeighborTile) {
			visitedTiles.push_back(tile->getRightTile());
			std::vector< std::vector<Block> > newBlocks = tile->getRightTile()->getInnerBlocks();
			buildLake(struc, tile->getRightTile(), newBlocks, std::pair<int,int>(row,col-2), visitedTiles);
		}
	}
	// std::cout<<"about to check col-1"<<std::endl;
	if((col - 1) >= 0 && !(tileBlocks[row][col-1].isVisited()) && tileBlocks[row][col - 1].getType() == "lake") {
		// std::cout<<"passing col-1"<<std::endl;
		buildLake(struc, tile, tileBlocks, std::pair<int,int>(row,col-1), visitedTiles);
	}
	else if(col-1 < 0 && tile->getLeftTile() != NULL) {
		bool visitedNeighborTile = false;
		for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile->getLeftTile())
				visitedNeighborTile = true;
		}
		if(!visitedNeighborTile) {
			visitedTiles.push_back(tile->getLeftTile());
			std::vector< std::vector<Block> > newBlocks = tile->getLeftTile()->getInnerBlocks();
			buildLake(struc, tile->getLeftTile(), newBlocks, std::pair<int,int>(row,col+2), visitedTiles);
		}
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbx
movq %rcx, %r12
movq %rdx, -0x30(%rbp)
movq %rsi, %rdx
movq %rdi, -0x40(%rbp)
movslq %r8d, %rcx
movq (%r12), %rax
movq %rcx, -0x78(%rbp)
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %r14
movq %r8, %r13
sarq $0x20, %r8
movq (%rax,%r14), %rsi
movq %r8, -0x70(%rbp)
leaq (,%r8,8), %rax
leaq (%rax,%rax,4), %r15
movb $0x1, 0x1(%rsi,%r15)
addq %r15, %rsi
movq %rdx, -0x38(%rbp)
leaq 0x28(%rdx), %rdi
callq 0x13d7a
movq %r12, -0x48(%rbp)
movq (%r12), %rcx
movq (%rcx,%r14), %rax
cmpb $0x1, (%rax,%r15)
jne 0x12c2f
movq -0x38(%rbp), %rax
movb $0x1, 0x50(%rax)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x1, %r13d
jg 0x12cfb
movq %r13, %rax
shlq $0x20, %rax
addq %r14, %rax
incq %rax
sarq $0x20, %rax
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
movq -0x70(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
cmpb $0x0, 0x1(%rax,%rcx,8)
movq %rbx, %r12
movq %r13, %rbx
jne 0x12de1
movq %r12, %r15
leaq -0x58(%rbp), %r13
movq %r13, -0x10(%r13)
movq 0x8(%rax,%rcx,8), %rsi
movq 0x10(%rax,%rcx,8), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x9cc4
leaq 0x5b16(%rip), %rsi      # 0x187b2
movq %r12, %rdi
callq 0x30b0
movl %eax, %r14d
movq (%r12), %rdi
cmpq %r13, %rdi
je 0x12cb5
callq 0x3200
testl %r14d, %r14d
movq %r15, %r12
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x12de1
leal 0x1(%rbx), %r8d
movq %rbx, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq %r12, %r9
callq 0x12baa
jmp 0x12de1
movq -0x30(%rbp), %rax
movq 0xb8(%rax), %rax
testq %rax, %rax
movq %rbx, %r12
movq %r13, %rbx
je 0x12df0
movq (%r12), %rcx
movq 0x8(%r12), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
je 0x12d54
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rax, (%rcx,%rdi,8)
sete %r9b
orb %r9b, %r8b
incq %rdi
cmpq %rdi, %rdx
jne 0x12d37
testb $0x1, %r8b
jne 0x12de1
movq %rax, -0x68(%rbp)
cmpq 0x10(%r12), %rsi
je 0x12d70
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x12d82
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq -0x68(%rbp), %rdx
movq %r12, %rdi
callq 0x146bc
movl $0xd0, %esi
movq -0x30(%rbp), %r15
addq 0xb8(%r15), %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x8cd0
movq 0xb8(%r15), %rdx
leal (%rbx,%r13), %r8d
decl %r8d
movq %rbx, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r14, %rcx
movq %r12, %r9
callq 0x12baa
leaq -0x68(%rbp), %rdi
callq 0x13dcc
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %ebx, %ebx
jle 0x12e99
movq -0x48(%rbp), %rax
movq (%rax), %rcx
leal (%rbx,%r14), %eax
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
movq -0x70(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
cmpb $0x0, 0x1(%rax,%rcx,8)
jne 0x12f66
movq %r12, %r13
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%rax,%rcx,8), %rsi
movq 0x10(%rax,%rcx,8), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x9cc4
leaq 0x5978(%rip), %rsi      # 0x187b2
movq %r12, %rdi
callq 0x30b0
movl %eax, %r14d
movq (%r12), %rdi
cmpq %r15, %rdi
je 0x12e53
callq 0x3200
testl %r14d, %r14d
movq %r13, %r12
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x12f66
leal (%rbx,%r14), %r8d
movq %rbx, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq %r12, %r9
callq 0x12baa
jmp 0x12f66
movq -0x30(%rbp), %rax
movq 0xb0(%rax), %rax
testq %rax, %rax
je 0x12f66
movq (%r12), %rcx
movq 0x8(%r12), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
je 0x12ee8
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rax, (%rcx,%rdi,8)
sete %r9b
orb %r9b, %r8b
incq %rdi
cmpq %rdi, %rdx
jne 0x12ecf
testb $0x1, %r8b
jne 0x12f66
movq %rax, -0x68(%rbp)
cmpq 0x10(%r12), %rsi
je 0x12efe
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x12f0a
leaq -0x68(%rbp), %rdx
movq %r12, %rdi
callq 0x146bc
movl $0xd0, %esi
movq -0x30(%rbp), %r15
addq 0xb0(%r15), %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x8cd0
movq 0xb0(%r15), %rdx
leal 0x2(%rbx), %r8d
movq %rbx, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r14, %rcx
movq %r12, %r9
callq 0x12baa
leaq -0x68(%rbp), %rdi
callq 0x13dcc
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %r13
shrq $0x20, %r13
movq -0x78(%rbp), %rax
leaq (%rax,%rax,2), %r15
cmpl $0x1, %r13d
jg 0x13039
movq -0x48(%rbp), %rax
movq (%rax), %rax
leaq (%r14,%rbx), %rcx
incq %rcx
sarq $0x20, %rcx
movq (%rax,%r15,8), %rax
leaq (%rcx,%rcx,4), %rcx
cmpb $0x0, 0x1(%rax,%rcx,8)
jne 0x13113
movq %r12, -0x70(%rbp)
leaq -0x58(%rbp), %rdx
movq %rdx, -0x10(%rdx)
movq 0x8(%rax,%rcx,8), %rsi
movq 0x10(%rax,%rcx,8), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x9cc4
leaq 0x57e2(%rip), %rsi      # 0x187b2
movq %r12, %rdi
callq 0x30b0
movl %eax, %r14d
movq (%r12), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x12fed
callq 0x3200
testl %r14d, %r14d
movq -0x70(%rbp), %r12
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x13113
movq %rbx, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
addq %r14, %rax
movl %ebx, %ecx
leaq (%rcx,%rax), %r8
incq %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq %r12, %r9
callq 0x12baa
jmp 0x13113
movq -0x30(%rbp), %rax
movq 0xc8(%rax), %rax
testq %rax, %rax
je 0x1311c
movq (%r12), %rcx
movq 0x8(%r12), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
je 0x1308c
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rax, (%rcx,%rdi,8)
sete %r9b
orb %r9b, %r8b
incq %rdi
cmpq %rdi, %rdx
jne 0x1306f
testb $0x1, %r8b
jne 0x13113
movq %rax, -0x68(%rbp)
cmpq 0x10(%r12), %rsi
je 0x130a2
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x130ae
leaq -0x68(%rbp), %rdx
movq %r12, %rdi
callq 0x146bc
movl $0xd0, %esi
movq -0x30(%rbp), %r14
addq 0xc8(%r14), %rsi
leaq -0x68(%rbp), %rdi
callq 0x8cd0
movq 0xc8(%r14), %rdx
movq %rbx, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
movl %ebx, %ecx
addq %rax, %rcx
movabsq $-0x200000000, %r8      # imm = 0xFFFFFFFE00000000
addq %rcx, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x68(%rbp), %rcx
movq %r12, %r9
callq 0x12baa
leaq -0x68(%rbp), %rdi
callq 0x13dcc
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %r13d, %r13d
jle 0x131c3
movq -0x48(%rbp), %rax
movq (%rax), %rax
addl %r14d, %r13d
movq (%rax,%r15,8), %rax
leaq (,%r13,4), %rcx
addq %r13, %rcx
cmpb $0x0, 0x1(%rax,%rcx,8)
jne 0x13296
movq %r12, %r13
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%rax,%rcx,8), %rsi
movq 0x10(%rax,%rcx,8), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x9cc4
leaq 0x5647(%rip), %rsi      # 0x187b2
movq %r12, %rdi
callq 0x30b0
movl %eax, %r14d
movq (%r12), %rdi
cmpq %r15, %rdi
je 0x13184
callq 0x3200
testl %r14d, %r14d
jne 0x13296
movq %r13, %r9
movq %rbx, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
addq %rcx, %rax
movl %ebx, %r8d
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
callq 0x12baa
jmp 0x13296
movq -0x30(%rbp), %rax
movq 0xc0(%rax), %rax
testq %rax, %rax
je 0x13296
movq (%r12), %rcx
movq 0x8(%r12), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
je 0x13216
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rax, (%rcx,%rdi,8)
sete %r9b
orb %r9b, %r8b
incq %rdi
cmpq %rdi, %rdx
jne 0x131f9
testb $0x1, %r8b
jne 0x13296
movq %rax, -0x68(%rbp)
cmpq 0x10(%r12), %rsi
je 0x1322c
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x13238
leaq -0x68(%rbp), %rdx
movq %r12, %rdi
callq 0x146bc
movl $0xd0, %esi
movq -0x30(%rbp), %r15
addq 0xc0(%r15), %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x8cd0
movq 0xc0(%r15), %rdx
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rbx, %rcx
movl %ebx, %eax
addq %rcx, %rax
movabsq $0x200000000, %r8       # imm = 0x200000000
addq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r14, %rcx
movq %r12, %r9
callq 0x12baa
leaq -0x68(%rbp), %rdi
callq 0x13dcc
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x132ab
jmp 0x132ab
jmp 0x132ab
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x13dcc
movq %rbx, %rdi
callq 0x33f0
nop