// File: codeandkey[P]neocortex/src/position.cpp
// Function: neocortex::Position::make_move(neocortex::Move)
bool Position::make_move(Move move) {
	assert(!test_check(!color_to_move));

	State last_state = ply.back();
	ply.push_back(last_state);

	State& next_state = ply.back();

	next_state.last_move = move;
	
	if (color_to_move == piece::BLACK) {
		next_state.fullmove_number++;
	}

	next_state.halfmove_clock++;

	next_state.en_passant_square = square::null;
	next_state.captured_piece = piece::null;
	next_state.captured_square = square::null;
	next_state.was_en_passant = false;
	next_state.was_castle = false;

	/* End early on null move, flip color and update zobrist as well. */
	if (move == Move::null) {
		bool ret = !check(); // null moves illegal in check
		color_to_move = !color_to_move;

		next_state.key = 0;
		next_state.key ^= board.get_tt_key();
		next_state.key ^= zobrist::en_passant(next_state.en_passant_square);
		next_state.key ^= zobrist::castle(next_state.castle_rights);

		if (color_to_move == piece::BLACK) {
			next_state.key ^= zobrist::black_to_move();
		}

		return ret;
	}

	int dst_piece = board.get_piece(move.dst());
	int src_piece = board.remove(move.src());

	assert(piece::color(src_piece) == color_to_move);

	if (piece::type(src_piece) == piece::PAWN) {
		next_state.halfmove_clock = 0;
	}

	/* Check for EP capture */
	if (piece::type(src_piece) == piece::PAWN && move.dst() == last_state.en_passant_square) {
		/* EP, need to remove piece */
		int adv_dir = (color_to_move == piece::WHITE) ? NORTH : SOUTH;
		int capture_square = last_state.en_passant_square - adv_dir;
 		int removed = board.remove(capture_square);

		next_state.captured_piece = removed;
		next_state.captured_square = capture_square;
		next_state.halfmove_clock = 0;
		next_state.was_en_passant = true;

		assert(piece::type(removed) == piece::PAWN);
	}

	/* Move rook also if castling */
	if (piece::type(src_piece) == piece::KING && abs(square::file(move.src()) - square::file(move.dst())) > 1) {
		int is_ks = move.dst() > move.src();
		int castle_rank = (color_to_move == piece::WHITE) ? 0 : 7;
		int rook_file = is_ks ? 7 : 0;
		int rook_dstfile = is_ks ? 5 : 3;

		int rook_src = square::at(castle_rank, rook_file);
		int rook_dst = square::at(castle_rank, rook_dstfile);

		board.place(rook_dst, board.remove(rook_src));

		next_state.was_castle = true;
	}

	/* Test if destination is occupied */
	if (piece::is_valid(dst_piece)) {
		/* Normal capture */
		next_state.captured_piece = board.replace(move.dst(), src_piece);
		next_state.captured_square = move.dst();
		next_state.halfmove_clock = 0;

		/* no king captures */
		assert(piece::type(next_state.captured_piece) != piece::KING);
	} else {
		/* Quiet */
		board.place(move.dst(), src_piece);
	}

	/* Apply promotion */
	if (piece::is_type(move.ptype())) {
		board.replace(move.dst(), piece::make_piece(color_to_move, move.ptype()));
	}

	/* Revoke castling rights */
	if (piece::type(src_piece) == piece::KING) {
		int rights = (color_to_move == piece::WHITE) ? 0x3 : 0xC;
		next_state.castle_rights &= ~rights;
	}

	static const bitboard white_ks_revoke = bb::mask(square::at(0, 4)) | bb::mask(square::at(0, 7));
	static const bitboard white_qs_revoke = bb::mask(square::at(0, 4)) | bb::mask(square::at(0, 0));
	static const bitboard black_ks_revoke = bb::mask(square::at(7, 4)) | bb::mask(square::at(7, 7));
	static const bitboard black_qs_revoke = bb::mask(square::at(7, 4)) | bb::mask(square::at(7, 0));

	bitboard src_dst_mask = bb::mask(move.src()) | bb::mask(move.dst());

	if (src_dst_mask & white_ks_revoke) {
		next_state.castle_rights &= ~CASTLE_WHITE_K;
	}

	if (src_dst_mask & white_qs_revoke) {
		next_state.castle_rights &= ~CASTLE_WHITE_Q;
	}

	if (src_dst_mask & black_ks_revoke) {
		next_state.castle_rights &= ~CASTLE_BLACK_K;
	}

	if (src_dst_mask & black_qs_revoke) {
		next_state.castle_rights &= ~CASTLE_BLACK_Q;
	}

	/* Update en passant */
	if (piece::type(src_piece) == piece::PAWN && abs(square::rank(move.dst()) - square::rank(move.src())) > 1) {
		int epsq = move.dst() + ((color_to_move == piece::WHITE) ? SOUTH : NORTH);
		next_state.en_passant_square = epsq;

		if (color_to_move == piece::WHITE) {
			assert(epsq >= 16 && epsq <= 23);
		}
		else {
			assert(epsq >= 40 && epsq <= 47);
		}
	}

	/* Flip color to move */
	color_to_move = !color_to_move;

	/* Update zobrist key */
	next_state.key = 0;
	next_state.key ^= board.get_tt_key();
	next_state.key ^= zobrist::en_passant(next_state.en_passant_square);
	next_state.key ^= zobrist::castle(next_state.castle_rights);

	next_state.in_check = test_check(color_to_move);

	if (color_to_move == piece::BLACK) {
		next_state.key ^= zobrist::black_to_move();
	}

	/* Check that king is not in attack */
	return !test_check(!color_to_move);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rsi, -0x20(%rbp)
movl %edx, -0x18(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x8(%rbp)
movq %rdi, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
cmpl $0x0, 0x170(%rdi)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %esi
callq 0x14b90
xorb $-0x1, %al
testb $0x1, %al
jne 0xd1dd
jmp 0xd1df
jmp 0xd1fe
leaq 0x1a61a(%rip), %rdi     # 0x27800
leaq 0x1a5d8(%rip), %rsi     # 0x277c5
movl $0x88, %edx
leaq 0x1a623(%rip), %rcx     # 0x2781c
callq 0x5290
movq -0xc8(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
movl $0x38, %edx
callq 0x5360
movq -0xc8(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
leaq -0x60(%rbp), %rsi
callq 0x14a60
movq -0xc8(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, -0x68(%rbp)
movq -0x68(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq %rdx, (%rcx)
movl -0x8(%rbp), %edx
movl %edx, 0x8(%rcx)
cmpl $0x1, 0x170(%rax)
jne 0xd281
movq -0x68(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq -0x68(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movq -0x68(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movq -0x68(%rbp), %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x68(%rbp), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movq -0x68(%rbp), %rax
movb $0x0, 0x28(%rax)
movq -0x68(%rbp), %rax
movb $0x0, 0x29(%rax)
leaq -0x10(%rbp), %rdi
leaq 0x2f9be(%rip), %rsi     # 0x3cc88
callq 0xadc0
testb $0x1, %al
jne 0xd2d8
jmp 0xd390
movq -0xc8(%rbp), %rdi
callq 0xbc10
movq -0xc8(%rbp), %rdi
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x69(%rbp)
cmpl $0x0, 0x170(%rdi)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x170(%rdi)
movq -0x68(%rbp), %rax
movq $0x0, 0x30(%rax)
callq 0x14a40
movq %rax, %rcx
movq -0x68(%rbp), %rax
xorq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x68(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x23d80
movq %rax, %rcx
movq -0x68(%rbp), %rax
xorq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x68(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x23d30
movq %rax, %rdx
movq -0xc8(%rbp), %rax
movq -0x68(%rbp), %rcx
xorq 0x30(%rcx), %rdx
movq %rdx, 0x30(%rcx)
cmpl $0x1, 0x170(%rax)
jne 0xd383
callq 0x23df0
movq %rax, %rcx
movq -0x68(%rbp), %rax
xorq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movb -0x69(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0xdcf9
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movq -0xc8(%rbp), %rdi
movl %eax, %esi
callq 0x14db0
movl %eax, -0x70(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x14df0
movq -0xc8(%rbp), %rdi
movl %eax, %esi
callq 0x7da0
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %edi
callq 0x8d70
movq -0xc8(%rbp), %rcx
cmpl 0x170(%rcx), %eax
jne 0xd3dd
jmp 0xd3fc
leaq 0x1a462(%rip), %rdi     # 0x27846
leaq 0x1a3da(%rip), %rsi     # 0x277c5
movl $0xb1, %edx
leaq 0x1a425(%rip), %rcx     # 0x2781c
callq 0x5290
movl -0x74(%rbp), %edi
callq 0x8d20
cmpl $0x0, %eax
jne 0xd414
movq -0x68(%rbp), %rax
movl $0x0, 0x1c(%rax)
movl -0x74(%rbp), %edi
callq 0x8d20
cmpl $0x0, %eax
jne 0xd4c2
leaq -0x10(%rbp), %rdi
callq 0x14dd0
cmpl -0x54(%rbp), %eax
jne 0xd4c2
movq -0xc8(%rbp), %rdi
movl 0x170(%rdi), %edx
movl $0xfffffff8, %eax       # imm = 0xFFFFFFF8
movl $0x8, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x78(%rbp)
movl -0x54(%rbp), %eax
subl -0x78(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %esi
callq 0x7da0
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x7c(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x68(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x68(%rbp), %rax
movb $0x1, 0x28(%rax)
movl -0x80(%rbp), %edi
callq 0x8d20
cmpl $0x0, %eax
jne 0xd4a1
jmp 0xd4c0
leaq 0x1a3c7(%rip), %rdi     # 0x2786f
leaq 0x1a316(%rip), %rsi     # 0x277c5
movl $0xc3, %edx
leaq 0x1a361(%rip), %rcx     # 0x2781c
callq 0x5290
jmp 0xd4c2
movl -0x74(%rbp), %edi
callq 0x8d20
cmpl $0x5, %eax
jne 0xd601
leaq -0x10(%rbp), %rdi
callq 0x14df0
movl %eax, %edi
callq 0x6b80
movl %eax, -0xcc(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movl %eax, %edi
callq 0x6b80
movl %eax, %ecx
movl -0xcc(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jle 0xd601
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movl %eax, -0xd4(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x14df0
movl -0xd4(%rbp), %ecx
movl %eax, %edx
movq -0xc8(%rbp), %rax
cmpl %edx, %ecx
setg %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl %ecx, -0x84(%rbp)
movl 0x170(%rax), %edx
movl $0x7, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x88(%rbp)
movl -0x84(%rbp), %edx
xorl %eax, %eax
movl $0x7, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x8c(%rbp)
movl -0x84(%rbp), %edx
movl $0x3, %eax
movl $0x5, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x90(%rbp)
movl -0x88(%rbp), %edi
movl -0x8c(%rbp), %esi
callq 0x6c20
movl %eax, -0x94(%rbp)
movl -0x88(%rbp), %edi
movl -0x90(%rbp), %esi
callq 0x6c20
movq -0xc8(%rbp), %rdi
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0x94(%rbp), %esi
callq 0x7da0
movq -0xc8(%rbp), %rdi
movl -0xd0(%rbp), %esi
movl %eax, %edx
callq 0x7b80
movq -0x68(%rbp), %rax
movb $0x1, 0x29(%rax)
movl -0x70(%rbp), %edi
callq 0x8cf0
testb $0x1, %al
jne 0xd60f
jmp 0xd683
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movq -0xc8(%rbp), %rdi
movl %eax, %esi
movl -0x74(%rbp), %edx
callq 0x7f10
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x14(%rax)
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x68(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x68(%rbp), %rax
movl 0x14(%rax), %edi
callq 0x8d20
cmpl $0x5, %eax
je 0xd662
jmp 0xd681
leaq 0x1a22a(%rip), %rdi     # 0x27893
leaq 0x1a155(%rip), %rsi     # 0x277c5
movl $0xdd, %edx
leaq 0x1a1a0(%rip), %rcx     # 0x2781c
callq 0x5290
jmp 0xd69d
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movq -0xc8(%rbp), %rdi
movl %eax, %esi
movl -0x74(%rbp), %edx
callq 0x7b80
leaq -0x10(%rbp), %rdi
callq 0xbdd0
movl %eax, %edi
callq 0xb080
testb $0x1, %al
jne 0xd6b3
jmp 0xd701
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movl %ecx, -0xd8(%rbp)
movl 0x170(%rax), %eax
movl %eax, -0xdc(%rbp)
leaq -0x10(%rbp), %rdi
callq 0xbdd0
movl -0xdc(%rbp), %edi
movl %eax, %esi
callq 0xc370
movq -0xc8(%rbp), %rdi
movl -0xd8(%rbp), %esi
movl %eax, %edx
callq 0x7f10
movl -0x74(%rbp), %edi
callq 0x8d20
cmpl $0x5, %eax
jne 0xd744
movq -0xc8(%rbp), %rax
movl 0x170(%rax), %edx
movl $0xc, %eax
movl $0x3, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %ecx
xorl $-0x1, %ecx
movq -0x68(%rbp), %rax
andl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
cmpb $0x0, 0x2f5ad(%rip)     # 0x3ccf8
jne 0xd7d6
leaq 0x2f5a0(%rip), %rdi     # 0x3ccf8
callq 0x56f0
cmpl $0x0, %eax
je 0xd7d6
xorl %edi, %edi
movl $0x4, %esi
callq 0x6c20
movl %eax, -0xe0(%rbp)
jmp 0xd776
movl -0xe0(%rbp), %edi
callq 0x6bd0
movq %rax, -0xe8(%rbp)
jmp 0xd78a
xorl %edi, %edi
movl $0x7, %esi
callq 0x6c20
movl %eax, -0xec(%rbp)
jmp 0xd79e
movl -0xec(%rbp), %edi
callq 0x6bd0
movq %rax, -0xf8(%rbp)
jmp 0xd7b2
movq -0xf8(%rbp), %rcx
movq -0xe8(%rbp), %rax
orq %rcx, %rax
movq %rax, 0x2f526(%rip)     # 0x3ccf0
leaq 0x2f527(%rip), %rdi     # 0x3ccf8
callq 0x5280
cmpb $0x0, 0x2f52b(%rip)     # 0x3cd08
jne 0xd865
leaq 0x2f51e(%rip), %rdi     # 0x3cd08
callq 0x56f0
cmpl $0x0, %eax
je 0xd865
xorl %edi, %edi
movl $0x4, %esi
callq 0x6c20
movl %eax, -0xfc(%rbp)
jmp 0xd808
movl -0xfc(%rbp), %edi
callq 0x6bd0
movq %rax, -0x108(%rbp)
jmp 0xd81c
xorl %esi, %esi
movl %esi, %edi
callq 0x6c20
movl %eax, -0x10c(%rbp)
jmp 0xd82d
movl -0x10c(%rbp), %edi
callq 0x6bd0
movq %rax, -0x118(%rbp)
jmp 0xd841
movq -0x118(%rbp), %rcx
movq -0x108(%rbp), %rax
orq %rcx, %rax
movq %rax, 0x2f4a7(%rip)     # 0x3cd00
leaq 0x2f4a8(%rip), %rdi     # 0x3cd08
callq 0x5280
cmpb $0x0, 0x2f4ac(%rip)     # 0x3cd18
jne 0xd8fa
leaq 0x2f49f(%rip), %rdi     # 0x3cd18
callq 0x56f0
cmpl $0x0, %eax
je 0xd8fa
movl $0x7, %edi
movl $0x4, %esi
callq 0x6c20
movl %eax, -0x11c(%rbp)
jmp 0xd89a
movl -0x11c(%rbp), %edi
callq 0x6bd0
movq %rax, -0x128(%rbp)
jmp 0xd8ae
movl $0x7, %esi
movl %esi, %edi
callq 0x6c20
movl %eax, -0x12c(%rbp)
jmp 0xd8c2
movl -0x12c(%rbp), %edi
callq 0x6bd0
movq %rax, -0x138(%rbp)
jmp 0xd8d6
movq -0x138(%rbp), %rcx
movq -0x128(%rbp), %rax
orq %rcx, %rax
movq %rax, 0x2f422(%rip)     # 0x3cd10
leaq 0x2f423(%rip), %rdi     # 0x3cd18
callq 0x5280
cmpb $0x0, 0x2f427(%rip)     # 0x3cd28
jne 0xd98f
leaq 0x2f41a(%rip), %rdi     # 0x3cd28
callq 0x56f0
cmpl $0x0, %eax
je 0xd98f
movl $0x7, %edi
movl $0x4, %esi
callq 0x6c20
movl %eax, -0x13c(%rbp)
jmp 0xd92f
movl -0x13c(%rbp), %edi
callq 0x6bd0
movq %rax, -0x148(%rbp)
jmp 0xd943
movl $0x7, %edi
xorl %esi, %esi
callq 0x6c20
movl %eax, -0x14c(%rbp)
jmp 0xd957
movl -0x14c(%rbp), %edi
callq 0x6bd0
movq %rax, -0x158(%rbp)
jmp 0xd96b
movq -0x158(%rbp), %rcx
movq -0x148(%rbp), %rax
orq %rcx, %rax
movq %rax, 0x2f39d(%rip)     # 0x3cd20
leaq 0x2f39e(%rip), %rdi     # 0x3cd28
callq 0x5280
leaq -0x10(%rbp), %rdi
callq 0x14df0
movl %eax, %edi
callq 0x6bd0
movq %rax, -0x160(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movl %eax, %edi
callq 0x6bd0
movq %rax, %rcx
movq -0x160(%rbp), %rax
orq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
andq 0x2f318(%rip), %rax     # 0x3ccf0
cmpq $0x0, %rax
je 0xda80
movq -0x68(%rbp), %rax
movl 0x10(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x10(%rax)
jmp 0xda80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq 0x2f2eb(%rip), %rdi     # 0x3ccf8
callq 0x5270
jmp 0xdd07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq 0x2f2d8(%rip), %rdi     # 0x3cd08
callq 0x5270
jmp 0xdd07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq 0x2f2c5(%rip), %rdi     # 0x3cd18
callq 0x5270
jmp 0xdd07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq 0x2f2b2(%rip), %rdi     # 0x3cd28
callq 0x5270
jmp 0xdd07
movq -0xb8(%rbp), %rax
andq 0x2f272(%rip), %rax     # 0x3cd00
cmpq $0x0, %rax
je 0xdaa1
movq -0x68(%rbp), %rax
movl 0x10(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x10(%rax)
movq -0xb8(%rbp), %rax
andq 0x2f261(%rip), %rax     # 0x3cd10
cmpq $0x0, %rax
je 0xdac2
movq -0x68(%rbp), %rax
movl 0x10(%rax), %ecx
andl $-0x5, %ecx
movl %ecx, 0x10(%rax)
movq -0xb8(%rbp), %rax
andq 0x2f250(%rip), %rax     # 0x3cd20
cmpq $0x0, %rax
je 0xdae3
movq -0x68(%rbp), %rax
movl 0x10(%rax), %ecx
andl $-0x9, %ecx
movl %ecx, 0x10(%rax)
movl -0x74(%rbp), %edi
callq 0x8d20
cmpl $0x0, %eax
jne 0xdc1c
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movl %eax, %edi
callq 0x6b30
movl %eax, -0x164(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x14df0
movl %eax, %edi
callq 0x6b30
movl %eax, %ecx
movl -0x164(%rbp), %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jle 0xdc1c
leaq -0x10(%rbp), %rdi
callq 0x14dd0
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movl 0x170(%rax), %edi
movl $0x8, %edx
movl $0xfffffff8, %esi       # imm = 0xFFFFFFF8
cmpl $0x0, %edi
cmovel %esi, %edx
addl %edx, %ecx
movl %ecx, -0xbc(%rbp)
movl -0xbc(%rbp), %edx
movq -0x68(%rbp), %rcx
movl %edx, 0xc(%rcx)
cmpl $0x0, 0x170(%rax)
jne 0xdbca
xorl %eax, %eax
cmpl $0x10, -0xbc(%rbp)
movb %al, -0x165(%rbp)
jl 0xdb9b
cmpl $0x17, -0xbc(%rbp)
setle %al
movb %al, -0x165(%rbp)
movb -0x165(%rbp), %al
testb $0x1, %al
jne 0xdba7
jmp 0xdba9
jmp 0xdbc8
leaq 0x19d19(%rip), %rdi     # 0x278c9
leaq 0x19c0e(%rip), %rsi     # 0x277c5
movl $0x10b, %edx            # imm = 0x10B
leaq 0x19c59(%rip), %rcx     # 0x2781c
callq 0x5290
jmp 0xdc1a
xorl %eax, %eax
cmpl $0x28, -0xbc(%rbp)
movb %al, -0x166(%rbp)
jl 0xdbeb
cmpl $0x2f, -0xbc(%rbp)
setle %al
movb %al, -0x166(%rbp)
movb -0x166(%rbp), %al
testb $0x1, %al
jne 0xdbf7
jmp 0xdbf9
jmp 0xdc18
leaq 0x19ce2(%rip), %rdi     # 0x278e2
leaq 0x19bbe(%rip), %rsi     # 0x277c5
movl $0x10e, %edx            # imm = 0x10E
leaq 0x19c09(%rip), %rcx     # 0x2781c
callq 0x5290
jmp 0xdc1a
jmp 0xdc1c
movq -0xc8(%rbp), %rdi
cmpl $0x0, 0x170(%rdi)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x170(%rdi)
movq -0x68(%rbp), %rax
movq $0x0, 0x30(%rax)
callq 0x14a40
movq %rax, %rcx
movq -0x68(%rbp), %rax
xorq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x68(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x23d80
movq %rax, %rcx
movq -0x68(%rbp), %rax
xorq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x68(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x23d30
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movq -0x68(%rbp), %rax
xorq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movl 0x170(%rdi), %esi
callq 0x14b90
movb %al, %cl
movq -0xc8(%rbp), %rax
andb $0x1, %cl
movzbl %cl, %edx
movq -0x68(%rbp), %rcx
movl %edx, 0x24(%rcx)
cmpl $0x1, 0x170(%rax)
jne 0xdcd5
callq 0x23df0
movq %rax, %rcx
movq -0x68(%rbp), %rax
xorq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0xc8(%rbp), %rdi
cmpl $0x0, 0x170(%rdi)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %esi
callq 0x14b90
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0xa8(%rbp), %rdi
callq 0x56c0
nopw %cs:(%rax,%rax)