// File: /workspace/github_c_makefile_star2_O3/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), %r13
callq 0x32bf6
movq %rax, %rbx
movzbl (%rax), %eax
cmpl $0x3, %eax
jne 0x3736c
movq 0x60(%rbx), %rbx
movzbl (%rbx), %eax
cmpl $0xa, %eax
jne 0x3738b
movq %rbx, %rdi
callq 0x2b0b8
movq %rax, %rbx
movzbl (%rax), %eax
cmpl $0x3, %eax
jne 0x3738b
movq 0x60(%rbx), %rbx
movzbl (%rbx), %eax
cmpl $0x9, %eax
jne 0x37394
movq 0x60(%rbx), %rbx
movq %rbx, %rdi
callq 0x2baa4
movq 0x20(%r14), %rcx
testb $0x40, 0x1(%rcx)
je 0x373b5
movq 0x28(%r14), %rcx
testb $0x10, 0x1(%rcx)
je 0x373b5
movb $0x40, 0x1(%r14)
testq %rax, %rax
je 0x373d3
movzbl (%rax), %edx
cmpl $0x3, %edx
je 0x373eb
movq %rax, %rcx
cmpl $0x5, %edx
jne 0x373ef
leaq 0x12c6a(%rip), %rsi     # 0x4a03b
jmp 0x373da
leaq 0x12c48(%rip), %rsi     # 0x4a022
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x11b04
jmp 0x37587
movq 0x60(%rax), %rcx
cmpq 0x28b52(%rip), %rcx     # 0x5ff48
je 0x3742c
movl 0x50(%rax), %eax
testl %eax, %eax
js 0x3745a
leaq 0x2d2fa(%rip), %rcx     # 0x64700
movl (%rcx), %ecx
addl %ecx, %eax
decl %eax
cltd
idivl %ecx
movl %eax, %ebp
cmpq 0x28ba0(%rip), %rbx     # 0x5ffb8
jne 0x37421
leaq 0x35117(%rip), %rbx     # 0x6c538
movq %rbx, 0x10(%r14)
cmpl $0x1, %ebp
je 0x37440
jmp 0x37473
cmpq 0x28b85(%rip), %rbx     # 0x5ffb8
jne 0x3743c
leaq 0x350fc(%rip), %rbx     # 0x6c538
movq %rbx, 0x10(%r14)
movl 0x50(%r12), %eax
leaq 0x2d2e0(%rip), %rcx     # 0x6472c
movl $0x1, %ebp
cmpl (%rcx), %eax
jne 0x37473
jmp 0x37587
cmpq 0x28b57(%rip), %rbx     # 0x5ffb8
jne 0x3746a
leaq 0x350ce(%rip), %rbx     # 0x6c538
movq %rbx, 0x10(%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, (%r13)
jne 0x374ff
movq 0x8(%r14), %r15
movq %r13, (%rsp)
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x2f9f5
movq %r15, 0x8(%rax)
movw $0x1, (%rax)
movb 0x50(%r12), %cl
decb %cl
movl $0x1, %edx
shlq %cl, %rdx
movq (%rsp), %rsi
movq 0x20(%rsi), %rsi
movzbl %cl, %ecx
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 0x2d254(%rip), %rcx     # 0x6472c
subb (%rcx), %r13b
movl %r13d, %ecx
shlq %cl, %rsi
shrq %cl, %rsi
movq %rsi, 0x20(%rax)
leaq 0x2d139(%rip), %rcx     # 0x64628
movq (%rcx), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x28(%r14)
jmp 0x37587
movl 0x50(%r12), %eax
leaq 0x2d221(%rip), %rcx     # 0x6472c
cmpl (%rcx), %eax
je 0x37524
leaq 0x2d112(%rip), %rax     # 0x64628
movq (%rax), %rsi
movq %r13, %rdi
callq 0x32aa9
movq %rax, %r13
cmpl $0x2, %ebp
jl 0x37583
movq 0x8(%r14), %r15
xorl %edi, %edi
callq 0x2f9f5
movq %rax, %r12
movq %r15, 0x8(%rax)
movw $0x1, (%rax)
movq 0x8(%r14), %r15
xorl %edi, %edi
callq 0x2f9f5
movq %r15, 0x8(%rax)
movw $0x5, (%rax)
leaq 0x2d0cd(%rip), %rcx     # 0x64628
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 %r13, 0x20(%rax)
movq %r12, 0x28(%rax)
movq %rax, %r13
movq %r13, 0x28(%r14)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq