// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/go.c
// Function: self_go
void self_go(char *filename, char *weightfile, char *f2, char *w2, int multi)
{
    mcts_tree *tree1 = 0;
    mcts_tree *tree2 = 0;
    network *net = load_network(filename, weightfile, 0);
    //set_batch_network(net, 1);

    network *net2;
    if (f2) {
        net2 = parse_network_cfg(f2);
        if(w2){
            load_weights(net2, w2);
        }
    } else {
        net2 = calloc(1, sizeof(network));
        *net2 = *net;
    }
    srand(time(0));
    char boards[600][93];
    int count = 0;
    //set_batch_network(net, 1);
    //set_batch_network(net2, 1);
    float *board = calloc(19*19*3, sizeof(float));
    flip_board(board);
    float *one = calloc(19*19*3, sizeof(float));
    float *two = calloc(19*19*3, sizeof(float));
    int done = 0;
    int player = 1;
    int p1 = 0;
    int p2 = 0;
    int total = 0;
    float temp = .1;
    int mcts_iters = 500;
    float cpuct = 5;
    while(1){
        if (done){
            tree1 = move_mcts(tree1, -1);
            tree2 = move_mcts(tree2, -1);
            float score = score_game(board);
            if((score > 0) == (total%2==0)) ++p1;
            else ++p2;
            ++total;
            fprintf(stderr, "Total: %d, Player 1: %f, Player 2: %f\n", total, (float)p1/total, (float)p2/total);
            sleep(1);
            /*
               int i = (score > 0)? 0 : 1;
               int j;
               for(; i < count; i += 2){
               for(j = 0; j < 93; ++j){
               printf("%c", boards[i][j]);
               }
               printf("\n");
               }
             */
            memset(board, 0, 3*19*19*sizeof(float));
            flip_board(board);
            player = 1;
            done = 0;
            count = 0;
            fflush(stdout);
            fflush(stderr);
        }
        //print_board(stderr, board, 1, 0);
        //sleep(1);

        if ((total%2==0) == (player==1)){
            //mcts_iters = 4500;   
            cpuct = 5;
        } else {
            //mcts_iters = 500;
            cpuct = 1;
        }
        network *use = ((total%2==0) == (player==1)) ? net : net2;
        mcts_tree *t = ((total%2==0) == (player==1)) ? tree1 : tree2;
        t = run_mcts(t, use, board, two, player, mcts_iters, cpuct, 0);
        move m = pick_move(t, temp, player);
        if(((total%2==0) == (player==1))) tree1 = t;
        else tree2 = t;

        tree1 = move_mcts(tree1, m.row*19 + m.col);
        tree2 = move_mcts(tree2, m.row*19 + m.col);

        if(m.row == 19){
            done = 1;
            continue;
        }
        int row = m.row;
        int col = m.col;

        float *swap = two;
        two = one;
        one = swap;

        if(player < 0) flip_board(board);
        boards[count][0] = row;
        boards[count][1] = col;
        board_to_string(boards[count] + 2, board);
        if(player < 0) flip_board(board);
        ++count;

        move_go(board, player, row, col);
        copy_cpu(19*19*3, board, 1, one, 1);

        player = -player;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xdad0, %rsp           # imm = 0xDAD0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x39a70
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x5d39c
movq -0x18(%rbp), %rdi
callq 0x400e0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x5d39a
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x42680
jmp 0x5d3c1
movl $0x1, %edi
movl $0x110, %esi            # imm = 0x110
callq 0x3220
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x110, %edx            # imm = 0x110
callq 0x3280
xorl %eax, %eax
movl %eax, %edi
callq 0x3290
movl %eax, %edi
callq 0x31e0
movl $0x0, -0xda44(%rbp)
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3220
movq %rax, -0xda50(%rbp)
movq -0xda50(%rbp), %rdi
callq 0x59560
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3220
movq %rax, -0xda58(%rbp)
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3220
movq %rax, -0xda60(%rbp)
movl $0x0, -0xda64(%rbp)
movl $0x1, -0xda68(%rbp)
movl $0x0, -0xda6c(%rbp)
movl $0x0, -0xda70(%rbp)
movl $0x0, -0xda74(%rbp)
movss 0x13dd1(%rip), %xmm0    # 0x71234
movss %xmm0, -0xda78(%rbp)
movl $0x1f4, -0xda7c(%rbp)   # imm = 0x1F4
movss 0x13d8f(%rip), %xmm0    # 0x7120c
movss %xmm0, -0xda80(%rbp)
cmpl $0x0, -0xda64(%rbp)
je 0x5d5ec
movq -0x30(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9a0
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9a0
movq %rax, -0x38(%rbp)
movq -0xda50(%rbp), %rdi
callq 0x5d1e0
movss %xmm0, -0xda84(%rbp)
movss -0xda84(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xdabc(%rbp)
movl -0xda74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl -0xdabc(%rbp), %eax
cmpl $0x0, %edx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x5d51b
movl -0xda6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xda6c(%rbp)
jmp 0x5d52a
movl -0xda70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xda70(%rbp)
movl -0xda74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xda74(%rbp)
movq 0x25ab8(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
movl -0xda74(%rbp), %edx
cvtsi2ssl -0xda6c(%rbp), %xmm0
cvtsi2ssl -0xda74(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
cvtsi2ssl -0xda70(%rbp), %xmm1
cvtsi2ssl -0xda74(%rbp), %xmm2
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x18bbf(%rip), %rsi     # 0x7613f
movb $0x2, %al
callq 0x3240
movl $0x1, %edi
callq 0x3460
movq -0xda50(%rbp), %rdi
xorl %esi, %esi
movl $0x10ec, %edx           # imm = 0x10EC
callq 0x3190
movq -0xda50(%rbp), %rdi
callq 0x59560
movl $0x1, -0xda68(%rbp)
movl $0x0, -0xda64(%rbp)
movl $0x0, -0xda44(%rbp)
movq 0x259fb(%rip), %rax     # 0x82fd0
movq (%rax), %rdi
callq 0x32e0
movq 0x25a14(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
callq 0x32e0
movl -0xda74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, -0xda68(%rbp)
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x5d62b
movss 0x13beb(%rip), %xmm0    # 0x7120c
movss %xmm0, -0xda80(%rbp)
jmp 0x5d63b
movss 0x139d9(%rip), %xmm0    # 0x7100c
movss %xmm0, -0xda80(%rbp)
movl -0xda74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, -0xda68(%rbp)
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x5d675
movq -0x40(%rbp), %rax
movq %rax, -0xdac8(%rbp)
jmp 0x5d680
movq -0x48(%rbp), %rax
movq %rax, -0xdac8(%rbp)
movq -0xdac8(%rbp), %rax
movq %rax, -0xda90(%rbp)
movl -0xda74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, -0xda68(%rbp)
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x5d6c8
movq -0x30(%rbp), %rax
movq %rax, -0xdad0(%rbp)
jmp 0x5d6d3
movq -0x38(%rbp), %rax
movq %rax, -0xdad0(%rbp)
movq -0xdad0(%rbp), %rax
movq %rax, -0xda98(%rbp)
movq -0xda98(%rbp), %rdi
movq -0xda90(%rbp), %rsi
movq -0xda50(%rbp), %rdx
movq -0xda60(%rbp), %rcx
movl -0xda68(%rbp), %r8d
movl -0xda7c(%rbp), %r9d
movss -0xda80(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x5a860
movq %rax, -0xda98(%rbp)
movq -0xda98(%rbp), %rdi
movss -0xda78(%rbp), %xmm0
movl -0xda68(%rbp), %esi
callq 0x5aa30
movlpd %xmm0, -0xdaa8(%rbp)
movq %rax, -0xdaa0(%rbp)
movl -0xda74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, -0xda68(%rbp)
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x5d785
movq -0xda98(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x5d790
movq -0xda98(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
imull $0x13, -0xdaa0(%rbp), %esi
addl -0xda9c(%rbp), %esi
callq 0x5a9a0
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
imull $0x13, -0xdaa0(%rbp), %esi
addl -0xda9c(%rbp), %esi
callq 0x5a9a0
movq %rax, -0x38(%rbp)
cmpl $0x13, -0xdaa0(%rbp)
jne 0x5d7dc
movl $0x1, -0xda64(%rbp)
jmp 0x5d485
movl -0xdaa0(%rbp), %eax
movl %eax, -0xdaac(%rbp)
movl -0xda9c(%rbp), %eax
movl %eax, -0xdab0(%rbp)
movq -0xda60(%rbp), %rax
movq %rax, -0xdab8(%rbp)
movq -0xda58(%rbp), %rax
movq %rax, -0xda60(%rbp)
movq -0xdab8(%rbp), %rax
movq %rax, -0xda58(%rbp)
cmpl $0x0, -0xda68(%rbp)
jge 0x5d833
movq -0xda50(%rbp), %rdi
callq 0x59560
movl -0xdaac(%rbp), %eax
movb %al, %cl
movslq -0xda44(%rbp), %rdx
leaq -0xda40(%rbp), %rax
imulq $0x5d, %rdx, %rdx
addq %rdx, %rax
movb %cl, (%rax)
movl -0xdab0(%rbp), %eax
movb %al, %cl
movslq -0xda44(%rbp), %rdx
leaq -0xda40(%rbp), %rax
imulq $0x5d, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x1(%rax)
movslq -0xda44(%rbp), %rax
leaq -0xda40(%rbp), %rdi
imulq $0x5d, %rax, %rax
addq %rax, %rdi
addq $0x2, %rdi
movq -0xda50(%rbp), %rsi
callq 0x58910
cmpl $0x0, -0xda68(%rbp)
jge 0x5d8ac
movq -0xda50(%rbp), %rdi
callq 0x59560
movl -0xda44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xda44(%rbp)
movq -0xda50(%rbp), %rdi
movl -0xda68(%rbp), %esi
movl -0xdaac(%rbp), %edx
movl -0xdab0(%rbp), %ecx
callq 0x598a0
movq -0xda50(%rbp), %rsi
movq -0xda58(%rbp), %rcx
movl $0x43b, %edi            # imm = 0x43B
movl $0x1, %r8d
movl %r8d, %edx
callq 0x2f960
xorl %eax, %eax
subl -0xda68(%rbp), %eax
movl %eax, -0xda68(%rbp)
jmp 0x5d485
nopl (%rax)