// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movq %rdi, %rbx
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7a57
xorl %r14d, %r14d
movl (%r15), %eax
cmpl $0x33, %eax
jg 0xa6a6
cmpl $0x7, %eax
je 0xa712
cmpl $0x33, %eax
jne 0xa836
movq %rbx, %rdi
callq 0x7a94
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %edi
movl $0x25, %esi
jmp 0xa7f6
cmpl $0x34, %eax
je 0xa7c7
cmpl $0x35, %eax
jne 0xa836
movq %rbx, %rdi
callq 0x7a94
movq 0x60(%rbx), %rdi
movq 0x50(%rsp), %rsi
callq 0xc219
movq %rax, %rbx
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %edi
movl $0x24, %esi
callq 0x356c
movq %rax, %r14
testq %rbx, %rbx
je 0xa800
movq %rbx, 0x18(%r14)
jmp 0xa817
movq %rbx, %rdi
callq 0x7a94
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7a57
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 0x7c69
testl %eax, %eax
je 0xa823
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7a57
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7ca7
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7c3b
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7ca7
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7c3b
xorl %r14d, %r14d
jmp 0xa836
movq %rbx, %rdi
callq 0x7a94
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %edi
movl $0x26, %esi
callq 0x356c
movq %rax, %r14
jmp 0xa836
leaq 0x38(%rsp), %rdi
movq 0x18(%rdi), %rdx
leaq 0x4387(%rip), %rsi      # 0xeb97
xorl %eax, %eax
callq 0x3250
movq 0x50(%rsp), %rdi
callq 0x3030
jmp 0xa836
movq %rbx, %rdi
callq 0x985d
movq %rax, %r14
movq %rbx, %rdi
callq 0x7a94
movq %r14, %rax
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %r15
retq