// File: /workspace/github_c_makefile_star2_O3/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 0x1563
cmpl $0x7, 0x2c(%rdx,%rcx,4)
je 0x1571
cmpl $0x7, 0x24(%rdx,%rcx,4)
je 0x1571
jmp 0x1572
cmpl $0x1, -0x2c(%rdx,%rcx,4)
je 0x1571
cmpl $0x1, -0x24(%rdx,%rcx,4)
jne 0x1572
retq
xorl %r8d, %r8d
leaq 0x5cc4(%rip), %r9       # 0x7240
movslq %edi, %rax
leaq 0x5dea(%rip), %rcx      # 0x7370
movslq (%r8,%r9), %r10
addq %rax, %r10
movl (%rdx,%r10,4), %r10d
cmpq $0x8, %r10
je 0x159d
cmpl $0x2, %r10d
jne 0x15a7
cmpl %esi, (%rcx,%r10,4)
je 0x1682
addq $0x4, %r8
cmpq $0x20, %r8
jne 0x1586
pushq %r14
pushq %rbx
xorl %r8d, %r8d
leaq 0x5ca2(%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 0x15e4
addq %r11, %rbx
jmp 0x15d7
cmpl $0x64, %r14d
je 0x15fa
btq %r14, %r10
jb 0x15fa
cmpl %esi, (%rcx,%r14,4)
je 0x1688
incq %r8
cmpq $0x4, %r8
jne 0x15c4
xorl %r8d, %r8d
leaq 0x5c03(%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 0x1633
addq %r11, %rbx
jmp 0x1626
cmpl $0x64, %r14d
je 0x1645
btq %r14, %r10
jb 0x1645
cmpl %esi, (%rcx,%r14,4)
je 0x1688
incq %r8
cmpq $0x4, %r8
jne 0x1613
xorl %edi, %edi
leaq 0x5bc9(%rip), %r8       # 0x7220
movslq (%rdi,%r8), %r9
addq %rax, %r9
movl (%rdx,%r9,4), %r9d
cmpq $0xc, %r9
je 0x166e
cmpl $0x6, %r9d
jne 0x1674
cmpl %esi, (%rcx,%r9,4)
je 0x1688
addq $0x4, %rdi
cmpq $0x20, %rdi
jne 0x1657
xorl %eax, %eax
jmp 0x168d
movl $0x1, %eax
retq
movl $0x1, %eax
popq %rbx
popq %r14
retq