#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 const log(double);
double cal_gconst(double *var, const int D) {
  int d;
  double gconst;
  gconst = D * log(6.2831853071795864769252867665590);
  for (d = 0; d < D; d++)
    gconst += log(var[d]);
  return (gconst);
}


x86 assembly (clang, -O0):
<cal_gconst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  0xed3(%rip),%xmm0
call   1030 <log@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1184 <cal_gconst+0x74>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <log@plt>
cvtsi2sd %eax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114a <cal_gconst+0x3a>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cal_gconst>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
movsd  0xedb(%rip),%xmm0
call   1030 <log@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
test   %ebp,%ebp
jle    1177 <cal_gconst+0x67>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
movsd  (%r14,%rbx,8),%xmm0
call   1030 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <cal_gconst+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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