// File: /workspace/github_cpp_makefile_star2_O3/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 0x24abc(%rip), %r13     # 0x296b4
xorl %ebp, %ebp
movb $0x0, (%rsp)
xorl %r12d, %r12d
movl %ebp, %edi
movl %r12d, %esi
callq 0xca94
movl %eax, %eax
movl (%rbx,%rax,4), %eax
addl $0x6, %eax
cmpl $0xc, %eax
ja 0x4d05
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x2080
movw $0x206b, (%rsp,%rax)    # imm = 0x206B
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x2051, (%rsp,%rax)    # imm = 0x2051
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x206e, (%rsp,%rax)    # imm = 0x206E
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x204b, (%rsp,%rax)    # imm = 0x204B
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x2042, (%rsp,%rax)    # imm = 0x2042
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x2072, (%rsp,%rax)    # imm = 0x2072
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x2062, (%rsp,%rax)    # imm = 0x2062
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x2050, (%rsp,%rax)    # imm = 0x2050
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x2071, (%rsp,%rax)    # imm = 0x2071
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x2070, (%rsp,%rax)    # imm = 0x2070
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x202d, (%rsp,%rax)    # imm = 0x202D
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x2052, (%rsp,%rax)    # imm = 0x2052
jmp 0x4d00
movq %r14, %rdi
callq 0x2080
movw $0x204e, (%rsp,%rax)    # imm = 0x204E
movb $0x0, 0x2(%rsp,%rax)
incl %r12d
cmpl $0x8, %r12d
jne 0x4c01
cmpl $0x2, %ebp
je 0x4dfc
cmpl $0x3, %ebp
je 0x4dd4
cmpl $0x4, %ebp
jne 0x4e71
movl 0x140(%rbx), %r12d
movq %r14, %rdi
callq 0x2080
addq %rsp, %rax
testl %r12d, %r12d
je 0x4e59
movabsq $0x3d676e696c7473, %rcx # imm = 0x3D676E696C7473
movq %rcx, 0x5(%rax)
movabsq $0x6c74736163202020, %rcx # imm = 0x6C74736163202020
movq %rcx, (%rax)
movq %rbx, %rdi
callq 0xa921
testb %al, %al
je 0x4d7d
movq %r14, %rdi
callq 0x2080
movw $0x4b, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa92a
testb %al, %al
je 0x4d97
movq %r14, %rdi
callq 0x2080
movw $0x51, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa935
testb %al, %al
je 0x4db1
movq %r14, %rdi
callq 0x2080
movw $0x6b, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa941
testb %al, %al
je 0x4e71
movq %r14, %rdi
callq 0x2080
movw $0x71, (%rsp,%rax)
jmp 0x4e71
movl 0x13c(%rbx), %edi
cmpl $0x40, %edi
jne 0x4e1d
movq %r14, %rdi
callq 0x2080
movabsq $0x7065206f6e202020, %rcx # imm = 0x7065206F6E202020
movq %rcx, (%rsp,%rax)
movb $0x0, 0x8(%rsp,%rax)
jmp 0x4e71
movl 0x138(%rbx), %r12d
movq %r14, %rdi
callq 0x2080
addq %rsp, %rax
cmpl $0x1, %r12d
jne 0x4e49
movups 0x248f1(%rip), %xmm0    # 0x2970c
jmp 0x4e50
movq %r15, %rsi
callq 0xdfc5
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
jmp 0x4e71
movups 0x248cd(%rip), %xmm0    # 0x2971d
movups %xmm0, (%rax)
movb $0x0, 0x10(%rax)
jmp 0x4e71
movups 0x248eb(%rip), %xmm0    # 0x2974b
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 0x64b9
incl %ebp
cmpl $0x8, %ebp
jne 0x4bfa
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq