#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 */
double exp(double);
double *exp_vec_1(double *res, double *vec, int lo1, int hi1) {
  int i;
  double sum = 0;
  for (i = 0; i <= hi1 - lo1; i++) {
    res[i] = exp(vec[i]);
    sum += res[i];
  }
  res[hi1 - lo1 + 1] = sum;
  return res;
}


x86 assembly (clang, -O0):
<exp_vec_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jg     118a <exp_vec_1+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <exp@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <exp_vec_1+0x25>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exp_vec_1>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdi,%r15
sub    %edx,%r14d
js     1178 <exp_vec_1+0x68>
mov    %rsi,%r12
lea    0x1(%r14),%r13d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
movsd  (%r12,%rbx,8),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,(%r15,%rbx,8)
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1140 <exp_vec_1+0x30>
jmp    117b <exp_vec_1+0x6b>
xorps  %xmm0,%xmm0
movslq %r14d,%rax
movsd  %xmm0,0x8(%r15,%rax,8)
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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