// File: /workspace/github_cpp_makefile_star2_O1/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 0x3a57
movq %rsi, %rbx
testq %rsi, %rsi
je 0x3a76
movq %rdi, %r14
movq (%rbx), %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x3a32
movq %rax, %r12
movb $0x0, (%rax)
movq (%rbx), %rdi
movzbl (%rdi), %eax
cmpl $0x20, %eax
jne 0x38ba
incq %rdi
movq %rdi, (%rbx)
jmp 0x38aa
testl %eax, %eax
jne 0x38cc
incq %rdi
movq %rdi, (%rbx)
xorl %r15d, %r15d
jmp 0x3a45
movl $0x20, %esi
callq 0x1050
testq %rax, %rax
je 0x392c
movq %r14, -0x38(%rbp)
movq %rax, -0x30(%rbp)
movb $0x0, (%rax)
movq (%rbx), %r15
leaq 0x5800(%rip), %r13      # 0x90f0
xorl %r14d, %r14d
movq (%r13), %rdi
movq %r15, %rsi
callq 0x1150
testl %eax, %eax
je 0x3916
incq %r14
addq $0x8, %r13
cmpq $0x10, %r14
jne 0x38f3
movl $0x10, %r14d
cmpl $0x10, %r14d
movq -0x38(%rbp), %r13
jne 0x3938
leaq 0x2467(%rip), %rdi      # 0x5d8e
jmp 0x3a39
leaq 0x2408(%rip), %rdi      # 0x5d3b
jmp 0x3a39
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 0x4062
incq %r12
movq %r12, (%rbx)
movq %r12, %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x3a32
incq %rax
movq %rax, (%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3862
movq %rax, 0x8(%r15)
movq (%rbx), %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x3a32
incq %rax
movq %rax, (%rbx)
movq %rax, %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x3a32
incq %rax
movq %rax, (%rbx)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3862
movq %rax, 0x10(%r15)
movq (%rbx), %rdi
movl $0xa, %esi
callq 0x1050
testq %rax, %rax
je 0x3a32
incq %rax
movq %rax, (%rbx)
movq 0x574f(%rip), %rax      # 0x9170
cmpq %rax, 0x8(%r15)
je 0x3a2d
cmpq %rax, 0x10(%r15)
jne 0x3a45
movq %rax, %r15
jmp 0x3a45
leaq 0x232e(%rip), %rdi      # 0x5d67
callq 0x1180
movq 0x572b(%rip), %r15      # 0x9170
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1f84(%rip), %rdi      # 0x59e2
leaq 0x1f82(%rip), %rsi      # 0x59e7
leaq 0x2209(%rip), %rcx      # 0x5c75
movl $0xdb, %edx
callq 0x1090
leaq 0x221b(%rip), %rdi      # 0x5c98
leaq 0x1f63(%rip), %rsi      # 0x59e7
leaq 0x21ea(%rip), %rcx      # 0x5c75
movl $0xdc, %edx
callq 0x1090
nopl (%rax)