// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x560, %rsp            # imm = 0x560
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movss 0x1b2e1(%rip), %xmm0    # 0x740dc
movss %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4850
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
leaq 0x1b585(%rip), %rdi     # 0x7439d
movb $0x0, %al
callq 0x3130
movl -0x24(%rbp), %esi
leaq 0x1a34d(%rip), %rdi     # 0x73176
movb $0x0, %al
callq 0x3130
movslq -0x24(%rbp), %rdi
movl $0x8, %esi
callq 0x3220
movq %rax, -0x40(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x3290
movl %eax, %edi
callq 0x31e0
callq 0x34b0
movl %eax, -0x44(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x58eb6
movl -0x44(%rbp), %edi
callq 0x31e0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x28(%rbp), %edx
callq 0x39a70
movq %rax, %rdx
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
cvtsi2ssl -0x24(%rbp), %xmm0
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
mulss 0x34(%rax), %xmm0
movss %xmm0, 0x34(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x58e61
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movss 0x34(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x50(%rbp), %rax
movss 0x38(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x50(%rbp), %rax
movss 0x3c(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x1c879(%rip), %rdi     # 0x75768
movb $0x3, %al
callq 0x3130
leaq 0x1ca78(%rip), %rax     # 0x75975
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
callq 0x58730
movq %rax, -0x170(%rbp)
movl %edx, -0x168(%rbp)
movl -0x168(%rbp), %eax
movl %eax, -0x174(%rbp)
movl -0x174(%rbp), %esi
leaq 0x1ccb5(%rip), %rdi     # 0x75be5
movb $0x0, %al
callq 0x3130
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x174(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x178(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39ad0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movslq 0x54(%rax), %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, -0x4d1(%rbp)
jb 0x58f86
movq -0x50(%rbp), %rax
cmpl $0x0, 0x54(%rax)
sete %al
movb %al, -0x4d1(%rbp)
movb -0x4d1(%rbp), %al
testb $0x1, %al
jne 0x58f95
jmp 0x59317
movb $0x0, %al
callq 0x3f10
movsd %xmm0, -0x180(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x50(%rbp), %rax
imull 0x1c(%rax), %ecx
imull -0x24(%rbp), %ecx
movq -0x170(%rbp), %rsi
movl -0x168(%rbp), %edx
leaq -0x1c0(%rbp), %rdi
callq 0x58a50
movb $0x0, %al
callq 0x3f10
subsd -0x180(%rbp), %xmm0
leaq 0x1c80e(%rip), %rdi     # 0x757f4
movb $0x1, %al
callq 0x3130
movb $0x0, %al
callq 0x3f10
movsd %xmm0, -0x180(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1c4(%rbp)
movq -0x50(%rbp), %rdi
movups -0x1c0(%rbp), %xmm0
movups -0x1b0(%rbp), %xmm1
movups -0x1a0(%rbp), %xmm2
movups -0x190(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x3a860
movss %xmm0, -0x1c4(%rbp)
movups -0x1c0(%rbp), %xmm0
movups -0x1b0(%rbp), %xmm1
movups -0x1a0(%rbp), %xmm2
movups -0x190(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x34400
movss -0x30(%rbp), %xmm0
movss 0x1b056(%rip), %xmm1    # 0x740dc
ucomiss %xmm1, %xmm0
jne 0x5909a
jp 0x5909a
movss -0x1c4(%rbp), %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x1c4(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x1c9c9(%rip), %xmm2    # 0x75a80
mulsd %xmm2, %xmm1
movsd 0x1c9c5(%rip), %xmm2    # 0x75a88
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39ad0
movq %rax, -0x4e8(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x4dc(%rbp)
testq %rax, %rax
movss %xmm0, -0x4d8(%rbp)
js 0x59130
movss -0x4dc(%rbp), %xmm0
movss %xmm0, -0x4d8(%rbp)
movss -0x4d8(%rbp), %xmm0
cvtsi2ssl -0x174(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x4f0(%rbp)
movss -0x1c4(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x508(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x500(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39b60
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x4f8(%rbp)
movb $0x0, %al
callq 0x3f10
movq -0x4e8(%rbp), %rsi
movsd -0x508(%rbp), %xmm1
movsd -0x500(%rbp), %xmm2
movsd -0x4f8(%rbp), %xmm3
movaps %xmm0, %xmm4
movsd -0x4f0(%rbp), %xmm0
subsd -0x180(%rbp), %xmm4
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
leaq 0x1c847(%rip), %rdi     # 0x75a1c
movb $0x5, %al
callq 0x3130
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x174(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movslq -0x178(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x59250
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x174(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x178(%rbp)
leaq -0x2d0(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl -0x178(%rbp), %r8d
leaq 0x1c784(%rip), %rsi     # 0x759bd
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x41980
movq -0x50(%rbp), %rdi
callq 0x39ad0
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x59296
leaq -0x3d0(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x1c74f(%rip), %rsi     # 0x759ce
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x41980
movq -0x50(%rbp), %rdi
callq 0x39ad0
movl $0x2710, %ecx           # imm = 0x2710
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x59312
leaq -0x4d0(%rbp), %rax
movq %rax, -0x520(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x518(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x510(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39ad0
movq -0x520(%rbp), %rdi
movq -0x518(%rbp), %rdx
movq -0x510(%rbp), %rcx
movq %rax, %r8
leaq 0x1c8f5(%rip), %rsi     # 0x75bf0
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x41980
jmp 0x58f54
leaq -0x160(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x1c728(%rip), %rsi     # 0x75a55
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x41980
movq -0x50(%rbp), %rdi
callq 0x3c0b0
movq -0x38(%rbp), %rdi
callq 0x3030
addq $0x560, %rsp            # imm = 0x560
popq %rbp
retq
nop