// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/evaluate.c
// Function: evaluate_ptr_add
static struct symbol *evaluate_ptr_add(struct expression *expr, struct symbol *itype)
{
	struct expression *index = expr->right;
	struct symbol *ctype, *base;
	int multiply;

	classify_type(degenerate(expr->left), &ctype);
	base = examine_pointer_target(ctype);

	/*
	 * An address constant +/- an integer constant expression
	 * yields an address constant again [6.6(7)].
	 */
	if ((expr->left->flags & CEF_ADDR) && (expr->right->flags & CEF_ICE))
		expr->flags = CEF_ADDR;

	if (!base) {
		expression_error(expr, "missing type information");
		return NULL;
	}
	if (is_function(base)) {
		expression_error(expr, "arithmetics on pointers to functions");
		return NULL;
	}

	/* Get the size of whatever the pointer points to */
	multiply = is_void_type(base) ? 1 : bits_to_bytes(base->bit_size);

	if (ctype == &null_ctype)
		ctype = &ptr_ctype;
	expr->ctype = ctype;

	if (multiply == 1 && itype->bit_size == bits_in_pointer)
		return ctype;

	if (index->type == EXPR_VALUE) {
		struct expression *val = alloc_expression(expr->pos, EXPR_VALUE);
		unsigned long long v = index->value, mask;
		mask = 1ULL << (itype->bit_size - 1);
		if (v & mask)
			v |= -mask;
		else
			v &= mask - 1;
		v *= multiply;
		mask = 1ULL << (bits_in_pointer - 1);
		v &= mask | (mask - 1);
		val->value = v;
		val->ctype = ssize_t_ctype;
		expr->right = val;
		return ctype;
	}

	if (itype->bit_size != bits_in_pointer)
		index = cast_to(index, ssize_t_ctype);

	if (multiply > 1) {
		struct expression *val = alloc_expression(expr->pos, EXPR_VALUE);
		struct expression *mul = alloc_expression(expr->pos, EXPR_BINOP);

		val->ctype = ssize_t_ctype;
		val->value = multiply;

		mul->op = '*';
		mul->ctype = ssize_t_ctype;
		mul->left = index;
		mul->right = val;
		index = mul;
	}

	expr->right = index;
	return ctype;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4c1c0
movq %rax, %rdi
leaq -0x28(%rbp), %rsi
callq 0x4bf20
movq -0x28(%rbp), %rdi
callq 0x40260
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl (%rax), %eax
shrl $0x8, %eax
andl $0xff, %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x520ea
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl (%rax), %eax
shrl $0x8, %eax
andl $0xff, %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x520ea
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xffff00ff, %ecx       # imm = 0xFFFF00FF
orl $0x4000, %ecx           # imm = 0x4000
movl %ecx, (%rax)
cmpq $0x0, -0x30(%rbp)
jne 0x52110
movq -0x10(%rbp), %rdi
leaq 0x19c46(%rip), %rsi     # 0x6bd42
movb $0x0, %al
callq 0x17030
movq $0x0, -0x8(%rbp)
jmp 0x52376
movq -0x30(%rbp), %rdi
callq 0x525f0
cmpl $0x0, %eax
je 0x5213d
movq -0x10(%rbp), %rdi
leaq 0x19c32(%rip), %rsi     # 0x6bd5b
movb $0x0, %al
callq 0x17030
movq $0x0, -0x8(%rbp)
jmp 0x52376
movq -0x30(%rbp), %rdi
callq 0x52630
cmpl $0x0, %eax
je 0x52155
movl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x52164
movq -0x30(%rbp), %rax
movl 0x50(%rax), %edi
callq 0x513e0
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x34(%rbp)
leaq 0x40c07(%rip), %rax     # 0x92d78
cmpq %rax, -0x28(%rbp)
jne 0x52182
leaq 0x4079a(%rip), %rax     # 0x92918
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpl $0x1, -0x34(%rbp)
jne 0x521b3
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
leaq 0x3855a(%rip), %rcx     # 0x8a6fc
cmpl (%rcx), %eax
jne 0x521b3
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x52376
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0xff, %eax
cmpl $0x1, %eax
jne 0x522a8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x50ab0
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
andq -0x50(%rbp), %rax
cmpq $0x0, %rax
je 0x52221
xorl %eax, %eax
subq -0x50(%rbp), %rax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x52231
movq -0x50(%rbp), %rax
subq $0x1, %rax
andq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movslq -0x34(%rbp), %rax
imulq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq 0x384b7(%rip), %rax     # 0x8a6fc
movl (%rax), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x50(%rbp), %rcx
subq $0x1, %rcx
orq %rcx, %rax
andq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
leaq 0x38374(%rip), %rax     # 0x8a5f8
movq (%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x52376
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
leaq 0x38446(%rip), %rcx     # 0x8a6fc
cmpl (%rcx), %eax
je 0x522d1
movq -0x20(%rbp), %rdi
leaq 0x38333(%rip), %rax     # 0x8a5f8
movq (%rax), %rsi
callq 0x4c020
movq %rax, -0x20(%rbp)
cmpl $0x1, -0x34(%rbp)
jle 0x52362
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x50ab0
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x5, %esi
callq 0x50ab0
movq %rax, -0x60(%rbp)
leaq 0x382ea(%rip), %rax     # 0x8a5f8
movq (%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
movslq -0x34(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x60(%rbp), %rax
movl $0x2a, 0x4(%rax)
leaq 0x382c1(%rip), %rax     # 0x8a5f8
movq (%rax), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq