// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/tag.c
// Function: train_tag
void train_tag(char *cfgfile, char *weightfile, int clear)
{
    srand(time(0));
    float avg_loss = -1;
    char *base = basecfg(cfgfile);
    char *backup_directory = "/home/pjreddie/backup/";
    printf("%s\n", base);
    network *net = load_network(cfgfile, weightfile, clear);
    printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
    int imgs = 1024;
    list *plist = get_paths("/home/pjreddie/tag/train.list");
    char **paths = (char **)list_to_array(plist);
    printf("%d\n", plist->size);
    int 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.min = net->w;
    args.max = net->max_crop;
    args.size = net->w;

    args.paths = paths;
    args.classes = net->outputs;
    args.n = imgs;
    args.m = N;
    args.d = &buffer;
    args.type = TAG_DATA;

    args.angle = net->angle;
    args.exposure = net->exposure;
    args.saturation = net->saturation;
    args.hue = net->hue;

    fprintf(stderr, "%d classes\n", net->outputs);

    load_thread = load_data_in_thread(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_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("%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);

    pthread_join(load_thread, 0);
    free_data(buffer);
    free_network(net);
    free_ptrs((void**)paths, plist->size);
    free_list(plist);
    free(base);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movq %r15, %rdi
callq 0xef02
movq %rax, 0xb0(%rsp)
movq %rax, %rdi
callq 0x30b0
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x316bc
movq %rax, %r14
cvtss2sd 0x34(%rax), %xmm0
cvtss2sd 0x38(%rax), %xmm1
cvtss2sd 0x3c(%rax), %xmm2
leaq 0x50d00(%rip), %rdi     # 0x59fd0
movb $0x3, %al
callq 0x3160
leaq 0x50f64(%rip), %rdi     # 0x5a242
callq 0x2af38
movq %rax, %rbx
movq %rax, %rdi
callq 0x11928
movq %rax, %r15
movl (%rbx), %esi
leaq 0x5129f(%rip), %rdi     # 0x5a599
xorl %eax, %eax
callq 0x3160
movq %rbx, 0xf0(%rsp)
movslq (%rbx), %r12
leaq 0x198(%rsp), %rbx
movl $0xa8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31c0
movl 0x94(%r14), %eax
movl %eax, 0x2c(%rbx)
movl 0x90(%r14), %ecx
movl %ecx, 0x28(%rbx)
movl %eax, 0x44(%rbx)
movl 0x9c(%r14), %ecx
movl %ecx, 0x48(%rbx)
movl %eax, 0x4c(%rbx)
movq %r15, 0xe8(%rsp)
movq %r15, 0x8(%rbx)
movl 0x84(%r14), %edx
movl %edx, 0x50(%rbx)
movl $0x400, 0x18(%rbx)      # imm = 0x400
movq %r12, 0xc8(%rsp)
movl %r12d, 0x1c(%rbx)
leaq 0x158(%rsp), %rax
movq %rax, 0x80(%rbx)
movl $0x8, 0x98(%rbx)
movss 0xb0(%r14), %xmm0
movss %xmm0, 0x68(%rbx)
movsd 0xb8(%r14), %xmm0
shufps $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movlps %xmm0, 0x70(%rbx)
movss 0xc0(%r14), %xmm0
movss %xmm0, 0x78(%rbx)
movq 0x62c3b(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
leaq 0x50e99(%rip), %rsi     # 0x5a260
xorl %eax, %eax
callq 0x3270
pushq $0x15
popq %rcx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq %rax, %r13
movq 0x8(%r14), %rax
movq (%rax), %rbx
movq %r14, %rdi
callq 0x316fa
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x9403
cmpq %rcx, %rax
jae 0x971a
movq 0xc8(%rsp), %rcx
cvtsi2ss %ecx, %xmm0
movss %xmm0, 0xc4(%rsp)
movq %rbx, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r15
movss 0x4be69(%rip), %xmm0    # 0x55294
leaq 0x240(%rsp), %r12
movaps %xmm0, 0xd0(%rsp)
callq 0x3120
movq %rax, %rbx
movq %r13, %rdi
xorl %esi, %esi
callq 0x3470
movups 0x158(%rsp), %xmm0
movups 0x168(%rsp), %xmm1
movups 0x178(%rsp), %xmm2
movups 0x188(%rsp), %xmm3
movaps %xmm0, 0x110(%rsp)
movaps %xmm1, 0x120(%rsp)
movaps %xmm2, 0x130(%rsp)
movaps %xmm3, 0x140(%rsp)
pushq $0x15
popq %rcx
movq %rsp, %rdi
leaq 0x198(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq %rax, %r13
callq 0x3120
subq %rbx, %rax
movq %rax, %rdi
callq 0xf0bf
cvtss2sd %xmm0, %xmm0
leaq 0x50b7d(%rip), %rdi     # 0x5a03e
movb $0x1, %al
callq 0x3160
callq 0x3120
movq %rax, %rbp
movaps 0x110(%rsp), %xmm0
movaps 0x120(%rsp), %xmm1
movaps 0x130(%rsp), %xmm2
movaps 0x140(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x31ea6
movaps 0xd0(%rsp), %xmm3
movaps %xmm3, %xmm1
cmpeqss 0x4bd75(%rip), %xmm1    # 0x55294
movaps %xmm1, %xmm2
andnps %xmm3, %xmm2
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x108(%rsp)
mulsd 0x4f13c(%rip), %xmm0    # 0x58680
movsd %xmm0, 0xb8(%rsp)
mulsd 0x50a73(%rip), %xmm1    # 0x59fc8
movsd %xmm1, 0xd0(%rsp)
movq %r14, %rdi
callq 0x316fa
movq %rax, %rbx
movq 0x8(%r14), %rax
movq (%rax), %rax
testq %rax, %rax
js 0x957c
cvtsi2ss %rax, %xmm0
jmp 0x9591
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
divss 0xc4(%rsp), %xmm0
movsd 0xd0(%rsp), %xmm1
addsd 0xb8(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x100(%rsp)
movaps %xmm1, 0xd0(%rsp)
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0xb8(%rsp)
movq %r14, %rdi
callq 0x31715
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xf8(%rsp)
callq 0x3120
subq %rbp, %rax
movq %rax, %rdi
callq 0xf0bf
cvtss2sd %xmm0, %xmm4
movq 0x8(%r14), %rax
movq (%rax), %rdx
leaq 0x50c63(%rip), %rdi     # 0x5a26c
movq %rbx, %rsi
movsd 0x100(%rsp), %xmm0
movsd 0x108(%rsp), %xmm1
movsd 0xb8(%rsp), %xmm2
movsd 0xf8(%rsp), %xmm3
movb $0x5, %al
callq 0x3160
movaps 0x110(%rsp), %xmm0
movaps 0x120(%rsp), %xmm1
movaps 0x130(%rsp), %xmm2
movaps 0x140(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x2d296
movq 0x8(%r14), %rax
movq (%rax), %rax
xorl %edx, %edx
divq 0xc8(%rsp)
movq %rax, %rbx
movslq %r15d, %rax
cmpq %rax, %rbx
jbe 0x96bc
movq %r12, %rdi
leaq 0x50b78(%rip), %rsi     # 0x5a20d
leaq 0x50b29(%rip), %rdx     # 0x5a1c5
movq 0xb0(%rsp), %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r12, %rsi
callq 0x6879
movl %ebx, %r15d
movq %r14, %rdi
callq 0x316fa
xorl %edx, %edx
pushq $0x64
popq %rcx
divq %rcx
testq %rdx, %rdx
jne 0x96fc
movq %r12, %rdi
leaq 0x50b43(%rip), %rsi     # 0x5a21e
leaq 0x50ae3(%rip), %rdx     # 0x5a1c5
movq 0xb0(%rsp), %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %r12, %rsi
callq 0x6879
movq %r14, %rdi
callq 0x316fa
movslq 0x54(%r14), %rcx
testq %rcx, %rcx
je 0x943b
cmpq %rcx, %rax
jb 0x943b
leaq 0x50b84(%rip), %rsi     # 0x5a2a5
leaq 0x50a9d(%rip), %rdx     # 0x5a1c5
leaq 0x240(%rsp), %rbx
movq %rbx, %rdi
movq 0xb0(%rsp), %r15
movq %r15, %rcx
xorl %eax, %eax
callq 0x3420
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6879
movq %r13, %rdi
xorl %esi, %esi
callq 0x3470
movups 0x158(%rsp), %xmm0
movups 0x168(%rsp), %xmm1
movups 0x178(%rsp), %xmm2
movups 0x188(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x2d296
movq %r14, %rdi
callq 0x33479
movq 0xf0(%rsp), %rbx
movl (%rbx), %esi
movq 0xe8(%rsp), %rdi
callq 0xf2f4
movq %rbx, %rdi
callq 0x118de
movq %r15, %rdi
callq 0x3040
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq