// File: /workspace/github_c_makefile_star2_O1/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 0x2f9e4
testq %r14, %r14
movq %rax, 0x38(%rsp)
je 0x46857
movq %r14, %rdi
callq 0x4ebd
testq %rbx, %rbx
movq %rax, 0x20(%rsp)
je 0x4687e
movq %rax, %rdi
movq %rbx, %rsi
callq 0x6c4b
jmp 0x4687e
movq %rax, %r15
movl $0x1, %edi
movl $0x110, %esi            # imm = 0x110
callq 0x3260
movl $0x110, %edx            # imm = 0x110
movq %rax, 0x20(%rsp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x32c0
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x32d0
movl %eax, %edi
callq 0x3230
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3260
movq %rax, %r15
movss 0xc760(%rip), %xmm2     # 0x53008
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 0x468a8
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3260
movq %rax, %r12
movl $0x43b, %edi            # imm = 0x43B
movl $0x4, %esi
callq 0x3260
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 0x46958
movss 0xc6ba(%rip), %xmm0     # 0x53008
movl 0x4(%rsp), %r12d
jmp 0x46a91
movq %r14, %rdi
callq 0x442a8
movq %rbx, %rdi
callq 0x442a8
movq %r15, %rdi
callq 0x4671d
ucomiss 0xc701(%rip), %xmm0     # 0x53078
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 0x23641(%rip), %rax     # 0x69ff8
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 0x11eb5(%rip), %rsi     # 0x58895
movl %r13d, %edx
movb $0x2, %al
callq 0x3280
movl $0x1, %edi
callq 0x34a0
movl $0x10ec, %edx           # imm = 0x10EC
movq %r15, %rdi
xorl %esi, %esi
callq 0x31d0
movq $-0x5a4, %rax           # imm = 0xFA5C
movss 0xc5f6(%rip), %xmm2     # 0x53008
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 0x46a12
movq 0x23572(%rip), %rax     # 0x69fd0
movq (%rax), %rdi
callq 0x3320
movq 0x2358b(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
callq 0x3320
movss 0xc58b(%rip), %xmm0     # 0x53008
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 0x46ac1
movss 0xc77f(%rip), %xmm0     # 0x53240
xorps %xmm1, %xmm1
movq %r15, %rdx
movq 0x28(%rsp), %rcx
movl %r12d, %r8d
movl $0x1f4, %r9d            # imm = 0x1F4
callq 0x44a53
testb $0x1, %bpl
cmovneq %rax, %rbx
cmoveq %rax, %r14
movq %rax, %rdi
movss 0xc77b(%rip), %xmm0     # 0x5326c
movl %r12d, 0x4(%rsp)
movl %r12d, %esi
callq 0x969b
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 0x44c31
movq %rax, %r14
movq %rbx, %rdi
movl %r13d, %esi
callq 0x44c31
movq %rax, %rbx
xorl %eax, %eax
cmpl $0x13, %ebp
movl 0xc(%rsp), %r13d
je 0x46942
movslq 0x10(%rsp), %rax
cmpl $0x0, 0x4(%rsp)
js 0x46b6c
imulq $0x5d, %rax, %rax
leaq (%rsp,%rax), %rdi
addq $0x42, %rdi
movb %bpl, -0x2(%rdi)
movb %r12b, -0x1(%rdi)
movq %r15, %rsi
callq 0x432b4
jmp 0x46c29
xorl %ecx, %ecx
movss 0xc492(%rip), %xmm2     # 0x53008
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 0x46b76
imulq $0x5d, %rax, %rax
leaq (%rsp,%rax), %rdi
addq $0x42, %rdi
movb %bpl, -0x2(%rdi)
movb %r12b, -0x1(%rdi)
movq %r15, %rsi
callq 0x432b4
movss 0xc42b(%rip), %xmm2     # 0x53008
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 0x46be4
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 0x43e98
movl $0x43b, %edi            # imm = 0x43B
movq %r15, %rsi
movl $0x1, %edx
movq 0x28(%rsp), %r12
movq %r12, %rcx
movl $0x1, %r8d
callq 0x2879c
negl %r13d
movl %r13d, 0x4(%rsp)
movq 0x30(%rsp), %rax
movl 0xc(%rsp), %r13d
jmp 0x46936