// File: ATOMIC-LICHESS[P]ATOMKRAFT/search.cpp
// Function: (anonymous namespace)::connected_moves(Position const&, Move, Move)
bool connected_moves(const Position& pos, Move m1, Move m2) {

    Square f1, t1, f2, t2;
    Piece p;

    assert(m1 && move_is_ok(m1));
    assert(m2 && move_is_ok(m2));

    // Case 1: The moving piece is the same in both moves
    f2 = move_from(m2);
    t1 = move_to(m1);
    if (f2 == t1)
        return true;

    // Case 2: The destination square for m2 was vacated by m1
    t2 = move_to(m2);
    f1 = move_from(m1);
    if (t2 == f1)
        return true;

    // Case 3: Moving through the vacated square
    if (   piece_is_slider(pos.piece_on(f2))
        && bit_is_set(squares_between(f2, t2), f1))
      return true;

    // Case 4: The destination square for m2 is defended by the moving piece in m1
    p = pos.piece_on(t1);
    if (bit_is_set(pos.attacks_from(p, t1), t2))
        return true;

    // Case 5: Discovered check, checking piece is the piece moved in m1
    if (    piece_is_slider(p)
        &&  bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), f2)
        && !bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), t2))
    {
        // discovered_check_candidates() works also if the Position's side to
        // move is the opposite of the checking piece.
        Color them = opposite_color(pos.side_to_move());
        Bitboard dcCandidates = pos.discovered_check_candidates(them);

        if (bit_is_set(dcCandidates, f2))
            return true;
    }
    return false;
  }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movl %esi, 0x44(%rsp)
movl %edx, 0x40(%rsp)
movl 0x40(%rsp), %edi
callq 0xf680
movl %eax, 0x34(%rsp)
movl 0x44(%rsp), %edi
callq 0xf690
movl %eax, 0x38(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x38(%rsp), %eax
jne 0x4e11f
movb $0x1, 0x57(%rsp)
jmp 0x4e2b9
movl 0x40(%rsp), %edi
callq 0xf690
movl %eax, 0x30(%rsp)
movl 0x44(%rsp), %edi
callq 0xf680
movl %eax, 0x3c(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jne 0x4e14d
movb $0x1, 0x57(%rsp)
jmp 0x4e2b9
movq 0x48(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0xf530
movl %eax, %edi
callq 0x4e680
testb $0x1, %al
jne 0x4e168
jmp 0x4e191
movl 0x34(%rsp), %edi
movl 0x30(%rsp), %esi
callq 0x339d0
movq %rax, %rdi
movl 0x3c(%rsp), %esi
callq 0xd760
cmpq $0x0, %rax
je 0x4e191
movb $0x1, 0x57(%rsp)
jmp 0x4e2b9
movq 0x48(%rsp), %rdi
movl 0x38(%rsp), %esi
callq 0xf530
movl %eax, 0x2c(%rsp)
movq 0x48(%rsp), %rdi
movl 0x2c(%rsp), %esi
movl 0x38(%rsp), %edx
callq 0x38b30
movq %rax, %rdi
movl 0x30(%rsp), %esi
callq 0xd760
cmpq $0x0, %rax
je 0x4e1d1
movb $0x1, 0x57(%rsp)
jmp 0x4e2b9
movl 0x2c(%rsp), %edi
callq 0x4e680
testb $0x1, %al
jne 0x4e1e3
jmp 0x4e2b4
movl 0x38(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %rdi
callq 0xf5d0
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x1b250
movl 0x1c(%rsp), %edi
movl %eax, %esi
callq 0x339d0
movq %rax, %rdi
movl 0x34(%rsp), %esi
callq 0xd760
cmpq $0x0, %rax
je 0x4e2b4
movl 0x38(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq 0x48(%rsp), %rdi
callq 0xf5d0
movq (%rsp), %rdi
movl %eax, %esi
callq 0x1b250
movl 0xc(%rsp), %edi
movl %eax, %esi
callq 0x339d0
movq %rax, %rdi
movl 0x30(%rsp), %esi
callq 0xd760
cmpq $0x0, %rax
jne 0x4e2b4
movq 0x48(%rsp), %rdi
callq 0xf5d0
movl %eax, %edi
callq 0x122b0
movl %eax, 0x28(%rsp)
movq 0x48(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x36440
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0xd760
cmpq $0x0, %rax
je 0x4e2b2
movb $0x1, 0x57(%rsp)
jmp 0x4e2b9
jmp 0x4e2b4
movb $0x0, 0x57(%rsp)
movb 0x57(%rsp), %al
andb $0x1, %al
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)