// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/cifar.c
// Function: train_cifar
void train_cifar(char *cfgfile, char *weightfile)
{
    srand(time(0));
    float avg_loss = -1;
    char *base = basecfg(cfgfile);
    printf("%s\n", base);
    network *net = load_network(cfgfile, weightfile, 0);
    printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);

    char *backup_directory = "/home/pjreddie/backup/";
    int classes = 10;
    int N = 50000;

    char **labels = get_labels("data/cifar/labels.txt");
    int epoch = (*net->seen)/N;
    data train = load_all_cifar10();
    while(get_current_batch(net) < net->max_batches || net->max_batches == 0){
        clock_t time=clock();

        float loss = train_network_sgd(net, train, 1);
        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), sec(clock()-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)%100 == 0){
            char buff[256];
            sprintf(buff, "%s/%s.backup",backup_directory,base);
            save_weights(net, buff);
        }
    }
    char buff[256];
    sprintf(buff, "%s/%s.weights", backup_directory, base);
    save_weights(net, buff);

    free_network(net);
    free_ptrs((void**)labels, classes);
    free(base);
    free_data(train);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rsi, %r14
movq %rdi, %r15
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movq %r15, %rdi
callq 0x41c8
movq %rax, %rbx
movq %rax, %rdi
callq 0x30b0
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x22658
movq %rax, %r14
cvtss2sd 0x34(%rax), %xmm0
cvtss2sd 0x38(%rax), %xmm1
cvtss2sd 0x3c(%rax), %xmm2
leaq 0x186a6(%rip), %rdi     # 0x50ed0
movb $0x3, %al
callq 0x3160
leaq 0x189b8(%rip), %rdi     # 0x511f0
callq 0x1e673
movq %rax, 0x60(%rsp)
movq 0x8(%r14), %rax
movq (%rax), %rax
movl $0xc350, %ecx           # imm = 0xC350
xorl %edx, %edx
divq %rcx
movq %rax, %r15
leaq 0x80(%rsp), %rdi
xorl %eax, %eax
callq 0x21749
movss 0x139f7(%rip), %xmm0    # 0x4c264
leaq 0xc0(%rsp), %r13
movaps %xmm0, 0x50(%rsp)
movq %r14, %rdi
callq 0x22693
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x38894
cmpq %rcx, %rax
jae 0x38a67
callq 0x3120
movq %rax, %rbp
movups 0x80(%rsp), %xmm0
movups 0x90(%rsp), %xmm1
movups 0xa0(%rsp), %xmm2
movups 0xb0(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x22d5a
movaps 0x50(%rsp), %xmm3
movaps %xmm3, %xmm1
cmpeqss 0x13979(%rip), %xmm1    # 0x4c264
movaps %xmm1, %xmm2
andnps %xmm3, %xmm2
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
mulsd 0x188cb(%rip), %xmm0    # 0x511d8
movsd %xmm0, 0x48(%rsp)
mulsd 0x188c5(%rip), %xmm1    # 0x511e0
movsd %xmm1, 0x50(%rsp)
movq %r14, %rdi
callq 0x22693
movq %rax, %r12
movq 0x8(%r14), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x3893f
cvtsi2ss %rax, %xmm0
jmp 0x38954
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
movsd 0x50(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
divss 0x18864(%rip), %xmm0    # 0x511d0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
movaps %xmm1, 0x50(%rsp)
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r14, %rdi
callq 0x226ae
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
callq 0x3120
subq %rbp, %rax
movq %rax, %rdi
callq 0x437c
cvtss2sd %xmm0, %xmm4
movq 0x8(%r14), %rax
movq (%rax), %rdx
leaq 0x187b3(%rip), %rdi     # 0x5116c
movq %r12, %rsi
movsd 0x70(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
movsd 0x68(%rsp), %xmm3
movb $0x5, %al
callq 0x3160
movq 0x8(%r14), %rax
movq (%rax), %rax
xorl %edx, %edx
movl $0xc350, %ecx           # imm = 0xC350
divq %rcx
movq %rax, %r12
movslq %r15d, %rax
cmpq %rax, %r12
jbe 0x38a23
movq %r13, %rdi
leaq 0x1870c(%rip), %rsi     # 0x5110d
leaq 0x186bd(%rip), %rdx     # 0x510c5
movq %rbx, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r13, %rsi
callq 0x28aed
movl %r12d, %r15d
movq %r14, %rdi
callq 0x22693
xorl %edx, %edx
pushq $0x64
popq %rcx
divq %rcx
testq %rdx, %rdx
jne 0x3887a
movq %r13, %rdi
leaq 0x186d8(%rip), %rsi     # 0x5111e
leaq 0x18678(%rip), %rdx     # 0x510c5
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r13, %rsi
callq 0x28aed
jmp 0x3887a
leaq 0x18737(%rip), %rsi     # 0x511a5
leaq 0x18650(%rip), %rdx     # 0x510c5
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r15, %rsi
callq 0x28aed
movq %r14, %rdi
callq 0x24067
pushq $0xa
popq %rsi
movq 0x60(%rsp), %rdi
callq 0x4582
movq %rbx, %rdi
callq 0x3040
movups 0x80(%rsp), %xmm0
movups 0x90(%rsp), %xmm1
movups 0xa0(%rsp), %xmm2
movups 0xb0(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1e69d
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq