// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/go.c
// Function: train_go
void train_go(char *cfgfile, char *weightfile, char *filename, int *gpus, int ngpus, int clear)
{
    int i;
    float avg_loss = -1;
    char *base = basecfg(cfgfile);
    printf("%s\n", base);
    printf("%d\n", ngpus);
    network **nets = calloc(ngpus, sizeof(network*));

    srand(time(0));
    int seed = rand();
    for(i = 0; i < ngpus; ++i){
        srand(seed);
        nets[i] = load_network(cfgfile, weightfile, clear);
        nets[i]->learning_rate *= ngpus;
    }
    network *net = nets[0];
    printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);

    char *backup_directory = "/home/pjreddie/backup/";

    char buff[256];
    moves m = load_go_moves(filename);
    //moves m = load_go_moves("games.txt");

    int N = m.n;
    printf("Moves: %d\n", N);
    int epoch = (*net->seen)/N;
    while(get_current_batch(net) < net->max_batches || net->max_batches == 0){
        double time=what_time_is_it_now();

        data train = random_go_moves(m, net->batch*net->subdivisions*ngpus);
        printf("Loaded: %lf seconds\n", what_time_is_it_now() - time);
        time=what_time_is_it_now();

        float loss = 0;
        loss = train_network(net, train);
        free_data(train);

        if(avg_loss == -1) avg_loss = loss;
        avg_loss = avg_loss*.95 + loss*.05;
        printf("%ld, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*net->seen)/N, loss, avg_loss, get_current_rate(net), what_time_is_it_now()-time, *net->seen);
        if(*net->seen/N > epoch){
            epoch = *net->seen/N;
            char buff[256];
            sprintf(buff, "%s/%s_%d.weights", backup_directory,base, epoch);
            save_weights(net, buff);

        }
        if(get_current_batch(net)%1000 == 0){
            char buff[256];
            sprintf(buff, "%s/%s.backup",backup_directory,base);
            save_weights(net, buff);
        }
        if(get_current_batch(net)%10000 == 0){
            char buff[256];
            sprintf(buff, "%s/%s_%ld.backup",backup_directory,base,get_current_batch(net));
            save_weights(net, buff);
        }
    }
    sprintf(buff, "%s/%s.weights", backup_directory, base);
    save_weights(net, buff);

    free_network(net);
    free(base);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movl %r9d, 0x70(%rsp)
movl %r8d, %ebx
movq %rdx, 0x80(%rsp)
movq %rsi, %r14
movq %rdi, %r12
callq 0xe717
movq %rax, 0x58(%rsp)
movq %rax, %rdi
callq 0x30c0
leaq 0x14e65(%rip), %rdi     # 0x58441
movl %ebx, %esi
xorl %eax, %eax
callq 0x3170
movl %ebx, 0x54(%rsp)
movslq %ebx, %rbx
movl $0x8, %esi
movq %rbx, %rdi
callq 0x3260
movq %rax, %r13
xorl %edi, %edi
callq 0x32d0
movl %eax, %edi
callq 0x3230
callq 0x34f0
testl %ebx, %ebx
jle 0x4365c
movl %eax, %r15d
movl 0x54(%rsp), %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x48(%rsp)
movl %eax, %ebx
xorl %ebp, %ebp
movl %r15d, %edi
callq 0x3230
movq %r12, %rdi
movq %r14, %rsi
movl 0x70(%rsp), %edx
callq 0x2f9e4
movq %rax, (%r13,%rbp,8)
movss 0x34(%rax), %xmm0
mulss 0x48(%rsp), %xmm0
movss %xmm0, 0x34(%rax)
incq %rbp
cmpq %rbp, %rbx
jne 0x43628
movq (%r13), %r14
xorps %xmm0, %xmm0
cvtss2sd 0x34(%r14), %xmm0
cvtss2sd 0x38(%r14), %xmm1
cvtss2sd 0x3c(%r14), %xmm2
leaq 0x1481c(%rip), %rdi     # 0x57e98
movb $0x3, %al
callq 0x3170
movq 0x80(%rsp), %rdi
callq 0x43189
movq %rax, 0x98(%rsp)
movl %edx, %r12d
leaq 0x14c9e(%rip), %rdi     # 0x58340
movl %edx, %esi
xorl %eax, %eax
callq 0x3170
movq 0x8(%r14), %rax
movq (%rax), %r15
movq %r14, %rdi
callq 0x2fa22
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x436cc
cmpq %rcx, %rax
jae 0x43a08
movslq %r12d, %rbx
movq %r15, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %rbp
xorps %xmm0, %xmm0
cvtsi2ss %r12d, %xmm0
movss %xmm0, 0x6c(%rsp)
movss 0xfb78(%rip), %xmm0     # 0x53268
leaq 0xf0(%rsp), %r13
movapd %xmm0, 0x70(%rsp)
xorl %eax, %eax
callq 0xdfdc
movsd %xmm0, 0x48(%rsp)
movl 0x4(%r14), %ecx
imull 0x54(%rsp), %ecx
imull 0x1c(%r14), %ecx
leaq 0xb0(%rsp), %rdi
movq 0x98(%rsp), %rsi
movl %r12d, %edx
callq 0x43348
xorl %eax, %eax
callq 0xdfdc
subsd 0x48(%rsp), %xmm0
leaq 0x147c1(%rip), %rdi     # 0x57f06
movb $0x1, %al
callq 0x3170
xorl %eax, %eax
callq 0xdfdc
movsd %xmm0, 0x48(%rsp)
movups 0xb0(%rsp), %xmm0
movups 0xc0(%rsp), %xmm1
movups 0xd0(%rsp), %xmm2
movups 0xe0(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x301c6
movaps %xmm0, 0x80(%rsp)
movups 0xb0(%rsp), %xmm0
movups 0xc0(%rsp), %xmm1
movups 0xd0(%rsp), %xmm2
movups 0xe0(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x2b6fd
movaps 0x70(%rsp), %xmm2
movaps %xmm2, %xmm0
cmpeqss 0xfa83(%rip), %xmm0     # 0x53268
movaps %xmm0, %xmm1
andnps %xmm2, %xmm1
movaps 0x80(%rsp), %xmm2
andps %xmm2, %xmm0
orps %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd %xmm0, 0x80(%rsp)
mulsd 0x14988(%rip), %xmm0    # 0x581a0
movsd %xmm0, 0x60(%rsp)
mulsd 0x14982(%rip), %xmm1    # 0x581a8
movsd %xmm1, 0x70(%rsp)
movq %r14, %rdi
callq 0x2fa22
movq %rax, %r15
movq 0x8(%r14), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x4384d
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x43865
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
divss 0x6c(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
addsd 0x60(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xa8(%rsp)
movaps %xmm1, 0x70(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movq %r14, %rdi
callq 0x2fa3d
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
xorl %eax, %eax
callq 0xdfdc
movaps %xmm0, %xmm4
subsd 0x48(%rsp), %xmm4
movq 0x8(%r14), %rax
movq (%rax), %rdx
leaq 0x14867(%rip), %rdi     # 0x58134
movq %r15, %rsi
movsd 0xa8(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
movsd 0xa0(%rsp), %xmm3
movb $0x5, %al
callq 0x3170
movq 0x8(%r14), %rax
movq (%rax), %rax
xorl %edx, %edx
divq %rbx
movq %rax, %r15
movslq %ebp, %rax
cmpq %rax, %r15
jbe 0x4393d
movq %r13, %rdi
leaq 0x147bc(%rip), %rsi     # 0x580d5
leaq 0x1476d(%rip), %rdx     # 0x5808d
movq 0x58(%rsp), %rcx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r13, %rsi
callq 0x66cd
movl %r15d, %ebp
movq %r14, %rdi
callq 0x2fa22
movabsq $0x1cac083126e978d5, %rcx # imm = 0x1CAC083126E978D5
imulq %rcx, %rax
rorq $0x3, %rax
movabsq $0x4189374bc6a7ef, %rcx # imm = 0x4189374BC6A7EF
cmpq %rcx, %rax
ja 0x4398e
movq %r13, %rdi
leaq 0x14776(%rip), %rsi     # 0x580e6
leaq 0x14716(%rip), %rdx     # 0x5808d
movq 0x58(%rsp), %rcx
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r13, %rsi
callq 0x66cd
movq %r14, %rdi
callq 0x2fa22
movabsq $-0x2d77318fc504816f, %rcx # imm = 0xD288CE703AFB7E91
imulq %rcx, %rax
rorq $0x4, %rax
movabsq $0x68db8bac710cb, %rcx  # imm = 0x68DB8BAC710CB
cmpq %rcx, %rax
ja 0x439ea
movq %r14, %rdi
callq 0x2fa22
movq %r13, %rdi
leaq 0x14982(%rip), %rsi     # 0x5834b
leaq 0x146bd(%rip), %rdx     # 0x5808d
movq 0x58(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r13, %rsi
callq 0x66cd
movq %r14, %rdi
callq 0x2fa22
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x436fe
cmpq %rcx, %rax
jb 0x436fe
leaq 0x1475e(%rip), %rsi     # 0x5816d
leaq 0x14677(%rip), %rdx     # 0x5808d
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
movq 0x58(%rsp), %r15
movq %r15, %rcx
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %rbx, %rsi
callq 0x66cd
movq %r14, %rdi
callq 0x314d2
movq %r15, %rdi
callq 0x3040
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq