// File: /workspace/github_cpp_makefile_star2_O2/philpoore[P]Math/./src/Parser.cpp
// Function: Parser::parseStatement()
AstStmt* Parser::parseStatement() {
    consumeWhiteSpace();
    AstExpr* expr = nullptr;

    Token t = peek();
    // Assignment statement
    if (t.type == TOKEN_IF) {
        expr = (AstExpr*)parseIf();
    } else if (t.type == TOKEN_IDENT) {
        if (peekNonWhitespace(1).type == TOKEN_EQ) {
            // parse assignment statement
            Token t_ident = expect(TOKEN_IDENT);
            consumeWhiteSpace();

            expect(TOKEN_EQ);
            AstAssign* ast = new AstAssign();
            ast->name = t_ident.source;
            ast->expr = parseExpr();
            expr = (AstExpr*)ast;
        }
    } else if (peek().type == TOKEN_LCURLY) {
        // Block statement
        consume();
        expr = (AstExpr*)parseBlock();
        expect(TOKEN_RCURLY, "Unmatched curly brace, missing closing bracket.");
    }

    // default to parsing expressions.
    if (expr == nullptr) {
        expr = parseExpr();
    }

    if (expr == nullptr) {
        return nullptr;
    }

    consumeWhiteSpace();
    if (expr->type != AST_TYPE_BLOCK && expr->type != AST_TYPE_IF &&
        peek().type != TOKEN_EOF) {
        expect(TOKEN_SEMI, "Missing semi colon");
    }

    AstStmt* stmt = new AstStmt();
    stmt->expr = expr;
    return stmt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, %rbx
callq 0x5ebc
leaq -0x100(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x5b68
movl (%r14), %eax
cmpl $0x101, %eax            # imm = 0x101
je 0x605f
cmpl $0x10e, %eax            # imm = 0x10E
jne 0x6161
movq %rbx, %rdi
callq 0x6324
movq %rax, %r14
jmp 0x6210
leaq -0x50(%rbp), %rdi
pushq $0x1
popq %rdx
movq %rbx, %rsi
callq 0x5b94
leaq -0x48(%rbp), %rdi
movl -0x8(%rdi), %r14d
callq 0x3110
cmpl $0x103, %r14d           # imm = 0x103
jne 0x61f7
leaq 0x4454(%rip), %rsi      # 0xa4e3
leaq -0xd0(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x7692
leaq -0x50(%rbp), %rdi
leaq -0xd0(%rbp), %rcx
movq %rbx, %rsi
movl $0x101, %edx            # imm = 0x101
callq 0x5cb2
leaq -0xd0(%rbp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x5ebc
leaq 0x4411(%rip), %rsi      # 0xa4e3
leaq -0xb0(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x7692
leaq -0x1c0(%rbp), %rdi
leaq -0xb0(%rbp), %rcx
movq %rbx, %rsi
movl $0x103, %edx            # imm = 0x103
callq 0x5cb2
leaq -0x1b8(%rbp), %rdi
callq 0x3110
leaq -0xb0(%rbp), %rdi
callq 0x3110
pushq $0x30
popq %rdi
callq 0x3200
movq %rax, %r14
movl $0x1, (%rax)
addq $0x18, %rax
movq %rax, 0x8(%r14)
andq $0x0, 0x10(%r14)
leaq 0x8(%r14), %rdi
movb $0x0, 0x18(%r14)
leaq -0x48(%rbp), %r15
movq %r15, %rsi
callq 0x3150
movq %rbx, %rdi
movl $0xffffd8f1, %esi       # imm = 0xFFFFD8F1
callq 0x666e
movq %rax, 0x28(%r14)
movq %r15, %rdi
jmp 0x61f0
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x5b68
leaq -0x48(%rbp), %rdi
movl -0x8(%rdi), %r14d
callq 0x3110
cmpl $0x10c, %r14d           # imm = 0x10C
jne 0x61f7
leaq -0x190(%rbp), %rdi
movq %rbx, %rsi
callq 0x5c86
leaq -0x188(%rbp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x6898
movq %rax, %r14
leaq 0x41fb(%rip), %rsi      # 0xa3ad
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x7692
leaq -0x160(%rbp), %rdi
leaq -0x90(%rbp), %rcx
movq %rbx, %rsi
movl $0x10d, %edx            # imm = 0x10D
callq 0x5cb2
leaq -0x158(%rbp), %rdi
callq 0x3110
leaq -0x90(%rbp), %rdi
callq 0x3110
jmp 0x6210
movq %rbx, %rdi
movl $0xffffd8f1, %esi       # imm = 0xFFFFD8F1
callq 0x666e
movq %rax, %r14
testq %rax, %rax
je 0x62b7
movq %rbx, %rdi
callq 0x5ebc
movl (%r14), %eax
andl $-0x2, %eax
cmpl $0x8, %eax
je 0x6288
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x5b68
leaq -0x48(%rbp), %rdi
movl -0x8(%rdi), %r15d
callq 0x3110
cmpl $0x112, %r15d           # imm = 0x112
je 0x6288
leaq 0x418f(%rip), %rsi      # 0xa3dd
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x7692
leaq -0x130(%rbp), %rdi
leaq -0x70(%rbp), %rcx
movq %rbx, %rsi
movl $0x110, %edx            # imm = 0x110
callq 0x5cb2
leaq -0x128(%rbp), %rdi
callq 0x3110
leaq -0x70(%rbp), %rdi
callq 0x3110
pushq $0x10
popq %rdi
callq 0x3200
movq %rax, %rbx
andl $0x0, (%rax)
movq %r14, 0x8(%rax)
leaq -0xf8(%rbp), %rdi
callq 0x3110
movq %rbx, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
jmp 0x629a
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x3110
jmp 0x6300
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x6304
jmp 0x62fd
jmp 0x630d
jmp 0x62fd
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
jmp 0x6304
jmp 0x630d
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x6304
jmp 0x630d
jmp 0x630d
jmp 0x630d
jmp 0x630d
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3110
jmp 0x6310
jmp 0x630d
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x3370