#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 */
scalar_t__ squared(int);
double index_size_squared(int ndim, int *index) {
  double sum = 0;
  for (int i = 0; i < ndim; i++) {
    sum += squared(index[i]);
  }
  return sum;
}


x86 assembly (clang, -O0):
<index_size_squared>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1167 <index_size_squared+0x57>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <squared@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <index_size_squared+0x1e>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<index_size_squared>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
jle    1168 <index_size_squared+0x58>
mov    %rsi,%r14
mov    %edi,%r15d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
mov    (%r14,%rbx,4),%edi
call   1030 <squared@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <index_size_squared+0x20>
jmp    116b <index_size_squared+0x5b>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @index_size_squared(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %7
7: ; preds = %21, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load i32*, i32** %4
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = call i64 @squared(i32 %16)
%18 = sitofp i64 %17 to double
%19 = load double, double* %5
%20 = fadd double %19, %18
store double %20, double* %5
br label %21
21: ; preds = %11
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %7
24: ; preds = %7
%25 = load double, double* %5
ret double %25
}

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