#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 sqrt(double);
void sphericalnfw_gradient(double *pars, double *r, double *grad) {
  double fac, u, v_h2;
  v_h2 = pars[0] * pars[0] / (log(2.) - 0.5);
  u = sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]) / pars[1];
  fac = v_h2 / (u * u * u) / (pars[1] * pars[1]) * (log(1 + u) - u / (1 + u));
  grad[0] = fac * r[0];
  grad[1] = fac * r[1];
  grad[2] = fac * r[2];
}


x86 assembly (clang, -O0):
<sphericalnfw_gradient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x2,%edi
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
movsd  0xea5(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    -0x8(%rbp),%rax
divsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xdfe(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  0xddb(%rip),%xmm3
addsd  -0x28(%rbp),%xmm3
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sphericalnfw_gradient>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movsd  (%rdi),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%edi
call   1030 <log@plt>
addsd  0xeae(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rbx),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1194 <sphericalnfw_gradient+0x74>
sqrtsd %xmm0,%xmm0
jmp    1199 <sphericalnfw_gradient+0x79>
call   1040 <sqrt@plt>
movsd  0x8(%r15),%xmm2
divsd  %xmm2,%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm3
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe2f(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x10(%rsp)
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
movsd  0x18(%rsp),%xmm1
divsd  0x10(%rsp),%xmm1
subsd  %xmm1,%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  (%rbx),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
movsd  0x8(%rbx),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%r14)
mulsd  0x10(%rbx),%xmm0
movsd  %xmm0,0x10(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @sphericalnfw_gradient(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%10 = load double*, double** %4
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = load double*, double** %4
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = fmul double %12, %15
%17 = call double @log(i32 2)
%18 = fsub double %17, 5.000000e-01
%19 = fdiv double %16, %18
store double %19, double* %9
%20 = load double*, double** %5
%21 = getelementptr inbounds double, double* %20, i64 0
%22 = load double, double* %21
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i64 0
%25 = load double, double* %24
%26 = load double*, double** %5
%27 = getelementptr inbounds double, double* %26, i64 1
%28 = load double, double* %27
%29 = load double*, double** %5
%30 = getelementptr inbounds double, double* %29, i64 1
%31 = load double, double* %30
%32 = fmul double %28, %31
%33 = call double @llvm.fmuladd.f64(double %22, double %25, double %32)
%34 = load double*, double** %5
%35 = getelementptr inbounds double, double* %34, i64 2
%36 = load double, double* %35
%37 = load double*, double** %5
%38 = getelementptr inbounds double, double* %37, i64 2
%39 = load double, double* %38
%40 = call double @llvm.fmuladd.f64(double %36, double %39, double %33)
%41 = call double @sqrt(double %40)
%42 = load double*, double** %4
%43 = getelementptr inbounds double, double* %42, i64 1
%44 = load double, double* %43
%45 = fdiv double %41, %44
store double %45, double* %8
%46 = load double, double* %9
%47 = load double, double* %8
%48 = load double, double* %8
%49 = fmul double %47, %48
%50 = load double, double* %8
%51 = fmul double %49, %50
%52 = fdiv double %46, %51
%53 = load double*, double** %4
%54 = getelementptr inbounds double, double* %53, i64 1
%55 = load double, double* %54
%56 = load double*, double** %4
%57 = getelementptr inbounds double, double* %56, i64 1
%58 = load double, double* %57
%59 = fmul double %55, %58
%60 = fdiv double %52, %59
%61 = load double, double* %8
%62 = fadd double 1.000000e+00, %61
%63 = fptosi double %62 to i32
%64 = call double @log(i32 %63)
%65 = load double, double* %8
%66 = load double, double* %8
%67 = fadd double 1.000000e+00, %66
%68 = fdiv double %65, %67
%69 = fsub double %64, %68
%70 = fmul double %60, %69
store double %70, double* %7
%71 = load double, double* %7
%72 = load double*, double** %5
%73 = getelementptr inbounds double, double* %72, i64 0
%74 = load double, double* %73
%75 = fmul double %71, %74
%76 = load double*, double** %6
%77 = getelementptr inbounds double, double* %76, i64 0
store double %75, double* %77
%78 = load double, double* %7
%79 = load double*, double** %5
%80 = getelementptr inbounds double, double* %79, i64 1
%81 = load double, double* %80
%82 = fmul double %78, %81
%83 = load double*, double** %6
%84 = getelementptr inbounds double, double* %83, i64 1
store double %82, double* %84
%85 = load double, double* %7
%86 = load double*, double** %5
%87 = getelementptr inbounds double, double* %86, i64 2
%88 = load double, double* %87
%89 = fmul double %85, %88
%90 = load double*, double** %6
%91 = getelementptr inbounds double, double* %90, i64 2
store double %89, double* %91
ret void
}

LLVM IR (-O2):
define void @sphericalnfw_gradient(double* nocapture %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = load double, double* %0
%5 = fmul double %4, %4
%6 = tail call double @log(i32 2)
%7 = fadd double %6, -5.000000e-01
%8 = fdiv double %5, %7
%9 = load double, double* %1
%10 = getelementptr inbounds double, double* %1, i64 1
%11 = load double, double* %10
%12 = fmul double %11, %11
%13 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %12)
%14 = getelementptr inbounds double, double* %1, i64 2
%15 = load double, double* %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %13)
%17 = tail call double @sqrt(double %16)
%18 = getelementptr inbounds double, double* %0, i64 1
%19 = load double, double* %18
%20 = fdiv double %17, %19
%21 = fmul double %20, %20
%22 = fmul double %20, %21
%23 = fdiv double %8, %22
%24 = fmul double %19, %19
%25 = fdiv double %23, %24
%26 = fadd double %20, 1.000000e+00
%27 = fptosi double %26 to i32
%28 = tail call double @log(i32 %27)
%29 = fdiv double %20, %26
%30 = fsub double %28, %29
%31 = fmul double %30, %25
%32 = load double, double* %1
%33 = fmul double %32, %31
store double %33, double* %2
%34 = load double, double* %10
%35 = fmul double %34, %31
%36 = getelementptr inbounds double, double* %2, i64 1
store double %35, double* %36
%37 = load double, double* %14
%38 = fmul double %31, %37
%39 = getelementptr inbounds double, double* %2, i64 2
store double %38, double* %39
ret void
}