// File: /workspace/github_c_makefile_star2_O0/Yamsman[P]scc/src/eval.c
// Function: eval_constexpr_ast
int _eval_constexpr_ast(ast_n *node, int *err) {
	if (node == NULL) return 0;

	//Perform action
	s_pos *loc = &node->tok.loc;
	int l_res = _eval_constexpr_ast(node->dat.expr.left, err);
	int r_res = _eval_constexpr_ast(node->dat.expr.right, err);
	int t_res = 0;
	switch (node->dat.expr.kind) {
		case EXPR_COND: {
			ast_n *res = node->dat.expr.right;
			r_res = _eval_constexpr_ast(res->dat.expr.left, err);
			t_res = _eval_constexpr_ast(res->dat.expr.right, err);
			}
			return do_op(node->tok.type, l_res, r_res, t_res); 
		case EXPR_COND_RES:
			return 0;
		case EXPR_LOGIC_OR:
		case EXPR_LOGIC_AND:
		case EXPR_OR:
		case EXPR_XOR:
		case EXPR_AND:
		case EXPR_GTH:
		case EXPR_LTH:
		case EXPR_GEQ:
		case EXPR_LEQ:
		case EXPR_LSHIFT:
		case EXPR_RSHIFT:
		case EXPR_EQ:
		case EXPR_NEQ:
		case EXPR_ADD:
		case EXPR_SUB:
		case EXPR_MUL:
		case EXPR_DIV:
			return do_op(node->tok.type, l_res, r_res, 0);
		case EXPR_MOD:
		case EXPR_POS:
		case EXPR_NEG:
		case EXPR_NOT:
		case EXPR_LOGIC_NOT:
			return do_op(node->tok.type, l_res, 0, 0);
			break;
		case EXPR_CAST:
		case EXPR_REF:
		case EXPR_DEREF:
		case EXPR_INC_PRE:
		case EXPR_DEC_PRE:
		case EXPR_ARRAY:
		case EXPR_CALL:
		case EXPR_MEMB:
		case EXPR_PTR_MEMB:
		case EXPR_INC_POST:
		case EXPR_DEC_POST:
			c_error(loc, "Invalid operation in constant expression\n");
			return 0;
		case EXPR_IDENT:
			c_error(loc, "Identifier in constant expression\n");
			return 0;
		case EXPR_CONST:
			if (node->tok.dtype->kind == TYPE_FLOAT)
				c_error(loc, "Floating point value in constant expression\n");
			return node->tok.dat.ival;
		default:
			c_error(loc, "Invalid constant expression\n");
			break;
	}
	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4213
movl $0x0, -0x4(%rbp)
jmp 0x4386
movq -0x10(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x41f0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x41f0
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x24, %eax
ja 0x436d
movq -0x40(%rbp), %rax
leaq 0xcf9f(%rip), %rcx      # 0x11210
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x41f0
movl %eax, -0x28(%rbp)
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x41f0
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x30(%rax), %edi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x2c(%rbp), %ecx
callq 0x3b70
movl %eax, -0x4(%rbp)
jmp 0x4386
movl $0x0, -0x4(%rbp)
jmp 0x4386
movq -0x10(%rbp), %rax
movl 0x30(%rax), %edi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
xorl %ecx, %ecx
callq 0x3b70
movl %eax, -0x4(%rbp)
jmp 0x4386
movq -0x10(%rbp), %rax
movl 0x30(%rax), %edi
movl -0x24(%rbp), %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x3b70
movl %eax, -0x4(%rbp)
jmp 0x4386
movq -0x20(%rbp), %rdi
leaq 0xd004(%rip), %rsi      # 0x1131a
movb $0x0, %al
callq 0x3880
movl $0x0, -0x4(%rbp)
jmp 0x4386
movq -0x20(%rbp), %rdi
leaq 0xd0c2(%rip), %rsi      # 0x113f3
movb $0x0, %al
callq 0x3880
movl $0x0, -0x4(%rbp)
jmp 0x4386
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x7, (%rax)
jne 0x4360
movq -0x20(%rbp), %rdi
leaq 0xcf4b(%rip), %rsi      # 0x112a4
movb $0x0, %al
callq 0x3880
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl %eax, -0x4(%rbp)
jmp 0x4386
movq -0x20(%rbp), %rdi
leaq 0xd09e(%rip), %rsi      # 0x11416
movb $0x0, %al
callq 0x3880
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop