#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int *);
int asum(int array[], const int n) {
  int sum = 0, *ptr;
  int *const aend = array + n;
  for (ptr = array; ptr < aend; ++ptr) {
    sum += *ptr;
    printf("ptr=%p\n", ptr);
  }
  return sum;
}


x86 assembly (clang, -O0):
<asum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    117c <asum+0x6c>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1141 <asum+0x31>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1148 <asum+0x38>
mov    %rdi,%rbx
movslq %esi,%rax
lea    (%rdi,%rax,4),%r15
xor    %ebp,%ebp
lea    0xed2(%rip),%r14
xchg   %ax,%ax
add    (%rbx),%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
add    $0x4,%rbx
cmp    %r15,%rbx
jb     1130 <asum+0x20>
jmp    114a <asum+0x3a>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"ptr=%p\0A\00"
define i32 @asum(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i32*, i32** %3
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %8, i64 %10
store i32* %11, i32** %7
%12 = load i32*, i32** %3
store i32* %12, i32** %6
br label %13
13: ; preds = %24, %2
%14 = load i32*, i32** %6
%15 = load i32*, i32** %7
%16 = icmp ult i32* %14, %15
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i32*, i32** %6
%19 = load i32, i32* %18
%20 = load i32, i32* %5
%21 = add nsw i32 %20, %19
store i32 %21, i32* %5
%22 = load i32*, i32** %6
%23 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %17
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i32 1
store i32* %26, i32** %6
br label %13
27: ; preds = %13
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@.str = [8 x i8] c"ptr=%p\0A\00"
define i32 @asum(i32* %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i32, i32* %0, i64 %3
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %14
6: ; preds = %2, %6
%7 = phi i32 [ %10, %6 ], [ 0, %2 ]
%8 = phi i32* [ %12, %6 ], [ %0, %2 ]
%9 = load i32, i32* %8
%10 = add nsw i32 %9, %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %8)
%12 = getelementptr inbounds i32, i32* %8, i64 1
%13 = icmp ult i32* %12, %4
br i1 %13, label %6, label %14
14: ; preds = %6, %2
%15 = phi i32 [ 0, %2 ], [ %10, %6 ]
ret i32 %15
}