// File: /workspace/github_cpp_makefile_star2_O2/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 0x3768
movq %rsi, %rbx
testq %rsi, %rsi
je 0x3787
movq %rdi, %r14
movq (%rbx), %rdi
pushq $0xa
popq %rsi
callq 0x1050
testq %rax, %rax
je 0x3743
movq %rax, %r12
movb $0x0, (%rax)
movq (%rbx), %rdi
movzbl (%rdi), %eax
cmpl $0x20, %eax
jne 0x35ea
incq %rdi
movq %rdi, (%rbx)
jmp 0x35da
testl %eax, %eax
jne 0x35fc
incq %rdi
movq %rdi, (%rbx)
xorl %r15d, %r15d
jmp 0x3756
pushq $0x20
popq %rsi
callq 0x1050
testq %rax, %rax
je 0x3640
movq %r14, -0x38(%rbp)
movq %rax, -0x30(%rbp)
movb $0x0, (%rax)
movq (%rbx), %r15
leaq 0x4ac2(%rip), %r13      # 0x80e0
xorl %r14d, %r14d
cmpq $0x10, %r14
je 0x364c
movq (%r13), %rdi
movq %r15, %rsi
callq 0x1140
testl %eax, %eax
je 0x3658
incq %r14
addq $0x8, %r13
jmp 0x3621
leaq 0x16dc(%rip), %rdi      # 0x4d23
jmp 0x374a
leaq 0x1723(%rip), %rdi      # 0x4d76
jmp 0x374a
movq -0x38(%rbp), %r13
leaq 0x8(%r13), %rdi
imulq $0x30, 0x18(%r13), %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 0x3c56
incq %r12
movq %r12, (%rbx)
pushq $0xa
popq %rsi
movq %r12, %rdi
callq 0x1050
testq %rax, %rax
je 0x3743
incq %rax
movq %rax, (%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3594
movq %rax, 0x8(%r15)
movq (%rbx), %rdi
pushq $0xa
popq %rsi
callq 0x1050
testq %rax, %rax
je 0x3743
incq %rax
movq %rax, (%rbx)
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x1050
testq %rax, %rax
je 0x3743
incq %rax
movq %rax, (%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3594
movq %rax, 0x10(%r15)
movq (%rbx), %rdi
pushq $0xa
popq %rsi
callq 0x1050
testq %rax, %rax
je 0x3743
incq %rax
movq %rax, (%rbx)
movq 0x4a2e(%rip), %rax      # 0x8160
cmpq %rax, 0x8(%r15)
je 0x373e
cmpq %rax, 0x10(%r15)
jne 0x3756
movq %rax, %r15
jmp 0x3756
leaq 0x1605(%rip), %rdi      # 0x4d4f
callq 0x1170
movq 0x4a0a(%rip), %r15      # 0x8160
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x125b(%rip), %rdi      # 0x49ca
leaq 0x1259(%rip), %rsi      # 0x49cf
leaq 0x14e0(%rip), %rcx      # 0x4c5d
movl $0xdb, %edx
callq 0x1080
leaq 0x14f2(%rip), %rdi      # 0x4c80
leaq 0x123a(%rip), %rsi      # 0x49cf
leaq 0x14c1(%rip), %rcx      # 0x4c5d
movl $0xdc, %edx
callq 0x1080
nop