// File: /workspace/github_c_makefile_star2_O0/ArchLuke[P]YouSuck/Engine.c
// Function: SqAttacked
int SqAttacked(const int sq, const int side, const S_BOARD *pos) {

    int pce,index,t_sq,dir;
    
    // pawn
    if(side == WHITE) {
        if(pos->pieces[sq-11] == wP || pos->pieces[sq-9] == wP) {
            return TRUE;
        }
    } else {
        if(pos->pieces[sq+11] == bP || pos->pieces[sq+9] == bP) {
            return TRUE;
        }    
    }
    
    // knights
    for(index = 0; index < 8; ++index) {        
        pce = pos->pieces[sq + KnDir[index]];
        if(pce != OFFBOARD && IsKn(pce) && PieceCol[pce]==side) {
            return TRUE;
        }
    }
    
    // rooks, queens
    for(index = 0; index < 4; ++index) {        
        dir = RkDir[index];
        t_sq = sq + dir;
        pce = pos->pieces[t_sq];
        while(pce != OFFBOARD) {
            if(pce != EMPTY) {
                if(IsRQ(pce) && PieceCol[pce] == side) {
                    return TRUE;
                }
                break;
            }
            t_sq += dir;
            pce = pos->pieces[t_sq];
        }
    }
    
    // bishops, queens
    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) {
                    return TRUE;
                }
                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) {
            return TRUE;
        }
    }
    
    return FALSE;
    
}

// Assembly:
movl %edi, -0x8(%rsp)
movl %esi, -0xc(%rsp)
movq %rdx, -0x18(%rsp)
cmpl $0x0, -0xc(%rsp)
jne 0x179d
movq -0x18(%rsp), %rax
movl -0x8(%rsp), %ecx
subl $0xb, %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
je 0x178e
movq -0x18(%rsp), %rax
movl -0x8(%rsp), %ecx
subl $0x9, %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x179b
movl $0x1, -0x4(%rsp)
jmp 0x1a41
jmp 0x17d6
movq -0x18(%rsp), %rax
movl -0x8(%rsp), %ecx
addl $0xb, %ecx
movslq %ecx, %rcx
cmpl $0x7, (%rax,%rcx,4)
je 0x17c7
movq -0x18(%rsp), %rax
movl -0x8(%rsp), %ecx
addl $0x9, %ecx
movslq %ecx, %rcx
cmpl $0x7, (%rax,%rcx,4)
jne 0x17d4
movl $0x1, -0x4(%rsp)
jmp 0x1a41
jmp 0x17d6
movl $0x0, -0x20(%rsp)
cmpl $0x8, -0x20(%rsp)
jge 0x1851
movq -0x18(%rsp), %rax
movl -0x8(%rsp), %ecx
movslq -0x20(%rsp), %rsi
leaq 0x9a36(%rip), %rdx      # 0xb230
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rsp)
cmpl $0x64, -0x1c(%rsp)
je 0x1842
movslq -0x1c(%rsp), %rcx
leaq 0xa276(%rip), %rax      # 0xba90
cmpl $0x0, (%rax,%rcx,4)
je 0x1842
movslq -0x1c(%rsp), %rcx
leaq 0x9b34(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0xc(%rsp), %eax
jne 0x1842
movl $0x1, -0x4(%rsp)
jmp 0x1a41
jmp 0x1844
movl -0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x17de
movl $0x0, -0x20(%rsp)
cmpl $0x4, -0x20(%rsp)
jge 0x1909
movslq -0x20(%rsp), %rcx
leaq 0x99e0(%rip), %rax      # 0xb250
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rsp)
movl -0x8(%rsp), %eax
addl -0x28(%rsp), %eax
movl %eax, -0x24(%rsp)
movq -0x18(%rsp), %rax
movslq -0x24(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rsp)
cmpl $0x64, -0x1c(%rsp)
je 0x18f7
cmpl $0x0, -0x1c(%rsp)
je 0x18d8
movslq -0x1c(%rsp), %rcx
leaq 0xa262(%rip), %rax      # 0xbb10
cmpl $0x0, (%rax,%rcx,4)
je 0x18d6
movslq -0x1c(%rsp), %rcx
leaq 0x9aa0(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0xc(%rsp), %eax
jne 0x18d6
movl $0x1, -0x4(%rsp)
jmp 0x1a41
jmp 0x18f7
movl -0x28(%rsp), %eax
addl -0x24(%rsp), %eax
movl %eax, -0x24(%rsp)
movq -0x18(%rsp), %rax
movslq -0x24(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rsp)
jmp 0x1894
jmp 0x18f9
movl -0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x1859
movl $0x0, -0x20(%rsp)
cmpl $0x4, -0x20(%rsp)
jge 0x19c1
movslq -0x20(%rsp), %rcx
leaq 0x98d8(%rip), %rax      # 0xb200
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rsp)
movl -0x8(%rsp), %eax
addl -0x28(%rsp), %eax
movl %eax, -0x24(%rsp)
movq -0x18(%rsp), %rax
movslq -0x24(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rsp)
cmpl $0x64, -0x1c(%rsp)
je 0x19af
cmpl $0x0, -0x1c(%rsp)
je 0x1990
movslq -0x1c(%rsp), %rcx
leaq 0xa0aa(%rip), %rax      # 0xba10
cmpl $0x0, (%rax,%rcx,4)
je 0x198e
movslq -0x1c(%rsp), %rcx
leaq 0x99e8(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0xc(%rsp), %eax
jne 0x198e
movl $0x1, -0x4(%rsp)
jmp 0x1a41
jmp 0x19af
movl -0x28(%rsp), %eax
addl -0x24(%rsp), %eax
movl %eax, -0x24(%rsp)
movq -0x18(%rsp), %rax
movslq -0x24(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rsp)
jmp 0x194c
jmp 0x19b1
movl -0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x1911
movl $0x0, -0x20(%rsp)
cmpl $0x8, -0x20(%rsp)
jge 0x1a39
movq -0x18(%rsp), %rax
movl -0x8(%rsp), %ecx
movslq -0x20(%rsp), %rsi
leaq 0x982b(%rip), %rdx      # 0xb210
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rsp)
cmpl $0x64, -0x1c(%rsp)
je 0x1a2a
movslq -0x1c(%rsp), %rcx
leaq 0xa04b(%rip), %rax      # 0xba50
cmpl $0x0, (%rax,%rcx,4)
je 0x1a2a
movslq -0x1c(%rsp), %rcx
leaq 0x9949(%rip), %rax      # 0xb360
movl (%rax,%rcx,4), %eax
cmpl -0xc(%rsp), %eax
jne 0x1a2a
movl $0x1, -0x4(%rsp)
jmp 0x1a41
jmp 0x1a2c
movl -0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0x19c9
movl $0x0, -0x4(%rsp)
movl -0x4(%rsp), %eax
retq
nopw %cs:(%rax,%rax)