// File: 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
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x469c
jmp 0x46bb
leaq 0x23a5(%rip), %rdi      # 0x6a48
leaq 0x23a3(%rip), %rsi      # 0x6a4d
movl $0xdb, %edx
leaq 0x26c6(%rip), %rcx      # 0x6d7c
callq 0x1080
cmpq $0x0, -0x18(%rbp)
je 0x46c4
jmp 0x46e3
leaq 0x26d4(%rip), %rdi      # 0x6d9f
leaq 0x237b(%rip), %rsi      # 0x6a4d
movl $0xdc, %edx
leaq 0x269e(%rip), %rcx      # 0x6d7c
callq 0x1080
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0xa, %esi
callq 0x1050
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x471d
leaq 0x26a1(%rip), %rdi      # 0x6da7
movb $0x0, %al
callq 0x1040
movq 0x5a3c(%rip), %rax      # 0xa150
movq %rax, -0x8(%rbp)
jmp 0x4a34
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x4743
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x4724
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x476d
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x4a34
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0x20, %esi
callq 0x1050
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x47a7
leaq 0x263f(%rip), %rdi      # 0x6dcf
movb $0x0, %al
callq 0x1040
movq 0x59b2(%rip), %rax      # 0xa150
movq %rax, -0x8(%rbp)
jmp 0x4a34
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x10, -0x2c(%rbp)
jge 0x47f1
movslq -0x2c(%rbp), %rcx
leaq 0x5903(%rip), %rax      # 0xa0d0
movq (%rax,%rcx,8), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x1130
cmpl $0x0, %eax
jne 0x47e4
jmp 0x47f1
jmp 0x47e6
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x47bc
cmpl $0x10, -0x2c(%rbp)
jne 0x4815
leaq 0x25fe(%rip), %rdi      # 0x6dfc
movb $0x0, %al
callq 0x1040
movq 0x5944(%rip), %rax      # 0xa150
movq %rax, -0x8(%rbp)
jmp 0x4a34
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
imulq $0x30, 0x18(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movl -0x2c(%rbp), %eax
movl %eax, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movb $0x0, -0x48(%rbp)
movups -0x70(%rbp), %xmm0
movups -0x60(%rbp), %xmm1
movups -0x50(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x5240
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0xa, %esi
callq 0x1050
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x48de
leaq 0x24e0(%rip), %rdi      # 0x6da7
movb $0x0, %al
callq 0x1040
movq 0x587b(%rip), %rax      # 0xa150
movq %rax, -0x8(%rbp)
jmp 0x4a34
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4680
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0xa, %esi
callq 0x1050
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x493f
leaq 0x247f(%rip), %rdi      # 0x6da7
movb $0x0, %al
callq 0x1040
movq 0x581a(%rip), %rax      # 0xa150
movq %rax, -0x8(%rbp)
jmp 0x4a34
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0xa, %esi
callq 0x1050
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x4988
leaq 0x2436(%rip), %rdi      # 0x6da7
movb $0x0, %al
callq 0x1040
movq 0x57d1(%rip), %rax      # 0xa150
movq %rax, -0x8(%rbp)
jmp 0x4a34
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4680
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0xa, %esi
callq 0x1050
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x49e6
leaq 0x23d5(%rip), %rdi      # 0x6da7
movb $0x0, %al
callq 0x1040
movq 0x5770(%rip), %rax      # 0xa150
movq %rax, -0x8(%rbp)
jmp 0x4a34
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpq 0x574c(%rip), %rax      # 0xa150
je 0x4a17
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
cmpq 0x573b(%rip), %rax      # 0xa150
jne 0x4a24
movq 0x5732(%rip), %rax      # 0xa150
movq %rax, -0x78(%rbp)
jmp 0x4a2c
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)