// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %r14
movq 0x20(%rdi), %rdi
movq 0x28(%r14), %r15
callq 0x33628
movq %rax, %rbx
cmpb $0x3, (%rax)
jne 0x37e83
movq 0x60(%rbx), %rbx
cmpb $0xa, (%rbx)
jne 0x37e9c
movq %rbx, %rdi
callq 0x2b5f4
movq %rax, %rbx
cmpb $0x3, (%rax)
jne 0x37e9c
movq 0x60(%rbx), %rbx
cmpb $0x9, (%rbx)
jne 0x37ea5
movq 0x60(%rbx), %rbx
movq %rbx, %rdi
callq 0x2bfd0
movq 0x20(%r14), %rcx
testb $0x40, 0x1(%rcx)
je 0x37ec6
movq 0x28(%r14), %rcx
testb $0x10, 0x1(%rcx)
je 0x37ec6
movb $0x40, 0x1(%r14)
testq %rax, %rax
je 0x37ed9
cmpb $0x5, (%rax)
jne 0x37efe
leaq 0x131f4(%rip), %rsi     # 0x4b0cb
jmp 0x37ee0
leaq 0x131d2(%rip), %rsi     # 0x4b0b2
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x11abc
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x3, (%rax)
movq %rax, %rcx
jne 0x37f0a
movq 0x60(%rax), %rcx
cmpq 0x29027(%rip), %rcx     # 0x60f38
je 0x37f2e
movl 0x50(%rax), %eax
testl %eax, %eax
js 0x37f35
leaq 0x2d7df(%rip), %rcx     # 0x65700
movl (%rcx), %ecx
addl %ecx, %eax
decl %eax
cltd
idivl %ecx
movl %eax, %ebp
jmp 0x37f3a
movl $0x1, %ebp
jmp 0x37f3a
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq 0x2906f(%rip), %rbx     # 0x60fb0
jne 0x37f4a
leaq 0x355ee(%rip), %rbx     # 0x6d538
movq %rbx, 0x10(%r14)
cmpl $0x1, %ebp
jne 0x37f63
movl 0x50(%r12), %eax
leaq 0x2d7cd(%rip), %rcx     # 0x6572c
cmpl (%rcx), %eax
je 0x37eec
cmpb $0x1, (%r15)
jne 0x37ff4
movl %ebp, 0x4(%rsp)
movq 0x8(%r14), %rbp
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x30029
movl (%rax), %ecx
orl $0x1, %ecx
movq %rbp, 0x8(%rax)
andl $0xffff0001, %ecx       # imm = 0xFFFF0001
movl %ecx, (%rax)
movb 0x50(%r12), %cl
decb %cl
movl $0x1, %edx
shlq %cl, %rdx
movq 0x20(%r15), %rsi
movzbl %cl, %ecx
movq %rdx, %rdi
negq %rdi
orq %rsi, %rdi
decq %rdx
andq %rsi, %rdx
btq %rcx, %rsi
cmovbq %rdi, %rdx
movslq 0x4(%rsp), %rsi
imulq %rdx, %rsi
leaq 0x2d75f(%rip), %rcx     # 0x6572c
subb (%rcx), %r13b
movl %r13d, %ecx
shlq %cl, %rsi
shrq %cl, %rsi
movq %rsi, 0x20(%rax)
leaq 0x2d644(%rip), %rcx     # 0x65628
movq (%rcx), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x28(%r14)
jmp 0x37eec
movl 0x50(%r12), %eax
leaq 0x2d72c(%rip), %rcx     # 0x6572c
cmpl (%rcx), %eax
je 0x38019
leaq 0x2d61d(%rip), %rax     # 0x65628
movq (%rax), %rsi
movq %r15, %rdi
callq 0x334cd
movq %rax, %r15
cmpl $0x2, %ebp
jl 0x3808a
movq 0x8(%r14), %r13
xorl %edi, %edi
callq 0x30029
movq %rax, %r12
movl (%rax), %eax
orl $0x1, %eax
movq %r13, 0x8(%r12)
andl $0xffff0001, %eax       # imm = 0xFFFF0001
movl %eax, (%r12)
movq 0x8(%r14), %r13
xorl %edi, %edi
callq 0x30029
movl (%rax), %ecx
orl $0x5, %ecx
movq %r13, 0x8(%rax)
andl $0xffff0005, %ecx       # imm = 0xFFFF0005
movl %ecx, (%rax)
leaq 0x2d5c6(%rip), %rcx     # 0x65628
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)
jmp 0x37eec