// File: /workspace/github_cpp_makefile_star2_O1/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 0x779c
movq %rsi, %rbx
testq %rsi, %rsi
je 0x77bb
movq (%rbx), %rax
subq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
jae 0x776e
movq %rdi, %r14
leaq 0x2e9e(%rip), %r15      # 0xa524
leaq -0x2c(%rbp), %r12
leaq 0x8(%r14), %r13
movq %rbx, %rdi
callq 0x54ac
movq (%rbx), %rdi
movzbl (%rdi), %eax
cmpl $0x7d, %eax
je 0x7756
cmpl $0x7b, %eax
je 0x7734
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 0x76eb
cmpl $0x4, %eax
je 0x76eb
cmpl $0xf, %eax
leaq 0x2e48(%rip), %rsi      # 0xa52e
movq %r13, %rdx
jmp 0x7710
movl $0x20, %edi
movl $0x1, %esi
callq 0x20c0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x777d
movq (%rbx), %rdi
leaq 0x2e38(%rip), %rsi      # 0xa545
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 0x768e
jmp 0x776e
xorl %r13d, %r13d
cmpq $0x0, 0x18(%r14)
setne %r13b
callq 0x6201
movq %rax, 0x18(%r14,%r13,8)
movq %r14, 0x10(%rax)
movq (%rbx), %rdi
movq %rax, %r14
jmp 0x775a
movq 0x10(%r14), %r14
incq %rdi
movq %rdi, (%rbx)
subq 0x8(%rbx), %rdi
cmpq 0x10(%rbx), %rdi
jb 0x768a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2db0(%rip), %rdi      # 0xa534
leaq 0x2cc5(%rip), %rsi      # 0xa450
leaq 0x2d69(%rip), %rcx      # 0xa4fb
movl $0x76, %edx
callq 0x20b0
leaq 0x27c9(%rip), %rdi      # 0x9f6c
leaq 0x2ca6(%rip), %rsi      # 0xa450
leaq 0x2d4a(%rip), %rcx      # 0xa4fb
movl $0x4a, %edx
callq 0x20b0
leaq 0x1ae6(%rip), %rdi      # 0x92a8
leaq 0x2c87(%rip), %rsi      # 0xa450
leaq 0x2d2b(%rip), %rcx      # 0xa4fb
movl $0x4b, %edx
callq 0x20b0