// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/super.c
// Function: train_super
void train_super(char *cfgfile, char *weightfile, int clear)
{
    char *train_images = "/data/imagenet/imagenet1k.train.list";
    char *backup_directory = "/home/pjreddie/backup/";
    srand(time(0));
    char *base = basecfg(cfgfile);
    printf("%s\n", base);
    float avg_loss = -1;
    network *net = load_network(cfgfile, weightfile, clear);
    printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
    int imgs = net->batch*net->subdivisions;
    int i = *net->seen/imgs;
    data train, buffer;


    list *plist = get_paths(train_images);
    //int N = plist->size;
    char **paths = (char **)list_to_array(plist);

    load_args args = {0};
    args.w = net->w;
    args.h = net->h;
    args.scale = 4;
    args.paths = paths;
    args.n = imgs;
    args.m = plist->size;
    args.d = &buffer;
    args.type = SUPER_DATA;

    pthread_t load_thread = load_data_in_thread(args);
    clock_t time;
    //while(i*imgs < N*120){
    while(get_current_batch(net) < net->max_batches){
        i += 1;
        time=clock();
        pthread_join(load_thread, 0);
        train = buffer;
        load_thread = load_data_in_thread(args);

        printf("Loaded: %lf seconds\n", sec(clock()-time));

        time=clock();
        float loss = train_network(net, train);
        if (avg_loss < 0) avg_loss = loss;
        avg_loss = avg_loss*.9 + loss*.1;

        printf("%d: %f, %f avg, %f rate, %lf seconds, %d images\n", i, loss, avg_loss, get_current_rate(net), sec(clock()-time), i*imgs);
        if(i%1000==0){
            char buff[256];
            sprintf(buff, "%s/%s_%d.weights", backup_directory, base, i);
            save_weights(net, buff);
        }
        if(i%100==0){
            char buff[256];
            sprintf(buff, "%s/%s.backup", backup_directory, base);
            save_weights(net, buff);
        }
        free_data(train);
    }
    char buff[256];
    sprintf(buff, "%s/%s_final.weights", backup_directory, base);
    save_weights(net, buff);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
xorl %edi, %edi
callq 0x32d0
movl %eax, %edi
callq 0x3230
movq %r15, %rdi
callq 0xe717
movq %rax, 0xb0(%rsp)
movq %rax, %rdi
callq 0x30c0
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x2f9e4
movq %rax, %r14
cvtss2sd 0x34(%rax), %xmm0
cvtss2sd 0x38(%rax), %xmm1
cvtss2sd 0x3c(%rax), %xmm2
leaq 0x162bf(%rip), %rdi     # 0x57e98
movb $0x3, %al
callq 0x3170
movslq 0x4(%r14), %rax
movslq 0x1c(%r14), %rbx
imulq %rax, %rbx
movq 0x8(%r14), %rax
movq (%rax), %r12
leaq 0x1644a(%rip), %rdi     # 0x58044
callq 0x296f8
movq %rax, %r15
movq %rax, %rdi
callq 0x10fa0
movq %rax, %r13
leaq 0x168(%rsp), %rbp
movl $0xa8, %edx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x31d0
movl 0x94(%r14), %eax
movl %eax, 0x2c(%rbp)
movl 0x90(%r14), %eax
movl %eax, 0x28(%rbp)
movl $0x4, 0x58(%rbp)
movq %r13, 0x8(%rbp)
movl %ebx, 0x18(%rbp)
movl (%r15), %eax
movl %eax, 0x1c(%rbp)
leaq 0x128(%rsp), %rax
movq %rax, 0x80(%rbp)
movl $0xc, 0x98(%rbp)
movl $0x15, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2dc84
movq %rax, %r15
movq %r14, %rdi
callq 0x2fa22
movslq 0x54(%r14), %rcx
cmpq %rcx, %rax
jae 0x41f24
movq %r12, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %r12
movss 0x115c5(%rip), %xmm0    # 0x53268
movaps %xmm0, 0xd0(%rsp)
movl %r12d, %ebp
leal 0x1(%rbp), %r12d
callq 0x3130
movq %rax, %r13
movq %r15, %rdi
xorl %esi, %esi
callq 0x3480
movups 0x128(%rsp), %xmm0
movups 0x138(%rsp), %xmm1
movups 0x148(%rsp), %xmm2
movups 0x158(%rsp), %xmm3
movaps %xmm0, 0xe0(%rsp)
movaps %xmm1, 0xf0(%rsp)
movaps %xmm2, 0x100(%rsp)
movaps %xmm3, 0x110(%rsp)
movl $0x15, %ecx
movq %rsp, %rdi
leaq 0x168(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2dc84
movq %rax, %r15
callq 0x3130
subq %r13, %rax
movq %rax, %rdi
callq 0xe8d4
cvtss2sd %xmm0, %xmm0
leaq 0x161cc(%rip), %rdi     # 0x57f06
movb $0x1, %al
callq 0x3170
callq 0x3130
movq %rax, %r13
movaps 0xe0(%rsp), %xmm0
movaps 0xf0(%rsp), %xmm1
movaps 0x100(%rsp), %xmm2
movaps 0x110(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x301c6
movaps 0xd0(%rsp), %xmm3
movaps %xmm3, %xmm1
cmpltss 0x112e0(%rip), %xmm1    # 0x53078
movaps %xmm1, %xmm2
andnps %xmm3, %xmm2
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xc8(%rsp)
mulsd 0x147f3(%rip), %xmm0    # 0x565b0
mulsd 0x160cb(%rip), %xmm1    # 0x57e90
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0xd0(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xc0(%rsp)
movq %r14, %rdi
callq 0x2fa3d
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb8(%rsp)
callq 0x3130
subq %r13, %rax
movq %rax, %rdi
callq 0xe8d4
xorps %xmm3, %xmm3
cvtss2sd %xmm0, %xmm3
movl %r12d, %edx
imull %ebx, %edx
leaq 0x16286(%rip), %rdi     # 0x580a4
movl %r12d, %esi
movsd 0xc8(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
movsd 0xb8(%rsp), %xmm2
movb $0x4, %al
callq 0x3170
imull $0x26e978d5, %ebp, %eax # imm = 0x26E978D5
addl $0x27ef9dad, %eax       # imm = 0x27EF9DAD
rorl $0x3, %eax
cmpl $0x418936, %eax         # imm = 0x418936
ja 0x41e8e
leaq 0x210(%rsp), %r13
movq %r13, %rdi
leaq 0x1626b(%rip), %rsi     # 0x580d5
leaq 0x1621c(%rip), %rdx     # 0x5808d
movq 0xb0(%rsp), %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r13, %rsi
callq 0x66cd
imull $0xc28f5c29, %r12d, %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
rorl $0x2, %eax
cmpl $0x28f5c28, %eax        # imm = 0x28F5C28
ja 0x41ed7
leaq 0x210(%rsp), %r13
movq %r13, %rdi
leaq 0x16230(%rip), %rsi     # 0x580e6
leaq 0x161d0(%rip), %rdx     # 0x5808d
movq 0xb0(%rsp), %rcx
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r13, %rsi
callq 0x66cd
movaps 0xe0(%rsp), %xmm0
movaps 0xf0(%rsp), %xmm1
movaps 0x100(%rsp), %xmm2
movaps 0x110(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x2b6fd
movq %r14, %rdi
callq 0x2fa22
movslq 0x54(%r14), %rcx
cmpq %rcx, %rax
jb 0x41cab
leaq 0x161c8(%rip), %rsi     # 0x580f3
leaq 0x1615b(%rip), %rdx     # 0x5808d
leaq 0x210(%rsp), %r15
movq %r15, %rdi
movq 0xb0(%rsp), %rcx
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %r15, %rsi
callq 0x66cd
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq