// File: /workspace/github_c_makefile_star2_O2/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 0x1f732(%rip), %rsi     # 0x51ce9
callq 0x3390
movq %rax, 0x48(%rsp)
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
pushq $0x4
popq %rbx
pushq $0x8
popq %rax
movq %rax, 0x50(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x28(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x48(%rsp), %rdi
callq 0x3d32
movslq %ebp, %r15
testq %rax, %rax
je 0x32747
movq %rax, %r13
movl %ebp, 0x44(%rsp)
movl %r12d, %ebp
movl $0x100, %edi            # imm = 0x100
pushq $0x1
popq %rsi
callq 0x3250
movq %rax, %r12
orl $-0x1, 0xc(%rsp)
movq %r13, %rdi
leaq 0x1e757(%rip), %rsi     # 0x50da7
movq %rax, %rdx
leaq 0xc(%rsp), %rcx
xorl %eax, %eax
callq 0x3320
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x3350
movl 0xc(%rsp), %r13d
movq %rax, 0x28(%rsp)
movl %r13d, (%rax,%r14,4)
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x3350
movq %rax, 0x10(%rsp)
orl $-0x1, (%rax,%r14,4)
movq 0x38(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x3350
movq %rax, 0x38(%rsp)
movq %r12, (%rax,%r14,8)
cmpl 0x8(%rsp), %r13d
jne 0x326bf
movl %ebp, %r12d
movl 0x44(%rsp), %r13d
movl 0x8(%rsp), %r15d
jmp 0x32704
leal 0x1(%r15), %r13d
leaq 0x4(,%r15,4), %r12
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x3350
movl %r14d, %edx
subl %ebp, %edx
movq %rax, 0x18(%rsp)
movl %edx, (%rax,%r15,4)
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x3350
movq %rax, 0x20(%rsp)
movl %ebp, (%rax,%r15,4)
xorl %r12d, %r12d
movl 0xc(%rsp), %r15d
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x3350
movq %rax, 0x30(%rsp)
movl %r13d, (%rax,%r14,4)
testl %r15d, %r15d
movl %r13d, %ebp
js 0x3272d
movl %r15d, %eax
movq 0x10(%rsp), %rcx
movl %ebp, (%rcx,%rax,4)
movl %r15d, 0x8(%rsp)
incl %r12d
addq $0x4, %rbx
addq $0x8, 0x50(%rsp)
incq %r14
jmp 0x32611
leal 0x1(%r15), %ebp
leaq 0x4(,%r15,4), %rbx
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x3350
movq %rax, %r13
movl %r14d, %eax
subl %r12d, %eax
movl %eax, (%r13,%r15,4)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x3350
movl %r12d, %ecx
movq %rax, %r12
movl %ecx, (%rax,%r15,4)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x3250
movq %rax, %rbx
xorl %eax, %eax
movq 0x28(%rsp), %r15
cmpq %rax, %r14
je 0x327ab
movl $0x1, (%rbx,%rax,4)
incq %rax
jmp 0x3279a
xorl %eax, %eax
cmpq %rax, %r14
je 0x327c4
movslq (%r15,%rax,4), %rcx
testq %rcx, %rcx
js 0x327bf
andl $0x0, (%rbx,%rcx,4)
incq %rax
jmp 0x327ad
movq 0x48(%rsp), %rdi
callq 0x3130
pushq $0x1
popq %rdi
pushq $0x48
popq %rsi
callq 0x3250
movq %rbx, (%rax)
movl %r14d, 0x8(%rax)
andl $0x0, 0xc(%rax)
movq %r15, 0x10(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq 0x30(%rsp), %rcx
movq %rcx, 0x20(%rax)
movq 0x38(%rsp), %rcx
movq %rcx, 0x28(%rax)
movl %ebp, 0x30(%rax)
andl $0x0, 0x34(%rax)
movq %r12, 0x38(%rax)
movq %r13, 0x40(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)