// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/parser.c
// Function: save_weights_upto
void save_weights_upto(network *net, char *filename, int cutoff)
{
    fprintf(stderr, "Saving weights to %s\n", filename);
    FILE *fp = fopen(filename, "wb");
    if(!fp) file_error(filename);

    int major = 0;
    int minor = 2;
    int revision = 0;
    fwrite(&major, sizeof(int), 1, fp);
    fwrite(&minor, sizeof(int), 1, fp);
    fwrite(&revision, sizeof(int), 1, fp);
    fwrite(net->seen, sizeof(size_t), 1, fp);

    int i;
    for(i = 0; i < net->n && i < cutoff; ++i){
        layer l = net->layers[i];
        if (l.dontsave) continue;
        if(l.type == CONVOLUTIONAL || l.type == DECONVOLUTIONAL){
            save_convolutional_weights(l, fp);
        } if(l.type == CONNECTED){
            save_connected_weights(l, fp);
        } if(l.type == BATCHNORM){
            save_batchnorm_weights(l, fp);
        } if(l.type == RNN){
            save_connected_weights(*(l.input_layer), fp);
            save_connected_weights(*(l.self_layer), fp);
            save_connected_weights(*(l.output_layer), fp);
        } if (l.type == LSTM) {
            save_connected_weights(*(l.wi), fp);
            save_connected_weights(*(l.wf), fp);
            save_connected_weights(*(l.wo), fp);
            save_connected_weights(*(l.wg), fp);
            save_connected_weights(*(l.ui), fp);
            save_connected_weights(*(l.uf), fp);
            save_connected_weights(*(l.uo), fp);
            save_connected_weights(*(l.ug), fp);
        } if (l.type == GRU) {
            if(1){
                save_connected_weights(*(l.wz), fp);
                save_connected_weights(*(l.wr), fp);
                save_connected_weights(*(l.wh), fp);
                save_connected_weights(*(l.uz), fp);
                save_connected_weights(*(l.ur), fp);
                save_connected_weights(*(l.uh), fp);
            }else{
                save_connected_weights(*(l.reset_layer), fp);
                save_connected_weights(*(l.update_layer), fp);
                save_connected_weights(*(l.state_layer), fp);
            }
        }  if(l.type == CRNN){
            save_convolutional_weights(*(l.input_layer), fp);
            save_convolutional_weights(*(l.self_layer), fp);
            save_convolutional_weights(*(l.output_layer), fp);
        } if(l.type == LOCAL){
            int locations = l.out_w*l.out_h;
            int size = l.size*l.size*l.c*l.n*locations;
            fwrite(l.biases, sizeof(float), l.outputs, fp);
            fwrite(l.weights, sizeof(float), size, fp);
        }
    }
    fclose(fp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4e8, %rsp            # imm = 0x4E8
movl %edx, 0x4a8(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movq 0x65bf3(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
leaq 0x533a2(%rip), %rsi     # 0x597b1
movq %r15, %rdx
xorl %eax, %eax
callq 0x3270
leaq 0x5134a(%rip), %rsi     # 0x5776a
movq %r15, %rdi
callq 0x3390
movq %rax, %r14
testq %rax, %rax
jne 0x6438
movq %r15, %rdi
callq 0xe925
leaq 0x4e4(%rsp), %rdi
andl $0x0, (%rdi)
leaq 0x4e0(%rsp), %r12
movl $0x2, (%r12)
leaq 0x4dc(%rsp), %r13
andl $0x0, (%r13)
pushq $0x4
popq %rbp
pushq $0x1
popq %r15
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3440
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3440
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3440
movq 0x8(%rbx), %rdi
pushq $0x8
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3440
movl 0x4a8(%rsp), %eax
testl %eax, %eax
jle 0x6860
cmpl $0x0, (%rbx)
jle 0x6860
movl %eax, %edi
xorl %r13d, %r13d
movq %rdi, 0x4a8(%rsp)
movq 0x20(%rbx), %rax
cmpl $0x0, 0x180(%rax,%r13)
jne 0x6803
leaq (%rax,%r13), %rsi
movl (%rax,%r13), %ecx
cmpl $0x1, %ecx
ja 0x6506
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x364ea
jmp 0x67fb
leal -0xc(%rcx), %edx
cmpl $0x7, %edx
ja 0x65a3
movslq 0x74(%rax,%r13), %r12
movq 0x390(%rax,%r13), %rsi
movq 0x398(%rax,%r13), %rbp
movq 0x3a0(%rax,%r13), %r9
leaq 0x52ac6(%rip), %r8      # 0x58ffc
movslq (%r8,%rdx,4), %rcx
addq %r8, %rcx
jmpq *%rcx
movslq 0x58(%rax,%r13), %rdx
movl 0x7c(%rax,%r13), %ecx
movl 0x90(%rax,%r13), %esi
movq 0x230(%rax,%r13), %rdi
movq 0x250(%rax,%r13), %r8
movq %r8, 0x4b0(%rsp)
imull 0x78(%rax,%r13), %ecx
imull %esi, %esi
imull %ecx, %esi
imull 0x84(%rax,%r13), %r12d
imull %esi, %r12d
pushq $0x4
popq %rbp
movq %rbp, %rsi
movq %r14, %rcx
callq 0x3440
movslq %r12d, %rdx
movq 0x4b0(%rsp), %rdi
movq %rbp, %rsi
jmp 0x6687
cmpl $0x2, %ecx
jne 0x6803
movl $0x94, %ecx
movq %rsp, %rdi
jmp 0x67f0
movq 0x420(%rax,%r13), %rsi
movq 0x428(%rax,%r13), %rcx
movq %rcx, 0x4b8(%rsp)
movq 0x430(%rax,%r13), %r12
movq 0x438(%rax,%r13), %rcx
movq %rcx, 0x4c0(%rsp)
movq 0x440(%rax,%r13), %rbp
movq 0x448(%rax,%r13), %rax
movq %rax, 0x4b0(%rsp)
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
jmp 0x6766
movq 0x240(%rax,%r13), %rdi
movq 0x2b0(%rax,%r13), %rbp
movq 0x2b8(%rax,%r13), %rax
movq %rax, 0x4b0(%rsp)
pushq $0x4
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x3440
movq %rbp, %rdi
pushq $0x4
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x3440
movq 0x4b0(%rsp), %rdi
pushq $0x4
popq %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x3440
jmp 0x67fb
movq 0x450(%rax,%r13), %rcx
movq %rcx, 0x4c0(%rsp)
movq 0x458(%rax,%r13), %r12
movq 0x460(%rax,%r13), %rcx
movq %rcx, 0x4b8(%rsp)
movq 0x468(%rax,%r13), %rbp
movq 0x470(%rax,%r13), %rcx
movq %rcx, 0x4d0(%rsp)
movq 0x478(%rax,%r13), %rsi
movq 0x480(%rax,%r13), %rcx
movq %rcx, 0x4b0(%rsp)
movq 0x488(%rax,%r13), %rax
movq %rax, 0x4c8(%rsp)
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4c8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4d0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4b8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4c0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4b0(%rsp), %rsi
jmp 0x67f0
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %r9, %r12
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movl $0x94, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x365f0
movq 0x4a8(%rsp), %rdi
cmpq %rdi, %r15
jae 0x6860
movslq (%rbx), %rax
addq $0x4a0, %r13            # imm = 0x4A0
leaq 0x1(%r15), %rcx
cmpq %rax, %r15
movq %rcx, %r15
jl 0x64ce
jmp 0x6860
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %r9, %r12
callq 0x364ea
movl $0x94, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x364ea
movl $0x94, %ecx
movq %rsp, %rdi
movq %r12, %rsi
jmp 0x64f6
movq %r14, %rdi
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3130