// File: /workspace/github_c_makefile_star2_O2/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 0x9e19
movq %rax, %r14
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x74e5
movl (%r15), %eax
cmpl $0x4, %eax
je 0x9b75
cmpl $0x7, %eax
je 0x9c4f
cmpl $0x24, %eax
je 0x9b75
cmpl $0x22, %eax
je 0x9b41
cmpl $0x23, %eax
je 0x9b41
cmpl $0x9, %eax
jne 0x9d02
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x1
popq %rdi
pushq $0x1e
popq %rsi
callq 0x333c
movq %rax, %r15
movq %r14, 0x20(%rax)
movq %rbx, %rdi
callq 0x7522
movq %rbx, %rdi
callq 0x90d4
movq %rax, 0x28(%r15)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x74e5
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 0x9c42
leaq 0x38(%rsp), %rdi
leaq 0x4022(%rip), %rsi      # 0xdb57
xorl %eax, %eax
callq 0x35e4
jmp 0x9c42
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x1
popq %rdi
pushq $0x22
popq %rsi
callq 0x333c
movq %rax, %r15
movq %r14, 0x20(%rax)
jmp 0x9c42
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)
pushq $0x1
popq %rdi
callq 0x333c
movq %rax, %r15
movq %rbx, %rdi
callq 0x7522
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x74e5
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 0x9c12
leaq 0x38(%rsp), %rdi
cmpl $0x4, %eax
leaq 0x384c(%rip), %rax      # 0xd445
leaq 0x344c(%rip), %rdx      # 0xd04c
cmoveq %rax, %rdx
leaq 0x3f6c(%rip), %rsi      # 0xdb77
xorl %eax, %eax
callq 0x35e4
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)
pushq $0x1
popq %rdi
pushq $0x24
popq %rsi
callq 0x333c
movq %rax, 0x28(%r15)
movq %rbx, %rdi
callq 0x7522
jmp 0x9d05
movq %rbx, %rdi
callq 0x7522
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x74e5
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 0x76a1
testl %eax, %eax
je 0x9d17
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x74e5
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x76dd
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7673
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x76dd
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7673
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)
pushq $0x1
popq %rdi
pushq $0x1f
popq %rsi
callq 0x333c
movq %rax, %r15
movq %r14, 0x20(%rax)
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x74e5
cmpl $0x8, (%r14)
je 0x9c42
movq %rbx, %rdi
callq 0x9dcb
movq %rax, 0x28(%r15)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x74e5
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 0x9db6
leaq 0x38(%rsp), %rdi
leaq 0x3d17(%rip), %rsi      # 0xdac6
xorl %eax, %eax
callq 0x35e4
movq %rbx, %rdi
callq 0x7522
movq %r15, %rdi
callq 0x33ed
jmp 0x9d05