// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xda38, %rsp           # imm = 0xDA38
movq %rcx, %rbx
movq %rdx, %r14
xorl %edx, %edx
callq 0x316bc
testq %r14, %r14
movq %rax, 0x38(%rsp)
je 0x48b64
movq %r14, %rdi
callq 0x5145
testq %rbx, %rbx
movq %rax, 0x20(%rsp)
je 0x48b8b
movq %rax, %rdi
movq %rbx, %rsi
callq 0x6eeb
jmp 0x48b8b
movq %rax, %r15
movl $0x1, %edi
movl $0x110, %esi            # imm = 0x110
callq 0x3250
movl $0x110, %edx            # imm = 0x110
movq %rax, 0x20(%rsp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x32b0
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3250
movq %rax, %r15
movss 0xc453(%rip), %xmm2     # 0x55008
movss (%r15,%rbx,4), %xmm0
movss 0x5a4(%r15,%rbx,4), %xmm1
movss %xmm1, (%r15,%rbx,4)
movss %xmm0, 0x5a4(%r15,%rbx,4)
movaps %xmm2, %xmm0
subss 0xb48(%r15,%rbx,4), %xmm0
movss %xmm0, 0xb48(%r15,%rbx,4)
incq %rbx
cmpq $0x169, %rbx            # imm = 0x169
jne 0x48bb5
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3250
movq %rax, %r12
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3250
movl $0x1, 0x4(%rsp)
movq $0x0, 0x18(%rsp)
xorl %r13d, %r13d
movl $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
movq %r12, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movb $0x1, %al
testb $0x1, %al
je 0x48c65
movss 0xc3ad(%rip), %xmm0     # 0x55008
movl 0x4(%rsp), %r12d
jmp 0x48d9e
movq %r14, %rdi
callq 0x4653b
movq %rbx, %rdi
callq 0x4653b
movq %r15, %rdi
callq 0x48a2a
ucomiss 0xc41c(%rip), %xmm0     # 0x550a0
setbe %al
xorb %r13b, %al
movzbl %al, %eax
movl %eax, %ecx
andl $0x1, %ecx
movq 0x18(%rsp), %rdx
addl %ecx, %edx
notb %al
movzbl %al, %eax
andl $0x1, %eax
movl 0x8(%rsp), %ecx
addl %eax, %ecx
movl %ecx, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
incl %r13d
xorps %xmm1, %xmm1
cvtsi2ss %r13d, %xmm1
movq 0x23334(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
movq %rdx, 0x18(%rsp)
xorps %xmm2, %xmm2
cvtsi2ss %edx, %xmm2
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
divss %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
leaq 0x11d00(%rip), %rsi     # 0x5a9ed
movl %r13d, %edx
movb $0x2, %al
callq 0x3270
movl $0x1, %edi
callq 0x3490
movl $0x10ec, %edx           # imm = 0x10EC
movq %r15, %rdi
xorl %esi, %esi
callq 0x31c0
movq $-0x5a4, %rax           # imm = 0xFA5C
movss 0xc2e9(%rip), %xmm2     # 0x55008
movss 0x5a4(%r15,%rax), %xmm0
movss 0xb48(%r15,%rax), %xmm1
movss %xmm1, 0x5a4(%r15,%rax)
movss %xmm0, 0xb48(%r15,%rax)
movaps %xmm2, %xmm0
subss 0x10ec(%r15,%rax), %xmm0
movss %xmm0, 0x10ec(%r15,%rax)
addq $0x4, %rax
jne 0x48d1f
movq 0x23265(%rip), %rax     # 0x6bfd0
movq (%rax), %rdi
callq 0x3310
movq 0x2327e(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
callq 0x3310
movss 0xc27e(%rip), %xmm0     # 0x55008
movq $0x0, 0x10(%rsp)
movl $0x1, %r12d
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpl $0x1, %r12d
setne %bpl
movl %r13d, 0xc(%rsp)
xorb %r13b, %bpl
movq %r14, %rdi
testb $0x1, %bpl
cmovneq %rbx, %rdi
movq 0x38(%rsp), %rsi
cmovneq 0x20(%rsp), %rsi
jne 0x48dce
movss 0xc4a2(%rip), %xmm0     # 0x55270
xorps %xmm1, %xmm1
movq %r15, %rdx
movq 0x28(%rsp), %rcx
movl %r12d, %r8d
movl $0x1f4, %r9d            # imm = 0x1F4
callq 0x46d4b
testb $0x1, %bpl
cmovneq %rax, %rbx
cmoveq %rax, %r14
movq %rax, %rdi
movss 0xc49a(%rip), %xmm0     # 0x55298
movl %r12d, 0x4(%rsp)
movl %r12d, %esi
callq 0x9c72
movq %rax, %rbp
leal (%rax,%rax,8), %eax
leal (%rbp,%rax,2), %r13d
movq %rbp, %r12
shrq $0x20, %r12
addl %r12d, %r13d
movq %r14, %rdi
movl %r13d, %esi
callq 0x46f29
movq %rax, %r14
movq %rbx, %rdi
movl %r13d, %esi
callq 0x46f29
movq %rax, %rbx
xorl %eax, %eax
cmpl $0x13, %ebp
movl 0xc(%rsp), %r13d
je 0x48c4f
movslq 0x10(%rsp), %rax
cmpl $0x0, 0x4(%rsp)
js 0x48e79
imulq $0x5d, %rax, %rax
leaq (%rsp,%rax), %rdi
addq $0x42, %rdi
movb %bpl, -0x2(%rdi)
movb %r12b, -0x1(%rdi)
movq %r15, %rsi
callq 0x4549c
jmp 0x48f36
xorl %ecx, %ecx
movss 0xc185(%rip), %xmm2     # 0x55008
movss (%r15,%rcx,4), %xmm0
movss 0x5a4(%r15,%rcx,4), %xmm1
movss %xmm1, (%r15,%rcx,4)
movss %xmm0, 0x5a4(%r15,%rcx,4)
movaps %xmm2, %xmm0
subss 0xb48(%r15,%rcx,4), %xmm0
movss %xmm0, 0xb48(%r15,%rcx,4)
incq %rcx
cmpq $0x169, %rcx            # imm = 0x169
jne 0x48e83
imulq $0x5d, %rax, %rax
leaq (%rsp,%rax), %rdi
addq $0x42, %rdi
movb %bpl, -0x2(%rdi)
movb %r12b, -0x1(%rdi)
movq %r15, %rsi
callq 0x4549c
movss 0xc11e(%rip), %xmm2     # 0x55008
movq $-0x5a4, %rax           # imm = 0xFA5C
movss 0x5a4(%r15,%rax), %xmm0
movss 0xb48(%r15,%rax), %xmm1
movss %xmm1, 0x5a4(%r15,%rax)
movss %xmm0, 0xb48(%r15,%rax)
movaps %xmm2, %xmm0
subss 0x10ec(%r15,%rax), %xmm0
movss %xmm0, 0x10ec(%r15,%rax)
addq $0x4, %rax
jne 0x48ef1
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movl 0x4(%rsp), %r13d
movl %r13d, %esi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x46164
movl $0x43b, %edi            # imm = 0x43B
movq %r15, %rsi
movl $0x1, %edx
movq 0x28(%rsp), %r12
movq %r12, %rcx
movl $0x1, %r8d
callq 0x29fe0
negl %r13d
movl %r13d, 0x4(%rsp)
movq 0x30(%rsp), %rax
movl 0xc(%rsp), %r13d
jmp 0x48c43