// File: tlaloc1313[P]chess-project/Board.cpp
// Function: Board::checkCheck(int, int)
int Board::checkCheck(int inputWhite, int inputBlack) {

	//Declaring variables
	bool whiteInCheck = 0;
	bool blackInCheck = 0;

  int kingSquare, kingRow, kingCol;

	int edges[4];					//Array of squares at the edge of board that could be attacking king, 0-3, anticlockwise starting east
	int pieceSquares[4];	//Array of squares with pieces, -1 if no piece

	//Increments for king row and column
	int kingRowIncr;
	int kingColIncr;

	//Squares that knighs could be on
	int knightSquares[8] = {17,10,-6,-15,-17,-10,6,15};

	//WHITE KING

	//Find what square the king is on, if it isn't passed
  if (inputWhite == -1) {
    for (int i = 0; i < 64; i++) {
  		if (activeArray[i]) {
  			if (pieceArray[i]->getType() == 'k' && pieceArray[i]->getIsWhite()) {
  				kingSquare = i;
  				break;
  			}
  		}
  	}
  } else {
    kingSquare = inputWhite;
  }

	//Find straight destinations
	kingRow = row(kingSquare);
	kingCol = col(kingSquare);

	edges[0] = 56 + kingRow;
	edges[1] = (8 * kingCol) + 7;
	edges[2] = 0 + kingRow;
	edges[3] = 8 * kingCol;

	//Find if pieces are on squares
	for (int i = 0; i < 4; i++) {
		pieceSquares[i] = pieceArray[kingSquare]->checkStraight(edges[i], activeArray);
		//checkStraight ignores the final square, so if it doesn't find anything, edges[i] is checked as well
		if (pieceSquares[i] == -1) {
			if (activeArray[edges[i]] == 1) {
				pieceSquares[i] = edges[i];
			}
		}
	}

	//Check squares
	for (int i = 0; i < 4; i++) {
		if (pieceSquares[i] != -1) {
			//If the piece is a black rook or queen
			if (strcmp(getPiece(pieceSquares[i]), u8"\u265C") == 0 || strcmp(getPiece(pieceSquares[i]), u8"\u265B") == 0) {
				whiteInCheck = 1;
			} else if ((abs(kingRow - row(pieceSquares[i])) <= 1 && abs(kingCol - col(pieceSquares[i])) <= 1) && strcmp(getPiece(pieceSquares[i]), u8"\u265A") == 0) {	//If the piece is a black king and within 1 square of the white king
				whiteInCheck = 1;
				blackInCheck = 1;
			}
		}
	}

	if (!whiteInCheck) {
		//Find diagonal destinations - edges now 0-3, anticlockwise starting north-east

		kingRowIncr = kingRow;
		kingColIncr = kingCol;

		while (kingRowIncr < 7 && kingColIncr < 7) {
			kingRowIncr++;
			kingColIncr++;
		}

		edges[0] = (kingColIncr * 8) + kingRowIncr;

		kingRowIncr = kingRow;
		kingColIncr = kingCol;

		while (kingRowIncr < 7 && kingColIncr > 0) {
			kingRowIncr++;
			kingColIncr--;
		}

		edges[1] = (kingColIncr * 8) + kingRowIncr;

		kingRowIncr = kingRow;
		kingColIncr = kingCol;

		while (kingRowIncr > 0 && kingColIncr > 0) {
			kingRowIncr--;
			kingColIncr--;
		}

		edges[2] = (kingColIncr * 8) + kingRowIncr;

		kingRowIncr = kingRow;
		kingColIncr = kingCol;

		while (kingRowIncr > 0 && kingColIncr < 7) {
			kingRowIncr--;
			kingColIncr++;
		}

		edges[3] = (kingColIncr * 8) + kingRowIncr;

		//Find if pieces are on squares
		for (int i = 0; i < 4; i++) {
			pieceSquares[i] = pieceArray[kingSquare]->checkDiagonal(edges[i], activeArray);
			//checkDiagonal ignores the final square, so if it doesn't find anything, edges[i] is checked as well
			if (pieceSquares[i] == -1) {
				if (activeArray[edges[i]] == 1) {
					pieceSquares[i] = edges[i];
				}
			}
		}

		//Check squares
		for (int i = 0; i < 4; i++) {
			if (pieceSquares[i] != -1) {
				//If the piece is a black bishop, queen or a pawn that is above white king on board
				if (strcmp(getPiece(pieceSquares[i]), u8"\u265D") == 0 || strcmp(getPiece(pieceSquares[i]), u8"\u265B") == 0 || (strcmp(getPiece(pieceSquares[i]), u8"\u265F") == 0 && row(pieceSquares[i]) - kingRow == 1)) {
					whiteInCheck = 1;
				} else if ((abs(kingRow - row(pieceSquares[i])) <= 1 && abs(kingCol - col(pieceSquares[i])) <= 1) && strcmp(getPiece(pieceSquares[i]), u8"\u265A") == 0) {	//If the piece is a black king and within 1 square of the white king
					whiteInCheck = 1;
					blackInCheck = 1;
				}
			}
		}
	}

	if (!whiteInCheck) {
		for (int i = 0; i < 8; i++) {
			knightSquares[i] += kingSquare;
		}

		for (int i = 0; i < 8; i++) {
			//If knightSquares[i] is an actual square
			if (knightSquares[i] >= 0 && knightSquares[i] <= 63) {
				//If there is a piece on knightSquares[i]
				if (activeArray[knightSquares[i]]) {
					//If the piece is a black knight and the within a radius of 2 squares from the king
					if (strcmp(getPiece(knightSquares[i]), u8"\u265E") == 0 && (abs(kingRow - row(knightSquares[i])) <= 2 && abs(kingCol - col(knightSquares[i])) <= 2)) {
						whiteInCheck = 1;
					}
				}
			}
		}
	}
	//BLACK KING
	//Find what square the king is on, if it isn't passed
  if (inputBlack == -1) {
    for (int i = 0; i < 64; i++) {
  		if (activeArray[i]) {
  			if (pieceArray[i]->getType() == 'k' && !pieceArray[i]->getIsWhite()) {
  				kingSquare = i;
  				break;
  			}
  		}
  	}
  } else {
    kingSquare = inputBlack;
  }

	kingRow = row(kingSquare);
	kingCol = col(kingSquare);

	//Find straight destinations
	edges[0] = 56 + kingRow;
	edges[1] = (8 * kingCol) + 7;
	edges[2] = 0 + kingRow;
	edges[3] = 8 * kingCol;

	//Find if pieces are on squares
	for (int i = 0; i < 4; i++) {
		pieceSquares[i] = pieceArray[kingSquare]->checkStraight(edges[i], activeArray);
		//checkStraight ignores the final square, so if it doesn't find anything, edges[i] is checked as well
		if (pieceSquares[i] == -1) {
			if (activeArray[edges[i]] == 1) {
				pieceSquares[i] = edges[i];
			}
		}
	}

	//Check squares
	for (int i = 0; i < 4; i++) {
		if (pieceSquares[i] != -1) {
			//If the piece is a white rook or queen
			if (strcmp(getPiece(pieceSquares[i]), u8"\u2656") == 0 || strcmp(getPiece(pieceSquares[i]), u8"\u2655") == 0) {
				blackInCheck = 1;
			}
		}
	}

	if (!blackInCheck) {
		//Find diagonal destinations - edges now 0-3, anticlockwise starting north-east
		kingRowIncr = kingRow;
		kingColIncr = kingCol;

		while (kingRowIncr < 7 && kingColIncr < 7) {
			kingRowIncr++;
			kingColIncr++;
		}

		edges[0] = (kingColIncr * 8) + kingRowIncr;

		kingRowIncr = kingRow;
		kingColIncr = kingCol;

		while (kingRowIncr < 7 && kingColIncr > 0) {
			kingRowIncr++;
			kingColIncr--;
		}

		edges[1] = (kingColIncr * 8) + kingRowIncr;

		kingRowIncr = kingRow;
		kingColIncr = kingCol;

		while (kingRowIncr > 0 && kingColIncr > 0) {
			kingRowIncr--;
			kingColIncr--;
		}

		edges[2] = (kingColIncr * 8) + kingRowIncr;

		kingRowIncr = kingRow;
		kingColIncr = kingCol;

		while (kingRowIncr > 0 && kingColIncr < 7) {
			kingRowIncr--;
			kingColIncr++;
		}

		edges[3] = (kingColIncr * 8) + kingRowIncr;

		//Find if pieces are on squares
		for (int i = 0; i < 4; i++) {
			pieceSquares[i] = pieceArray[kingSquare]->checkDiagonal(edges[i], activeArray);
			//checkDiagonal ignores the final square, so if it doesn't find anything, edges[i] is checked as well
			if (pieceSquares[i] == -1) {
				if (activeArray[edges[i]] == 1) {
					pieceSquares[i] = edges[i];
				}
			}
		}

		//Check squares
		for (int i = 0; i < 4; i++) {
			if (pieceSquares[i] != -1) {
				//If the piece is a white bishop, queen or a pawn that is below black king on board
				if (strcmp(getPiece(pieceSquares[i]), u8"\u2657") == 0 || strcmp(getPiece(pieceSquares[i]), u8"\u2655") == 0 || (strcmp(getPiece(pieceSquares[i]), u8"\u2659") == 0 && row(pieceSquares[i]) - kingRow == -1)) {
					blackInCheck = 1;
				} else if ((abs(kingRow - row(pieceSquares[i])) <= 1 && abs(kingCol - col(pieceSquares[i])) <= 1) && strcmp(getPiece(pieceSquares[i]), u8"♔") == 0) {	//If the piece is a white king and within 1 square of the black king
					whiteInCheck = 1;
					blackInCheck = 1;
				}
			}
		}
	}

	if (!blackInCheck) {

		for (int i = 0; i < 8; i++) {
			knightSquares[i] += kingSquare;
		}

		for (int i = 0; i < 8; i++) {
			//If knightSquares[i] is an actual square
			if (knightSquares[i] >= 0 && knightSquares[i] <= 63) {
				//If there is a piece on knightSquares[i]
				if (activeArray[knightSquares[i]]) {
					//If the piece is a white knight and the within a radius of 2 squares from the king
					if (strcmp(getPiece(knightSquares[i]), u8"\u2658") == 0 && (abs(kingRow - row(knightSquares[i])) <= 2 && abs(kingCol - col(knightSquares[i])) <= 2)) {
						blackInCheck = 1;
					}
				}
			}
		}
	}

	if (whiteInCheck && blackInCheck) {
		return 3;
	} else if (blackInCheck) {
		return 2;
	} else if (whiteInCheck) {
		return 1;
	}
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movb $0x0, -0x19(%rbp)
movb $0x0, -0x1a(%rbp)
movq 0x50d1(%rip), %rax      # 0xa690
movq %rax, -0x80(%rbp)
movq 0x50ce(%rip), %rax      # 0xa698
movq %rax, -0x78(%rbp)
movq 0x50cb(%rip), %rax      # 0xa6a0
movq %rax, -0x70(%rbp)
movq 0x50c8(%rip), %rax      # 0xa6a8
movq %rax, -0x68(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x5679
movl $0x0, -0x84(%rbp)
cmpl $0x40, -0x84(%rbp)
jge 0x5677
movq -0xc0(%rbp), %rax
movslq -0x84(%rbp), %rcx
testb $0x1, 0x208(%rax,%rcx)
je 0x5664
movq -0xc0(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x9880
movsbl %al, %eax
cmpl $0x6b, %eax
jne 0x5662
movq -0xc0(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x98a0
testb $0x1, %al
jne 0x5657
jmp 0x5662
movl -0x84(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x5677
jmp 0x5664
jmp 0x5666
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x55f8
jmp 0x567f
movl -0x14(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %edi
callq 0x47f0
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %edi
callq 0x4810
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x38, %eax
movl %eax, -0x40(%rbp)
movl -0x28(%rbp), %eax
shll $0x3, %eax
addl $0x7, %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl $0x0, %eax
movl %eax, -0x38(%rbp)
movl -0x28(%rbp), %eax
shll $0x3, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x88(%rbp)
cmpl $0x4, -0x88(%rbp)
jge 0x5767
movq -0xc0(%rbp), %rdx
movslq -0x20(%rbp), %rax
movq 0x8(%rdx,%rax,8), %rdi
movslq -0x88(%rbp), %rax
movl -0x40(%rbp,%rax,4), %esi
addq $0x208, %rdx            # imm = 0x208
callq 0x9540
movl %eax, %ecx
movslq -0x88(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,4)
movslq -0x88(%rbp), %rax
cmpl $-0x1, -0x50(%rbp,%rax,4)
jne 0x5751
movq -0xc0(%rbp), %rax
movslq -0x88(%rbp), %rcx
movslq -0x40(%rbp,%rcx,4), %rcx
movb 0x208(%rax,%rcx), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x574f
movslq -0x88(%rbp), %rax
movl -0x40(%rbp,%rax,4), %ecx
movslq -0x88(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,4)
jmp 0x5751
jmp 0x5753
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x56c6
movl $0x0, -0x8c(%rbp)
cmpl $0x4, -0x8c(%rbp)
jge 0x589a
movslq -0x8c(%rbp), %rax
cmpl $-0x1, -0x50(%rbp,%rax,4)
je 0x5884
movq -0xc0(%rbp), %rdi
movslq -0x8c(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4e52(%rip), %rsi      # 0xa603
callq 0x21e0
cmpl $0x0, %eax
je 0x57e6
movq -0xc0(%rbp), %rdi
movslq -0x8c(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4e37(%rip), %rsi      # 0xa613
callq 0x21e0
cmpl $0x0, %eax
jne 0x57ef
movb $0x1, -0x19(%rbp)
jmp 0x5882
movl -0x24(%rbp), %eax
movl %eax, -0xc4(%rbp)
movslq -0x8c(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x47f0
movl %eax, %ecx
movl -0xc4(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jg 0x5880
movl -0x28(%rbp), %eax
movl %eax, -0xc8(%rbp)
movslq -0x8c(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x4810
movl %eax, %ecx
movl -0xc8(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jg 0x5880
movq -0xc0(%rbp), %rdi
movslq -0x8c(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4da1(%rip), %rsi      # 0xa60f
callq 0x21e0
cmpl $0x0, %eax
jne 0x5880
movb $0x1, -0x19(%rbp)
movb $0x1, -0x1a(%rbp)
jmp 0x5882
jmp 0x5884
jmp 0x5886
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x5771
testb $0x1, -0x19(%rbp)
jne 0x5c13
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x7, -0x54(%rbp)
movb %al, -0xc9(%rbp)
jge 0x58cb
cmpl $0x7, -0x58(%rbp)
setl %al
movb %al, -0xc9(%rbp)
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x58d7
jmp 0x58eb
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x58b0
movl -0x58(%rbp), %eax
shll $0x3, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x7, -0x54(%rbp)
movb %al, -0xca(%rbp)
jge 0x591e
cmpl $0x0, -0x58(%rbp)
setg %al
movb %al, -0xca(%rbp)
movb -0xca(%rbp), %al
testb $0x1, %al
jne 0x592a
jmp 0x593e
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x5903
movl -0x58(%rbp), %eax
shll $0x3, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x54(%rbp)
movb %al, -0xcb(%rbp)
jle 0x5971
cmpl $0x0, -0x58(%rbp)
setg %al
movb %al, -0xcb(%rbp)
movb -0xcb(%rbp), %al
testb $0x1, %al
jne 0x597d
jmp 0x5991
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x5956
movl -0x58(%rbp), %eax
shll $0x3, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x54(%rbp)
movb %al, -0xcc(%rbp)
jle 0x59c4
cmpl $0x7, -0x58(%rbp)
setl %al
movb %al, -0xcc(%rbp)
movb -0xcc(%rbp), %al
testb $0x1, %al
jne 0x59d0
jmp 0x59e4
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x59a9
movl -0x58(%rbp), %eax
shll $0x3, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x90(%rbp)
cmpl $0x4, -0x90(%rbp)
jge 0x5a9b
movq -0xc0(%rbp), %rdx
movslq -0x20(%rbp), %rax
movq 0x8(%rdx,%rax,8), %rdi
movslq -0x90(%rbp), %rax
movl -0x40(%rbp,%rax,4), %esi
addq $0x208, %rdx            # imm = 0x208
callq 0x96b0
movl %eax, %ecx
movslq -0x90(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,4)
movslq -0x90(%rbp), %rax
cmpl $-0x1, -0x50(%rbp,%rax,4)
jne 0x5a85
movq -0xc0(%rbp), %rax
movslq -0x90(%rbp), %rcx
movslq -0x40(%rbp,%rcx,4), %rcx
movb 0x208(%rax,%rcx), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x5a83
movslq -0x90(%rbp), %rax
movl -0x40(%rbp,%rax,4), %ecx
movslq -0x90(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,4)
jmp 0x5a85
jmp 0x5a87
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x59fa
movl $0x0, -0x94(%rbp)
cmpl $0x4, -0x94(%rbp)
jge 0x5c11
movslq -0x94(%rbp), %rax
cmpl $-0x1, -0x50(%rbp,%rax,4)
je 0x5bfb
movq -0xc0(%rbp), %rdi
movslq -0x94(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4b22(%rip), %rsi      # 0xa607
callq 0x21e0
cmpl $0x0, %eax
je 0x5b5d
movq -0xc0(%rbp), %rdi
movslq -0x94(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4b03(%rip), %rsi      # 0xa613
callq 0x21e0
cmpl $0x0, %eax
je 0x5b5d
movq -0xc0(%rbp), %rdi
movslq -0x94(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4ac4(%rip), %rsi      # 0xa5ff
callq 0x21e0
cmpl $0x0, %eax
jne 0x5b66
movslq -0x94(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x47f0
subl -0x24(%rbp), %eax
cmpl $0x1, %eax
jne 0x5b66
movb $0x1, -0x19(%rbp)
jmp 0x5bf9
movl -0x24(%rbp), %eax
movl %eax, -0xd0(%rbp)
movslq -0x94(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x47f0
movl %eax, %ecx
movl -0xd0(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jg 0x5bf7
movl -0x28(%rbp), %eax
movl %eax, -0xd4(%rbp)
movslq -0x94(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x4810
movl %eax, %ecx
movl -0xd4(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jg 0x5bf7
movq -0xc0(%rbp), %rdi
movslq -0x94(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4a2a(%rip), %rsi      # 0xa60f
callq 0x21e0
cmpl $0x0, %eax
jne 0x5bf7
movb $0x1, -0x19(%rbp)
movb $0x1, -0x1a(%rbp)
jmp 0x5bf9
jmp 0x5bfb
jmp 0x5bfd
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x5aa5
jmp 0x5c13
testb $0x1, -0x19(%rbp)
jne 0x5d58
movl $0x0, -0x98(%rbp)
cmpl $0x8, -0x98(%rbp)
jge 0x5c53
movl -0x20(%rbp), %ecx
movslq -0x98(%rbp), %rax
addl -0x80(%rbp,%rax,4), %ecx
movl %ecx, -0x80(%rbp,%rax,4)
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x5c27
movl $0x0, -0x9c(%rbp)
cmpl $0x8, -0x9c(%rbp)
jge 0x5d56
movslq -0x9c(%rbp), %rax
cmpl $0x0, -0x80(%rbp,%rax,4)
jl 0x5d40
movslq -0x9c(%rbp), %rax
cmpl $0x3f, -0x80(%rbp,%rax,4)
jg 0x5d40
movq -0xc0(%rbp), %rax
movslq -0x9c(%rbp), %rcx
movslq -0x80(%rbp,%rcx,4), %rcx
testb $0x1, 0x208(%rax,%rcx)
je 0x5d3e
movq -0xc0(%rbp), %rdi
movslq -0x9c(%rbp), %rax
movl -0x80(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x493b(%rip), %rsi      # 0xa60b
callq 0x21e0
cmpl $0x0, %eax
jne 0x5d3c
movl -0x24(%rbp), %eax
movl %eax, -0xd8(%rbp)
movslq -0x9c(%rbp), %rax
movl -0x80(%rbp,%rax,4), %edi
callq 0x47f0
movl %eax, %ecx
movl -0xd8(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x2, %eax
jg 0x5d3c
movl -0x28(%rbp), %eax
movl %eax, -0xdc(%rbp)
movslq -0x9c(%rbp), %rax
movl -0x80(%rbp,%rax,4), %edi
callq 0x4810
movl %eax, %ecx
movl -0xdc(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x2, %eax
jg 0x5d3c
movb $0x1, -0x19(%rbp)
jmp 0x5d3e
jmp 0x5d40
jmp 0x5d42
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x5c5d
jmp 0x5d58
cmpl $-0x1, -0x18(%rbp)
jne 0x5deb
movl $0x0, -0xa0(%rbp)
cmpl $0x40, -0xa0(%rbp)
jge 0x5de9
movq -0xc0(%rbp), %rax
movslq -0xa0(%rbp), %rcx
testb $0x1, 0x208(%rax,%rcx)
je 0x5dd6
movq -0xc0(%rbp), %rax
movslq -0xa0(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x9880
movsbl %al, %eax
cmpl $0x6b, %eax
jne 0x5dd4
movq -0xc0(%rbp), %rax
movslq -0xa0(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x98a0
testb $0x1, %al
jne 0x5dd4
movl -0xa0(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x5de9
jmp 0x5dd6
jmp 0x5dd8
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x5d6c
jmp 0x5df1
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %edi
callq 0x47f0
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %edi
callq 0x4810
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x38, %eax
movl %eax, -0x40(%rbp)
movl -0x28(%rbp), %eax
shll $0x3, %eax
addl $0x7, %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl $0x0, %eax
movl %eax, -0x38(%rbp)
movl -0x28(%rbp), %eax
shll $0x3, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0xa4(%rbp)
cmpl $0x4, -0xa4(%rbp)
jge 0x5ed9
movq -0xc0(%rbp), %rdx
movslq -0x20(%rbp), %rax
movq 0x8(%rdx,%rax,8), %rdi
movslq -0xa4(%rbp), %rax
movl -0x40(%rbp,%rax,4), %esi
addq $0x208, %rdx            # imm = 0x208
callq 0x9540
movl %eax, %ecx
movslq -0xa4(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,4)
movslq -0xa4(%rbp), %rax
cmpl $-0x1, -0x50(%rbp,%rax,4)
jne 0x5ec3
movq -0xc0(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movslq -0x40(%rbp,%rcx,4), %rcx
movb 0x208(%rax,%rcx), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x5ec1
movslq -0xa4(%rbp), %rax
movl -0x40(%rbp,%rax,4), %ecx
movslq -0xa4(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,4)
jmp 0x5ec3
jmp 0x5ec5
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x5e38
movl $0x0, -0xa8(%rbp)
cmpl $0x4, -0xa8(%rbp)
jge 0x5f70
movslq -0xa8(%rbp), %rax
cmpl $-0x1, -0x50(%rbp,%rax,4)
je 0x5f5a
movq -0xc0(%rbp), %rdi
movslq -0xa8(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x46cc(%rip), %rsi      # 0xa5eb
callq 0x21e0
cmpl $0x0, %eax
je 0x5f54
movq -0xc0(%rbp), %rdi
movslq -0xa8(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x46b1(%rip), %rsi      # 0xa5fb
callq 0x21e0
cmpl $0x0, %eax
jne 0x5f58
movb $0x1, -0x1a(%rbp)
jmp 0x5f5a
jmp 0x5f5c
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x5ee3
testb $0x1, -0x1a(%rbp)
jne 0x62e9
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x7, -0x54(%rbp)
movb %al, -0xdd(%rbp)
jge 0x5fa1
cmpl $0x7, -0x58(%rbp)
setl %al
movb %al, -0xdd(%rbp)
movb -0xdd(%rbp), %al
testb $0x1, %al
jne 0x5fad
jmp 0x5fc1
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x5f86
movl -0x58(%rbp), %eax
shll $0x3, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x7, -0x54(%rbp)
movb %al, -0xde(%rbp)
jge 0x5ff4
cmpl $0x0, -0x58(%rbp)
setg %al
movb %al, -0xde(%rbp)
movb -0xde(%rbp), %al
testb $0x1, %al
jne 0x6000
jmp 0x6014
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x5fd9
movl -0x58(%rbp), %eax
shll $0x3, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x54(%rbp)
movb %al, -0xdf(%rbp)
jle 0x6047
cmpl $0x0, -0x58(%rbp)
setg %al
movb %al, -0xdf(%rbp)
movb -0xdf(%rbp), %al
testb $0x1, %al
jne 0x6053
jmp 0x6067
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x602c
movl -0x58(%rbp), %eax
shll $0x3, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x54(%rbp)
movb %al, -0xe0(%rbp)
jle 0x609a
cmpl $0x7, -0x58(%rbp)
setl %al
movb %al, -0xe0(%rbp)
movb -0xe0(%rbp), %al
testb $0x1, %al
jne 0x60a6
jmp 0x60ba
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x607f
movl -0x58(%rbp), %eax
shll $0x3, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0xac(%rbp)
cmpl $0x4, -0xac(%rbp)
jge 0x6171
movq -0xc0(%rbp), %rdx
movslq -0x20(%rbp), %rax
movq 0x8(%rdx,%rax,8), %rdi
movslq -0xac(%rbp), %rax
movl -0x40(%rbp,%rax,4), %esi
addq $0x208, %rdx            # imm = 0x208
callq 0x96b0
movl %eax, %ecx
movslq -0xac(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,4)
movslq -0xac(%rbp), %rax
cmpl $-0x1, -0x50(%rbp,%rax,4)
jne 0x615b
movq -0xc0(%rbp), %rax
movslq -0xac(%rbp), %rcx
movslq -0x40(%rbp,%rcx,4), %rcx
movb 0x208(%rax,%rcx), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x6159
movslq -0xac(%rbp), %rax
movl -0x40(%rbp,%rax,4), %ecx
movslq -0xac(%rbp), %rax
movl %ecx, -0x50(%rbp,%rax,4)
jmp 0x615b
jmp 0x615d
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x60d0
movl $0x0, -0xb0(%rbp)
cmpl $0x4, -0xb0(%rbp)
jge 0x62e7
movslq -0xb0(%rbp), %rax
cmpl $-0x1, -0x50(%rbp,%rax,4)
je 0x62d1
movq -0xc0(%rbp), %rdi
movslq -0xb0(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4434(%rip), %rsi      # 0xa5ef
callq 0x21e0
cmpl $0x0, %eax
je 0x6233
movq -0xc0(%rbp), %rdi
movslq -0xb0(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x4415(%rip), %rsi      # 0xa5fb
callq 0x21e0
cmpl $0x0, %eax
je 0x6233
movq -0xc0(%rbp), %rdi
movslq -0xb0(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x43d6(%rip), %rsi      # 0xa5e7
callq 0x21e0
cmpl $0x0, %eax
jne 0x623c
movslq -0xb0(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x47f0
subl -0x24(%rbp), %eax
cmpl $-0x1, %eax
jne 0x623c
movb $0x1, -0x1a(%rbp)
jmp 0x62cf
movl -0x24(%rbp), %eax
movl %eax, -0xe4(%rbp)
movslq -0xb0(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x47f0
movl %eax, %ecx
movl -0xe4(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jg 0x62cd
movl -0x28(%rbp), %eax
movl %eax, -0xe8(%rbp)
movslq -0xb0(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x4810
movl %eax, %ecx
movl -0xe8(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jg 0x62cd
movq -0xc0(%rbp), %rdi
movslq -0xb0(%rbp), %rax
movl -0x50(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x433c(%rip), %rsi      # 0xa5f7
callq 0x21e0
cmpl $0x0, %eax
jne 0x62cd
movb $0x1, -0x19(%rbp)
movb $0x1, -0x1a(%rbp)
jmp 0x62cf
jmp 0x62d1
jmp 0x62d3
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0(%rbp)
jmp 0x617b
jmp 0x62e9
testb $0x1, -0x1a(%rbp)
jne 0x642e
movl $0x0, -0xb4(%rbp)
cmpl $0x8, -0xb4(%rbp)
jge 0x6329
movl -0x20(%rbp), %ecx
movslq -0xb4(%rbp), %rax
addl -0x80(%rbp,%rax,4), %ecx
movl %ecx, -0x80(%rbp,%rax,4)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x62fd
movl $0x0, -0xb8(%rbp)
cmpl $0x8, -0xb8(%rbp)
jge 0x642c
movslq -0xb8(%rbp), %rax
cmpl $0x0, -0x80(%rbp,%rax,4)
jl 0x6416
movslq -0xb8(%rbp), %rax
cmpl $0x3f, -0x80(%rbp,%rax,4)
jg 0x6416
movq -0xc0(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movslq -0x80(%rbp,%rcx,4), %rcx
testb $0x1, 0x208(%rax,%rcx)
je 0x6414
movq -0xc0(%rbp), %rdi
movslq -0xb8(%rbp), %rax
movl -0x80(%rbp,%rax,4), %esi
callq 0x5210
movq %rax, %rdi
leaq 0x424d(%rip), %rsi      # 0xa5f3
callq 0x21e0
cmpl $0x0, %eax
jne 0x6412
movl -0x24(%rbp), %eax
movl %eax, -0xec(%rbp)
movslq -0xb8(%rbp), %rax
movl -0x80(%rbp,%rax,4), %edi
callq 0x47f0
movl %eax, %ecx
movl -0xec(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x2, %eax
jg 0x6412
movl -0x28(%rbp), %eax
movl %eax, -0xf0(%rbp)
movslq -0xb8(%rbp), %rax
movl -0x80(%rbp,%rax,4), %edi
callq 0x4810
movl %eax, %ecx
movl -0xf0(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x2, %eax
jg 0x6412
movb $0x1, -0x1a(%rbp)
jmp 0x6414
jmp 0x6416
jmp 0x6418
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x6333
jmp 0x642e
testb $0x1, -0x19(%rbp)
je 0x6443
testb $0x1, -0x1a(%rbp)
je 0x6443
movl $0x3, -0x4(%rbp)
jmp 0x646c
testb $0x1, -0x1a(%rbp)
je 0x6452
movl $0x2, -0x4(%rbp)
jmp 0x646c
testb $0x1, -0x19(%rbp)
je 0x6461
movl $0x1, -0x4(%rbp)
jmp 0x646c
jmp 0x6463
jmp 0x6465
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax,%rax)