// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/go.c
// Function: test_go
void test_go(char *cfg, char *weights, int multi)
{
    int i;
    network *net = load_network(cfg, weights, 0);
    set_batch_network(net, 1);
    srand(time(0));
    float *board = calloc(19*19*3, sizeof(float));
    flip_board(board);
    float *move = calloc(19*19+1, sizeof(float));
    int color = 1;
    while(1){
        float result = predict_move2(net, board, move, multi);
        printf("%.2f%% Win Chance\n", (result+1)/2*100);

        int indexes[nind];
        int row, col;
        top_k(move, 19*19+1, nind, indexes);
        print_board(stderr, board, color, indexes);
        for(i = 0; i < nind; ++i){
            int index = indexes[i];
            row = index / 19;
            col = index % 19;
            if(row == 19){
                printf("%d: Pass, %.2f%%\n", i+1, move[index]*100);
            } else {
                printf("%d: %c %d, %.2f%%\n", i+1, col + 'A' + 1*(col > 7 && noi), (inverted)?19 - row : row+1, move[index]*100);
            }
        }
        //if(color == 1) printf("\u25EF Enter move: ");
        //else printf("\u25C9 Enter move: ");
        if(color == 1) printf("X Enter move: ");
        else printf("O Enter move: ");

        char c;
        char *line = fgetl(stdin);
        int picked = 1;
        int dnum = sscanf(line, "%d", &picked);
        int cnum = sscanf(line, "%c", &c);
        if (strlen(line) == 0 || dnum) {
            --picked;
            if (picked < nind){
                int index = indexes[picked];
                row = index / 19;
                col = index % 19;
                if(row < 19){
                    move_go(board, 1, row, col);
                }
            }
        } else if (cnum){
            if (c <= 'T' && c >= 'A'){
                int num = sscanf(line, "%c %d", &c, &row);
                row = (inverted)?19 - row : row-1;
                col = c - 'A';
                if (col > 7 && noi) col -= 1;
                if (num == 2) move_go(board, 1, row, col);
            } else if (c == 'p') {
                // Pass
            } else if(c=='b' || c == 'w'){
                char g;
                int num = sscanf(line, "%c %c %d", &g, &c, &row);
                row = (inverted)?19 - row : row-1;
                col = c - 'A';
                if (col > 7 && noi) col -= 1;
                if (num == 3) {
                    int mc = (g == 'b') ? 1 : -1;
                    if (mc == color) {
                        board[row*19 + col] = 1;
                    } else {
                        board[19*19 + row*19 + col] = 1;
                    }
                }
            } else if(c == 'c'){
                char g;
                int num = sscanf(line, "%c %c %d", &g, &c, &row);
                row = (inverted)?19 - row : row-1;
                col = c - 'A';
                if (col > 7 && noi) col -= 1;
                if (num == 3) {
                    board[row*19 + col] = 0;
                    board[19*19 + row*19 + col] = 0;
                }
            }
        }
        free(line);
        flip_board(board);
        color = -color;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, -0x44(%rbp)
xorl %edx, %edx
callq 0x22658
pushq $0x1
popq %r12
movq %rax, -0x58(%rbp)
movq %rax, %rdi
movl %r12d, %esi
callq 0x22f00
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
pushq $0x4
popq %rbx
movl $0x43b, %edi            # imm = 0x43B
movq %rbx, %rsi
callq 0x3250
movq %rax, %r15
movq %rax, %rdi
callq 0x3a26f
movl $0x16a, %edi            # imm = 0x16A
movq %rbx, %rsi
callq 0x3250
movq %rax, %r13
pushq $0x13
popq %rbx
movq %r15, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rdx
movl -0x44(%rbp), %ecx
callq 0x3a2c3
addss 0xf7b3(%rip), %xmm0     # 0x4c008
mulss 0xf9d7(%rip), %xmm0     # 0x4c234
mulss 0xf9df(%rip), %xmm0     # 0x4c244
cvtss2sd %xmm0, %xmm0
leaq 0x14fb8(%rip), %rdi     # 0x51828
movb $0x1, %al
callq 0x3160
movq %rsp, -0x60(%rbp)
movq %rsp, %r14
addq $-0x30, %r14
movq %r14, %rsp
movq %r13, %rdi
movl $0x16a, %esi            # imm = 0x16A
pushq $0xa
popq %rdx
movq %r14, %rcx
callq 0x438a
movq 0x27759(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
movq %r15, %rsi
movl %r12d, -0x38(%rbp)
movl %r12d, %edx
movq %r14, %rcx
callq 0x3a0b6
xorl %r12d, %r12d
cmpq $0xa, %r12
je 0x3c95d
movl (%r14,%r12,4), %ecx
movl %ecx, %eax
cltd
idivl %ebx
movl %eax, -0x30(%rbp)
leal -0x169(%rcx), %esi
incq %r12
cmpl $0x12, %esi
ja 0x3c901
movss (%r13,%rcx,4), %xmm0
mulss 0xf95a(%rip), %xmm0     # 0x4c244
cvtss2sd %xmm0, %xmm0
leaq 0x14f46(%rip), %rdi     # 0x5183b
movl %r12d, %esi
movb $0x1, %al
callq 0x3160
jmp 0x3c8b7
cmpl $0x8, %edx
setge %sil
cmpl $0x0, 0x27a21(%rip)     # 0x64330
setne %dil
andb %sil, %dil
movzbl %dil, %esi
addl %esi, %edx
addl $0x41, %edx
movl %ebx, %esi
subl %eax, %esi
incl %eax
cmpl $0x0, 0x27a00(%rip)     # 0x6432c
cmovnel %esi, %eax
movslq %ecx, %rcx
movss (%r13,%rcx,4), %xmm0
mulss 0xf903(%rip), %xmm0     # 0x4c244
cvtss2sd %xmm0, %xmm0
leaq 0x14f01(%rip), %rdi     # 0x5184d
movl %r12d, %esi
movl %eax, %ecx
movb $0x1, %al
callq 0x3160
jmp 0x3c8b7
cmpl $0x1, -0x38(%rbp)
leaq 0x14f07(%rip), %rdi     # 0x5186f
leaq 0x14ef1(%rip), %rax     # 0x51860
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x3160
movq 0x27657(%rip), %rax     # 0x63fd8
movq (%rax), %rdi
callq 0x3d32
movq %rax, %r12
movl $0x1, -0x3c(%rbp)
movq %rax, %rdi
leaq 0x152a6(%rip), %rsi     # 0x51c43
leaq -0x3c(%rbp), %rdx
xorl %eax, %eax
callq 0x3320
movl %eax, %r15d
movq %r12, %rdi
leaq 0x14ec9(%rip), %rsi     # 0x5187e
leaq -0x29(%rbp), %rdx
xorl %eax, %eax
callq 0x3320
movq %r12, %rdi
testl %r15d, %r15d
jne 0x3ca55
cmpb $0x0, (%rdi)
je 0x3ca55
testl %eax, %eax
movq -0x50(%rbp), %r15
movl -0x38(%rbp), %r12d
je 0x3ca97
movzbl -0x29(%rbp), %eax
leal -0x41(%rax), %ecx
cmpb $0x13, %cl
ja 0x3cab0
movq %rdi, %r14
leaq 0x14e85(%rip), %rsi     # 0x51884
leaq -0x29(%rbp), %rdx
leaq -0x30(%rbp), %rcx
xorl %eax, %eax
callq 0x3320
movq %r14, %rdi
movl -0x30(%rbp), %edx
movl %ebx, %ecx
subl %edx, %ecx
decl %edx
cmpl $0x0, 0x2790b(%rip)     # 0x6432c
cmovnel %ecx, %edx
movl %edx, -0x30(%rbp)
cmpl $0x2, %eax
jne 0x3ca97
movsbl -0x29(%rbp), %eax
cmpl $0x49, %eax
setge %cl
cmpl $0x0, 0x278f3(%rip)     # 0x64330
setne %sil
andb %cl, %sil
movzbl %sil, %ecx
xorl $-0x41, %ecx
addl %eax, %ecx
movq %r15, %rdi
pushq $0x1
popq %rsi
jmp 0x3ca8f
movslq -0x3c(%rbp), %rax
leal -0x1(%rax), %ecx
movl %ecx, -0x3c(%rbp)
cmpq $0xa, %rax
movq -0x50(%rbp), %r15
movl -0x38(%rbp), %r12d
jg 0x3ca97
movl -0x4(%r14,%rax,4), %esi
movl %esi, %eax
cltd
idivl %ebx
movl %eax, -0x30(%rbp)
cmpl $0x168, %esi            # imm = 0x168
jg 0x3ca97
movl %edx, %ecx
movq %rdi, %r14
movq %r15, %rdi
pushq $0x1
popq %rsi
movl %eax, %edx
callq 0x3a4b9
movq %r14, %rdi
callq 0x3040
movq %r15, %rdi
callq 0x3a26f
negl %r12d
movq -0x60(%rbp), %rsp
jmp 0x3c83b
cmpl $0x77, %eax
je 0x3cac3
cmpl $0x63, %eax
je 0x3cb4d
cmpl $0x62, %eax
jne 0x3ca97
movq %rdi, %r14
leaq 0x14db4(%rip), %rsi     # 0x51881
leaq -0x31(%rbp), %rdx
leaq -0x29(%rbp), %rcx
leaq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x3320
movl -0x30(%rbp), %ecx
movl %ebx, %edx
subl %ecx, %edx
decl %ecx
cmpl $0x0, 0x2783c(%rip)     # 0x6432c
cmovnel %edx, %ecx
movl %ecx, -0x30(%rbp)
cmpl $0x3, %eax
jne 0x3ca94
movsbl -0x29(%rbp), %eax
cmpl $0x49, %eax
setge %dl
cmpl $0x0, 0x27824(%rip)     # 0x64330
setne %sil
andb %dl, %sil
movzbl %sil, %edx
xorl $-0x41, %edx
addl %eax, %edx
xorl %eax, %eax
cmpb $0x62, -0x31(%rbp)
sete %al
leal -0x1(,%rax,2), %eax
imull $0x13, %ecx, %ecx
leal 0x169(%rcx), %esi
cmpl %r12d, %eax
cmovel %ecx, %esi
addl %edx, %esi
movslq %esi, %rax
movl $0x3f800000, (%r15,%rax,4) # imm = 0x3F800000
jmp 0x3ca94
movq %rdi, %r14
leaq 0x14d2a(%rip), %rsi     # 0x51881
leaq -0x3d(%rbp), %rdx
leaq -0x29(%rbp), %rcx
leaq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x3320
movl -0x30(%rbp), %ecx
movl %ebx, %edx
subl %ecx, %edx
decl %ecx
cmpl $0x0, 0x277b2(%rip)     # 0x6432c
cmovnel %edx, %ecx
movl %ecx, -0x30(%rbp)
cmpl $0x3, %eax
jne 0x3ca94
movsbl -0x29(%rbp), %eax
cmpl $0x49, %eax
setge %dl
cmpl $0x0, 0x27796(%rip)     # 0x64330
setne %sil
andb %dl, %sil
movzbl %sil, %edx
xorl $-0x41, %edx
addl %eax, %edx
imull $0x13, %ecx, %eax
leal (%rdx,%rax), %ecx
movslq %ecx, %rcx
andl $0x0, (%r15,%rcx,4)
addl %edx, %eax
addl $0x169, %eax            # imm = 0x169
cltq
andl $0x0, (%r15,%rax,4)
jmp 0x3ca94