// File: /workspace/github_cpp_makefile_star2_O3/vssense[P]Compiler/src/front-end/translator.cpp
// Function: TranslateStatement(Node*, _IO_FILE*, unsigned long)
void TranslateStatement(Node* node, FILE* file, size_t num_tabs)
{
    assert(node);
    assert(file);

    SetTabs(file, num_tabs);

    switch (node->type)
    {
        case ASSG_TYPE :
        {
            if (node->left->type == ID_TYPE)
            {
                fprintf(file, "%s %s ", node->left->value.name, OPERATORS[ASSIGNMENT].rus_name);
            }
            else
            {
                fprintf(file, "can't interpret this construction");
            }
            
            TranslateExpression(node->right, file);
            fprintf(file, ";\n");
            break;
        }
        case DECL_TYPE :
        {
            fprintf(file, "%s %s %s ", OPERATORS[DECLARATOR].rus_name, node->left->value.name, OPERATORS[ASSIGNMENT].rus_name);
            TranslateExpression(node->right, file);
            fprintf(file, ";\n");
            break;
        }
        case COND_TYPE :
        {
            TranslateCondition(node, file, num_tabs);
            break;
        }
        case LOOP_TYPE :
        {
            TranslateLoop(node, file, num_tabs);
            break;
        }
        case CALL_TYPE :
        {
            if (!TranslateStdCall(node, file))
            {
                fprintf(file, "%s(", node->left->value.name);
                TranslateParams(node->right, file);
                fprintf(file, ");\n");
            }
            break;
        }
        case JUMP_TYPE :
        {
            fprintf(file, "%s ", OPERATORS[RET].rus_name);
            if (node->right != nullptr)
            {
                TranslateExpression(node->right, file);
            }
            fprintf(file, ";\n");
            break;
        }
        default :
        {
            fprintf(file, "can't interpret this construction ");
            break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x4ff3
movq %rsi, %rbx
testq %rsi, %rsi
je 0x5012
movq %rdx, %r15
movq %rdi, %r14
testq %rdx, %rdx
je 0x4e8e
movq %r15, %r12
movl $0x9, %edi
movq %rbx, %rsi
callq 0x2120
decq %r12
jne 0x4e7c
movl (%r14), %eax
decl %eax
cmpl $0xc, %eax
ja 0x4f14
leaq 0x2361(%rip), %rcx      # 0x7200
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x18(%r14), %rax
movq 0x8(%rax), %rcx
leaq 0x255b(%rip), %rsi      # 0x7412
leaq 0x169b(%rip), %rdx      # 0x6559
leaq 0x16fd(%rip), %r8       # 0x65c2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2150
jmp 0x4f93
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x52bc
leaq 0x2527(%rip), %rsi      # 0x7418
leaq 0x16a3(%rip), %rdx      # 0x659b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2150
movq 0x20(%r14), %rdi
testq %rdi, %rdi
jne 0x4f97
jmp 0x4f9f
leaq 0x2505(%rip), %rdi      # 0x7420
movl $0x22, %esi
jmp 0x4fab
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x51a7
movq 0x18(%r14), %rax
cmpl $0x4, (%rax)
jne 0x4f7a
movq 0x8(%rax), %rdx
leaq 0x24c6(%rip), %rsi      # 0x7415
leaq 0x166c(%rip), %rcx      # 0x65c2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2150
jmp 0x4f93
movq %r14, %rdi
movq %rbx, %rsi
callq 0x536d
testb %al, %al
je 0x4fc0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x246f(%rip), %rdi      # 0x73f0
movl $0x21, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x21b0
movq 0x20(%r14), %rdi
movq %rbx, %rsi
callq 0x5031
leaq 0x1ce9(%rip), %rdi      # 0x6c8f
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x21b0
movq 0x18(%r14), %rax
movq 0x8(%rax), %rdx
leaq 0x2372(%rip), %rsi      # 0x7341
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2150
movq 0x20(%r14), %rdi
movq %rbx, %rsi
callq 0x5458
leaq 0x2430(%rip), %rdi      # 0x741c
movl $0x3, %esi
jmp 0x4fab
leaq 0x10e2(%rip), %rdi      # 0x60dc
leaq 0x2233(%rip), %rsi      # 0x7234
leaq 0x23b8(%rip), %rcx      # 0x73c0
movl $0x78, %edx
callq 0x2090
leaq 0x17ea(%rip), %rdi      # 0x6803
leaq 0x2214(%rip), %rsi      # 0x7234
leaq 0x2399(%rip), %rcx      # 0x73c0
movl $0x79, %edx
callq 0x2090