// File: /workspace/github_cpp_makefile_star2_O1/jswaff[P]prophet3/src/drawboard.cpp
// Function: draw_board(position*)
void draw_board(position *p) {
    char text[100];

    for (int r=0;r<8;r++) {  // every rank
        strcpy(text,"");
        for (int f=0;f<8;f++) { // every file
            switch(p->piece[get_square((rank_t)r,(file_t)f)]) {
            case NO_PIECE: strcat(text,"- "); break;
            case PAWN: strcat(text,"P "); break;
            case -PAWN: strcat(text,"p "); break;
            case ROOK: strcat(text,"R "); break;
            case -ROOK: strcat(text,"r "); break;
            case BISHOP: strcat(text,"B "); break;
            case -BISHOP: strcat(text,"b "); break;
            case KNIGHT: strcat(text,"N "); break;
            case -KNIGHT: strcat(text,"n "); break;
            case QUEEN: strcat(text,"Q "); break;
            case -QUEEN: strcat(text,"q "); break;
            case KING: strcat(text,"K "); break;
            case -KING: strcat(text,"k "); break;
            }
        }

        // print the player to move
        if (r==RANK_6) {
            if (p->player==WHITE) {
                strcat(text,"   white to move");
            } else {
                strcat(text,"   black to move");
            }
        }

        // print the en passant square
        if (r==RANK_5) {
            if (p->ep_sq==NO_SQUARE) {
                strcat(text,"   no ep");
            } else {
                char buffer[3];
                sq_to_str(p->ep_sq,buffer);
                strcat(text,"   ep=");
                strcat(text,buffer);
            }
        }

        // print the castling rights on the fourth row
        if (r==RANK_4) {
            if (p->castling_rights) {
                strcat(text,"   castling=");
                if (can_castle_wk(p))
                    strcat(text,"K");
                if (can_castle_wq(p))
                    strcat(text,"Q");
                if (can_castle_bk(p))
                    strcat(text,"k");
                if (can_castle_bq(p))
                    strcat(text,"q");
            } else {
                strcat(text,"   no castling rights");
            }
        }

        strcat(text,"\n");
        print(text);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq %rsp, %r14
leaq 0x65(%rsp), %r15
leaq 0x24ad0(%rip), %r13     # 0x2966c
xorl %ebp, %ebp
movb $0x0, (%rsp)
xorl %r12d, %r12d
movl %ebp, %edi
movl %r12d, %esi
callq 0xcaa0
movl %eax, %eax
movl (%rbx,%rax,4), %eax
addl $0x6, %eax
cmpl $0xc, %eax
ja 0x4ca9
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x2080
movw $0x206b, (%rsp,%rax)    # imm = 0x206B
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x2051, (%rsp,%rax)    # imm = 0x2051
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x206e, (%rsp,%rax)    # imm = 0x206E
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x204b, (%rsp,%rax)    # imm = 0x204B
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x2042, (%rsp,%rax)    # imm = 0x2042
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x2072, (%rsp,%rax)    # imm = 0x2072
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x2062, (%rsp,%rax)    # imm = 0x2062
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x2050, (%rsp,%rax)    # imm = 0x2050
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x2071, (%rsp,%rax)    # imm = 0x2071
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x2070, (%rsp,%rax)    # imm = 0x2070
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x202d, (%rsp,%rax)    # imm = 0x202D
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x2052, (%rsp,%rax)    # imm = 0x2052
jmp 0x4ca4
movq %r14, %rdi
callq 0x2080
movw $0x204e, (%rsp,%rax)    # imm = 0x204E
movb $0x0, 0x2(%rsp,%rax)
incl %r12d
cmpl $0x8, %r12d
jne 0x4ba5
cmpl $0x2, %ebp
je 0x4cc6
cmpl $0x3, %ebp
jne 0x4d55
jmp 0x4d03
movl 0x138(%rbx), %r12d
movq %r14, %rdi
callq 0x2080
addq %rsp, %rax
cmpl $0x1, %r12d
jne 0x4ce7
movups 0x249df(%rip), %xmm0    # 0x296c4
jmp 0x4cee
movups 0x249e7(%rip), %xmm0    # 0x296d5
movups %xmm0, (%rax)
movb $0x0, 0x10(%rax)
cmpl $0x4, %ebp
je 0x4d5e
cmpl $0x3, %ebp
jne 0x4e16
movl 0x13c(%rbx), %edi
cmpl $0x40, %edi
jne 0x4d2b
movq %r14, %rdi
callq 0x2080
movabsq $0x7065206f6e202020, %rcx # imm = 0x7065206F6E202020
movq %rcx, (%rsp,%rax)
movb $0x0, 0x8(%rsp,%rax)
jmp 0x4d55
movq %r15, %rsi
callq 0xe01b
movq %r14, %rdi
callq 0x2080
movl $0x65202020, (%rsp,%rax) # imm = 0x65202020
movl $0x3d7065, 0x3(%rsp,%rax) # imm = 0x3D7065
movq %r14, %rdi
movq %r15, %rsi
callq 0x22f0
cmpl $0x4, %ebp
jne 0x4e16
movl 0x140(%rbx), %r12d
movq %r14, %rdi
callq 0x2080
addq %rsp, %rax
testl %r12d, %r12d
je 0x4dfe
movabsq $0x3d676e696c7473, %rcx # imm = 0x3D676E696C7473
movq %rcx, 0x5(%rax)
movabsq $0x6c74736163202020, %rcx # imm = 0x6C74736163202020
movq %rcx, (%rax)
movq %rbx, %rdi
callq 0xa966
testb %al, %al
je 0x4dae
movq %r14, %rdi
callq 0x2080
movw $0x4b, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa96f
testb %al, %al
je 0x4dc8
movq %r14, %rdi
callq 0x2080
movw $0x51, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa97a
testb %al, %al
je 0x4de2
movq %r14, %rdi
callq 0x2080
movw $0x6b, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa986
testb %al, %al
je 0x4e16
movq %r14, %rdi
callq 0x2080
movw $0x71, (%rsp,%rax)
jmp 0x4e16
movups 0x248fe(%rip), %xmm0    # 0x29703
movups %xmm0, (%rax)
movabsq $0x73746867697220, %rcx # imm = 0x73746867697220
movq %rcx, 0xe(%rax)
movq %r14, %rdi
callq 0x2080
movw $0xa, (%rsp,%rax)
movq %r14, %rdi
xorl %eax, %eax
callq 0x640d
incl %ebp
cmpl $0x8, %ebp
jne 0x4b9e
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq