// File: bjohnsonfl[P]Overhead-Chess-Engine-/moveGen.cpp
// Function: generateEnPassent(position const&, candidate*)
candidate* generateEnPassent (const position& pos, candidate* moveList)
{
   
    player us = pos.get_sideToPlay();
    // player them = player(!us);
    // bitboard occupied  = pos.get_pieces();
    //bitboard enemy = pos.get_pieces(them);
    square enPsq = pos.get_enPassent();
    
    square capturedPawn, leftPawn, rightPawn;
    capturedPawn = us == white ? square(enPsq + south) : square(enPsq + nort);
    
    //TO avoid wrapping off the board to the next rank,
    //A file and H file squares must be avoided for left and right accordingly
    //Set them to a1 as it is impossible for a pawn to be in the 1st rank, the if later will be false
    //however if a bug causes a pawn to be on a1 by a faulty promotion, not good.
    //Think of a more robust fix later.
    //just hope promotions never fail!
    
    leftPawn = square_to_file(capturedPawn) != file_a ? square(capturedPawn + west) : a1;
    rightPawn = square_to_file(capturedPawn) != file_h ? square (capturedPawn + east) : a1;
    
    bitboard leftPawnBB, rightPawnBB, pawns; // postEP, capturePawnBB,
    leftPawnBB = squareBitMask[leftPawn];
    rightPawnBB = squareBitMask[rightPawn];
    pawns = pos.get_pieces(us, p_pawn);
    
    if(pawns & leftPawnBB)
    {
        (*moveList++).mv = make_move(leftPawn, enPsq, pieceType(0) ,enPass);

    }
    
    
    if(pawns & rightPawnBB)
    {
        
        (*moveList++).mv = make_move(rightPawn, enPsq, pieceType(0) ,enPass);
        
    }
    
    
    return moveList;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x75c0
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rdi
callq 0x75e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x65e9
movl -0x18(%rbp), %eax
addl $-0x8, %eax
movl %eax, -0x44(%rbp)
jmp 0x65f2
movl -0x18(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %edi
callq 0x59f0
cmpl $0x0, %eax
je 0x6610
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6617
xorl %eax, %eax
movl %eax, -0x48(%rbp)
jmp 0x6617
movl -0x48(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %edi
callq 0x59f0
cmpl $0x7, %eax
je 0x6635
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x663c
xorl %eax, %eax
movl %eax, -0x4c(%rbp)
jmp 0x663c
movl -0x4c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
movl %eax, %ecx
leaq 0xc852(%rip), %rax      # 0x12ea0
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %ecx
leaq 0xc83e(%rip), %rax      # 0x12ea0
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
xorl %edx, %edx
callq 0x76b0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
andq -0x30(%rbp), %rax
cmpq $0x0, %rax
je 0x66af
movl -0x20(%rbp), %edi
movl -0x18(%rbp), %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x7830
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x10(%rbp)
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
andq -0x38(%rbp), %rax
cmpq $0x0, %rax
je 0x66e2
movl -0x24(%rbp), %edi
movl -0x18(%rbp), %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x7830
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x10(%rbp)
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)