#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*/ putd(double);
double stub1(double);
double sum_transform_array(double *values, int length, double (*fn)(double)) {
  double sum = 0;
  int i = 0;
  double x;
  for (i = 0; i != length; ++i) {
    x = values[i];
    putd(x);
    sum += (*fn)(values[i]);
  }
  return sum;
}


x86 assembly (clang, -O0):
<sum_transform_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     118c <sum_transform_array+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <putd@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
call   *%rax
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1139 <sum_transform_array+0x29>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_transform_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1167 <sum_transform_array+0x57>
mov    %rdx,%r14
mov    %rdi,%r12
mov    %esi,%r15d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%r12,%rbx,8),%xmm0
call   1030 <putd@plt>
movsd  (%r12,%rbx,8),%xmm0
call   *%r14
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <sum_transform_array+0x20>
jmp    116a <sum_transform_array+0x5a>
xorps  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @sum_transform_array(double* %0, i32 %1, double (double)* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double (double)*
%7 = alloca double
%8 = alloca i32
%9 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double (double)* %2, double (double)** %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
store i32 0, i32* %8
br label %10
10: ; preds = %31, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %5
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %10
%15 = load double*, double** %4
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
store double %19, double* %9
%20 = load double, double* %9
%21 = call i32 @putd(double %20)
%22 = load double (double)*, double (double)** %6
%23 = load double*, double** %4
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = call double %22(double %27)
%29 = load double, double* %7
%30 = fadd double %29, %28
store double %30, double* %7
br label %31
31: ; preds = %14
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %10
34: ; preds = %10
%35 = load double, double* %7
ret double %35
}

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