// File: /workspace/github_c_makefile_star2_O0/gregtour[P]minimal-compiler/preprocess.c
// Function: ReduceProgramAST
void ReduceProgramAST(SYNTAX_TREE** astPosition)
{
    SYNTAX_TREE* node;
    SYNTAX_TREE* branch;
    unsigned int reducible = 1;
    const unsigned int empty_production = 0;
    int i;

    unsigned int reducibleTokens[] = 
    { //SYMBOL_BLOCK,
        SYMBOL_EXPR, 
        SYMBOL_CONDITION, 
        SYMBOL_LOGIC, 
        SYMBOL_COMPARISON, 
        SYMBOL_ARITHMETIC, 
        SYMBOL_TERM, 
        SYMBOL_FACTOR, 
        SYMBOL_FINAL
    };

    if (astPosition == NULL) return;
    node = *astPosition;

    // continue while reducible
    while (reducible)
    {
        reducible = 0;

        // productions that reduce to node->children[0]
        for (i = 0; i < sizeof(reducibleTokens)/sizeof(int); i++)
        {
            if (node->token == reducibleTokens[i] &&
                node->numChildren == 1)
            {
                SYNTAX_TREE* cur = *astPosition;
                int child;

                for (child = 1; child < cur->numChildren; child++)
                {
                    FreeParseTree(cur->children[child]);
                }

                *astPosition = node->children[0];
                node = *astPosition;
                free(cur->children);
                free(cur);
                reducible = 1;
            }
        }

        // parentheses expression
        if (node->production == PROD_FINAL)
        {
            SYNTAX_TREE* cur = *astPosition;
            *astPosition = node->children[1];
            node = *astPosition;
            free(cur->children);
            free(cur);
            reducible = 1;
        }
    }

    // apply for all sub-trees
    branch = *astPosition;
    for (i = 0; i < branch->numChildren; i++)
    {
        ReduceProgramAST(&branch->children[i]);
        branch = *astPosition;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq 0x327f(%rip), %rax      # 0xb850
movq %rax, -0x50(%rbp)
movq 0x327c(%rip), %rax      # 0xb858
movq %rax, -0x48(%rbp)
movq 0x3279(%rip), %rax      # 0xb860
movq %rax, -0x40(%rbp)
movq 0x3276(%rip), %rax      # 0xb868
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x8602
jmp 0x877a
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x872e
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rax
cmpq $0x8, %rax
jae 0x86d9
movq -0x10(%rbp), %rax
movl (%rax), %eax
movslq -0x24(%rbp), %rcx
cmpl -0x50(%rbp,%rcx,4), %eax
jne 0x86c9
movq -0x10(%rbp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x86c9
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movl $0x1, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x868f
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x76f0
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x8663
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2030
movq -0x58(%rbp), %rdi
callq 0x2030
movl $0x1, -0x1c(%rbp)
jmp 0x86cb
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8625
movq -0x10(%rbp), %rax
cmpl $0x3a, 0x4(%rax)
jne 0x8729
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2030
movq -0x68(%rbp), %rdi
callq 0x2030
movl $0x1, -0x1c(%rbp)
jmp 0x860d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x877a
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
movslq -0x24(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x85b0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8740
addq $0x70, %rsp
popq %rbp
retq