// File: /workspace/github_c_makefile_star2_O1/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:
movslq %edi, %rcx
movl $0x1, %eax
testl %esi, %esi
je 0x155f
cmpl $0x7, 0x2c(%rdx,%rcx,4)
je 0x156d
cmpl $0x7, 0x24(%rdx,%rcx,4)
je 0x156d
jmp 0x156e
cmpl $0x1, -0x2c(%rdx,%rcx,4)
je 0x156d
cmpl $0x1, -0x24(%rdx,%rcx,4)
jne 0x156e
retq
xorl %r8d, %r8d
leaq 0x5cc8(%rip), %r9       # 0x7240
movslq %edi, %rax
leaq 0x5dee(%rip), %rcx      # 0x7370
movslq (%r8,%r9), %r10
addq %rax, %r10
movslq (%rdx,%r10,4), %r10
cmpq $0x8, %r10
je 0x1599
cmpl $0x2, %r10d
jne 0x15a3
cmpl %esi, (%rcx,%r10,4)
je 0x167e
addq $0x4, %r8
cmpq $0x20, %r8
jne 0x1582
pushq %r14
pushq %rbx
xorl %r8d, %r8d
leaq 0x5ca6(%rip), %r9       # 0x7260
movl $0x13cf, %r10d          # imm = 0x13CF
movslq (%r9,%r8,4), %r11
leal (%r11,%rdi), %ebx
movslq %ebx, %rbx
leaq (%rdx,%rbx,4), %rbx
shlq $0x2, %r11
movslq (%rbx), %r14
testq %r14, %r14
jne 0x15e0
addq %r11, %rbx
jmp 0x15d3
cmpl $0x64, %r14d
je 0x15f6
btq %r14, %r10
jb 0x15f6
cmpl %esi, (%rcx,%r14,4)
je 0x1684
incq %r8
cmpq $0x4, %r8
jne 0x15c0
xorl %r8d, %r8d
leaq 0x5c07(%rip), %r9       # 0x7210
movl $0x15d7, %r10d          # imm = 0x15D7
movslq (%r9,%r8,4), %r11
leal (%r11,%rdi), %ebx
movslq %ebx, %rbx
leaq (%rdx,%rbx,4), %rbx
shlq $0x2, %r11
movslq (%rbx), %r14
testq %r14, %r14
jne 0x162f
addq %r11, %rbx
jmp 0x1622
cmpl $0x64, %r14d
je 0x1641
btq %r14, %r10
jb 0x1641
cmpl %esi, (%rcx,%r14,4)
je 0x1684
incq %r8
cmpq $0x4, %r8
jne 0x160f
xorl %edi, %edi
leaq 0x5bcd(%rip), %r8       # 0x7220
movslq (%rdi,%r8), %r9
addq %rax, %r9
movslq (%rdx,%r9,4), %r9
cmpq $0xc, %r9
je 0x166a
cmpl $0x6, %r9d
jne 0x1670
cmpl %esi, (%rcx,%r9,4)
je 0x1684
addq $0x4, %rdi
cmpq $0x20, %rdi
jne 0x1653
xorl %eax, %eax
jmp 0x1689
movl $0x1, %eax
retq
movl $0x1, %eax
popq %rbx
popq %r14
retq