// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/parser.c
// Function: parse_route
route_layer parse_route(list *options, size_params params, network *net)
{
    char *l = option_find(options, "layers");
    int len = strlen(l);
    if(!l) error("Route Layer must specify input layers");
    int n = 1;
    int i;
    for(i = 0; i < len; ++i){
        if (l[i] == ',') ++n;
    }

    int *layers = calloc(n, sizeof(int));
    int *sizes = calloc(n, sizeof(int));
    for(i = 0; i < n; ++i){
        int index = atoi(l);
        l = strchr(l, ',')+1;
        if(index < 0) index = params.index + index;
        layers[i] = index;
        sizes[i] = net->layers[index].outputs;
    }
    int batch = params.batch;

    route_layer layer = make_route_layer(batch, n, layers, sizes);

    convolutional_layer first = net->layers[layers[0]];
    layer.out_w = first.out_w;
    layer.out_h = first.out_h;
    layer.out_c = first.out_c;
    for(i = 1; i < n; ++i){
        int index = layers[i];
        convolutional_layer next = net->layers[index];
        if(next.out_w == first.out_w && next.out_h == first.out_h){
            layer.out_c += next.out_c;
        }else{
            layer.out_h = layer.out_w = layer.out_c = 0;
        }
    }

    return layer;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r13
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x23b9b(%rip), %rsi     # 0x59545
movq %rax, %rdi
callq 0x36fbf
movq %rax, %r12
movq %rax, %rdi
callq 0x3140
movq %rax, %r15
testq %r12, %r12
jne 0x359d1
leaq 0x23b5a(%rip), %rdi     # 0x59526
callq 0xf141
movq %rbx, 0x20(%rsp)
leaq 0x60(%rsp), %rbx
movl $0x1, %ebp
testl %r15d, %r15d
jle 0x35a02
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %eax, %eax
xorl %ecx, %ecx
cmpb $0x2c, (%r12,%rax)
sete %cl
addl %ecx, %ebp
incq %rax
cmpq %rax, %r15
jne 0x359ee
movslq %ebp, %r14
movl $0x4, %esi
movq %r14, %rdi
callq 0x3250
movq %rax, 0x10(%rsp)
movl $0x4, %esi
movq %r14, %rdi
callq 0x3250
movq %rax, 0x8(%rsp)
movl 0x14(%rbx), %eax
movl %eax, 0x4(%rsp)
movq %r13, 0x18(%rsp)
movq 0x20(%r13), %r15
cmpl $0x2, %r14d
movl $0x1, %ebx
cmovgel %ebp, %ebx
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x3400
movl %eax, %r14d
movq %r12, %rdi
movl $0x2c, %esi
callq 0x3150
movq %rax, %r12
incq %r12
movl %r14d, %eax
sarl $0x1f, %eax
andl 0x4(%rsp), %eax
addl %r14d, %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%r13,4)
cltq
imulq $0x4a0, %rax, %rax      # imm = 0x4A0
movl 0x58(%r15,%rax), %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx,%r13,4)
incq %r13
cmpq %r13, %rbx
jne 0x35a48
leaq 0x60(%rsp), %rax
movl (%rax), %esi
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %edx
movq 0x10(%rsp), %r14
movq %r14, %rcx
movq 0x8(%rsp), %r8
callq 0x6f32
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movslq (%r14), %rcx
imulq $0x4a0, %rcx, %rsi      # imm = 0x4A0
movl 0x78(%rax,%rsi), %ecx
movl 0x7c(%rax,%rsi), %edx
movl 0x80(%rax,%rsi), %esi
movl %edx, 0x7c(%rbx)
movl %ecx, 0x78(%rbx)
movl %esi, 0x80(%rbx)
cmpl $0x2, %ebp
jl 0x35b41
movl %ebp, %edi
movl $0x1, %r8d
movslq (%r14,%r8,4), %r9
imulq $0x4a0, %r9, %r9        # imm = 0x4A0
cmpl %edx, 0x7c(%rax,%r9)
jne 0x35b25
leaq (%rax,%r9), %r10
cmpl %ecx, 0x78(%r10)
jne 0x35b25
addl 0x80(%rax,%r9), %esi
movl %esi, 0x80(%rbx)
jmp 0x35b39
movl $0x0, 0x80(%rbx)
movq $0x0, 0x78(%rbx)
xorl %esi, %esi
incq %r8
cmpq %r8, %rdi
jne 0x35af9
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq