#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 foo(int *);
int myaddint_ref(int *a, int *b, int n) {
  for (int i = 0; i < n; i++) {
    a[i] = foo(&b[i]);
  }
  return a[n - 1];
}


x86 assembly (clang, -O0):
<myaddint_ref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1165 <myaddint_ref+0x55>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <foo@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <myaddint_ref+0x1a>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myaddint_ref>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rdi,%r12
test   %edx,%edx
jle    1146 <myaddint_ref+0x36>
mov    %rsi,%r15
mov    %r14d,%ebp
shl    $0x2,%rbp
xor    %ebx,%ebx
xchg   %ax,%ax
lea    (%r15,%rbx,1),%rdi
call   1030 <foo@plt>
mov    %eax,(%r12,%rbx,1)
add    $0x4,%rbx
cmp    %rbx,%rbp
jne    1130 <myaddint_ref+0x20>
movslq %r14d,%rax
mov    -0x4(%r12,%rax,4),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @myaddint_ref(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %22, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i32*, i32** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = call i32 @foo(i32* %16)
%18 = load i32*, i32** %4
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
store i32 %17, i32* %21
br label %22
22: ; preds = %12
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %8
25: ; preds = %8
%26 = load i32*, i32** %4
%27 = load i32, i32* %6
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %26, i64 %29
%31 = load i32, i32* %30
ret i32 %31
}

LLVM IR (-O2):
define i32 @myaddint_ref(i32* nocapture %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %12
7: ; preds = %12, %3
%8 = add nsw i32 %2, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
ret i32 %11
12: ; preds = %5, %12
%13 = phi i64 [ 0, %5 ], [ %17, %12 ]
%14 = getelementptr inbounds i32, i32* %1, i64 %13
%15 = tail call i32 @foo(i32* %14)
%16 = getelementptr inbounds i32, i32* %0, i64 %13
store i32 %15, i32* %16
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %6
br i1 %18, label %7, label %12
}