// File: /workspace/github_c_makefile_star2_O3/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 0xef02
movq %rax, %rbx
movq %rax, %rdi
callq 0x30b0
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x316bc
movq %rax, %r14
cvtss2sd 0x34(%rax), %xmm0
cvtss2sd 0x38(%rax), %xmm1
cvtss2sd 0x3c(%rax), %xmm2
leaq 0x15926(%rip), %rdi     # 0x59fd0
movb $0x3, %al
callq 0x3160
leaq 0x15c38(%rip), %rdi     # 0x5a2f0
callq 0x2d26c
movq %rax, 0x60(%rsp)
movq 0x8(%r14), %rax
movq (%rax), %r15
leaq 0x80(%rsp), %rdi
xorl %eax, %eax
callq 0x30679
movq %r14, %rdi
callq 0x316fa
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x446f2
cmpq %rcx, %rax
jae 0x44934
shrq $0x4, %r15
movabsq $0x14f8b588e368f085, %rcx # imm = 0x14F8B588E368F085
movq %r15, %rax
mulq %rcx
movq %rdx, %r13
shrq $0x8, %r13
movss 0x10b7f(%rip), %xmm0    # 0x55294
leaq 0xc0(%rsp), %r15
movaps %xmm0, 0x50(%rsp)
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
movl $0x1, %esi
callq 0x31e05
movaps 0x50(%rsp), %xmm3
movaps %xmm3, %xmm1
cmpeqss 0x10b19(%rip), %xmm1    # 0x55294
movaps %xmm1, %xmm2
andnps %xmm3, %xmm2
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
mulsd 0x15b3b(%rip), %xmm0    # 0x5a2d8
movsd %xmm0, 0x48(%rsp)
mulsd 0x15b35(%rip), %xmm1    # 0x5a2e0
movsd %xmm1, 0x50(%rsp)
movq %r14, %rdi
callq 0x316fa
movq %rax, %r12
movq 0x8(%r14), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x447d2
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x447ea
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
movsd 0x50(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
divss 0x15ace(%rip), %xmm0    # 0x5a2d0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
movaps %xmm1, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r14, %rdi
callq 0x31715
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
callq 0x3120
subq %rbp, %rax
movq %rax, %rdi
callq 0xf0bf
cvtss2sd %xmm0, %xmm4
movq 0x8(%r14), %rax
movq (%rax), %rdx
leaq 0x15a1a(%rip), %rdi     # 0x5a26c
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
shrq $0x4, %rax
movabsq $0x14f8b588e368f085, %rcx # imm = 0x14F8B588E368F085
mulq %rcx
movq %rdx, %r12
shrq $0x8, %r12
movslq %r13d, %rax
cmpq %rax, %r12
jbe 0x448c7
movq %r15, %rdi
leaq 0x15968(%rip), %rsi     # 0x5a20d
leaq 0x15919(%rip), %rdx     # 0x5a1c5
movq %rbx, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r15, %rsi
callq 0x6879
movl %r12d, %r13d
movq %r14, %rdi
callq 0x316fa
movabsq $-0x70a3d70a3d70a3d7, %rcx # imm = 0x8F5C28F5C28F5C29
imulq %rcx, %rax
rorq $0x2, %rax
movabsq $0x28f5c28f5c28f5c, %rcx # imm = 0x28F5C28F5C28F5C
cmpq %rcx, %rax
ja 0x44916
movq %r15, %rdi
leaq 0x15924(%rip), %rsi     # 0x5a21e
leaq 0x158c4(%rip), %rdx     # 0x5a1c5
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r15, %rsi
callq 0x6879
movq %r14, %rdi
callq 0x316fa
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x44722
cmpq %rcx, %rax
jb 0x44722
leaq 0x1596a(%rip), %rsi     # 0x5a2a5
leaq 0x15883(%rip), %rdx     # 0x5a1c5
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r15, %rsi
callq 0x6879
movq %r14, %rdi
callq 0x33479
movq 0x60(%rsp), %rdi
movl $0xa, %esi
callq 0xf2f4
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 0x2d296
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq