// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/tree.c
// Function: read_tree
tree *read_tree(char *filename)
{
    tree t = {0};
    FILE *fp = fopen(filename, "r");

    char *line;
    int last_parent = -1;
    int group_size = 0;
    int groups = 0;
    int n = 0;
    while((line=fgetl(fp)) != 0){
        char *id = calloc(256, sizeof(char));
        int parent = -1;
        sscanf(line, "%s %d", id, &parent);
        t.parent = realloc(t.parent, (n+1)*sizeof(int));
        t.parent[n] = parent;

        t.child = realloc(t.child, (n+1)*sizeof(int));
        t.child[n] = -1;

        t.name = realloc(t.name, (n+1)*sizeof(char *));
        t.name[n] = id;
        if(parent != last_parent){
            ++groups;
            t.group_offset = realloc(t.group_offset, groups * sizeof(int));
            t.group_offset[groups - 1] = n - group_size;
            t.group_size = realloc(t.group_size, groups * sizeof(int));
            t.group_size[groups - 1] = group_size;
            group_size = 0;
            last_parent = parent;
        }
        t.group = realloc(t.group, (n+1)*sizeof(int));
        t.group[n] = groups;
        if (parent >= 0) {
            t.child[parent] = groups;
        }
        ++n;
        ++group_size;
    }
    ++groups;
    t.group_offset = realloc(t.group_offset, groups * sizeof(int));
    t.group_offset[groups - 1] = n - group_size;
    t.group_size = realloc(t.group_size, groups * sizeof(int));
    t.group_size[groups - 1] = group_size;
    t.n = n;
    t.groups = groups;
    t.leaf = calloc(n, sizeof(int));
    int i;
    for(i = 0; i < n; ++i) t.leaf[i] = 1;
    for(i = 0; i < n; ++i) if(t.parent[i] >= 0) t.leaf[t.parent[i]] = 0;

    fclose(fp);
    tree *tree_ptr = calloc(1, sizeof(tree));
    *tree_ptr = t;
    //error(0);
    return tree_ptr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq 0x1bf25(%rip), %rsi     # 0x58cd1
callq 0x33a0
movq %rax, 0x40(%rsp)
movq %rax, %rdi
callq 0xe165
testq %rax, %rax
je 0x3cf78
movq %rax, %r14
movl $0x4, %ebp
movl $0x8, %ebx
xorl %r12d, %r12d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x28(%rsp)
xorl %r13d, %r13d
movl $0x100, %edi            # imm = 0x100
movl $0x1, %esi
callq 0x3260
movq %rax, %r15
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x4(%rsp)
movq %r14, %rdi
leaq 0x1af4c(%rip), %rsi     # 0x57d8f
movq %r15, %rdx
leaq 0x4(%rsp), %rcx
xorl %eax, %eax
callq 0x3330
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x3360
movl 0x4(%rsp), %r14d
movq %rax, 0x20(%rsp)
movl %r14d, (%rax,%r12,4)
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x3360
movq %rax, 0x10(%rsp)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, (%rax,%r12,4)
movq %r13, %rdi
movq %rbx, 0x48(%rsp)
movq %rbx, %rsi
callq 0x3360
movq %rax, 0x50(%rsp)
movq %r15, (%rax,%r12,8)
cmpl 0x1c(%rsp), %r14d
jne 0x3ceb3
movl (%rsp), %r13d
movl 0x8(%rsp), %r14d
jmp 0x3cf05
movl (%rsp), %r13d
movslq %r13d, %r15
incl %r13d
leaq 0x4(,%r15,4), %r14
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x3360
movl %r12d, %edx
movl 0x8(%rsp), %ebx
subl %ebx, %edx
movq %rax, 0x30(%rsp)
movl %edx, (%rax,%r15,4)
movq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x3360
movq %rax, 0x38(%rsp)
movl %ebx, (%rax,%r15,4)
xorl %r14d, %r14d
movl 0x4(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x3360
movq %rax, 0x28(%rsp)
movl %r13d, (%rax,%r12,4)
movslq 0x4(%rsp), %rax
testq %rax, %rax
js 0x3cf2e
movq 0x10(%rsp), %rcx
movl %r13d, (%rcx,%rax,4)
movl %r13d, (%rsp)
incl %r14d
movl %r14d, 0x8(%rsp)
movq 0x40(%rsp), %rdi
callq 0xe165
movq %rax, %r14
addq $0x4, %rbp
movq 0x48(%rsp), %rbx
addq $0x8, %rbx
incq %r12
testq %rax, %rax
movq 0x50(%rsp), %r13
jne 0x3ce1e
movl (%rsp), %eax
movl 0x8(%rsp), %ebp
movq 0x38(%rsp), %r14
movq 0x30(%rsp), %rdi
jmp 0x3cfa2
xorl %r13d, %r13d
movq $0x0, 0x28(%rsp)
xorl %r14d, %r14d
xorl %edi, %edi
movq $0x0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
xorl %ebp, %ebp
xorl %eax, %eax
xorl %r12d, %r12d
movslq %eax, %r15
incl %eax
movl %eax, (%rsp)
leaq 0x4(,%r15,4), %rbx
movq %rbx, %rsi
callq 0x3360
movl %r12d, %ecx
subl %ebp, %ecx
movq %rax, 0x8(%rsp)
movl %ecx, (%rax,%r15,4)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3360
movq %rax, %r14
movl %ebp, (%rax,%r15,4)
movl %r12d, %ebx
movl $0x4, %esi
movq %rbx, %rdi
callq 0x3260
movq %rax, %rbp
testl %r12d, %r12d
movq 0x20(%rsp), %r15
je 0x3d024
xorl %eax, %eax
movl $0x1, (%rbp,%rax,4)
incq %rax
cmpq %rax, %rbx
jne 0x3cff9
xorl %eax, %eax
movslq (%r15,%rax,4), %rcx
testq %rcx, %rcx
js 0x3d01c
movl $0x0, (%rbp,%rcx,4)
incq %rax
cmpq %rax, %rbx
jne 0x3d00b
movq 0x40(%rsp), %rdi
callq 0x3140
movl $0x1, %edi
movl $0x48, %esi
callq 0x3260
movq %rbp, (%rax)
movl %r12d, 0x8(%rax)
xorl %ecx, %ecx
movl %ecx, 0xc(%rax)
movq %r15, 0x10(%rax)
movq 0x10(%rsp), %rdx
movq %rdx, 0x18(%rax)
movq 0x28(%rsp), %rdx
movq %rdx, 0x20(%rax)
movq %r13, 0x28(%rax)
movl (%rsp), %edx
movl %edx, 0x30(%rax)
movl %ecx, 0x34(%rax)
movq %r14, 0x38(%rax)
movq 0x8(%rsp), %rcx
movq %rcx, 0x40(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq