#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 log(int);
double dt_log(double *x, int n, double df, double location, double scale) {
  int i;
  double logDensity = 0, z, logScale;
  logScale = log(scale);
  for (i = 0; i < n; i++) {
    z = (x[i] - location) / scale;
    logDensity += -(df + 1) / 2 * log(1 + z * z / df) - logScale;
  }
  return logDensity;
}


x86 assembly (clang, -O0):
<dt_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x28(%rbp),%edi
call   1030 <log@plt>
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1211 <dt_log+0x101>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe84(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe68(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xe40(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114c <dt_log+0x3c>
movsd  -0x38(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dt_log>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
movsd  %xmm1,0x30(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %esi,%ebp
mov    %rdi,%r14
movsd  %xmm2,0x38(%rsp)
cvttsd2si %xmm2,%edi
call   1030 <log@plt>
movaps %xmm0,0x10(%rsp)
test   %ebp,%ebp
jle    11dc <dt_log+0xcc>
movsd  0xeb3(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
mulsd  0xead(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
movaps 0x10(%rsp),%xmm0
xorps  0xea3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %ebp,%ebp
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   0x0(%rax)
movsd  %xmm0,(%rsp)
movsd  (%r14,%rbx,8),%xmm0
subsd  0x30(%rsp),%xmm0
divsd  0x38(%rsp),%xmm0
mulsd  %xmm0,%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0xe57(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
mulsd  0x28(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <dt_log+0x70>
jmp    11df <dt_log+0xcf>
xorps  %xmm0,%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @dt_log(double* %0, i32 %1, double %2, double %3, double %4) {
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double* %0, double** %6
store i32 %1, i32* %7
store double %2, double* %8
store double %3, double* %9
store double %4, double* %10
store double 0.000000e+00, double* %12
%15 = load double, double* %10
%16 = fptosi double %15 to i32
%17 = call double @log(i32 %16)
store double %17, double* %14
store i32 0, i32* %11
br label %18
18: ; preds = %49, %5
%19 = load i32, i32* %11
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %52
22: ; preds = %18
%23 = load double*, double** %6
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double, double* %9
%29 = fsub double %27, %28
%30 = load double, double* %10
%31 = fdiv double %29, %30
store double %31, double* %13
%32 = load double, double* %8
%33 = fadd double %32, 1.000000e+00
%34 = fneg double %33
%35 = fdiv double %34, 2.000000e+00
%36 = load double, double* %13
%37 = load double, double* %13
%38 = fmul double %36, %37
%39 = load double, double* %8
%40 = fdiv double %38, %39
%41 = fadd double 1.000000e+00, %40
%42 = fptosi double %41 to i32
%43 = call double @log(i32 %42)
%44 = load double, double* %14
%45 = fneg double %44
%46 = call double @llvm.fmuladd.f64(double %35, double %43, double %45)
%47 = load double, double* %12
%48 = fadd double %47, %46
store double %48, double* %12
br label %49
49: ; preds = %22
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %18
52: ; preds = %18
%53 = load double, double* %12
ret double %53
}

LLVM IR (-O2):
define double @dt_log(double* nocapture %0, i32 %1, double %2, double %3, double %4) {
%6 = fptosi double %4 to i32
%7 = tail call double @log(i32 %6)
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %30
9: ; preds = %5
%10 = fadd double %2, 1.000000e+00
%11 = fmul double %10, -5.000000e-01
%12 = fneg double %7
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %9, %14
%15 = phi i64 [ 0, %9 ], [ %28, %14 ]
%16 = phi double [ 0.000000e+00, %9 ], [ %27, %14 ]
%17 = getelementptr inbounds double, double* %0, i64 %15
%18 = load double, double* %17
%19 = fsub double %18, %3
%20 = fdiv double %19, %4
%21 = fmul double %20, %20
%22 = fdiv double %21, %2
%23 = fadd double %22, 1.000000e+00
%24 = fptosi double %23 to i32
%25 = tail call double @log(i32 %24)
%26 = tail call double @llvm.fmuladd.f64(double %11, double %25, double %12)
%27 = fadd double %16, %26
%28 = add nuw nsw i64 %15, 1
%29 = icmp eq i64 %28, %13
br i1 %29, label %30, label %14
30: ; preds = %14, %5
%31 = phi double [ 0.000000e+00, %5 ], [ %27, %14 ]
ret double %31
}