// File: /workspace/github_c_makefile_star2_O0/ArchLuke[P]YouSuck/Engine.c
// Function: FillPieces
int FillPieces(const S_BOARD *pos, int pieces[MAXPIECES], const int side, int sq, int fromsq) {
    int pce,index,t_sq,dir;
    int count;

    if(fromsq==NO_SQ)
	count=0;
    else
	count=1;

    // pawn
    if(side == WHITE) {
        if(pos->pieces[sq-11] == wP && ((sq-11) != fromsq)) {
	    pieces[count]=sq-11;
            count ++;
        }
	if(pos->pieces[sq-9]==wP && ((sq-9) != fromsq)){
	    pieces[count]=sq-9;
	    count ++;
	}
    } else {
        if(pos->pieces[sq+11] == bP && ((sq+11) != fromsq)) {
	    pieces[count]=sq+11;
            count ++;
        }   
	if(pos->pieces[sq+9] == bP && ((sq+9) != fromsq)) {
	    pieces[count]=sq+9;
            count ++;
        }    
    }
    
    // knights
    for(index = 0; index < 8; ++index) {        
        pce = pos->pieces[sq + KnDir[index]];
        if(pce != OFFBOARD && IsKn(pce) && PieceCol[pce]==side && ((sq+KnDir[index])!=fromsq)) {
	 
	    pieces[count]=sq+KnDir[index];
            count ++;

        }
    }
     
    
    // bishops
    for(index = 0; index < 4; ++index) {        
        dir = BiDir[index];
        t_sq = sq + dir;
        pce = pos->pieces[t_sq];
        while(pce != OFFBOARD) {
            if(pce != EMPTY) {
                if(IsBQ(pce) && PieceCol[pce] == side && (t_sq!=fromsq)) {
		    pieces[count]=t_sq;
                    count ++;

                }else if(t_sq != fromsq)
			break;
		

                
            }
            t_sq += dir;
            pce = pos->pieces[t_sq];
        }
    }
    int queenBeforeRook=FALSE;
    // rooks, queens
    for(index = 0; index < 4; ++index) { 
	queenBeforeRook=FALSE;
        dir = RkDir[index];
        t_sq = sq + dir;
        pce = pos->pieces[t_sq];
        while(pce != OFFBOARD) {
            if(pce != EMPTY) {
                if(IsRk(pce) && PieceCol[pce] == side && (t_sq != fromsq)) {
		    if(count>0)
		    {
			    if((pos->pieces[pieces[count-1]]==(side?bQ:wQ)) && !queenBeforeRook)
			    {
				int sq=pieces[count-1];
				pieces[count-1]=t_sq;
				pieces[count]=sq;
				
				count++;
		
				t_sq += dir;
				pce=pos->pieces[t_sq];
				continue;
			    }
			    if((pos->pieces[pieces[count-1]]==(side?bB:wB)) && (pos->pieces[pieces[count-2]]==(side?bQ:wQ)))
			    {
				int sq1=pieces[count-2];
				int sq2=pieces[count-1];
				pieces[count-2]=t_sq;
				pieces[count-1]=sq1;
				pieces[count]=sq2;
				
				count ++;
				
				t_sq += dir;
				pce=pos->pieces[t_sq];
				continue;
					
			    }
		     }
		    pieces[count]=t_sq;
                    count ++;
                }else if(IsQn(pce) && PieceCol[pce] == side && (t_sq!=fromsq)) {
		    pieces[count]=t_sq;
                    
		    queenBeforeRook=TRUE;
		    count ++;

		}
		else if(t_sq != fromsq)
			break;
                
            }
            t_sq += dir;
            pce = pos->pieces[t_sq];
        }
    }
       
    // kings
    for(index = 0; index < 8; ++index) {        
        pce = pos->pieces[sq + KiDir[index]];
        if(pce != OFFBOARD && IsKi(pce) && PieceCol[pce]==side && ((sq+KiDir[index])!=fromsq)) {
	    pieces[count]=sq+KiDir[index];
            count ++;

        }
    }
    
    return count;
      
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movl %edx, -0x14(%rsp)
movl %ecx, -0x18(%rsp)
movl %r8d, -0x1c(%rsp)
cmpl $0x63, -0x1c(%rsp)
jne 0x8748
movl $0x0, -0x30(%rsp)
jmp 0x8750
movl $0x1, -0x30(%rsp)
cmpl $0x0, -0x14(%rsp)
jne 0x87e2
movq -0x8(%rsp), %rax
movl -0x18(%rsp), %ecx
subl $0xb, %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x879c
movl -0x18(%rsp), %eax
subl $0xb, %eax
cmpl -0x1c(%rsp), %eax
je 0x879c
movl -0x18(%rsp), %edx
subl $0xb, %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
movq -0x8(%rsp), %rax
movl -0x18(%rsp), %ecx
subl $0x9, %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x87dd
movl -0x18(%rsp), %eax
subl $0x9, %eax
cmpl -0x1c(%rsp), %eax
je 0x87dd
movl -0x18(%rsp), %edx
subl $0x9, %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x8866
movq -0x8(%rsp), %rax
movl -0x18(%rsp), %ecx
addl $0xb, %ecx
movslq %ecx, %rcx
cmpl $0x7, (%rax,%rcx,4)
jne 0x8823
movl -0x18(%rsp), %eax
addl $0xb, %eax
cmpl -0x1c(%rsp), %eax
je 0x8823
movl -0x18(%rsp), %edx
addl $0xb, %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
movq -0x8(%rsp), %rax
movl -0x18(%rsp), %ecx
addl $0x9, %ecx
movslq %ecx, %rcx
cmpl $0x7, (%rax,%rcx,4)
jne 0x8864
movl -0x18(%rsp), %eax
addl $0x9, %eax
cmpl -0x1c(%rsp), %eax
je 0x8864
movl -0x18(%rsp), %edx
addl $0x9, %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x8866
movl $0x0, -0x24(%rsp)
cmpl $0x8, -0x24(%rsp)
jge 0x891f
movq -0x8(%rsp), %rax
movl -0x18(%rsp), %ecx
movslq -0x24(%rsp), %rsi
leaq 0x29a2(%rip), %rdx      # 0xb230
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
cmpl $0x64, -0x20(%rsp)
je 0x890d
movslq -0x20(%rsp), %rcx
leaq 0x31e2(%rip), %rax      # 0xba90
cmpl $0x0, (%rax,%rcx,4)
je 0x890d
movslq -0x20(%rsp), %rcx
leaq 0x2aa0(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0x14(%rsp), %eax
jne 0x890d
movl -0x18(%rsp), %eax
movslq -0x24(%rsp), %rdx
leaq 0x2957(%rip), %rcx      # 0xb230
addl (%rcx,%rdx,4), %eax
cmpl -0x1c(%rsp), %eax
je 0x890d
movl -0x18(%rsp), %edx
movslq -0x24(%rsp), %rcx
leaq 0x293e(%rip), %rax      # 0xb230
addl (%rax,%rcx,4), %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x890f
movl -0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rsp)
jmp 0x886e
movl $0x0, -0x24(%rsp)
cmpl $0x4, -0x24(%rsp)
jge 0x8a07
movslq -0x24(%rsp), %rcx
leaq 0x28c2(%rip), %rax      # 0xb200
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rsp)
movl -0x18(%rsp), %eax
addl -0x2c(%rsp), %eax
movl %eax, -0x28(%rsp)
movq -0x8(%rsp), %rax
movslq -0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
cmpl $0x64, -0x20(%rsp)
je 0x89f5
cmpl $0x0, -0x20(%rsp)
je 0x89d3
movslq -0x20(%rsp), %rcx
leaq 0x3090(%rip), %rax      # 0xba10
cmpl $0x0, (%rax,%rcx,4)
je 0x89c3
movslq -0x20(%rsp), %rcx
leaq 0x29ce(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0x14(%rsp), %eax
jne 0x89c3
movl -0x28(%rsp), %eax
cmpl -0x1c(%rsp), %eax
je 0x89c3
movl -0x28(%rsp), %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x89d1
movl -0x28(%rsp), %eax
cmpl -0x1c(%rsp), %eax
je 0x89cf
jmp 0x89f5
jmp 0x89d1
jmp 0x89d3
movl -0x2c(%rsp), %eax
addl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movq -0x8(%rsp), %rax
movslq -0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
jmp 0x8962
jmp 0x89f7
movl -0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rsp)
jmp 0x8927
movl $0x0, -0x34(%rsp)
movl $0x0, -0x24(%rsp)
cmpl $0x4, -0x24(%rsp)
jge 0x8d1d
movl $0x0, -0x34(%rsp)
movslq -0x24(%rsp), %rcx
leaq 0x281a(%rip), %rax      # 0xb250
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rsp)
movl -0x18(%rsp), %eax
addl -0x2c(%rsp), %eax
movl %eax, -0x28(%rsp)
movq -0x8(%rsp), %rax
movslq -0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
cmpl $0x64, -0x20(%rsp)
je 0x8d0b
cmpl $0x0, -0x20(%rsp)
je 0x8ce9
movslq -0x20(%rsp), %rcx
leaq 0x3054(%rip), %rax      # 0xbad0
cmpl $0x0, (%rax,%rcx,4)
je 0x8c80
movslq -0x20(%rsp), %rcx
leaq 0x28ce(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0x14(%rsp), %eax
jne 0x8c80
movl -0x28(%rsp), %eax
cmpl -0x1c(%rsp), %eax
je 0x8c80
cmpl $0x0, -0x30(%rsp)
jle 0x8c62
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
movl -0x30(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %eax
movl -0x14(%rsp), %esi
movl $0x5, %ecx
movl $0xb, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
cmpl %ecx, %eax
jne 0x8b5c
cmpl $0x0, -0x34(%rsp)
jne 0x8b5c
movq -0x10(%rsp), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rsp)
movl -0x28(%rsp), %edx
movq -0x10(%rsp), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rsp), %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
movl -0x2c(%rsp), %eax
addl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movq -0x8(%rsp), %rax
movslq -0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
jmp 0x8a5a
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
movl -0x30(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %eax
movl -0x14(%rsp), %esi
movl $0x3, %ecx
movl $0x9, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
cmpl %ecx, %eax
jne 0x8c60
movq -0x8(%rsp), %rax
movq -0x10(%rsp), %rcx
movl -0x30(%rsp), %edx
subl $0x2, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %eax
movl -0x14(%rsp), %esi
movl $0x5, %ecx
movl $0xb, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
cmpl %ecx, %eax
jne 0x8c60
movq -0x10(%rsp), %rax
movl -0x30(%rsp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rsp)
movq -0x10(%rsp), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rsp)
movl -0x28(%rsp), %edx
movq -0x10(%rsp), %rax
movl -0x30(%rsp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rsp), %edx
movq -0x10(%rsp), %rax
movl -0x30(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x40(%rsp), %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
movl -0x2c(%rsp), %eax
addl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movq -0x8(%rsp), %rax
movslq -0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
jmp 0x8a5a
jmp 0x8c62
movl -0x28(%rsp), %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x8ce7
movslq -0x20(%rsp), %rcx
leaq 0x2ec4(%rip), %rax      # 0xbb50
cmpl $0x0, (%rax,%rcx,4)
je 0x8cd7
movslq -0x20(%rsp), %rcx
leaq 0x26c2(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0x14(%rsp), %eax
jne 0x8cd7
movl -0x28(%rsp), %eax
cmpl -0x1c(%rsp), %eax
je 0x8cd7
movl -0x28(%rsp), %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x1, -0x34(%rsp)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x8ce5
movl -0x28(%rsp), %eax
cmpl -0x1c(%rsp), %eax
je 0x8ce3
jmp 0x8d0b
jmp 0x8ce5
jmp 0x8ce7
jmp 0x8ce9
movl -0x2c(%rsp), %eax
addl -0x28(%rsp), %eax
movl %eax, -0x28(%rsp)
movq -0x8(%rsp), %rax
movslq -0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
jmp 0x8a5a
jmp 0x8d0d
movl -0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rsp)
jmp 0x8a17
movl $0x0, -0x24(%rsp)
cmpl $0x8, -0x24(%rsp)
jge 0x8dd6
movq -0x8(%rsp), %rax
movl -0x18(%rsp), %ecx
movslq -0x24(%rsp), %rsi
leaq 0x24cb(%rip), %rdx      # 0xb210
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rsp)
cmpl $0x64, -0x20(%rsp)
je 0x8dc4
movslq -0x20(%rsp), %rcx
leaq 0x2ceb(%rip), %rax      # 0xba50
cmpl $0x0, (%rax,%rcx,4)
je 0x8dc4
movslq -0x20(%rsp), %rcx
leaq 0x25e9(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0x14(%rsp), %eax
jne 0x8dc4
movl -0x18(%rsp), %eax
movslq -0x24(%rsp), %rdx
leaq 0x2480(%rip), %rcx      # 0xb210
addl (%rcx,%rdx,4), %eax
cmpl -0x1c(%rsp), %eax
je 0x8dc4
movl -0x18(%rsp), %edx
movslq -0x24(%rsp), %rcx
leaq 0x2467(%rip), %rax      # 0xb210
addl (%rax,%rcx,4), %edx
movq -0x10(%rsp), %rax
movslq -0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x8dc6
movl -0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rsp)
jmp 0x8d25
movl -0x30(%rsp), %eax
retq
nopl (%rax,%rax)