// File: /workspace/github_c_makefile_star2_O1/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 0xa636
movq %rax, %r14
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7a57
movl (%r15), %eax
cmpl $0x21, %eax
jg 0xa315
cmpl $0x4, %eax
je 0xa330
cmpl $0x7, %eax
je 0xa445
cmpl $0x9, %eax
jne 0xa4f8
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 0x7a94
movq %rbx, %rdi
callq 0x985d
movq %rax, 0x28(%r15)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7a57
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 0xa438
leaq 0x38(%rsp), %rdi
leaq 0x484e(%rip), %rsi      # 0xeb57
xorl %eax, %eax
callq 0x3250
jmp 0xa438
cmpl $0x22, %eax
je 0xa405
cmpl $0x23, %eax
je 0xa405
cmpl $0x24, %eax
jne 0xa4f8
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 0x7a94
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x7a57
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 0xa3cf
leaq 0x38(%rsp), %rdi
cmpl $0x4, %eax
leaq 0x408f(%rip), %rax      # 0xe445
leaq 0x3c8f(%rip), %rdx      # 0xe04c
cmoveq %rax, %rdx
leaq 0x47af(%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 0xa438
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 0x7a94
jmp 0xa4fb
movq %rbx, %rdi
callq 0x7a94
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7a57
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 0x7c69
testl %eax, %eax
je 0xa50d
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7a57
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7ca7
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7c3b
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7ca7
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7c3b
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 0x7a57
cmpl $0x8, (%r14)
je 0xa438
movq %rbx, %rdi
callq 0xa5c5
movq %rax, 0x28(%r15)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7a57
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 0xa5b0
leaq 0x38(%rsp), %rdi
leaq 0x451d(%rip), %rsi      # 0xeac6
xorl %eax, %eax
callq 0x3250
movq %rbx, %rdi
callq 0x7a94
movq %r15, %rdi
callq 0x3626
jmp 0xa4fb