// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/nightmare.c
// Function: run_nightmare
void run_nightmare(int argc, char **argv)
{
    srand(0);
    if(argc < 4){
        fprintf(stderr, "usage: %s %s [cfg] [weights] [image] [layer] [options! (optional)]\n", argv[0], argv[1]);
        return;
    }

    char *cfg = argv[2];
    char *weights = argv[3];
    char *input = argv[4];
    int max_layer = atoi(argv[5]);

    int range = find_int_arg(argc, argv, "-range", 1);
    int norm = find_int_arg(argc, argv, "-norm", 1);
    int rounds = find_int_arg(argc, argv, "-rounds", 1);
    int iters = find_int_arg(argc, argv, "-iters", 10);
    int octaves = find_int_arg(argc, argv, "-octaves", 4);
    float zoom = find_float_arg(argc, argv, "-zoom", 1.);
    float rate = find_float_arg(argc, argv, "-rate", .04);
    float thresh = find_float_arg(argc, argv, "-thresh", 1.);
    float rotate = find_float_arg(argc, argv, "-rotate", 0);
    float momentum = find_float_arg(argc, argv, "-momentum", .9);
    float lambda = find_float_arg(argc, argv, "-lambda", .01);
    char *prefix = find_char_arg(argc, argv, "-prefix", 0);
    int reconstruct = find_arg(argc, argv, "-reconstruct");
    int smooth_size = find_int_arg(argc, argv, "-smooth", 1);

    network *net = load_network(cfg, weights, 0);
    char *cfgbase = basecfg(cfg);
    char *imbase = basecfg(input);

    set_batch_network(net, 1);
    image im = load_image_color(input, 0, 0);
    if(0){
        float scale = 1;
        if(im.w > 512 || im.h > 512){
            if(im.w > im.h) scale = 512.0/im.w;
            else scale = 512.0/im.h;
        }
        image resized = resize_image(im, scale*im.w, scale*im.h);
        free_image(im);
        im = resized;
    }
    //im = letterbox_image(im, net->w, net->h);

    float *features = 0;
    image update;
    if (reconstruct){
        net->n = max_layer;
        im = letterbox_image(im, net->w, net->h);
        //resize_network(&net, im.w, im.h);

        network_predict(net, im.data);
        if(net->layers[net->n-1].type == REGION){
            printf("region!\n");
            zero_objectness(net->layers[net->n-1]);
        }
        image out_im = copy_image(get_network_image(net));
        /*
           image crop = crop_image(out_im, zz, zz, out_im.w-2*zz, out_im.h-2*zz);
        //flip_image(crop);
        image f_im = resize_image(crop, out_im.w, out_im.h);
        free_image(crop);
         */
        printf("%d features\n", out_im.w*out_im.h*out_im.c);

        features = out_im.data;

        /*
        int i;
           for(i = 0; i < 14*14*512; ++i){
        //features[i] += rand_uniform(-.19, .19);
        }
        free_image(im);
        im = make_random_image(im.w, im.h, im.c);
         */
        update = make_image(im.w, im.h, im.c);
    }

    int e;
    int n;
    for(e = 0; e < rounds; ++e){
        fprintf(stderr, "Iteration: ");
        fflush(stderr);
        for(n = 0; n < iters; ++n){  
            fprintf(stderr, "%d, ", n);
            fflush(stderr);
            if(reconstruct){
                reconstruct_picture(net, features, im, update, rate, momentum, lambda, smooth_size, 1);
                //if ((n+1)%30 == 0) rate *= .5;
                show_image(im, "reconstruction", 10);
            }else{
                int layer = max_layer + rand()%range - range/2;
                int octave = rand()%octaves;
                optimize_picture(net, im, layer, 1/pow(1.33333333, octave), rate, thresh, norm);
            }
        }
        fprintf(stderr, "done\n");
        if(0){
            image g = grayscale_image(im);
            free_image(im);
            im = g;
        }
        char buff[256];
        if (prefix){
            sprintf(buff, "%s/%s_%s_%d_%06d",prefix, imbase, cfgbase, max_layer, e);
        }else{
            sprintf(buff, "%s_%s_%d_%06d",imbase, cfgbase, max_layer, e);
        }
        printf("%d %s\n", e, buff);
        save_image(im, buff);
        //show_image(im, buff, 0);

        if(rotate){
            image rot = rotate_image(im, rotate);
            free_image(im);
            im = rot;
        }
        image crop = crop_image(im, im.w * (1. - zoom)/2., im.h * (1.-zoom)/2., im.w*zoom, im.h*zoom);
        image resized = resize_image(crop, im.w, im.h);
        free_image(im);
        free_image(crop);
        im = resized;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x730, %rsp            # imm = 0x730
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
xorl %edi, %edi
callq 0x31e0
cmpl $0x4, -0x4(%rbp)
jge 0x6cd2b
movq 0x162f2(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0x9d8f(%rip), %rsi      # 0x76aae
movb $0x0, %al
callq 0x3240
jmp 0x6d5b5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x33d0
movl %eax, -0x2c(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9d85(%rip), %rdx      # 0x76af2
movl $0x1, %ecx
callq 0x4630
movl %eax, -0x30(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9d71(%rip), %rdx      # 0x76af9
movl $0x1, %ecx
callq 0x4630
movl %eax, -0x34(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9d5c(%rip), %rdx      # 0x76aff
movl $0x1, %ecx
callq 0x4630
movl %eax, -0x38(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x93bb(%rip), %rdx      # 0x76179
movl $0xa, %ecx
callq 0x4630
movl %eax, -0x3c(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9d2e(%rip), %rdx      # 0x76b07
movl $0x4, %ecx
callq 0x4630
movl %eax, -0x40(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9d1c(%rip), %rdx      # 0x76b10
movss 0x4210(%rip), %xmm0     # 0x7100c
callq 0x46e0
movss %xmm0, -0x44(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9d02(%rip), %rdx      # 0x76b16
movss 0x9c60(%rip), %xmm0     # 0x76a7c
callq 0x46e0
movss %xmm0, -0x48(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9a6f(%rip), %rdx      # 0x768a3
movss 0x41d0(%rip), %xmm0     # 0x7100c
callq 0x46e0
movss %xmm0, -0x4c(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9cc8(%rip), %rdx      # 0x76b1c
xorps %xmm0, %xmm0
callq 0x46e0
movss %xmm0, -0x50(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9cb5(%rip), %rdx      # 0x76b24
movss 0x7975(%rip), %xmm0     # 0x747ec
callq 0x46e0
movss %xmm0, -0x54(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9c9f(%rip), %rdx      # 0x76b2e
movss 0x8695(%rip), %xmm0     # 0x7552c
callq 0x46e0
movss %xmm0, -0x58(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x99ec(%rip), %rdx      # 0x7689b
xorl %eax, %eax
movl %eax, %ecx
callq 0x47a0
movq %rax, -0x60(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9c6c(%rip), %rdx      # 0x76b36
callq 0x45a0
movl %eax, -0x64(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9c63(%rip), %rdx      # 0x76b43
movl $0x1, %ecx
callq 0x4630
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x39a70
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4850
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4850
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
movl $0x1, %esi
callq 0x3a9b0
movq -0x28(%rbp), %rsi
leaq -0x98(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0xf510
movq $0x0, -0xa0(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0x6d0e6
movl -0x2c(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movq -0x70(%rbp), %rax
movl 0x94(%rax), %esi
movq -0x70(%rbp), %rax
movl 0x90(%rax), %edx
leaq -0xd0(%rbp), %rdi
leaq -0x98(%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 0x12c60
movq -0xd0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x70(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x3b160
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x70(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
addq %rcx, %rax
cmpl $0x16, (%rax)
jne 0x6d032
leaq 0x9b4d(%rip), %rdi      # 0x76b4b
movb $0x0, %al
callq 0x3130
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x70(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
cltq
imulq $0x4a0, %rax, %rax      # imm = 0x4A0
addq %rax, %rsi
movq %rsp, %rdi
movl $0x94, %ecx
rep  movsq (%rsi), %es:(%rdi)
callq 0x4e6c0
movq -0x70(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x3afe0
leaq -0xe8(%rbp), %rdi
leaq -0x100(%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 0xea60
movl -0xe8(%rbp), %esi
imull -0xe4(%rbp), %esi
imull -0xe0(%rbp), %esi
leaq 0x9acb(%rip), %rdi      # 0x76b54
movb $0x0, %al
callq 0x3130
movq -0xd8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0x98(%rbp), %esi
movl -0x94(%rbp), %edx
movl -0x90(%rbp), %ecx
leaq -0x118(%rbp), %rdi
callq 0xe3e0
movq -0x118(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x6d5b5
movq 0x15ef2(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
leaq 0x9a51(%rip), %rsi      # 0x76b61
movb $0x0, %al
callq 0x3240
movq 0x15eda(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
callq 0x32e0
movl $0x0, -0x120(%rbp)
movl -0x120(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x6d2f2
movq 0x15eb2(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
movl -0x120(%rbp), %edx
leaq 0x8735(%rip), %rsi      # 0x7588b
movb $0x0, %al
callq 0x3240
movq 0x15e94(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
callq 0x32e0
cmpl $0x0, -0x64(%rbp)
je 0x6d214
movq -0x70(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movss -0x48(%rbp), %xmm0
movss -0x54(%rbp), %xmm1
movss -0x58(%rbp), %xmm2
movl -0x68(%rbp), %edx
leaq -0x98(%rbp), %r8
leaq -0xb8(%rbp), %rax
movl $0x1, %ecx
movq (%r8), %r9
movq %r9, (%rsp)
movq 0x8(%r8), %r9
movq %r9, 0x8(%rsp)
movq 0x10(%r8), %r8
movq %r8, 0x10(%rsp)
movq (%rax), %r8
movq %r8, 0x18(%rsp)
movq 0x8(%rax), %r8
movq %r8, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0x6cb20
leaq -0x98(%rbp), %rax
leaq 0x9981(%rip), %rdi      # 0x76b6d
movl $0xa, %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
jmp 0x6d2dc
movl -0x2c(%rbp), %eax
movl %eax, -0x290(%rbp)
callq 0x34b0
cltd
idivl -0x30(%rbp)
movl -0x290(%rbp), %eax
addl %edx, %eax
movl %eax, -0x28c(%rbp)
movl -0x30(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x28c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x124(%rbp)
callq 0x34b0
cltd
idivl -0x40(%rbp)
movl %edx, -0x128(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x288(%rbp)
movl -0x124(%rbp), %eax
movl %eax, -0x27c(%rbp)
cvtsi2sdl -0x128(%rbp), %xmm1
movsd 0x97fb(%rip), %xmm0     # 0x76a80
callq 0x30e0
movq -0x288(%rbp), %rdi
movl -0x27c(%rbp), %esi
movaps %xmm0, %xmm1
movsd 0x3dbe(%rip), %xmm0     # 0x71060
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss -0x48(%rbp), %xmm1
movss -0x4c(%rbp), %xmm2
movl -0x34(%rbp), %edx
leaq -0x98(%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 0x6c4b0
jmp 0x6d2de
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
jmp 0x6d130
movq 0x15cff(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
leaq 0x9879(%rip), %rsi      # 0x76b7c
movb $0x0, %al
callq 0x3240
cmpq $0x0, -0x60(%rbp)
je 0x6d341
leaq -0x230(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq -0x78(%rbp), %r8
movl -0x2c(%rbp), %r9d
movl -0x11c(%rbp), %eax
leaq 0x984d(%rip), %rsi      # 0x76b82
movl %eax, (%rsp)
movb $0x0, %al
callq 0x33f0
jmp 0x6d369
leaq -0x230(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x78(%rbp), %rcx
movl -0x2c(%rbp), %r8d
movl -0x11c(%rbp), %r9d
leaq 0x9823(%rip), %rsi      # 0x76b85
movb $0x0, %al
callq 0x33f0
movl -0x11c(%rbp), %esi
leaq -0x230(%rbp), %rdx
leaq 0x9816(%rip), %rdi      # 0x76b93
movb $0x0, %al
callq 0x3130
leaq -0x230(%rbp), %rdi
leaq -0x98(%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 0x11330
movss -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x6d3c4
jp 0x6d3c4
jmp 0x6d444
movss -0x50(%rbp), %xmm0
leaq -0x248(%rbp), %rdi
leaq -0x98(%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 0x12130
leaq -0x98(%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
movq -0x248(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x240(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x238(%rbp), %rax
movq %rax, -0x88(%rbp)
cvtsi2sdl -0x98(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3c03(%rip), %xmm1     # 0x71060
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x3beb(%rip), %xmm1     # 0x71058
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %esi
cvtsi2sdl -0x94(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3bd2(%rip), %xmm1     # 0x71060
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x3bba(%rip), %xmm1     # 0x71058
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
cvtsi2ssl -0x98(%rbp), %xmm0
mulss -0x44(%rbp), %xmm0
cvttss2si %xmm0, %ecx
cvtsi2ssl -0x94(%rbp), %xmm0
mulss -0x44(%rbp), %xmm0
cvttss2si %xmm0, %r8d
leaq -0x260(%rbp), %rdi
leaq -0x98(%rbp), %rax
movq (%rax), %r9
movq %r9, (%rsp)
movq 0x8(%rax), %r9
movq %r9, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x11ca0
movl -0x98(%rbp), %esi
movl -0x94(%rbp), %edx
leaq -0x278(%rbp), %rdi
leaq -0x260(%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 0xfc00
leaq -0x98(%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 -0x260(%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
movq -0x278(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x6d0f0
addq $0x730, %rsp            # imm = 0x730
popq %rbp
retq
nop