// File: /workspace/github_cpp_makefile_star2_O3/cb92[P]Battleship/Board.cpp
// Function: Board::placeShip(int, int, int, bool)
bool Board::placeShip(int shipNum, int x, int y, bool isHorizontal)
{
	//if x or y is out of bounds, return false
	if (x>=BOARD_DIM || y>=BOARD_DIM)
		return false;

	//if ship has already been placed, return false
	if (shipVec[shipNum].getX()>=0 && shipVec[shipNum].getY()>=0)
		return false;

	//loop through the positions required for the ship
	for (int i=0; i<shipVec[shipNum].getSize(); i++)
	{
		//if any of the desired spaces are filled, return false
		if ((isHorizontal && gameBoard[y][x+i]!=isWATER) || 
							(!isHorizontal && gameBoard[y+i][x]!=isWATER))
			return false;
		//if any of the desired spaces are out of bounds, return false
		if ((isHorizontal && (x+i)>=BOARD_DIM) || 
							(!isHorizontal && (y+i)>=BOARD_DIM))
			return false;
	}

	//if the for loop finishes, and all the positions are empty, 
	//1. place the Ship in the desired position on the board
	for (int i=0; i<shipVec[shipNum].getSize(); i++)
	{
		if (isHorizontal)
			gameBoard[y][x+i]=isSAFESHIP;
		else 
			gameBoard[y+i][x]=isSAFESHIP;
	}

	//2. set the x/y parameters for the Ship object 
	shipVec[shipNum].setPosition(x, y, isHorizontal);

	//... and return true
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r15d
cmpl $0xa, %edx
setge %al
cmpl $0xa, %ecx
setge %cl
orb %al, %cl
jne 0x43a4
movl %r8d, %r14d
movl %edx, %ebx
movq %rdi, %r12
movslq %esi, %rax
imulq $0x38, %rax, %r13
movq 0x68(%rdi), %rdi
addq %r13, %rdi
callq 0x4e2c
testl %eax, %eax
js 0x43ab
movq 0x68(%r12), %rdi
addq %r13, %rdi
callq 0x4e36
testl %eax, %eax
js 0x43ab
xorl %eax, %eax
jmp 0x44c7
movl %r14d, -0x2c(%rbp)
movq 0x68(%r12), %rdi
addq %r13, %rdi
callq 0x4df4
movl %ebx, -0x4c(%rbp)
movslq %ebx, %rcx
movq %rcx, -0x40(%rbp)
movl %r15d, -0x50(%rbp)
movslq %r15d, %rcx
movq %rcx, -0x38(%rbp)
testl %eax, %eax
jle 0x444c
movq -0x38(%rbp), %rax
leaq (%rax,%rax,4), %rax
movq -0x40(%rbp), %rcx
leaq (%rcx,%rax,2), %r15
addq %r12, %r15
xorl %r14d, %r14d
xorl %ebx, %ebx
cmpb $0x0, -0x2c(%rbp)
je 0x4413
movq -0x40(%rbp), %rax
leaq (%rax,%rbx), %rcx
xorl %eax, %eax
cmpq $0x9, %rcx
jg 0x44c7
cmpb $0x77, (%r15,%rbx)
je 0x4431
jmp 0x44c7
xorl %eax, %eax
cmpb $0x77, (%r15,%r14)
jne 0x44c7
movq -0x38(%rbp), %rcx
addq %rbx, %rcx
cmpq $0x9, %rcx
jg 0x44c7
incq %rbx
movq 0x68(%r12), %rdi
addq %r13, %rdi
callq 0x4df4
cltq
addq $0xa, %r14
cmpq %rax, %rbx
jl 0x43ed
movq 0x68(%r12), %rdi
addq %r13, %rdi
callq 0x4df4
testl %eax, %eax
movq %r12, -0x48(%rbp)
movl -0x2c(%rbp), %r12d
jle 0x44ab
movq -0x38(%rbp), %rax
leaq (%rax,%rax,4), %rax
movq -0x40(%rbp), %rcx
leaq (%rcx,%rax,2), %r15
addq -0x48(%rbp), %r15
xorl %r14d, %r14d
movq %r15, %rbx
leaq (%r15,%r14), %rax
testb %r12b, %r12b
cmoveq %rbx, %rax
movb $0x5f, (%rax)
incq %r14
movq -0x48(%rbp), %rax
movq 0x68(%rax), %rdi
addq %r13, %rdi
callq 0x4df4
cltq
addq $0xa, %rbx
cmpq %rax, %r14
jl 0x447f
movq -0x48(%rbp), %rax
addq 0x68(%rax), %r13
movzbl %r12b, %ecx
movq %r13, %rdi
movl -0x4c(%rbp), %esi
movl -0x50(%rbp), %edx
callq 0x4f6a
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq