// File: /workspace/github_cpp_makefile_star2_O2/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 0x735d
movq %rsi, %rbx
testq %rsi, %rsi
je 0x7376
movq %rdi, %r14
movq (%rbx), %rdi
leaq 0x3306(%rip), %r15      # 0xa564
leaq -0x2c(%rbp), %r12
leaq 0x8(%r14), %r13
subq 0x8(%rbx), %rdi
cmpq 0x10(%rbx), %rdi
jae 0x7331
movq %rbx, %rdi
callq 0x51f6
movq (%rbx), %rdi
movzbl (%rdi), %eax
cmpl $0x7d, %eax
je 0x7300
cmpl $0x7b, %eax
je 0x7306
andl $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 0x72c6
cmpl $0x4, %eax
je 0x72c6
cmpl $0xf, %eax
leaq 0x32ad(%rip), %rsi      # 0xa56e
movq %r13, %rdx
jmp 0x72e7
pushq $0x20
popq %rdi
pushq $0x1
popq %rsi
callq 0x20c0
movq %rax, (%r13)
testq %rax, %rax
je 0x7340
movq (%rbx), %rdi
leaq 0x32a1(%rip), %rsi      # 0xa585
movq %rax, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x20f0
movslq -0x2c(%rbp), %rdi
addq (%rbx), %rdi
movq %rdi, (%rbx)
jmp 0x7266
movq 0x10(%r14), %r14
jmp 0x7326
xorl %r13d, %r13d
cmpq $0x0, 0x18(%r14)
setne %r13b
callq 0x5eb0
movq %rax, 0x18(%r14,%r13,8)
movq %r14, 0x10(%rax)
movq (%rbx), %rdi
movq %rax, %r14
incq %rdi
movq %rdi, (%rbx)
jmp 0x7262
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x322d(%rip), %rdi      # 0xa574
leaq 0x3142(%rip), %rsi      # 0xa490
leaq 0x31e6(%rip), %rcx      # 0xa53b
pushq $0x76
popq %rdx
callq 0x20b0
leaq 0x2c44(%rip), %rdi      # 0x9fa8
leaq 0x3125(%rip), %rsi      # 0xa490
leaq 0x31c9(%rip), %rcx      # 0xa53b
pushq $0x4a
jmp 0x7357
leaq 0x1f2b(%rip), %rdi      # 0x92a8
leaq 0x310c(%rip), %rsi      # 0xa490
leaq 0x31b0(%rip), %rcx      # 0xa53b
pushq $0x4b
jmp 0x7357