// File: /workspace/github_c_makefile_star2_O3/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, 0x80(%rsp)
movl %r8d, %ebx
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %r13
callq 0xef02
movq %rax, 0x60(%rsp)
movq %rax, %rdi
callq 0x30b0
leaq 0x14d02(%rip), %rdi     # 0x5a599
xorl %r14d, %r14d
movl %ebx, %esi
xorl %eax, %eax
callq 0x3160
movl %ebx, 0x5c(%rsp)
movslq %ebx, %rbx
movl $0x8, %esi
movq %rbx, %rdi
callq 0x3250
movq %rax, %r15
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
callq 0x34e0
testl %ebx, %ebx
jle 0x4593b
movl %eax, %ecx
movq %rbp, 0x48(%rsp)
movl 0x5c(%rsp), %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x70(%rsp)
movl %eax, %eax
movq %rax, 0x50(%rsp)
xorl %ebp, %ebp
movq %r12, %rbx
movl 0x80(%rsp), %r12d
movl %ecx, %r14d
movl %ecx, %edi
callq 0x3220
movq %r13, %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x316bc
movl %r14d, %ecx
movq %rax, (%r15,%rbp,8)
movss 0x34(%rax), %xmm0
mulss 0x70(%rsp), %xmm0
movss %xmm0, 0x34(%rax)
incq %rbp
cmpq %rbp, 0x50(%rsp)
jne 0x458fa
movq (%r15), %r14
movq 0x48(%rsp), %rbp
xorps %xmm0, %xmm0
cvtss2sd 0x34(%r14), %xmm0
cvtss2sd 0x38(%r14), %xmm1
cvtss2sd 0x3c(%r14), %xmm2
leaq 0x14679(%rip), %rdi     # 0x59fd0
movb $0x3, %al
callq 0x3160
movq %rbp, %rdi
callq 0x45371
movq %rax, 0x98(%rsp)
movl %edx, %r12d
leaq 0x14b20(%rip), %rdi     # 0x5a498
movl %edx, %esi
xorl %eax, %eax
callq 0x3160
movq 0x8(%r14), %rax
movq (%rax), %rbx
movq %r14, %rdi
callq 0x316fa
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x459a2
cmpq %rcx, %rax
jae 0x45cea
movslq %r12d, %rcx
movq %rbx, %rax
xorl %edx, %edx
movq %rcx, 0x90(%rsp)
divq %rcx
movq %rax, %rbp
xorps %xmm0, %xmm0
cvtsi2ss %r12d, %xmm0
movss %xmm0, 0x6c(%rsp)
movss 0xf8c6(%rip), %xmm0     # 0x55294
leaq 0xf0(%rsp), %r13
movapd %xmm0, 0x70(%rsp)
xorl %eax, %eax
callq 0xe79c
movsd %xmm0, 0x50(%rsp)
movl 0x4(%r14), %ecx
imull 0x5c(%rsp), %ecx
imull 0x1c(%r14), %ecx
leaq 0xb0(%rsp), %rdi
movq 0x98(%rsp), %rsi
movl %r12d, %edx
callq 0x45530
xorl %eax, %eax
callq 0xe79c
subsd 0x50(%rsp), %xmm0
leaq 0x1461b(%rip), %rdi     # 0x5a03e
movb $0x1, %al
callq 0x3160
xorl %eax, %eax
callq 0xe79c
movsd %xmm0, 0x50(%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 0x31ea6
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 0x2d296
movaps 0x70(%rsp), %xmm2
movaps %xmm2, %xmm0
cmpeqss 0xf7d1(%rip), %xmm0     # 0x55294
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 0x147e2(%rip), %xmm0    # 0x5a2d8
movsd %xmm0, 0x48(%rsp)
mulsd 0x147dc(%rip), %xmm1    # 0x5a2e0
movsd %xmm1, 0x70(%rsp)
movq %r14, %rdi
callq 0x316fa
movq %rax, %r15
movq 0x8(%r14), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x45b2b
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x45b43
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 0x48(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xa8(%rsp)
movaps %xmm1, 0x70(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r14, %rdi
callq 0x31715
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
xorl %eax, %eax
callq 0xe79c
movaps %xmm0, %xmm4
subsd 0x50(%rsp), %xmm4
movq 0x8(%r14), %rax
movq (%rax), %rdx
leaq 0x146c1(%rip), %rdi     # 0x5a26c
movq %r15, %rsi
movsd 0xa8(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
movsd 0xa0(%rsp), %xmm3
movb $0x5, %al
callq 0x3160
movq 0x8(%r14), %rax
movq (%rax), %rax
xorl %edx, %edx
divq 0x90(%rsp)
movq %rax, %rbx
movslq %ebp, %rax
cmpq %rax, %rbx
jbe 0x45c1f
movq %r13, %rdi
leaq 0x14611(%rip), %rsi     # 0x5a20d
leaq 0x145c2(%rip), %rdx     # 0x5a1c5
movq 0x60(%rsp), %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r13, %rsi
callq 0x6879
movl %ebx, %ebp
movq %r14, %rdi
callq 0x316fa
movabsq $0x1cac083126e978d5, %rcx # imm = 0x1CAC083126E978D5
imulq %rcx, %rax
rorq $0x3, %rax
movabsq $0x4189374bc6a7ef, %rcx # imm = 0x4189374BC6A7EF
cmpq %rcx, %rax
ja 0x45c70
movq %r13, %rdi
leaq 0x145cc(%rip), %rsi     # 0x5a21e
leaq 0x1456c(%rip), %rdx     # 0x5a1c5
movq 0x60(%rsp), %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r13, %rsi
callq 0x6879
movq %r14, %rdi
callq 0x316fa
movabsq $-0x2d77318fc504816f, %rcx # imm = 0xD288CE703AFB7E91
imulq %rcx, %rax
rorq $0x4, %rax
movabsq $0x68db8bac710cb, %rcx  # imm = 0x68DB8BAC710CB
cmpq %rcx, %rax
ja 0x45ccc
movq %r14, %rdi
callq 0x316fa
movq %r13, %rdi
leaq 0x147f8(%rip), %rsi     # 0x5a4a3
leaq 0x14513(%rip), %rdx     # 0x5a1c5
movq 0x60(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r13, %rsi
callq 0x6879
movq %r14, %rdi
callq 0x316fa
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x459dc
cmpq %rcx, %rax
jb 0x459dc
leaq 0x145b4(%rip), %rsi     # 0x5a2a5
leaq 0x144cd(%rip), %rdx     # 0x5a1c5
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
movq 0x60(%rsp), %r15
movq %r15, %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6879
movq %r14, %rdi
callq 0x33479
movq %r15, %rdi
callq 0x3040
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq