// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/regressor.c
// Function: train_regressor
void train_regressor(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/");
    char *train_list = option_find_str(options, "train", "data/train.list");
    int classes = option_find_int(options, "classes", 1);

    list *plist = get_paths(train_list);
    char **paths = (char **)list_to_array(plist);
    printf("%d\n", plist->size);
    int N = plist->size;
    clock_t time;

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

    args.min = net->min_ratio*net->w;
    args.max = net->max_ratio*net->w;
    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.n = imgs;
    args.m = N;
    args.type = REGRESSION_DATA;

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

    int epoch = (*net->seen)/N;
    while(get_current_batch(net) < net->max_batches || net->max_batches == 0){
        time=clock();

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

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

        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), sec(clock()-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)%100 == 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);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5b0, %rsp            # imm = 0x5B0
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 0x13451(%rip), %xmm0    # 0x740dc
movss %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4850
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
leaq 0x136f5(%rip), %rdi     # 0x7439d
movb $0x0, %al
callq 0x3130
movl -0x24(%rbp), %esi
leaq 0x124bd(%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 0x60d46
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 0x60cf1
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 0x149c3(%rip), %rdi     # 0x75768
movb $0x3, %al
callq 0x3130
movq -0x8(%rbp), %rdi
callq 0x426b0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x14e36(%rip), %rsi     # 0x75bfa
leaq 0x14bb8(%rip), %rdx     # 0x75983
callq 0x42920
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x14ddd(%rip), %rsi     # 0x75bbc
leaq 0x155d2(%rip), %rdx     # 0x763b8
callq 0x42920
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x13c5d(%rip), %rsi     # 0x74a57
movl $0x1, %edx
callq 0x42990
movl %eax, -0x74(%rbp)
movq -0x70(%rbp), %rdi
callq 0x31450
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0x9020
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movl (%rax), %esi
leaq 0x12345(%rip), %rdi     # 0x73176
movb $0x0, %al
callq 0x3130
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
leaq -0x140(%rbp), %rdi
xorl %esi, %esi
movl $0xa8, %edx
callq 0x3190
movq -0x50(%rbp), %rax
movl 0x94(%rax), %eax
movl %eax, -0x114(%rbp)
movq -0x50(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, -0x118(%rbp)
movl $0x20, -0x140(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0xf0(%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, -0xfc(%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, -0xf8(%rbp)
movq -0x50(%rbp), %rax
movss 0xb0(%rax), %xmm0
movss %xmm0, -0xd8(%rbp)
movq -0x50(%rbp), %rax
movss 0xb4(%rax), %xmm0
movss %xmm0, -0xd4(%rbp)
movq -0x50(%rbp), %rax
movss 0xb8(%rax), %xmm0
movss %xmm0, -0xcc(%rbp)
movq -0x50(%rbp), %rax
movss 0xbc(%rax), %xmm0
movss %xmm0, -0xd0(%rbp)
movq -0x50(%rbp), %rax
movss 0xc0(%rax), %xmm0
movss %xmm0, -0xc8(%rbp)
movq -0x50(%rbp), %rax
movl 0x94(%rax), %eax
movl %eax, -0xf4(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x138(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x128(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x124(%rbp)
movl $0xe, -0xa8(%rbp)
leaq -0x1c0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x140(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37900
movq %rax, -0x1c8(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x8c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x1cc(%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, -0x4d1(%rbp)
jb 0x60ff2
movq -0x50(%rbp), %rax
cmpl $0x0, 0x54(%rax)
sete %al
movb %al, -0x4d1(%rbp)
movb -0x4d1(%rbp), %al
testb $0x1, %al
jne 0x61001
jmp 0x6132d
callq 0x30f0
movq %rax, -0x98(%rbp)
movq -0x1c8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3440
leaq -0x180(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
movl $0x40, %edx
callq 0x3280
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x140(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37900
movq %rax, -0x1c8(%rbp)
callq 0x30f0
movq %rax, %rdi
subq -0x98(%rbp), %rdi
callq 0x4b50
cvtss2sd %xmm0, %xmm0
leaq 0x14782(%rip), %rdi     # 0x757f4
movb $0x1, %al
callq 0x3130
callq 0x30f0
movq %rax, -0x98(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1d0(%rbp)
movq -0x50(%rbp), %rdi
movups -0x180(%rbp), %xmm0
movups -0x170(%rbp), %xmm1
movups -0x160(%rbp), %xmm2
movups -0x150(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x3a860
movss %xmm0, -0x1d0(%rbp)
movss -0x30(%rbp), %xmm0
movss 0x13000(%rip), %xmm1    # 0x740dc
ucomiss %xmm1, %xmm0
jne 0x610f0
jp 0x610f0
movss -0x1d0(%rbp), %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x1d0(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x12fab(%rip), %xmm2    # 0x740b8
mulsd %xmm2, %xmm1
movsd 0x14647(%rip), %xmm2    # 0x75760
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39ad0
movq %rax, -0x4e8(%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, -0x4dc(%rbp)
testq %rax, %rax
movss %xmm0, -0x4d8(%rbp)
js 0x61186
movss -0x4dc(%rbp), %xmm0
movss %xmm0, -0x4d8(%rbp)
movss -0x4d8(%rbp), %xmm0
cvtsi2ssl -0x8c(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x4f0(%rbp)
movss -0x1d0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x508(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x500(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39b60
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x4f8(%rbp)
callq 0x30f0
movq %rax, %rdi
subq -0x98(%rbp), %rdi
callq 0x4b50
movq -0x4e8(%rbp), %rsi
movsd -0x508(%rbp), %xmm1
movsd -0x500(%rbp), %xmm2
movsd -0x4f8(%rbp), %xmm3
movaps %xmm0, %xmm4
movsd -0x4f0(%rbp), %xmm0
cvtss2sd %xmm4, %xmm4
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
leaq 0x147e8(%rip), %rdi     # 0x75a1c
movb $0x5, %al
callq 0x3130
movups -0x180(%rbp), %xmm0
movups -0x170(%rbp), %xmm1
movups -0x160(%rbp), %xmm2
movups -0x150(%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 -0x8c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movslq -0x1cc(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x612e2
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x8c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x1cc(%rbp)
leaq -0x2d0(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl -0x1cc(%rbp), %r8d
leaq 0x146f2(%rip), %rsi     # 0x759bd
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x41980
movq -0x50(%rbp), %rdi
callq 0x39ad0
movl $0x64, %ecx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x61328
leaq -0x3d0(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x146bd(%rip), %rsi     # 0x759ce
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x41980
jmp 0x60fc0
leaq -0x4d0(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x14712(%rip), %rsi     # 0x75a55
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
callq 0x41980
movq -0x50(%rbp), %rdi
callq 0x3c0b0
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rax
movl (%rax), %esi
callq 0x4f40
movq -0x80(%rbp), %rdi
callq 0x8fb0
movq -0x38(%rbp), %rdi
callq 0x3030
addq $0x5b0, %rsp            # imm = 0x5B0
popq %rbp
retq