// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r12
movq %rdi, %r14
movq 0x28(%rdi), %r15
movq 0x20(%rdi), %rdi
callq 0x2f6c0
leaq 0x8(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2f4dd
movq (%rbx), %rbx
movq %rbx, %rdi
callq 0x270ef
movq 0x20(%r14), %rcx
testb $0x40, 0x1(%rcx)
je 0x31209
movq 0x28(%r14), %rcx
testb $0x10, 0x1(%rcx)
je 0x31209
movb $0x40, 0x1(%r14)
testq %rax, %rax
je 0x31227
movzbl (%rax), %edx
cmpl $0x3, %edx
je 0x3123f
movq %rax, %rcx
cmpl $0x5, %edx
jne 0x31243
leaq 0x12068(%rip), %rsi     # 0x4328d
jmp 0x3122e
leaq 0x12046(%rip), %rsi     # 0x43274
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x11292
jmp 0x31380
movq 0x60(%rax), %rcx
cmpq 0x28cfe(%rip), %rcx     # 0x59f48
je 0x31267
movl 0x50(%rax), %eax
testl %eax, %eax
js 0x3126b
leaq 0x2d4a6(%rip), %rcx     # 0x5e700
movl (%rcx), %ecx
addl %ecx, %eax
decl %eax
cltd
idivl %ecx
movl %eax, %ebp
jmp 0x3126e
pushq $0x1
jmp 0x3126d
pushq $-0x1
popq %rbp
cmpq 0x28d3b(%rip), %rbx     # 0x59fb0
jne 0x3127e
leaq 0x352ba(%rip), %rbx     # 0x66538
movq %rbx, 0x10(%r14)
cmpl $0x1, %ebp
jne 0x3129b
movl 0x50(%r12), %eax
leaq 0x2d499(%rip), %rcx     # 0x5e72c
cmpl (%rcx), %eax
je 0x31380
cmpb $0x1, (%r15)
jne 0x31308
movq 0x8(%r14), %rdi
pushq $0x1
popq %rsi
callq 0x30712
movb 0x50(%r12), %cl
decb %cl
pushq $0x1
popq %rdx
shlq %cl, %rdx
movzbl %cl, %ecx
movq 0x20(%r15), %rsi
movq %rdx, %rdi
negq %rdi
orq %rsi, %rdi
decq %rdx
andq %rsi, %rdx
btq %rcx, %rsi
cmovbq %rdi, %rdx
movslq %ebp, %rsi
imulq %rdx, %rsi
leaq 0x2d446(%rip), %rdx     # 0x5e72c
xorl %ecx, %ecx
subb (%rdx), %cl
shlq %cl, %rsi
shrq %cl, %rsi
movq %rsi, 0x20(%rax)
leaq 0x2d32d(%rip), %rcx     # 0x5e628
movq (%rcx), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x28(%r14)
jmp 0x31380
movl 0x50(%r12), %eax
leaq 0x2d418(%rip), %rcx     # 0x5e72c
cmpl (%rcx), %eax
je 0x3132d
leaq 0x2d309(%rip), %rax     # 0x5e628
movq (%rax), %rsi
movq %r15, %rdi
callq 0x2f54c
movq %rax, %r15
cmpl $0x2, %ebp
jl 0x3137c
movq 0x8(%r14), %rdi
pushq $0x1
popq %rsi
callq 0x30712
movq %rax, %r12
movq 0x8(%r14), %rdi
pushq $0x5
popq %rsi
callq 0x30712
leaq 0x2d2d4(%rip), %rcx     # 0x5e628
movq (%rcx), %rdx
movq %rdx, 0x10(%r12)
movl %ebp, %edx
movq %rdx, 0x20(%r12)
movl $0x2a, 0x4(%rax)
movq (%rcx), %rcx
movq %rcx, 0x10(%rax)
movq %r15, 0x20(%rax)
movq %r12, 0x28(%rax)
movq %rax, %r15
movq %r15, 0x28(%r14)
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq