// File: /workspace/github_c_makefile_star2_O2/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 0x3b9ea(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
leaq 0x280e9(%rip), %rsi     # 0x50701
movq %r15, %rdx
xorl %eax, %eax
callq 0x3270
leaq 0x26061(%rip), %rsi     # 0x4e68a
movq %r15, %rdi
callq 0x3390
movq %rax, %r14
testq %rax, %rax
jne 0x28641
movq %r15, %rdi
callq 0x3d0f
leaq 0x4e4(%rsp), %rdi
andl $0x0, (%rdi)
leaq 0x4e0(%rsp), %r15
movl $0x2, (%r15)
leaq 0x4dc(%rsp), %r12
andl $0x0, (%r12)
pushq $0x4
popq %rbp
pushq $0x1
popq %r13
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3440
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3440
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3440
movq 0x8(%rbx), %rdi
pushq $0x8
popq %rsi
movq %r13, %rdx
movq %r14, 0x4a0(%rsp)
movq %r14, %rcx
callq 0x3440
movslq 0x4a8(%rsp), %r13
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpq %r13, %r14
jge 0x28acf
movslq (%rbx), %rax
cmpq %rax, %r14
jge 0x28acf
movq 0x20(%rbx), %rcx
cmpl $0x0, 0x180(%rcx,%rbp)
jne 0x28a71
leaq (%rcx,%rbp), %rsi
movl (%rcx,%rbp), %eax
cmpl $0x1, %eax
ja 0x28716
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %rdi
callq 0x28440
jmp 0x28a71
leal -0xc(%rax), %edx
cmpl $0x7, %edx
ja 0x287bd
movq 0x390(%rcx,%rbp), %rax
movq 0x398(%rcx,%rbp), %r15
movq 0x3a0(%rcx,%rbp), %r12
leaq 0x2780b(%rip), %rdi     # 0x4ff4c
movslq (%rdi,%rdx,4), %rdx
addq %rdi, %rdx
jmpq *%rdx
movslq 0x58(%rcx,%rbp), %rdx
movl 0x7c(%rcx,%rbp), %eax
movl 0x84(%rcx,%rbp), %r12d
movl 0x90(%rcx,%rbp), %esi
movq 0x230(%rcx,%rbp), %rdi
movq 0x250(%rcx,%rbp), %r8
movq %r8, 0x4a8(%rsp)
imull 0x78(%rcx,%rbp), %eax
imull %esi, %esi
imull %eax, %esi
imull 0x74(%rcx,%rbp), %r12d
imull %esi, %r12d
pushq $0x4
popq %rsi
movq 0x4a0(%rsp), %r15
movq %r15, %rcx
callq 0x3440
movslq %r12d, %rdx
movq 0x4a8(%rsp), %rdi
pushq $0x4
popq %rsi
movq %r15, %rcx
callq 0x3440
jmp 0x28a71
cmpl $0x2, %eax
jne 0x28a71
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %rdi
jmp 0x28a6c
movq 0x420(%rcx,%rbp), %rsi
movq 0x428(%rcx,%rbp), %rax
movq %rax, 0x4b8(%rsp)
movq 0x430(%rcx,%rbp), %r15
movq 0x438(%rcx,%rbp), %rax
movq %rax, 0x4c0(%rsp)
movq 0x440(%rcx,%rbp), %rax
movq %rax, 0x4b0(%rsp)
movq 0x448(%rcx,%rbp), %rax
movq %rax, 0x4a8(%rsp)
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %r12
movq %r12, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4b0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4b8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4c0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4a8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
jmp 0x28a6c
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %rdi
callq 0x284d9
jmp 0x28a71
movq 0x450(%rcx,%rbp), %rax
movq %rax, 0x4c0(%rsp)
movq 0x458(%rcx,%rbp), %rax
movq %rax, 0x4c8(%rsp)
movq 0x460(%rcx,%rbp), %rax
movq %rax, 0x4b8(%rsp)
movq 0x468(%rcx,%rbp), %r12
movq 0x470(%rcx,%rbp), %rax
movq %rax, 0x4b0(%rsp)
movq 0x478(%rcx,%rbp), %rsi
movq 0x480(%rcx,%rbp), %rax
movq %rax, 0x4a8(%rsp)
movq 0x488(%rcx,%rbp), %rax
movq %rax, 0x4d0(%rsp)
movl $0x94, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %r15
movq %r15, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4c8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4d0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4b0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4b8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4c0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq 0x4a8(%rsp), %rsi
jmp 0x28a66
movl $0x94, %ecx
movq %rsp, %rdi
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %r15
movq %r15, %rdi
callq 0x28534
movl $0x94, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x28534
incq %r14
addq $0x4a0, %rbp            # imm = 0x4A0
jmp 0x286c6
movl $0x94, %ecx
movq %rsp, %rdi
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %rdi
callq 0x28440
movl $0x94, %ecx
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x4a0(%rsp), %r15
movq %r15, %rdi
callq 0x28440
movl $0x94, %ecx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
jmp 0x2870c
movq 0x4a0(%rsp), %rdi
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3130