// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/cifar.c
// Function: train_cifar_distill
void train_cifar_distill(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();
    matrix soft = csv_to_matrix("results/ensemble.csv");

    float weight = .9;
    scale_matrix(soft, weight);
    scale_matrix(train.y, 1. - weight);
    matrix_add_matrix(soft, train.y);

    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 0x18376(%rip), %rdi     # 0x50ed0
movb $0x3, %al
callq 0x3160
leaq 0x18688(%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, %r12
leaq 0x80(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x21749
leaq 0x18667(%rip), %rdi     # 0x51206
callq 0x22350
movq %rax, %r13
movq %rdx, %rbp
movss 0x16d4a(%rip), %xmm0    # 0x4f8fc
movq %rax, %rdi
movq %rdx, %rsi
callq 0x21fe0
movq 0x18(%r15), %rdi
movq 0x20(%r15), %rsi
movss 0x18607(%rip), %xmm0    # 0x511d4
callq 0x21fe0
movq 0x18(%r15), %rdx
movq 0x20(%r15), %rcx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x220de
movss 0x13677(%rip), %xmm0    # 0x4c264
leaq 0xc0(%rsp), %r15
movaps %xmm0, 0x50(%rsp)
movq %r14, %rdi
callq 0x22693
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x38c14
cmpq %rcx, %rax
jae 0x38de7
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 0x135f9(%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 0x1854b(%rip), %xmm0    # 0x511d8
movsd %xmm0, 0x48(%rsp)
mulsd 0x18545(%rip), %xmm1    # 0x511e0
movsd %xmm1, 0x50(%rsp)
movq %r14, %rdi
callq 0x22693
movq %rax, %r13
movq 0x8(%r14), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x38cbf
cvtsi2ss %rax, %xmm0
jmp 0x38cd4
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 0x184e4(%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 0x18433(%rip), %rdi     # 0x5116c
movq %r13, %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, %r13
movslq %r12d, %rax
cmpq %rax, %r13
jbe 0x38da3
movq %r15, %rdi
leaq 0x1838c(%rip), %rsi     # 0x5110d
leaq 0x1833d(%rip), %rdx     # 0x510c5
movq %rbx, %rcx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r15, %rsi
callq 0x28aed
movl %r13d, %r12d
movq %r14, %rdi
callq 0x22693
xorl %edx, %edx
pushq $0x64
popq %rcx
divq %rcx
testq %rdx, %rdx
jne 0x38bfa
movq %r15, %rdi
leaq 0x18358(%rip), %rsi     # 0x5111e
leaq 0x182f8(%rip), %rdx     # 0x510c5
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r15, %rsi
callq 0x28aed
jmp 0x38bfa
leaq 0x183b7(%rip), %rsi     # 0x511a5
leaq 0x182d0(%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