// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/classifier.c
// Function: train_classifier
void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear)
{
    int i;

    float avg_loss = -1;
    char *base = basecfg(cfgfile);
    printf("%s\n", base);
    printf("%d\n", ngpus);
    network **nets = calloc(ngpus, sizeof(network*));

    srand(time(0));
    int seed = rand();
    for(i = 0; i < ngpus; ++i){
        srand(seed);
        nets[i] = load_network(cfgfile, weightfile, clear);
        nets[i]->learning_rate *= ngpus;
    }
    srand(time(0));
    network *net = nets[0];

    int imgs = net->batch * net->subdivisions * ngpus;

    printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
    list *options = read_data_cfg(datacfg);

    char *backup_directory = option_find_str(options, "backup", "/backup/");
    int tag = option_find_int_quiet(options, "tag", 0);
    char *label_list = option_find_str(options, "labels", "data/labels.list");
    char *train_list = option_find_str(options, "train", "data/train.list");
    char *tree = option_find_str(options, "tree", 0);
    if (tree) net->hierarchy = read_tree(tree);
    int classes = option_find_int(options, "classes", 2);

    char **labels = 0;
    if(!tag){
        labels = get_labels(label_list);
    }
    list *plist = get_paths(train_list);
    char **paths = (char **)list_to_array(plist);
    printf("%d\n", plist->size);
    int N = plist->size;
    double time;

    load_args args = {0};
    args.w = net->w;
    args.h = net->h;
    args.threads = 32;
    args.hierarchy = net->hierarchy;

    args.min = net->min_ratio*net->w;
    args.max = net->max_ratio*net->w;
    printf("%d %d\n", args.min, args.max);
    args.angle = net->angle;
    args.aspect = net->aspect;
    args.exposure = net->exposure;
    args.saturation = net->saturation;
    args.hue = net->hue;
    args.size = net->w;

    args.paths = paths;
    args.classes = classes;
    args.n = imgs;
    args.m = N;
    args.labels = labels;
    if (tag){
        args.type = TAG_DATA;
    } else {
        args.type = CLASSIFICATION_DATA;
    }

    data train;
    data buffer;
    pthread_t load_thread;
    args.d = &buffer;
    load_thread = load_data(args);

    int count = 0;
    int epoch = (*net->seen)/N;
    while(get_current_batch(net) < net->max_batches || net->max_batches == 0){
        if(net->random && count++%40 == 0){
            printf("Resizing\n");
            int dim = (rand() % 11 + 4) * 32;
            //if (get_current_batch(net)+200 > net->max_batches) dim = 608;
            //int dim = (rand() % 4 + 16) * 32;
            printf("%d\n", dim);
            args.w = dim;
            args.h = dim;
            args.size = dim;
            args.min = net->min_ratio*dim;
            args.max = net->max_ratio*dim;
            printf("%d %d\n", args.min, args.max);

            pthread_join(load_thread, 0);
            train = buffer;
            free_data(train);
            load_thread = load_data(args);

            for(i = 0; i < ngpus; ++i){
                resize_network(nets[i], dim, dim);
            }
            net = nets[0];
        }
        time = what_time_is_it_now();

        pthread_join(load_thread, 0);
        train = buffer;
        load_thread = load_data(args);

        printf("Loaded: %lf seconds\n", what_time_is_it_now()-time);
        time = what_time_is_it_now();

        float loss = 0;
        loss = train_network(net, train);
        if(avg_loss == -1) avg_loss = loss;
        avg_loss = avg_loss*.9 + loss*.1;
        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), what_time_is_it_now()-time, *net->seen);
        free_data(train);
        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)%1000 == 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);
    pthread_join(load_thread, 0);

    free_network(net);
    if(labels) free_ptrs((void**)labels, classes);
    free_ptrs((void**)paths, plist->size);
    free_list(plist);
    free(base);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5e0, %rsp            # imm = 0x5E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movss 0x127d1(%rip), %xmm0    # 0x740dc
