// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movl %ecx, %r13d
cmpl $0xa, %edx
setge %al
cmpl $0xa, %ecx
setge %cl
orb %al, %cl
jne 0x44aa
movl %r8d, %r15d
movl %edx, %ebx
movq %rdi, %r12
movslq %esi, %rax
imulq $0x38, %rax, %r14
movq 0x68(%rdi), %rdi
addq %r14, %rdi
callq 0x4e3e
testl %eax, %eax
js 0x43e2
movq 0x68(%r12), %rdi
addq %r14, %rdi
callq 0x4e48
testl %eax, %eax
jns 0x44aa
movq %r12, -0x40(%rbp)
movq 0x68(%r12), %rdi
movq %r14, -0x58(%rbp)
addq %r14, %rdi
callq 0x4e06
movl %ebx, -0x44(%rbp)
movslq %ebx, %rcx
movq %rcx, -0x38(%rbp)
movl %r13d, -0x48(%rbp)
movslq %r13d, %rdx
movq %rdx, -0x50(%rbp)
testl %eax, %eax
setg %al
jle 0x44ae
movl $0x9, %r13d
movq -0x38(%rbp), %rdx
subq %rdx, %r13
movl $0xa, %esi
movq -0x50(%rbp), %rcx
subq %rcx, %rsi
movq %rsi, -0x30(%rbp)
leaq (%rcx,%rcx,4), %rcx
leaq (%rdx,%rcx,2), %r12
addq -0x40(%rbp), %r12
xorl %ebx, %ebx
xorl %r14d, %r14d
testb %r15b, %r15b
je 0x4465
cmpb $0x77, (%r12,%r14)
jne 0x44a6
testb %r15b, %r15b
je 0x4465
movq -0x38(%rbp), %rcx
addq %r14, %rcx
cmpq $0x9, %rcx
jle 0x4477
jmp 0x44a6
cmpq %r13, %r14
setg %cl
cmpb $0x77, (%r12,%rbx)
jne 0x44a6
andb %r15b, %cl
jne 0x44a6
testb %r15b, %r15b
jne 0x4482
cmpq -0x30(%rbp), %r14
jge 0x44a6
incq %r14
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rdi
addq -0x58(%rbp), %rdi
callq 0x4e06
cltq
addq $0xa, %rbx
cmpq %rax, %r14
setl %al
jl 0x4445
jmp 0x44ae
testb $0x1, %al
je 0x44ae
xorl %eax, %eax
jmp 0x4524
movl %r15d, -0x30(%rbp)
movq -0x40(%rbp), %r15
movq 0x68(%r15), %rdi
movq -0x58(%rbp), %r12
addq %r12, %rdi
callq 0x4e06
testl %eax, %eax
jle 0x450c
movq -0x50(%rbp), %rax
leaq (%rax,%rax,4), %rax
movq -0x38(%rbp), %rcx
leaq (%rcx,%rax,2), %r13
addq %r15, %r13
xorl %r14d, %r14d
movq %r13, %rbx
leaq (%r14,%r13), %rax
cmpb $0x0, -0x30(%rbp)
cmoveq %rbx, %rax
movb $0x5f, (%rax)
incq %r14
movq 0x68(%r15), %rdi
addq %r12, %rdi
callq 0x4e06
cltq
addq $0xa, %rbx
cmpq %rax, %r14
jl 0x44e3
addq 0x68(%r15), %r12
movzbl -0x30(%rbp), %ecx
movq %r12, %rdi
movl -0x44(%rbp), %esi
movl -0x48(%rbp), %edx
callq 0x4f7a
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop