// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/captcha.c
// Function: train_captcha
void train_captcha(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);
    int imgs = 1024;
    int i = *net->seen/imgs;
    int solved = 1;
    list *plist;
    char **labels = get_labels("/data/captcha/reimgs.labels.list");
    if (solved){
        plist = get_paths("/data/captcha/reimgs.solved.list");
    }else{
        plist = get_paths("/data/captcha/reimgs.raw.list");
    }
    char **paths = (char **)list_to_array(plist);
    printf("%d\n", plist->size);
    clock_t time;
    pthread_t load_thread;
    data train;
    data buffer;

    load_args args = {0};
    args.w = net->w;
    args.h = net->h;
    args.paths = paths;
    args.classes = 26;
    args.n = imgs;
    args.m = plist->size;
    args.labels = labels;
    args.d = &buffer;
    args.type = CLASSIFICATION_DATA;

    load_thread = load_data_in_thread(args);
    while(1){
        ++i;
        time=clock();
        pthread_join(load_thread, 0);
        train = buffer;
        fix_data_captcha(train, solved);

        /*
           image im = float_to_image(256, 256, 3, train.X.vals[114]);
           show_image(im, "training");
           cvWaitKey(0);
         */

        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 == -1) avg_loss = loss;
        avg_loss = avg_loss*.9 + loss*.1;
        printf("%d: %f, %f avg, %lf seconds, %ld images\n", i, loss, avg_loss, sec(clock()-time), *net->seen);
        free_data(train);
        if(i%100==0){
            char buff[256];
            sprintf(buff, "/home/pjreddie/imagenet_backup/%s_%d.weights",base, i);
            save_weights(net, buff);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rsi, %rbx
movq %rdi, %r14
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movq %r14, %rdi
callq 0xef02
movq %rax, 0xa8(%rsp)
movq %rax, %rdi
callq 0x30b0
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x316bc
movq %rax, %r14
cvtss2sd 0x34(%rax), %xmm0
cvtss2sd 0x38(%rax), %xmm1
cvtss2sd 0x3c(%rax), %xmm2
leaq 0x17410(%rip), %rdi     # 0x59fd0
movb $0x3, %al
callq 0x3160
movq 0x8(%r14), %rax
movq (%rax), %r15
shrq $0xa, %r15
leaq 0x17423(%rip), %rdi     # 0x59ffc
callq 0x2d26c
movq %rax, %rbx
leaq 0x17435(%rip), %rdi     # 0x5a01d
callq 0x2af38
movq %rax, %r12
movq %rax, %rdi
callq 0x11928
movq %rax, %r13
movl (%r12), %esi
leaq 0x17993(%rip), %rdi     # 0x5a599
xorl %eax, %eax
callq 0x3160
leaq 0x158(%rsp), %rbp
movl $0xa8, %edx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x31c0
movq 0x90(%r14), %rax
movq %rax, 0x28(%rbp)
movq %r13, 0x8(%rbp)
movl $0x1a, 0x50(%rbp)
movl $0x400, 0x18(%rbp)      # imm = 0x400
movl (%r12), %eax
movl %eax, 0x1c(%rbp)
movq %rbx, 0x20(%rbp)
leaq 0x118(%rsp), %rax
movq %rax, 0x80(%rbp)
movl $0x15, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq %rax, %rbx
leaq 0x173c6(%rip), %r13     # 0x5a03e
leaq 0x173d4(%rip), %rbp     # 0x5a053
movss 0x1260d(%rip), %xmm0    # 0x55294
movaps %xmm0, 0x100(%rsp)
callq 0x3120
movq %rax, %r12
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3470
movups 0x118(%rsp), %xmm0
movups 0x128(%rsp), %xmm1
movups 0x138(%rsp), %xmm2
movups 0x148(%rsp), %xmm3
movaps %xmm1, 0xd0(%rsp)
movaps %xmm2, 0xe0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm3, 0xf0(%rsp)
movslq 0xd8(%rsp), %rax
testq %rax, %rax
xorps %xmm1, %xmm1
movsd 0x15cd9(%rip), %xmm2    # 0x589d0
jle 0x42d52
movq 0xe0(%rsp), %rcx
movslq 0xdc(%rsp), %rdx
xorl %esi, %esi
testl %edx, %edx
jle 0x42d4a
movq (%rcx,%rsi,8), %rdi
xorl %r8d, %r8d
movss (%rdi,%r8,4), %xmm0
ucomiss %xmm1, %xmm0
jne 0x42d23
jnp 0x42d3b
movss 0x4(%rdi,%r8,4), %xmm0
ucomiss %xmm1, %xmm0
jne 0x42d31
jnp 0x42d41
movl $0x0, (%rdi,%r8,4)
jmp 0x42d41
movsd %xmm2, (%rdi,%r8,4)
addq $0x2, %r8
cmpq %rdx, %r8
jl 0x42d16
incq %rsi
cmpq %rax, %rsi
jne 0x42d0b
incl %r15d
movl $0x15, %ecx
movq %rsp, %rdi
leaq 0x158(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq %rax, %rbx
callq 0x3120
subq %r12, %rax
movq %rax, %rdi
callq 0xf0bf
cvtss2sd %xmm0, %xmm0
movq %r13, %rdi
movb $0x1, %al
callq 0x3160
callq 0x3120
movq %rax, %r12
movaps 0xc0(%rsp), %xmm0
movaps 0xd0(%rsp), %xmm1
movaps 0xe0(%rsp), %xmm2
movaps 0xf0(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x31ea6
movaps 0x100(%rsp), %xmm3
movaps %xmm3, %xmm1
cmpeqss 0x124af(%rip), %xmm1    # 0x55294
movaps %xmm1, %xmm2
andnps %xmm3, %xmm2
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb8(%rsp)
mulsd 0x15876(%rip), %xmm0    # 0x58680
mulsd 0x171b6(%rip), %xmm1    # 0x59fc8
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0x100(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb0(%rsp)
callq 0x3120
subq %r12, %rax
movq %rax, %rdi
callq 0xf0bf
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
movq 0x8(%r14), %rax
movq (%rax), %rdx
movq %rbp, %rdi
movl %r15d, %esi
movsd 0xb8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
movb $0x3, %al
callq 0x3160
movaps 0xc0(%rsp), %xmm0
movaps 0xd0(%rsp), %xmm1
movaps 0xe0(%rsp), %xmm2
movaps 0xf0(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x2d296
imull $0xc28f5c29, %r15d, %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
rorl $0x2, %eax
cmpl $0x28f5c28, %eax        # imm = 0x28F5C28
ja 0x42c8f
leaq 0x200(%rsp), %r12
movq %r12, %rdi
leaq 0x171a9(%rip), %rsi     # 0x5a07c
movq 0xa8(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r12, %rsi
callq 0x6879
jmp 0x42c8f