// File: /workspace/github_c_makefile_star2_O3/Yamsman[P]scc/src/parse.c
// Function: parse_expr_postfix
ast_n *parse_expr_postfix(lexer *lx) {
	ast_n *node = parse_expr_primary(lx);

	ast_n *n_node;
	token t = lex_peek(lx);
	switch (t.type) {
		case TOK_LBK: //Array accessor
			n_node = astn_new(EXPR, EXPR_ARRAY, t);
			n_node->dat.expr.left = node;
			lex_adv(lx);

			//Get offset
			n_node->dat.expr.right = parse_expr(lx);
			//n_node->dat.expr.right = parse_expr_primary(lx);
			
			t = lex_peek(lx);
			if (t.type != TOK_RBK)
				c_error(&t.loc, "Missing ']' after array offset\n");
			lex_adv(lx);

			return n_node;
		case TOK_LPR: //Function calls
			//Check for a cast expression
			lex_adv(lx);
			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;
			}
			n_node = astn_new(EXPR, EXPR_CALL, t);
			n_node->dat.expr.left = node;

			//Empty parameter list
			if (lex_peek(lx).type == TOK_RPR) {
				lex_adv(lx);
				return n_node;
			}

			//Get parameter list
			n_node->dat.expr.right = parse_expr_arglist(lx);
			
			t = lex_peek(lx);
			if (t.type != TOK_RPR)
				c_error(&t.loc, "Missing ')' after parameter list\n");
			lex_adv(lx);
			s_type *type = astn_type(n_node);

			return n_node;
		case TOK_PRD:
		case TOK_PTR:
			n_node = astn_new(EXPR, (t.type == TOK_PRD) ? EXPR_MEMB : EXPR_PTR_MEMB, t);
			lex_adv(lx);

			//Check for identifier
			t = lex_peek(lx);
			if (t.type != TOK_IDENT) {
				c_error(&t.loc, "Expected identifier after '%s'\n",
					(t.type == TOK_PRD) ? "." : "->");
			}
			n_node->dat.expr.left = node;
			n_node->dat.expr.right = astn_new(EXPR, EXPR_IDENT, t);
			lex_adv(lx);
			return n_node;
		case TOK_INC:
			n_node = astn_new(EXPR, EXPR_INC_POST, t);
			n_node->dat.expr.left = node;
			lex_adv(lx);
			return n_node;
		case TOK_DEC:
			n_node = astn_new(EXPR, EXPR_INC_POST, t);
			n_node->dat.expr.left = node;
			lex_adv(lx);
			return n_node;
	}

	return node;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
callq 0xa5b2
movq %rax, %r14
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x79dc
movl (%r15), %eax
cmpl $0x21, %eax
jg 0xa291
cmpl $0x4, %eax
je 0xa2ac
cmpl $0x7, %eax
je 0xa3c1
cmpl $0x9, %eax
jne 0xa474
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %edi
movl $0x1e, %esi
callq 0x356c
movq %rax, %r15
movq %r14, 0x20(%rax)
movq %rbx, %rdi
callq 0x7a19
movq %rbx, %rdi
callq 0x97d3
movq %rax, 0x28(%r15)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x79dc
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movaps %xmm2, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
cmpl $0xa, 0x30(%rsp)
je 0xa3b4
leaq 0x38(%rsp), %rdi
leaq 0x48d2(%rip), %rsi      # 0xeb57
xorl %eax, %eax
callq 0x3250
jmp 0xa3b4
cmpl $0x22, %eax
je 0xa381
cmpl $0x23, %eax
je 0xa381
cmpl $0x24, %eax
jne 0xa474
xorl %esi, %esi
cmpl $0x4, %eax
sete %sil
xorl $0x21, %esi
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %edi
callq 0x356c
movq %rax, %r15
movq %rbx, %rdi
callq 0x7a19
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x79dc
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movaps %xmm2, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl $0x35, %eax
je 0xa34b
leaq 0x38(%rsp), %rdi
cmpl $0x4, %eax
leaq 0x4113(%rip), %rax      # 0xe445
leaq 0x3d13(%rip), %rdx      # 0xe04c
cmoveq %rax, %rdx
leaq 0x4833(%rip), %rsi      # 0xeb77
xorl %eax, %eax
callq 0x3250
movq %r14, 0x20(%r15)
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %edi
movl $0x24, %esi
callq 0x356c
movq %rax, 0x28(%r15)
jmp 0xa3b4
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 $0x22, %esi
callq 0x356c
movq %rax, %r15
movq %r14, 0x20(%rax)
movq %rbx, %rdi
callq 0x7a19
jmp 0xa477
movq %rbx, %rdi
callq 0x7a19
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x79dc
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x7bd6
testl %eax, %eax
je 0xa489
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x79dc
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7ba8
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7ba8
movq %r14, %r15
movq %r15, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %edi
movl $0x1f, %esi
callq 0x356c
movq %rax, %r15
movq %r14, 0x20(%rax)
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x79dc
cmpl $0x8, (%r14)
je 0xa3b4
movq %rbx, %rdi
callq 0xa541
movq %rax, 0x28(%r15)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x79dc
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movaps %xmm2, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
cmpl $0x8, 0x30(%rsp)
je 0xa52c
leaq 0x38(%rsp), %rdi
leaq 0x45a1(%rip), %rsi      # 0xeac6
xorl %eax, %eax
callq 0x3250
movq %rbx, %rdi
callq 0x7a19
movq %r15, %rdi
callq 0x3626
jmp 0xa477