// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x3290
movl %eax, %edi
callq 0x31e0
movss 0x1f9a1(%rip), %xmm0    # 0x740dc
movss %xmm0, -0x14(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4850
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rsi
leaq 0x1fc45(%rip), %rdi     # 0x7439d
movb $0x0, %al
callq 0x3130
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x39a70
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movss 0x34(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x28(%rbp), %rax
movss 0x38(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x28(%rbp), %rax
movss 0x3c(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x20fc8(%rip), %rdi     # 0x75768
movb $0x3, %al
callq 0x3130
movl $0x400, -0x2c(%rbp)     # imm = 0x400
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
leaq 0x20fc1(%rip), %rdi     # 0x75794
callq 0x343c0
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x547f4
leaq 0x20fcc(%rip), %rdi     # 0x757b5
callq 0x31450
movq %rax, -0x40(%rbp)
jmp 0x54804
leaq 0x20fdb(%rip), %rdi     # 0x757d6
callq 0x31450
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x9020
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %esi
leaq 0x1e958(%rip), %rdi     # 0x73176
movb $0x0, %al
callq 0x3130
leaq -0x188(%rbp), %rdi
xorl %esi, %esi
movl $0xa8, %edx
callq 0x3190
movq -0x28(%rbp), %rax
movl 0x94(%rax), %eax
movl %eax, -0x15c(%rbp)
movq -0x28(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, -0x160(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x180(%rbp)
movl $0x1a, -0x138(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x170(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x16c(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0xe0(%rbp), %rax
movq %rax, -0x108(%rbp)
movl $0x0, -0xf0(%rbp)
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x188(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37500
movq %rax, -0x60(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
callq 0x30f0
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3440
leaq -0xa0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movl $0x40, %edx
callq 0x3280
movl -0x34(%rbp), %edi
movups -0xa0(%rbp), %xmm0
movups -0x90(%rbp), %xmm1
movups -0x80(%rbp), %xmm2
movups -0x70(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x54590
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x188(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37500
movq %rax, -0x60(%rbp)
callq 0x30f0
movq %rax, %rdi
subq -0x58(%rbp), %rdi
callq 0x4b50
cvtss2sd %xmm0, %xmm0
leaq 0x20e96(%rip), %rdi     # 0x757f4
movb $0x1, %al
callq 0x3130
callq 0x30f0
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
movups -0xa0(%rbp), %xmm0
movups -0x90(%rbp), %xmm1
movups -0x80(%rbp), %xmm2
movups -0x70(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x3a860
movss %xmm0, -0x18c(%rbp)
movss -0x14(%rbp), %xmm0
movss 0x1f728(%rip), %xmm1    # 0x740dc
ucomiss %xmm1, %xmm0
jne 0x549c8
jp 0x549c8
movss -0x18c(%rbp), %xmm0
movss %xmm0, -0x14(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x18c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x1f6d3(%rip), %xmm2    # 0x740b8
mulsd %xmm2, %xmm1
movsd 0x20d6f(%rip), %xmm2    # 0x75760
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x14(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x2a4(%rbp)
movss -0x18c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x298(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x2a0(%rbp)
callq 0x30f0
movq %rax, %rdi
subq -0x58(%rbp), %rdi
callq 0x4b50
movl -0x2a4(%rbp), %esi
movsd -0x2a0(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x298(%rbp), %xmm0
cvtss2sd %xmm2, %xmm2
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
leaq 0x20d99(%rip), %rdi     # 0x75809
movb $0x3, %al
callq 0x3130
movups -0xa0(%rbp), %xmm0
movups -0x90(%rbp), %xmm1
movups -0x80(%rbp), %xmm2
movups -0x70(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x34400
movl -0x30(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x54ae0
leaq -0x290(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl -0x30(%rbp), %ecx
leaq 0x20d69(%rip), %rsi     # 0x75832
movb $0x0, %al
callq 0x33f0
movq -0x28(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x41980
jmp 0x548c0
nopw %cs:(%rax,%rax)