// File: /workspace/github_c_makefile_star2_O2/johnvtan[P]ccccc/parse.c
// Function: parse_stmt
static stmt_t *parse_stmt(list_t *tokens, env_t *env) {
    if (!tokens || !env)
        return NULL;
    stmt_t *ret = malloc(sizeof(stmt_t));
    token_t *curr = list_peek(tokens);

    if (curr->type == TOK_OPEN_BRACE) {
        ret->block = parse_block(tokens, env);
        ret->type = STMT_BLOCK;
        return ret;
    }

    if (curr->type == TOK_RETURN) {
        debug("parse_stmt: Found return statement\n");
        return_stmt_t *ret_stmt = parse_return_stmt(tokens, env);
        if (!ret_stmt)
            return NULL;
        ret->type = STMT_RETURN;
        ret->ret = ret_stmt;
        return ret;
    }

    if (curr->type == TOK_IF) {
        if_stmt_t *if_stmt = parse_if_stmt(tokens, env);
        ret->type = STMT_IF;
        ret->if_stmt = if_stmt;
        return ret;
    }

    if (curr->type == TOK_FOR) {
        ret->for_stmt = parse_for_stmt(tokens, env);
        ret->type = STMT_FOR;
        return ret;
    }

    if (curr->type == TOK_WHILE) {
        ret->while_stmt = parse_while_stmt(tokens, env);
        ret->type = STMT_WHILE;
        return ret;
    }

    if (curr->type == TOK_DO) {
        debug("Found do stmt\n");
        ret->do_stmt = parse_do_stmt(tokens, env);
        ret->type = STMT_DO;
        return ret;
    }

    if (match(tokens, TOK_BREAK)) {
        debug("parse_stmt: Found break\n");
        expect_next(tokens, TOK_SEMICOLON);
        ret->type = STMT_BREAK;
        return ret;
    }

    if (match(tokens, TOK_CONTINUE)) {
        debug("parse_stmt: Found continue\n");
        expect_next(tokens, TOK_SEMICOLON);
        ret->type = STMT_CONTINUE;
        return ret;
    }

    // The first token in a declaration is a type
    if (is_type(curr->type)) {
        debug("parse_stmt: Found declaration statement\n");
        declare_stmt_t *declare = parse_declare_stmt(tokens, env);
        if (!declare)
            return NULL;
        ret->type = STMT_DECLARE;
        ret->declare = declare;
        return ret;
    }

    // Otherwise, try to parse an expression
    if (match(tokens, TOK_SEMICOLON)) {
        debug("parse_stmt: Found null expr stmt\n");
        ret->type = STMT_NULL;
        return ret;
    }

    debug("parse_stmt: Found nonnull expr stmt\n");
    expr_t *expr = parse_expr(tokens, env);
    ret->type = STMT_EXPR;
    ret->expr = expr; 
    expect_next(tokens, TOK_SEMICOLON);
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x3aaa
movq %rsi, %r15
movq %rdi, %r14
pushq $0x10
popq %rdi
callq 0x10e0
movq %rax, %rbx
movq %r14, %rdi
callq 0x2d68
movq %rax, %r12
movl (%rax), %eax
leal -0x24(%rax), %ecx
cmpl $0x6, %ecx
ja 0x377c
leaq 0x2170(%rip), %rax      # 0x5860
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
pushq $0x24
popq %rsi
movq %r14, %rdi
callq 0x3666
pushq $0x18
popq %rdi
callq 0x10e0
movq %rax, %r12
pushq $0xe
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r14, %rdi
movq %r15, %rsi
callq 0x3b59
movq %rax, (%r12)
pushq $0xf
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r14, %rdi
movq %r15, %rsi
callq 0x3bf7
movq %rax, 0x8(%r12)
andq $0x0, 0x10(%r12)
pushq $0x25
popq %rsi
movq %r14, %rdi
callq 0x3c7c
testb %al, %al
je 0x3771
movq %r14, %rdi
callq 0x2d0a
movq %r14, %rdi
movq %r15, %rsi
callq 0x3bf7
movq %rax, 0x10(%r12)
movl $0x2, (%rbx)
jmp 0x3924
cmpl $0x4, %eax
je 0x38f1
cmpl $0xc, %eax
jne 0x37a4
movq %r14, %rdi
movq %r15, %rsi
callq 0x3b20
movq %rax, 0x8(%rbx)
movl $0x3, (%rbx)
jmp 0x3aac
pushq $0x2b
popq %rsi
movq %r14, %rdi
callq 0x35a8
testb %al, %al
je 0x392d
pushq $0x12
popq %rsi
movq %r14, %rdi
callq 0x3666
movl $0x9, (%rbx)
jmp 0x3aac
pushq $0x2a
popq %rsi
movq %r14, %rdi
callq 0x3666
pushq $0x10
popq %rdi
callq 0x10e0
movq %rax, %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x3bf7
movq %rax, 0x8(%r12)
pushq $0x29
popq %rsi
movq %r14, %rdi
callq 0x3666
pushq $0xe
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r14, %rdi
movq %r15, %rsi
callq 0x3b59
movq %rax, (%r12)
pushq $0xf
popq %rsi
movq %r14, %rdi
callq 0x3666
pushq $0x12
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r12, 0x8(%rbx)
movl $0x8, (%rbx)
jmp 0x3aac
pushq $0x28
popq %rsi
movq %r14, %rdi
callq 0x3666
pushq $0x28
popq %rdi
callq 0x10e0
movq %rax, %r12
movq %r15, %rdi
callq 0x2b4c
movq %rax, %r15
movq %rax, 0x20(%r12)
pushq $0xe
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r14, %rdi
callq 0x2d68
movl (%rax), %eax
addl $-0x5, %eax
cmpl $0x1, %eax
ja 0x3956
movq %r14, %rdi
movq %r15, %rsi
callq 0x36a0
movq %rax, %r13
jmp 0x3985
pushq $0x29
popq %rsi
movq %r14, %rdi
callq 0x3666
pushq $0x10
popq %rdi
callq 0x10e0
movq %rax, %r12
pushq $0xe
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r14, %rdi
movq %r15, %rsi
callq 0x3b59
movq %rax, (%r12)
pushq $0xf
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r14, %rdi
movq %r15, %rsi
callq 0x3bf7
movq %rax, 0x8(%r12)
movq %r12, 0x8(%rbx)
movl $0x7, (%rbx)
jmp 0x3aac
pushq $0x8
popq %rdi
callq 0x10e0
movq %rax, %r12
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r14, %rdi
movq %r15, %rsi
callq 0x3b59
movq %rax, (%r12)
pushq $0x12
popq %rsi
movq %r14, %rdi
callq 0x3666
andl $0x0, (%rbx)
movq %r12, 0x8(%rbx)
jmp 0x3aac
pushq $0x2c
popq %rsi
movq %r14, %rdi
callq 0x35a8
testb %al, %al
je 0x39f7
pushq $0x12
popq %rsi
movq %r14, %rdi
callq 0x3666
movl $0xa, (%rbx)
jmp 0x3aac
pushq $0x10
popq %rdi
callq 0x10e0
movq %rax, %r13
movl $0x4, (%rax)
pushq $0x12
popq %rbp
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x3c94
movq %rax, 0x8(%r13)
movq %r14, %rdi
movl %ebp, %esi
callq 0x3666
movq %r13, (%r12)
pushq $0x12
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x3c94
movq %rax, 0x8(%r12)
cmpl $0x5, (%rax)
jne 0x39ae
pushq $0x1
popq %rdi
callq 0x3cd8
movq %rax, 0x8(%r12)
pushq $0x12
popq %rsi
movq %r14, %rdi
callq 0x3666
pushq $0xf
popq %rbp
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x3c94
movq %rax, 0x10(%r12)
movq %r14, %rdi
movl %ebp, %esi
callq 0x3666
movq %r14, %rdi
movq %r15, %rsi
callq 0x3bf7
movq %rax, 0x18(%r12)
movq %r12, 0x8(%rbx)
movl $0x6, (%rbx)
jmp 0x3aac
movl (%r12), %eax
addl $-0x5, %eax
cmpl $0x1, %eax
ja 0x3abe
pushq $0x18
popq %rdi
callq 0x10e0
movq %rax, %r12
andq $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0x2d0a
movl (%rax), %edi
callq 0x362c
movl %eax, %ebp
movl %eax, (%r12)
movq %r14, %rdi
callq 0x2d68
cmpl $0x3, (%rax)
jne 0x3aaa
movq 0x8(%rax), %r13
movq %r13, 0x8(%r12)
movq (%r15), %rdi
movq %r13, %rsi
callq 0x2fab
testb %al, %al
jne 0x3af7
movq %r15, %rdi
movq %r13, %rsi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x2bfd
movq %r14, %rdi
callq 0x2d0a
movq %r14, %rdi
callq 0x2d68
cmpl $0x12, (%rax)
je 0x3a94
pushq $0xb
popq %rsi
movq %r14, %rdi
callq 0x3666
movq %r14, %rdi
movq %r15, %rsi
callq 0x3b59
movq %rax, 0x10(%r12)
pushq $0x12
popq %rsi
movq %r14, %rdi
callq 0x3666
movl $0x1, (%rbx)
jmp 0x3924
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x12
popq %rsi
movq %r14, %rdi
callq 0x35a8
testb %al, %al
je 0x3ad5
movl $0x5, (%rbx)
jmp 0x3aac
movq %r14, %rdi
movq %r15, %rsi
callq 0x3b59
movl $0x4, (%rbx)
movq %rax, 0x8(%rbx)
pushq $0x12
popq %rsi
movq %r14, %rdi
callq 0x3666
jmp 0x3aac
leaq 0x1636(%rip), %rdi      # 0x5134
leaq 0x1d77(%rip), %rsi      # 0x587c
leaq 0x1e9f(%rip), %rcx      # 0x59ab
movl $0x242, %edx            # imm = 0x242
xorl %eax, %eax
callq 0x1080
pushq $-0x1
popq %rdi
callq 0x1110