// File: /workspace/github_cpp_makefile_star2_O3/AndreyVV-100[P]GachiLang/TreeBase/Tree.cpp
// Function: LoadElem(Tree*, char**)
element* LoadElem (Tree* tree, char** pos_now)
{
    assert (tree);
    assert (pos_now);

    char* newline = strchr (*pos_now, '\n');
    if (!newline)
    {
        printf ("Bad tree-input format: no end of line.\n");
        return PARSE_ERR;
    }
    *newline = '\0';

    while (**pos_now == ' ')
        *pos_now += 1;

    if (**pos_now == '\0')
    {
        *pos_now += 1;
        return nullptr;
    }

    char* space = strchr (*pos_now, ' ');
    if (!space)
    {
        printf ("Bad tree-input format: no space after type.\n");
        return PARSE_ERR;
    }
    *space = '\0';

    int i_type = NIL;
    for (i_type = NIL; i_type < SIZEOF_TYPES; i_type++)
        if (strcmp (TYPES_STR[i_type], *pos_now) == 0)
            break;

    if (i_type == SIZEOF_TYPES)
    {
        printf ("Bad tree-input format: unknown type.\n");
        return PARSE_ERR;
    }

    element* elem_now = tree->stk.buffer + tree->stk.size;
    size_t ind_len = newline - space - 1;
    StackPush (&(tree->stk), {(Types) i_type, nullptr, nullptr, space + 1, ind_len, '\0'});

    *pos_now = newline + 1;
    #define skip_line newline = strchr (*pos_now, '\n');                        \
                      if (!newline)                                             \
                      {                                                         \
                          printf ("Bad tree-input format: no end of line.\n");  \
                          return PARSE_ERR;                                     \
                      }                                                         \
                      *pos_now = newline + 1

    skip_line;
    elem_now->left  = LoadElem (tree, pos_now);
    skip_line;
    skip_line;
    elem_now->right = LoadElem (tree, pos_now);
    skip_line;

    return (elem_now->left == PARSE_ERR || elem_now->right == PARSE_ERR) ? PARSE_ERR : elem_now;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
testq %rdi, %rdi
je 0x3a1d
movq %rsi, %rbx
testq %rsi, %rsi
je 0x3a3c
movq %rdi, %r14
movq (%rbx), %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x39f8
movq %rax, %r12
movb $0x0, (%rax)
movq (%rbx), %rdi
movzbl (%rdi), %eax
cmpl $0x20, %eax
jne 0x388c
incq %rdi
movq %rdi, (%rbx)
jmp 0x387c
testl %eax, %eax
jne 0x389e
incq %rdi
movq %rdi, (%rbx)
xorl %r15d, %r15d
jmp 0x3a0b
movl $0x20, %esi
callq 0x1050
testq %rax, %rax
je 0x38ee
movq %r14, -0x38(%rbp)
movq %rax, -0x30(%rbp)
movb $0x0, (%rax)
movq (%rbx), %r15
leaq 0x582e(%rip), %r13      # 0x90f0
xorl %r14d, %r14d
movq (%r13), %rdi
movq %r15, %rsi
callq 0x1150
testl %eax, %eax
je 0x38fa
incq %r14
addq $0x8, %r13
cmpq $0x10, %r14
jne 0x38c5
leaq 0x248d(%rip), %rdi      # 0x5d76
jmp 0x39ff
leaq 0x242e(%rip), %rdi      # 0x5d23
jmp 0x39ff
movq -0x38(%rbp), %r13
leaq 0x8(%r13), %rdi
movq 0x18(%r13), %rax
leaq (%rax,%rax,2), %r15
shlq $0x4, %r15
addq 0x10(%r13), %r15
movq -0x30(%rbp), %rcx
movq %rcx, %rax
notq %rax
addq %r12, %rax
movl %r14d, -0x68(%rbp)
incq %rcx
xorps %xmm0, %xmm0
movups %xmm0, -0x60(%rbp)
movq %rcx, -0x50(%rbp)
movq %rax, -0x48(%rbp)
movb $0x0, -0x40(%rbp)
movups -0x68(%rbp), %xmm0
movups -0x58(%rbp), %xmm1
movups -0x48(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x4025
incq %r12
movq %r12, (%rbx)
movq %r12, %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x39f8
incq %rax
movq %rax, (%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3834
movq %rax, 0x8(%r15)
movq (%rbx), %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x39f8
incq %rax
movq %rax, (%rbx)
movq %rax, %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x39f8
incq %rax
movq %rax, (%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3834
movq %rax, 0x10(%r15)
movq (%rbx), %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x39f8
incq %rax
movq %rax, (%rbx)
movq 0x5789(%rip), %rax      # 0x9170
cmpq %rax, 0x8(%r15)
je 0x39f3
cmpq %rax, 0x10(%r15)
jne 0x3a0b
movq %rax, %r15
jmp 0x3a0b
leaq 0x2350(%rip), %rdi      # 0x5d4f
callq 0x1180
movq 0x5765(%rip), %r15      # 0x9170
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fa6(%rip), %rdi      # 0x59ca
leaq 0x1fa4(%rip), %rsi      # 0x59cf
leaq 0x222b(%rip), %rcx      # 0x5c5d
movl $0xdb, %edx
callq 0x1090
leaq 0x223d(%rip), %rdi      # 0x5c80
leaq 0x1f85(%rip), %rsi      # 0x59cf
leaq 0x220c(%rip), %rcx      # 0x5c5d
movl $0xdc, %edx
callq 0x1090
nop