// File: /workspace/github_c_makefile_star2_O1/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 0x32d0
movl %eax, %edi
callq 0x3230
movq %r15, %rdi
callq 0xe717
movq %rax, %rbx
movq %rax, %rdi
callq 0x30c0
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2f9e4
movq %rax, %r14
cvtss2sd 0x34(%rax), %xmm0
cvtss2sd 0x38(%rax), %xmm1
cvtss2sd 0x3c(%rax), %xmm2
leaq 0x15657(%rip), %rdi     # 0x57e98
movb $0x3, %al
callq 0x3170
leaq 0x15969(%rip), %rdi     # 0x581b8
callq 0x2b6d3
movq %rax, 0x60(%rsp)
movq 0x8(%r14), %rax
movq (%rax), %r15
leaq 0x80(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x2e9af
leaq 0x15955(%rip), %rdi     # 0x581ce
callq 0x2f66f
movq %rax, %r13
movq %rdx, %rbp
movss 0x14050(%rip), %xmm0    # 0x568dc
movq %rax, %rdi
movq %rdx, %rsi
callq 0x2f34a
movq 0x18(%r12), %rdi
movq 0x20(%r12), %rsi
movss 0x158f3(%rip), %xmm0    # 0x5819c
callq 0x2f34a
movq 0x18(%r12), %rdx
movq 0x20(%r12), %rcx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2f42f
movq %r14, %rdi
callq 0x2fa22
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x428dd
cmpq %rcx, %rax
jae 0x42b1f
shrq $0x4, %r15
movabsq $0x14f8b588e368f085, %rcx # imm = 0x14F8B588E368F085
movq %r15, %rax
mulq %rcx
movq %rdx, %r13
shrq $0x8, %r13
movss 0x10968(%rip), %xmm0    # 0x53268
leaq 0xc0(%rsp), %r15
movaps %xmm0, 0x50(%rsp)
callq 0x3130
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 0x30125
movaps 0x50(%rsp), %xmm3
movaps %xmm3, %xmm1
cmpeqss 0x10902(%rip), %xmm1    # 0x53268
movaps %xmm1, %xmm2
andnps %xmm3, %xmm2
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
mulsd 0x15818(%rip), %xmm0    # 0x581a0
movsd %xmm0, 0x48(%rsp)
mulsd 0x15812(%rip), %xmm1    # 0x581a8
movsd %xmm1, 0x50(%rsp)
movq %r14, %rdi
callq 0x2fa22
movq %rax, %r12
movq 0x8(%r14), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x429bd
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x429d5
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 0x157ab(%rip), %xmm0    # 0x58198
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 0x2fa3d
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
callq 0x3130
subq %rbp, %rax
movq %rax, %rdi
callq 0xe8d4
cvtss2sd %xmm0, %xmm4
movq 0x8(%r14), %rax
movq (%rax), %rdx
leaq 0x156f7(%rip), %rdi     # 0x58134
movq %r12, %rsi
movsd 0x70(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
movsd 0x68(%rsp), %xmm3
movb $0x5, %al
callq 0x3170
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 0x42ab2
movq %r15, %rdi
leaq 0x15645(%rip), %rsi     # 0x580d5
leaq 0x155f6(%rip), %rdx     # 0x5808d
movq %rbx, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r15, %rsi
callq 0x66cd
movl %r12d, %r13d
movq %r14, %rdi
callq 0x2fa22
movabsq $-0x70a3d70a3d70a3d7, %rcx # imm = 0x8F5C28F5C28F5C29
imulq %rcx, %rax
rorq $0x2, %rax
movabsq $0x28f5c28f5c28f5c, %rcx # imm = 0x28F5C28F5C28F5C
cmpq %rcx, %rax
ja 0x42b01
movq %r15, %rdi
leaq 0x15601(%rip), %rsi     # 0x580e6
leaq 0x155a1(%rip), %rdx     # 0x5808d
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r15, %rsi
callq 0x66cd
movq %r14, %rdi
callq 0x2fa22
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x4290d
cmpq %rcx, %rax
jb 0x4290d
leaq 0x15647(%rip), %rsi     # 0x5816d
leaq 0x15560(%rip), %rdx     # 0x5808d
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r15, %rsi
callq 0x66cd
movq %r14, %rdi
callq 0x314d2
movq 0x60(%rsp), %rdi
movl $0xa, %esi
callq 0xeb09
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 0x2b6fd
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq