// File: /workspace/github_cpp_makefile_star2_O2/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 0x22d2c(%rip), %r13     # 0x27684
xorl %ebp, %ebp
cmpl $0x8, %ebp
je 0x4bfe
movb $0x0, (%rsp)
xorl %r12d, %r12d
cmpl $0x8, %r12d
je 0x4a80
movl %ebp, %edi
movl %r12d, %esi
callq 0xc02a
movl %eax, %eax
movl (%rbx,%rax,4), %eax
addl $0x6, %eax
cmpl $0xc, %eax
ja 0x4a78
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x2080
movw $0x206b, (%rsp,%rax)    # imm = 0x206B
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x2051, (%rsp,%rax)    # imm = 0x2051
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x206e, (%rsp,%rax)    # imm = 0x206E
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x204b, (%rsp,%rax)    # imm = 0x204B
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x2042, (%rsp,%rax)    # imm = 0x2042
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x2072, (%rsp,%rax)    # imm = 0x2072
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x2062, (%rsp,%rax)    # imm = 0x2062
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x2050, (%rsp,%rax)    # imm = 0x2050
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x2071, (%rsp,%rax)    # imm = 0x2071
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x2070, (%rsp,%rax)    # imm = 0x2070
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x202d, (%rsp,%rax)    # imm = 0x202D
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x2052, (%rsp,%rax)    # imm = 0x2052
jmp 0x4a73
movq %r14, %rdi
callq 0x2080
movw $0x204e, (%rsp,%rax)    # imm = 0x204E
movb $0x0, 0x2(%rsp,%rax)
incl %r12d
jmp 0x496a
cmpl $0x2, %ebp
je 0x4b6a
cmpl $0x3, %ebp
je 0x4b42
cmpl $0x4, %ebp
jne 0x4bdf
movl 0x140(%rbx), %r12d
movq %r14, %rdi
callq 0x2080
addq %rsp, %rax
testl %r12d, %r12d
je 0x4bc7
movabsq $0x3d676e696c7473, %rcx # imm = 0x3D676E696C7473
movq %rcx, 0x5(%rax)
movabsq $0x6c74736163202020, %rcx # imm = 0x6C74736163202020
movq %rcx, (%rax)
movq %rbx, %rdi
callq 0xa0ba
testb %al, %al
je 0x4aeb
movq %r14, %rdi
callq 0x2080
movw $0x4b, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa0c3
testb %al, %al
je 0x4b05
movq %r14, %rdi
callq 0x2080
movw $0x51, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa0ce
testb %al, %al
je 0x4b1f
movq %r14, %rdi
callq 0x2080
movw $0x6b, (%rsp,%rax)
movq %rbx, %rdi
callq 0xa0da
testb %al, %al
je 0x4bdf
movq %r14, %rdi
callq 0x2080
movw $0x71, (%rsp,%rax)
jmp 0x4bdf
movl 0x13c(%rbx), %edi
cmpl $0x40, %edi
jne 0x4b8b
movq %r14, %rdi
callq 0x2080
movabsq $0x7065206f6e202020, %rcx # imm = 0x7065206F6E202020
movq %rcx, (%rsp,%rax)
movb $0x0, 0x8(%rsp,%rax)
jmp 0x4bdf
movl 0x138(%rbx), %r12d
movq %r14, %rdi
callq 0x2080
addq %rsp, %rax
cmpl $0x1, %r12d
jne 0x4bb7
movups 0x22b53(%rip), %xmm0    # 0x276dc
jmp 0x4bbe
movq %r15, %rsi
callq 0xd527
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 0x4bdf
movups 0x22b2f(%rip), %xmm0    # 0x276ed
movups %xmm0, (%rax)
movb $0x0, 0x10(%rax)
jmp 0x4bdf
movups 0x22b4d(%rip), %xmm0    # 0x2771b
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 0x5fdd
incl %ebp
jmp 0x495a
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq