// File: /workspace/github_c_makefile_star2_O3/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 0x79dc
xorl %r14d, %r14d
movl (%r15), %eax
cmpl $0x33, %eax
jg 0xa622
cmpl $0x7, %eax
je 0xa68e
cmpl $0x33, %eax
jne 0xa7b2
movq %rbx, %rdi
callq 0x7a19
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 0xa772
cmpl $0x34, %eax
je 0xa743
cmpl $0x35, %eax
jne 0xa7b2
movq %rbx, %rdi
callq 0x7a19
movq 0x60(%rbx), %rdi
movq 0x50(%rsp), %rsi
callq 0xc187
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 0xa77c
movq %rbx, 0x18(%r14)
jmp 0xa793
movq %rbx, %rdi
callq 0x7a19
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x79dc
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 0x7bd6
testl %eax, %eax
je 0xa79f
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x79dc
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7ba8
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7ba8
xorl %r14d, %r14d
jmp 0xa7b2
movq %rbx, %rdi
callq 0x7a19
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 0xa7b2
leaq 0x38(%rsp), %rdi
movq 0x18(%rdi), %rdx
leaq 0x440b(%rip), %rsi      # 0xeb97
xorl %eax, %eax
callq 0x3250
movq 0x50(%rsp), %rdi
callq 0x3030
jmp 0xa7b2
movq %rbx, %rdi
callq 0x97d3
movq %rax, %r14
movq %rbx, %rdi
callq 0x7a19
movq %r14, %rax
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %r15
retq