void Thomas_Fermi(Z, Vtmp) double Z;
double Vtmp[];
{
  int i, Ngrid;
  double *rgrid, x, t;
  Ngrid = N_LogGrid();
  rgrid = r_LogGrid();
  for (i = 0; i < Ngrid; ++i) {
    x = rgrid[i] * pow((Z / 0.69395656), (1.0 / 3.0));
    t = Z / (1.0 + sqrt(x) * (0.02747 - x * (0.1486 - 0.007298 * x)) +
             x * (1.243 + x * (0.2302 + 0.006944 * x)));
    if (t < 1.0)
      t = 1.0;
    Vtmp[i] = -t / rgrid[i];
  }
}


x86 assembly (clang, -O0):
<Thomas_Fermi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <N_LogGrid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <r_LogGrid@plt>
cltq
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12dd <Thomas_Fermi+0x19d>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xea6(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe92(%rip),%xmm1
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm3
movsd  0xe3e(%rip),%xmm4
mulsd  %xmm4,%xmm3
movsd  0xe3a(%rip),%xmm4
addsd  %xmm4,%xmm3
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm3,%xmm1
movsd  0xe03(%rip),%xmm3
addsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm2
movsd  0xdd3(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm4
movsd  0xdc8(%rip),%xmm5
mulsd  %xmm5,%xmm4
movsd  0xdc4(%rip),%xmm5
addsd  %xmm5,%xmm4
mulsd  %xmm4,%xmm3
movsd  0xda4(%rip),%xmm4
addsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd7f(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1299 <Thomas_Fermi+0x159>
movsd  0xd6c(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <Thomas_Fermi+0x2f>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Thomas_Fermi>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <N_LogGrid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <r_LogGrid@plt>
test   %r14d,%r14d
jle    126f <Thomas_Fermi+0x12f>
movslq %eax,%rbp
movsd  0x8(%rsp),%xmm0
divsd  0xe82(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r14d,%r14d
xor    %ebx,%ebx
jmp    122e <Thomas_Fermi+0xee>
xchg   %ax,%ax
movapd %xmm4,%xmm0
movsd  %xmm4,(%rsp)
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm4
movapd %xmm4,%xmm1
mulsd  0xe61(%rip),%xmm1
addsd  0xe61(%rip),%xmm1
mulsd  %xmm4,%xmm1
movsd  0xe5d(%rip),%xmm2
subsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
movsd  0xe55(%rip),%xmm3
addsd  %xmm3,%xmm2
movapd %xmm4,%xmm0
mulsd  0xe4d(%rip),%xmm0
addsd  0xe4d(%rip),%xmm0
mulsd  %xmm4,%xmm0
addsd  0xe49(%rip),%xmm0
mulsd  %xmm4,%xmm0
addsd  %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
maxsd  %xmm1,%xmm0
xorpd  0xe37(%rip),%xmm0
divsd  0x0(%rbp,%rbx,8),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
je     126f <Thomas_Fermi+0x12f>
movsd  0x0(%rbp,%rbx,8),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0xdc1(%rip),%xmm1
call   1040 <pow@plt>
movapd %xmm0,%xmm4
mulsd  (%rsp),%xmm4
ucomisd 0xdeb(%rip),%xmm4
jb     1190 <Thomas_Fermi+0x50>
xorps  %xmm0,%xmm0
sqrtsd %xmm4,%xmm0
jmp    11a3 <Thomas_Fermi+0x63>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @Thomas_Fermi(double %0, double* %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double
%9 = alloca double
store double %0, double* %3
store double* %1, double** %4
%10 = call i32 (...) @N_LogGrid()
store i32 %10, i32* %6
%11 = call i32 (...) @r_LogGrid()
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to double*
store double* %13, double** %7
store i32 0, i32* %5
br label %14
14: ; preds = %60, %2
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %63
18: ; preds = %14
%19 = load double*, double** %7
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = load double, double* %3
%25 = fdiv double %24, 0x3FE634E463416DDE
%26 = call double @pow(double %25, double 0x3FD5555555555555)
%27 = fmul double %23, %26
store double %27, double* %8
%28 = load double, double* %3
%29 = load double, double* %8
%30 = call double @sqrt(double %29)
%31 = load double, double* %8
%32 = load double, double* %8
%33 = call double @llvm.fmuladd.f64(double 0xBF7DE481F53825E1, double %32, double 1.486000e-01)
%34 = fneg double %31
%35 = call double @llvm.fmuladd.f64(double %34, double %33, double 2.747000e-02)
%36 = call double @llvm.fmuladd.f64(double %30, double %35, double 1.000000e+00)
%37 = load double, double* %8
%38 = load double, double* %8
%39 = load double, double* %8
%40 = call double @llvm.fmuladd.f64(double 0x3F7C714FCE746CB9, double %39, double 2.302000e-01)
%41 = call double @llvm.fmuladd.f64(double %38, double %40, double 1.243000e+00)
%42 = call double @llvm.fmuladd.f64(double %37, double %41, double %36)
%43 = fdiv double %28, %42
store double %43, double* %9
%44 = load double, double* %9
%45 = fcmp olt double %44, 1.000000e+00
br i1 %45, label %46, label %47
46: ; preds = %18
store double 1.000000e+00, double* %9
br label %47
47: ; preds = %46, %18
%48 = load double, double* %9
%49 = fneg double %48
%50 = load double*, double** %7
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = fdiv double %49, %54
%56 = load double*, double** %4
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
store double %55, double* %59
br label %60
60: ; preds = %47
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %14
63: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @Thomas_Fermi(double %0, double* nocapture writeonly %1) {
%3 = tail call i32 (...) @N_LogGrid()
%4 = tail call i32 (...) @r_LogGrid()
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to double*
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %34
8: ; preds = %2
%9 = fdiv double %0, 0x3FE634E463416DDE
%10 = zext i32 %3 to i64
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ 0, %8 ], [ %32, %11 ]
%13 = getelementptr inbounds double, double* %6, i64 %12
%14 = load double, double* %13
%15 = tail call double @pow(double %9, double 0x3FD5555555555555)
%16 = fmul double %14, %15
%17 = tail call double @sqrt(double %16)
%18 = tail call double @llvm.fmuladd.f64(double %16, double 0xBF7DE481F53825E1, double 1.486000e-01)
%19 = fneg double %16
%20 = tail call double @llvm.fmuladd.f64(double %19, double %18, double 2.747000e-02)
%21 = tail call double @llvm.fmuladd.f64(double %17, double %20, double 1.000000e+00)
%22 = tail call double @llvm.fmuladd.f64(double %16, double 0x3F7C714FCE746CB9, double 2.302000e-01)
%23 = tail call double @llvm.fmuladd.f64(double %16, double %22, double 1.243000e+00)
%24 = tail call double @llvm.fmuladd.f64(double %16, double %23, double %21)
%25 = fdiv double %0, %24
%26 = fcmp olt double %25, 1.000000e+00
%27 = select i1 %26, double 1.000000e+00, double %25
%28 = fneg double %27
%29 = load double, double* %13
%30 = fdiv double %28, %29
%31 = getelementptr inbounds double, double* %1, i64 %12
store double %30, double* %31
%32 = add nuw nsw i64 %12, 1
%33 = icmp eq i64 %32, %10
br i1 %33, label %34, label %11
34: ; preds = %11, %2
ret void
}