// File: /workspace/github_cpp_makefile_star2_O3/vssense[P]Compiler/src/front-end/iotree.cpp
// Function: GetTreeFromBuffer(Node*, Buffer*)
void GetTreeFromBuffer(Node* node, Buffer* buffer)
{
    assert(node);
    assert(buffer);

    while (size_t(buffer->str - buffer->original_str) < buffer->lenght)
    {
        IgnoreSpaces(buffer);

        if (*buffer->str == '{')
        {
            if (node->left == nullptr)
            {
                node->left = NewNode();
                node->left->parent = node;
                node = node->left;
            }
            else
            {
                node->right = NewNode();
                node->right->parent = node;
                node = node->right;
            }

            buffer->str++;
            continue;
        }

        if (*buffer->str == '}')
        {
            node = node->parent;
            buffer->str++;
            continue;
        }

        int len = 0;
        sscanf(buffer->str, "%d %*c %n", (int*)&node->type, &len);
        buffer->str += len;

        if (node->type == NUMB_TYPE)
        {
            sscanf(buffer->str, "%d %n", &node->value.number, &len);
        }
        else if (node->type == ID_TYPE || node->type == DECL_TYPE)
        {
            node->value.name = (char*)calloc(MAX_NAME_LEN, sizeof(char));
            assert(node->value.name);

            sscanf(buffer->str, "%s %n", node->value.name, &len);
        }
        else
        {
            sscanf(buffer->str, "%d %n", &node->value.op, &len);
        }

        buffer->str += len;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x7710
movq %rsi, %rbx
testq %rsi, %rsi
je 0x772f
movq (%rbx), %rax
subq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
jae 0x76e2
movq %rdi, %r14
leaq 0x2f3a(%rip), %r15      # 0xa534
leaq -0x2c(%rbp), %r12
leaq 0x8(%r14), %r13
movq %rbx, %rdi
callq 0x53d8
movq (%rbx), %rdi
movzbl (%rdi), %eax
cmpl $0x7d, %eax
je 0x76ca
cmpl $0x7b, %eax
je 0x76a8
movl $0x0, -0x2c(%rbp)
movq %r15, %rsi
movq %r14, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x20f0
movslq -0x2c(%rbp), %rdi
addq (%rbx), %rdi
movq %rdi, (%rbx)
movl (%r14), %eax
cmpl $0x1, %eax
je 0x765f
cmpl $0x4, %eax
je 0x765f
cmpl $0xf, %eax
leaq 0x2ee4(%rip), %rsi      # 0xa53e
movq %r13, %rdx
jmp 0x7684
movl $0x20, %edi
movl $0x1, %esi
callq 0x20c0
movq %rax, (%r13)
testq %rax, %rax
je 0x76f1
movq (%rbx), %rdi
leaq 0x2ed4(%rip), %rsi      # 0xa555
movq %rax, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x20f0
movslq -0x2c(%rbp), %rax
addq (%rbx), %rax
movq %rax, (%rbx)
subq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
jb 0x7602
jmp 0x76e2
xorl %r13d, %r13d
cmpq $0x0, 0x18(%r14)
setne %r13b
callq 0x6171
movq %rax, 0x18(%r14,%r13,8)
movq %r14, 0x10(%rax)
movq (%rbx), %rdi
movq %rax, %r14
jmp 0x76ce
movq 0x10(%r14), %r14
incq %rdi
movq %rdi, (%rbx)
subq 0x8(%rbx), %rdi
cmpq 0x10(%rbx), %rdi
jb 0x75fe
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2e4c(%rip), %rdi      # 0xa544
leaq 0x2d61(%rip), %rsi      # 0xa460
leaq 0x2e05(%rip), %rcx      # 0xa50b
movl $0x76, %edx
callq 0x20b0
leaq 0x2869(%rip), %rdi      # 0x9f80
leaq 0x2d42(%rip), %rsi      # 0xa460
leaq 0x2de6(%rip), %rcx      # 0xa50b
movl $0x4a, %edx
callq 0x20b0
leaq 0x1b72(%rip), %rdi      # 0x92a8
leaq 0x2d23(%rip), %rsi      # 0xa460
leaq 0x2dc7(%rip), %rcx      # 0xa50b
movl $0x4b, %edx
callq 0x20b0