movss %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4850
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
leaq 0x12a75(%rip), %rdi     # 0x7439d
movb $0x0, %al
callq 0x3130
movl -0x24(%rbp), %esi
leaq 0x1183d(%rip), %rdi     # 0x73176
movb $0x0, %al
callq 0x3130
movslq -0x24(%rbp), %rdi
movl $0x8, %esi
callq 0x3220
movq %rax, -0x40(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x3290
movl %eax, %edi
callq 0x31e0
callq 0x34b0
movl %eax, -0x44(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x619c6
movl -0x44(%rbp), %edi
callq 0x31e0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x28(%rbp), %edx
callq 0x39a70
movq %rax, %rdx
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
cvtsi2ssl -0x24(%rbp), %xmm0
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
mulss 0x34(%rax), %xmm0
movss %xmm0, 0x34(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x61971
xorl %eax, %eax
movl %eax, %edi
callq 0x3290
movl %eax, %edi
callq 0x31e0
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x50(%rbp), %rcx
imull 0x1c(%rcx), %eax
imull -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movss 0x34(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x50(%rbp), %rax
movss 0x38(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x50(%rbp), %rax
movss 0x3c(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x13d43(%rip), %rdi     # 0x75768
movb $0x3, %al
callq 0x3130
movq -0x8(%rbp), %rdi
callq 0x426b0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x141b6(%rip), %rsi     # 0x75bfa
leaq 0x13f38(%rip), %rdx     # 0x75983
callq 0x42920
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x1498d(%rip), %rsi     # 0x763ec
xorl %edx, %edx
callq 0x42b50
movl %eax, -0x6c(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x128d2(%rip), %rsi     # 0x74346
leaq 0x14975(%rip), %rdx     # 0x763f0
callq 0x42920
movq %rax, -0x78(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x1412d(%rip), %rsi     # 0x75bbc
leaq 0x14922(%rip), %rdx     # 0x763b8
callq 0x42920
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x12f99(%rip), %rsi     # 0x74a43
xorl %eax, %eax
movl %eax, %edx
callq 0x42920
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x61ade
movq -0x88(%rbp), %rdi
callq 0x4f1c0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x60(%rbp), %rdi
leaq 0x12f6e(%rip), %rsi     # 0x74a57
movl $0x2, %edx
callq 0x42990
movl %eax, -0x8c(%rbp)
movq $0x0, -0x98(%rbp)
cmpl $0x0, -0x6c(%rbp)
jne 0x61b1a
movq -0x78(%rbp), %rdi
callq 0x343c0
movq %rax, -0x98(%rbp)
movq -0x80(%rbp), %rdi
callq 0x31450
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x9020
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movl (%rax), %esi
leaq 0x11629(%rip), %rdi     # 0x73176
movb $0x0, %al
callq 0x3130
movq -0xa0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xac(%rbp)
leaq -0x160(%rbp), %rdi
xorl %esi, %esi
movl $0xa8, %edx
callq 0x3190
movq -0x50(%rbp), %rax
movl 0x94(%rax), %eax
movl %eax, -0x134(%rbp)
movq -0x50(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, -0x138(%rbp)
movl $0x20, -0x160(%rbp)
movq -0x50(%rbp), %rax
movq 0xd0(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x50(%rbp), %rax
movss 0xa8(%rax), %xmm0
movq -0x50(%rbp), %rax
cvtsi2ssl 0x94(%rax), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x11c(%rbp)
movq -0x50(%rbp), %rax
movss 0xa4(%rax), %xmm0
movq -0x50(%rbp), %rax
cvtsi2ssl 0x94(%rax), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x118(%rbp)
movl -0x11c(%rbp), %esi
movl -0x118(%rbp), %edx
leaq 0x1351f(%rip), %rdi     # 0x75130
movb $0x0, %al
callq 0x3130
movq -0x50(%rbp), %rax
movss 0xb0(%rax), %xmm0
movss %xmm0, -0xf8(%rbp)
movq -0x50(%rbp), %rax
movss 0xb4(%rax), %xmm0
movss %xmm0, -0xf4(%rbp)
movq -0x50(%rbp), %rax
movss 0xb8(%rax), %xmm0
movss %xmm0, -0xec(%rbp)
movq -0x50(%rbp), %rax
movss 0xbc(%rax), %xmm0
movss %xmm0, -0xf0(%rbp)
movq -0x50(%rbp), %rax
movss 0xc0(%rax), %xmm0
movss %xmm0, -0xe8(%rbp)
movq -0x50(%rbp), %rax
movl 0x94(%rax), %eax
movl %eax, -0x114(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x158(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x110(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x148(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0x144(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x140(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x61cdb
movl $0x8, -0xc8(%rbp)
jmp 0x61ce5
movl $0x0, -0xc8(%rbp)
leaq -0x1e0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x160(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37900
movq %rax, -0x1e8(%rbp)
movl $0x0, -0x1ec(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0xac(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x1f0(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39ad0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movslq 0x54(%rax), %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, -0x501(%rbp)
jb 0x61d6a
movq -0x50(%rbp), %rax
cmpl $0x0, 0x54(%rax)
sete %al
movb %al, -0x501(%rbp)
movb -0x501(%rbp), %al
testb $0x1, %al
jne 0x61d79
jmp 0x62246
movq -0x50(%rbp), %rax
cmpl $0x0, 0xc4(%rax)
je 0x61f26
movl -0x1ec(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x1ec(%rbp)
movl $0x28, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x61f26
leaq 0x1464e(%rip), %rdi     # 0x76401
movb $0x0, %al
callq 0x3130
callq 0x34b0
movl $0xb, %ecx
cltd
idivl %ecx
movl %edx, %eax
addl $0x4, %eax
shll $0x5, %eax
movl %eax, -0x1f4(%rbp)
movl -0x1f4(%rbp), %esi
leaq 0x11394(%rip), %rdi     # 0x73176
movb $0x0, %al
callq 0x3130
movl -0x1f4(%rbp), %eax
movl %eax, -0x134(%rbp)
movl -0x1f4(%rbp), %eax
movl %eax, -0x138(%rbp)
movl -0x1f4(%rbp), %eax
movl %eax, -0x114(%rbp)
movq -0x50(%rbp), %rax
movss 0xa8(%rax), %xmm0
cvtsi2ssl -0x1f4(%rbp), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x11c(%rbp)
movq -0x50(%rbp), %rax
movss 0xa4(%rax), %xmm0
cvtsi2ssl -0x1f4(%rbp), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x118(%rbp)
movl -0x11c(%rbp), %esi
movl -0x118(%rbp), %edx
leaq 0x132cc(%rip), %rdi     # 0x75130
movb $0x0, %al
callq 0x3130
movq -0x1e8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3440
leaq -0x1a0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
movl $0x40, %edx
callq 0x3280
movups -0x1a0(%rbp), %xmm0
movups -0x190(%rbp), %xmm1
movups -0x180(%rbp), %xmm2
movups -0x170(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x34400
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x160(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37900
movq %rax, -0x1e8(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x61f1b
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x1f4(%rbp), %esi
movl -0x1f4(%rbp), %edx
callq 0x3aa00
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x61eeb
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movb $0x0, %al
callq 0x3f10
movsd %xmm0, -0xb8(%rbp)
movq -0x1e8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3440
leaq -0x1a0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
movl $0x40, %edx
callq 0x3280
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x160(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37900
movq %rax, -0x1e8(%rbp)
movb $0x0, %al
callq 0x3f10
subsd -0xb8(%rbp), %xmm0
leaq 0x13863(%rip), %rdi     # 0x757f4
movb $0x1, %al
callq 0x3130
movb $0x0, %al
callq 0x3f10
movsd %xmm0, -0xb8(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1f8(%rbp)
movq -0x50(%rbp), %rdi
movups -0x1a0(%rbp), %xmm0
movups -0x190(%rbp), %xmm1
movups -0x180(%rbp), %xmm2
movups -0x170(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x3a860
movss %xmm0, -0x1f8(%rbp)
movss -0x30(%rbp), %xmm0
movss 0x120de(%rip), %xmm1    # 0x740dc
ucomiss %xmm1, %xmm0
jne 0x62012
jp 0x62012
movss -0x1f8(%rbp), %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x1f8(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x12089(%rip), %xmm2    # 0x740b8
mulsd %xmm2, %xmm1
movsd 0x13725(%rip), %xmm2    # 0x75760
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39ad0
movq %rax, -0x518(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x50c(%rbp)
testq %rax, %rax
movss %xmm0, -0x508(%rbp)
js 0x620a8
movss -0x50c(%rbp), %xmm0
movss %xmm0, -0x508(%rbp)
movss -0x508(%rbp), %xmm0
cvtsi2ssl -0xac(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x520(%rbp)
movss -0x1f8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x538(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x530(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39b60
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x528(%rbp)
movb $0x0, %al
callq 0x3f10
movq -0x518(%rbp), %rsi
movsd -0x538(%rbp), %xmm1
movsd -0x530(%rbp), %xmm2
movsd -0x528(%rbp), %xmm3
movaps %xmm0, %xmm4
movsd -0x520(%rbp), %xmm0
subsd -0xb8(%rbp), %xmm4
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
leaq 0x138cf(%rip), %rdi     # 0x75a1c
movb $0x5, %al
callq 0x3130
movups -0x1a0(%rbp), %xmm0
movups -0x190(%rbp), %xmm1
movups -0x180(%rbp), %xmm2
movups -0x170(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x34400
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0xac(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movslq -0x1f0(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x621fb
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0xac(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x1f0(%rbp)
leaq -0x300(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl -0x1f0(%rbp), %r8d
leaq 0x137d9(%rip), %rsi     # 0x759bd
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x41980
movq -0x50(%rbp), %rdi
callq 0x39ad0
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x62241
leaq -0x400(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x137a4(%rip), %rsi     # 0x759ce
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x41980
jmp 0x61d38
leaq -0x500(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x137f9(%rip), %rsi     # 0x75a55
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x500(%rbp), %rsi
callq 0x41980
movq -0x1e8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3440
movq -0x50(%rbp), %rdi
callq 0x3c0b0
cmpq $0x0, -0x98(%rbp)
je 0x622a8
movq -0x98(%rbp), %rdi
movl -0x8c(%rbp), %esi
callq 0x4f40
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rax
movl (%rax), %esi
callq 0x4f40
movq -0xa0(%rbp), %rdi
callq 0x8fb0
movq -0x38(%rbp), %rdi
callq 0x3030
addq $0x5e0, %rsp            # imm = 0x5E0
popq %rbp
retq
nopl (%rax,%rax)