// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/segmenter.c
// Function: train_segmenter
void train_segmenter(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear, int display)
{
    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];
    image pred = get_network_image(net);

    int div = net->w/pred.w;
    assert(pred.w * div == net->w);
    assert(pred.h * div == net->h);

    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");

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

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

    args.min = net->min_crop;
    args.max = net->max_crop;
    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.classes = 80;

    args.paths = paths;
    args.n = imgs;
    args.m = N;
    args.type = SEGMENTATION_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){
        double 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(display){
            image tr = float_to_image(net->w/div, net->h/div, 80, train.y.vals[net->batch*(net->subdivisions-1)]);
            image im = float_to_image(net->w, net->h, net->c, train.X.vals[net->batch*(net->subdivisions-1)]);
            image mask = mask_to_rgb(tr);
            image prmask = mask_to_rgb(pred);
            show_image(im, "input", 1);
            show_image(prmask, "pred", 1);
            show_image(mask, "truth", 100);
            free_image(mask);
            free_image(prmask);
        }
        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)%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 $0x630, %rsp            # imm = 0x630
movl 0x10(%rbp), %eax
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 0x1435e(%rip), %xmm0    # 0x740dc
movss %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4850
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
leaq 0x14602(%rip), %rdi     # 0x7439d
movb $0x0, %al
callq 0x3130
movl -0x24(%rbp), %esi
leaq 0x133ca(%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 0x5fe39
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 0x5fde4
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), %rsi
leaq -0x68(%rbp), %rdi
callq 0x3afe0
movq -0x50(%rbp), %rax
movl 0x94(%rax), %eax
cltd
idivl -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl -0x68(%rbp), %eax
imull -0x6c(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0x94(%rcx), %eax
jne 0x5fe87
jmp 0x5fea6
leaq 0x164b9(%rip), %rdi     # 0x76347
leaq 0x16d0e(%rip), %rsi     # 0x76ba3
movl $0x1b, %edx
leaq 0x164bd(%rip), %rcx     # 0x7635e
callq 0x3180
movl -0x64(%rbp), %eax
imull -0x6c(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0x90(%rcx), %eax
jne 0x5febb
jmp 0x5feda
leaq 0x164df(%rip), %rdi     # 0x763a1
leaq 0x16cda(%rip), %rsi     # 0x76ba3
movl $0x1c, %edx
leaq 0x16489(%rip), %rcx     # 0x7635e
callq 0x3180
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x50(%rbp), %rcx
imull 0x1c(%rcx), %eax
imull -0x24(%rbp), %eax
movl %eax, -0x70(%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 0x1584a(%rip), %rdi     # 0x75768
movb $0x3, %al
callq 0x3130
movq -0x8(%rbp), %rdi
callq 0x426b0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
leaq 0x15cbd(%rip), %rsi     # 0x75bfa
leaq 0x15a3f(%rip), %rdx     # 0x75983
callq 0x42920
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
leaq 0x15c64(%rip), %rsi     # 0x75bbc
leaq 0x16459(%rip), %rdx     # 0x763b8
callq 0x42920
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0x31450
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0x9020
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
movl (%rax), %esi
leaq 0x131d5(%rip), %rdi     # 0x73176
movb $0x0, %al
callq 0x3130
movq -0x90(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
leaq -0x148(%rbp), %rdi
xorl %esi, %esi
movl $0xa8, %edx
callq 0x3190
movq -0x50(%rbp), %rax
movl 0x94(%rax), %eax
movl %eax, -0x11c(%rbp)
movq -0x50(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, -0x120(%rbp)
movl $0x20, -0x148(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0xf0(%rbp)
movq -0x50(%rbp), %rax
movl 0xa0(%rax), %eax
movl %eax, -0x104(%rbp)
movq -0x50(%rbp), %rax
movl 0x9c(%rax), %eax
movl %eax, -0x100(%rbp)
movq -0x50(%rbp), %rax
movss 0xb0(%rax), %xmm0
movss %xmm0, -0xe0(%rbp)
movq -0x50(%rbp), %rax
movss 0xb4(%rax), %xmm0
movss %xmm0, -0xdc(%rbp)
movq -0x50(%rbp), %rax
movss 0xb8(%rax), %xmm0
movss %xmm0, -0xd4(%rbp)
movq -0x50(%rbp), %rax
movss 0xbc(%rax), %xmm0
movss %xmm0, -0xd8(%rbp)
movq -0x50(%rbp), %rax
movss 0xc0(%rax), %xmm0
movss %xmm0, -0xd0(%rbp)
movq -0x50(%rbp), %rax
movl 0x94(%rax), %eax
movl %eax, -0xfc(%rbp)
movl $0x50, -0xf8(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x140(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x130(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x12c(%rbp)
movl $0xf, -0xb0(%rbp)
leaq -0x1c8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x148(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37900
movq %rax, -0x1d0(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x9c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x1d4(%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, -0x551(%rbp)
jb 0x60143
movq -0x50(%rbp), %rax
cmpl $0x0, 0x54(%rax)
sete %al
movb %al, -0x551(%rbp)
movb -0x551(%rbp), %al
testb $0x1, %al
jne 0x60152
jmp 0x60650
movb $0x0, %al
callq 0x3f10
movsd %xmm0, -0x1e0(%rbp)
movq -0x1d0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3440
leaq -0x188(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x40, %edx
callq 0x3280
movq %rsp, %rdi
movl $0x15, %ecx
leaq -0x148(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x37900
movq %rax, -0x1d0(%rbp)
movb $0x0, %al
callq 0x3f10
subsd -0x1e0(%rbp), %xmm0
leaq 0x15637(%rip), %rdi     # 0x757f4
movb $0x1, %al
callq 0x3130
movb $0x0, %al
callq 0x3f10
movsd %xmm0, -0x1e0(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1e4(%rbp)
movq -0x50(%rbp), %rdi
movups -0x188(%rbp), %xmm0
movups -0x178(%rbp), %xmm1
movups -0x168(%rbp), %xmm2
movups -0x158(%rbp), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x3a860
movss %xmm0, -0x1e4(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x603fb
movq -0x50(%rbp), %rax
movl 0x94(%rax), %eax
cltd
idivl -0x6c(%rbp)
movl %eax, %esi
movq -0x50(%rbp), %rax
movl 0x90(%rax), %eax
cltd
idivl -0x6c(%rbp)
movl %eax, %edx
movq -0x168(%rbp), %rax
movq -0x50(%rbp), %rcx
movl 0x4(%rcx), %ecx
movq -0x50(%rbp), %rdi
movl 0x1c(%rdi), %edi
subl $0x1, %edi
imull %edi, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %r8
leaq -0x200(%rbp), %rdi
movl $0x50, %ecx
callq 0xfbb0
movq -0x50(%rbp), %rax
movl 0x94(%rax), %esi
movq -0x50(%rbp), %rax
movl 0x90(%rax), %edx
movq -0x50(%rbp), %rax
movl 0x98(%rax), %ecx
movq -0x178(%rbp), %rax
movq -0x50(%rbp), %rdi
movl 0x4(%rdi), %edi
movq -0x50(%rbp), %r8
movl 0x1c(%r8), %r8d
subl $0x1, %r8d
imull %r8d, %edi
movslq %edi, %rdi
movq (%rax,%rdi,8), %r8
leaq -0x218(%rbp), %rdi
callq 0xfbb0
leaq -0x230(%rbp), %rdi
leaq -0x200(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xe230
leaq -0x248(%rbp), %rdi
leaq -0x68(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xe230
leaq -0x218(%rbp), %rax
leaq 0x1609c(%rip), %rdi     # 0x763c8
movl $0x1, %esi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x112c0
leaq -0x248(%rbp), %rax
leaq 0x16071(%rip), %rdi     # 0x763ce
movl $0x1, %esi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x112c0
leaq -0x230(%rbp), %rax
leaq 0x149fb(%rip), %rdi     # 0x74d89
movl $0x64, %esi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x112c0
leaq -0x230(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xedb0
leaq -0x248(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xedb0
movss -0x30(%rbp), %xmm0
movss 0x13cd4(%rip), %xmm1    # 0x740dc
ucomiss %xmm1, %xmm0
jne 0x6041c
jp 0x6041c
movss -0x1e4(%rbp), %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x1e4(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x13c7f(%rip), %xmm2    # 0x740b8
mulsd %xmm2, %xmm1
movsd 0x1531b(%rip), %xmm2    # 0x75760
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39ad0
movq %rax, -0x568(%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, -0x55c(%rbp)
testq %rax, %rax
movss %xmm0, -0x558(%rbp)
js 0x604b2
movss -0x55c(%rbp), %xmm0
movss %xmm0, -0x558(%rbp)
movss -0x558(%rbp), %xmm0
cvtsi2ssl -0x9c(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x570(%rbp)
movss -0x1e4(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x588(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x580(%rbp)
movq -0x50(%rbp), %rdi
callq 0x39b60
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x578(%rbp)
movb $0x0, %al
callq 0x3f10
movq -0x568(%rbp), %rsi
movsd -0x588(%rbp), %xmm1
movsd -0x580(%rbp), %xmm2
movsd -0x578(%rbp), %xmm3
movaps %xmm0, %xmm4
movsd -0x570(%rbp), %xmm0
subsd -0x1e0(%rbp), %xmm4
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
leaq 0x154c5(%rip), %rdi     # 0x75a1c
movb $0x5, %al
callq 0x3130
movups -0x188(%rbp), %xmm0
movups -0x178(%rbp), %xmm1
movups -0x168(%rbp), %xmm2
movups -0x158(%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 -0x9c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movslq -0x1d4(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x60605
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x9c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x1d4(%rbp)
leaq -0x350(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl -0x1d4(%rbp), %r8d
leaq 0x153cf(%rip), %rsi     # 0x759bd
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x41980
movq -0x50(%rbp), %rdi
callq 0x39ad0
movl $0x64, %ecx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x6064b
leaq -0x450(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x1539a(%rip), %rsi     # 0x759ce
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0x41980
jmp 0x60111
leaq -0x550(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x153ef(%rip), %rsi     # 0x75a55
movb $0x0, %al
callq 0x33f0
movq -0x50(%rbp), %rdi
leaq -0x550(%rbp), %rsi
callq 0x41980
movq -0x50(%rbp), %rdi
callq 0x3c0b0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rax
movl (%rax), %esi
callq 0x4f40
movq -0x90(%rbp), %rdi
callq 0x8fb0
movq -0x38(%rbp), %rdi
callq 0x3030
addq $0x630, %rsp            # imm = 0x630
popq %rbp
retq
nopl (%rax)