// File: /workspace/github_c_makefile_star2_O2/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 0x41c8
movq %rax, 0xa8(%rsp)
movq %rax, %rdi
callq 0x30b0
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x22658
movq %rax, %r14
cvtss2sd 0x34(%rax), %xmm0
cvtss2sd 0x38(%rax), %xmm1
cvtss2sd 0x3c(%rax), %xmm2
leaq 0x1a692(%rip), %rdi     # 0x50ed0
movb $0x3, %al
callq 0x3160
movq 0x8(%r14), %rax
movq (%rax), %r15
shrq $0xa, %r15
leaq 0x1a6a5(%rip), %rdi     # 0x50efc
callq 0x1e673
movq %rax, %rbx
leaq 0x1a6b7(%rip), %rdi     # 0x50f1d
callq 0x1c8c8
movq %rax, %r12
movq %rax, %rdi
callq 0x72f5
movq %rax, %r13
movl (%r12), %esi
leaq 0x1abcd(%rip), %rdi     # 0x51451
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)
pushq $0x15
popq %rcx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x20b03
movq %rax, %r13
incl %r15d
movss 0x1596c(%rip), %xmm0    # 0x4c264
leaq 0x1a654(%rip), %r12     # 0x50f53
pushq $0x64
popq %rbx
movaps %xmm0, 0xc0(%rsp)
callq 0x3120
movq %rax, %rbp
movq %r13, %rdi
xorl %esi, %esi
callq 0x3470
movups 0x118(%rsp), %xmm0
movups 0x128(%rsp), %xmm1
movups 0x138(%rsp), %xmm2
movups 0x148(%rsp), %xmm3
movaps %xmm0, 0xd0(%rsp)
movaps %xmm1, 0xe0(%rsp)
movaps %xmm2, 0xf0(%rsp)
movaps %xmm3, 0x100(%rsp)
movups 0x118(%rsp), %xmm0
movups 0x128(%rsp), %xmm1
movups 0x138(%rsp), %xmm2
movups 0x148(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x1
popq %rdi
callq 0x36758
pushq $0x15
popq %rcx
movq %rsp, %rdi
leaq 0x158(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x20b03
movq %rax, %r13
callq 0x3120
subq %rbp, %rax
movq %rax, %rdi
callq 0x437c
cvtss2sd %xmm0, %xmm0
leaq 0x1a573(%rip), %rdi     # 0x50f3e
movb $0x1, %al
callq 0x3160
callq 0x3120
movq %rax, %rbp
movaps 0xd0(%rsp), %xmm0
movaps 0xe0(%rsp), %xmm1
movaps 0xf0(%rsp), %xmm2
movaps 0x100(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x22df8
movaps 0xc0(%rsp), %xmm3
movaps %xmm3, %xmm1
cmpeqss 0x1583b(%rip), %xmm1    # 0x4c264
movaps %xmm1, %xmm2
andnps %xmm3, %xmm2
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb8(%rsp)
mulsd 0x18b82(%rip), %xmm0    # 0x4f5d0
mulsd 0x1a472(%rip), %xmm1    # 0x50ec8
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0xc0(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb0(%rsp)
callq 0x3120
subq %rbp, %rax
movq %rax, %rdi
callq 0x437c
cvtss2sd %xmm0, %xmm2
movq 0x8(%r14), %rax
movq (%rax), %rdx
movq %r12, %rdi
movl %r15d, %esi
movsd 0xb8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
movb $0x3, %al
callq 0x3160
movaps 0xd0(%rsp), %xmm0
movaps 0xe0(%rsp), %xmm1
movaps 0xf0(%rsp), %xmm2
movaps 0x100(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1e69d
movl %r15d, %eax
cltd
idivl %ebx
testl %edx, %edx
jne 0x36b1e
leaq 0x200(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1a47b(%rip), %rsi     # 0x50f7c
movq 0xa8(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %rbp, %rsi
callq 0x28aed
incl %r15d
jmp 0x3690a