// File: /workspace/github_c_makefile_star2_O2/Yamsman[P]scc/src/parse.c
// Function: parse_expr_primary
ast_n *parse_expr_primary(lexer *lx) {
	ast_n *node;
	token t = lex_peek(lx);
	switch (t.type) {
		case TOK_IDENT: //TODO: improve handling of undefined variables
			lex_adv(lx);
			symbol *s = symtable_search(lx->stb, t.dat.sval);
			node = astn_new(EXPR, EXPR_IDENT, t);
			if (s != NULL) {
				node->dat.expr.sym = s;
			} else {
				c_error(&t.loc, "Undeclared variable \"%s\"\n", t.dat.sval);
			}
			free(t.dat.sval);

			return node;
		case TOK_CONST:
			lex_adv(lx);
			node = astn_new(EXPR, EXPR_CONST, t);
			return node;
		case TOK_STR:
			lex_adv(lx);
			node = astn_new(EXPR, EXPR_STR, t);
			return node;
		case TOK_LPR:
			lex_adv(lx);
			
			//Check for a cast expression
			if (is_type_spec(lx, lex_peek(lx))) {
				lex_unget(lx, make_tok_node(lex_peek(lx)));
				lex_unget(lx, make_tok_node(t));
				break;
			}
			
			node = parse_expr(lx);
			lex_adv(lx); //expect ')'
			return node;
	}
	return NULL;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x74e5
movl (%r14), %eax
cmpl $0x7, %eax
je 0x9f13
cmpl $0x33, %eax
je 0x9eaf
cmpl $0x34, %eax
je 0x9edb
cmpl $0x35, %eax
jne 0x9fc3
movq %rbx, %rdi
callq 0x7522
movq 0x60(%rbx), %rdi
movq 0x58(%rsp), %rsi
callq 0xb822
movq %rax, %rbx
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups 0x58(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x1
popq %rdi
pushq $0x24
popq %rsi
callq 0x333c
movq %rax, %r14
testq %rbx, %rbx
je 0x9fc8
movq %rbx, 0x18(%r14)
jmp 0x9fdf
movq %rbx, %rdi
callq 0x7522
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups 0x58(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x1
popq %rdi
pushq $0x25
jmp 0x9f05
movq %rbx, %rdi
callq 0x7522
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups 0x58(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x1
popq %rdi
pushq $0x26
popq %rsi
callq 0x333c
movq %rax, %r14
jmp 0x9ffe
movq %rbx, %rdi
callq 0x7522
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x74e5
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x76a1
testl %eax, %eax
je 0x9feb
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x74e5
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x76dd
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7673
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups 0x58(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x76dd
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7673
xorl %r14d, %r14d
jmp 0x9ffe
leaq 0x40(%rsp), %rdi
movq 0x18(%rdi), %rdx
leaq 0x3bbf(%rip), %rsi      # 0xdb97
xorl %eax, %eax
callq 0x35e4
movq 0x58(%rsp), %rdi
callq 0x3030
jmp 0x9ffe
movq %rbx, %rdi
callq 0x90d4
movq %rax, %r14
movq %rbx, %rdi
callq 0x7522
movq %r14, %rax
addq $0xc8, %rsp
popq %rbx
popq %r14
retq