void grad_log_det_inverse_transform_simplex(const double *z, double *dz,
                                            int K) {
  for (int k = 0; k < K - 1; k++) {
    dz[k] = 1.0 / z[k] + 1.0 / (z[k] - 1.0);
  }
}


x86 assembly (clang, -O0):
<grad_log_det_inverse_transform_simplex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1180 <grad_log_det_inverse_transform_simplex+0x80>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  0xec9(%rip),%xmm0
divsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  0xeaf(%rip),%xmm1
subsd  %xmm1,%xmm2
movsd  0xea3(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1116 <grad_log_det_inverse_transform_simplex+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<grad_log_det_inverse_transform_simplex>:
cmp    $0x2,%edx
jl     116b <grad_log_det_inverse_transform_simplex+0x6b>
add    $0xffffffff,%edx
cmp    $0x2,%edx
jb     111f <grad_log_det_inverse_transform_simplex+0x1f>
lea    (%rdi,%rdx,8),%rax
cmp    %rsi,%rax
jbe    116c <grad_log_det_inverse_transform_simplex+0x6c>
lea    (%rsi,%rdx,8),%rax
cmp    %rdi,%rax
jbe    116c <grad_log_det_inverse_transform_simplex+0x6c>
xor    %eax,%eax
movsd  0xef7(%rip),%xmm0
movsd  0xef7(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rax,8),%xmm2
movapd %xmm0,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm1,%xmm2
movapd %xmm0,%xmm4
divsd  %xmm2,%xmm4
addsd  %xmm3,%xmm4
movsd  %xmm4,(%rsi,%rax,8)
add    $0x1,%rax
cmp    %rax,%rdx
jne    1140 <grad_log_det_inverse_transform_simplex+0x40>
ret
mov    %edx,%eax
and    $0xfffffffe,%eax
lea    -0x2(%rax),%rcx
mov    %rcx,%r8
shr    %r8
add    $0x1,%r8
test   %rcx,%rcx
je     123e <grad_log_det_inverse_transform_simplex+0x13e>
mov    %r8,%r9
and    $0xfffffffffffffffe,%r9
xor    %ecx,%ecx
movapd 0xe67(%rip),%xmm0
movapd 0xe6f(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movupd (%rdi,%rcx,8),%xmm2
movapd %xmm0,%xmm3
divpd  %xmm2,%xmm3
addpd  %xmm1,%xmm2
movapd %xmm0,%xmm4
divpd  %xmm2,%xmm4
addpd  %xmm3,%xmm4
movupd %xmm4,(%rsi,%rcx,8)
movupd 0x10(%rdi,%rcx,8),%xmm2
movapd %xmm0,%xmm3
divpd  %xmm2,%xmm3
addpd  %xmm1,%xmm2
movapd %xmm0,%xmm4
divpd  %xmm2,%xmm4
addpd  %xmm3,%xmm4
movupd %xmm4,0x10(%rsi,%rcx,8)
add    $0x4,%rcx
add    $0xfffffffffffffffe,%r9
jne    11b0 <grad_log_det_inverse_transform_simplex+0xb0>
test   $0x1,%r8b
je     1230 <grad_log_det_inverse_transform_simplex+0x130>
movupd (%rdi,%rcx,8),%xmm0
movapd 0xded(%rip),%xmm1
movapd %xmm1,%xmm2
divpd  %xmm0,%xmm2
addpd  0xded(%rip),%xmm0
divpd  %xmm0,%xmm1
addpd  %xmm2,%xmm1
movupd %xmm1,(%rsi,%rcx,8)
cmp    %rdx,%rax
je     116b <grad_log_det_inverse_transform_simplex+0x6b>
jmp    1121 <grad_log_det_inverse_transform_simplex+0x21>
xor    %ecx,%ecx
test   $0x1,%r8b
jne    1206 <grad_log_det_inverse_transform_simplex+0x106>
jmp    1230 <grad_log_det_inverse_transform_simplex+0x130>

LLVM IR (-O0):
define void @grad_log_det_inverse_transform_simplex(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %32, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = sub nsw i32 %10, 1
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %35
13: ; preds = %8
%14 = load double*, double** %4
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = fdiv double 1.000000e+00, %18
%20 = load double*, double** %4
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = fsub double %24, 1.000000e+00
%26 = fdiv double 1.000000e+00, %25
%27 = fadd double %19, %26
%28 = load double*, double** %5
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
store double %27, double* %31
br label %32
32: ; preds = %13
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %8
35: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @grad_log_det_inverse_transform_simplex(double* nocapture %0, double* nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 1
br i1 %4, label %5, label %66
5: ; preds = %3
%6 = add nsw i32 %2, -1
%7 = zext i32 %6 to i64
%8 = icmp ult i32 %6, 2
br i1 %8, label %64, label %9
9: ; preds = %5
%10 = getelementptr double, double* %1, i64 %7
%11 = getelementptr double, double* %0, i64 %7
%12 = icmp ugt double* %11, %1
%13 = icmp ugt double* %10, %0
%14 = and i1 %12, %13
br i1 %14, label %64, label %15
15: ; preds = %9
%16 = and i64 %7, 4294967294
%17 = add nsw i64 %16, -2
%18 = lshr exact i64 %17, 1
%19 = add nuw i64 %18, 1
%20 = and i64 %19, 1
%21 = icmp eq i64 %17, 0
br i1 %21, label %49, label %22
22: ; preds = %15
%23 = and i64 %19, -2
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 0, %22 ], [ %46, %24 ]
%26 = phi i64 [ 0, %22 ], [ %47, %24 ]
%27 = getelementptr inbounds double, double* %0, i64 %25
%28 = bitcast double* %27 to <2 x double>*
%29 = load <2 x double>, <2 x double>* %28
%30 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %29
%31 = fadd <2 x double> %29, <double -1.000000e+00, double -1.000000e+00>
%32 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %31
%33 = fadd <2 x double> %30, %32
%34 = getelementptr inbounds double, double* %1, i64 %25
%35 = bitcast double* %34 to <2 x double>*
store <2 x double> %33, <2 x double>* %35
%36 = or i64 %25, 2
%37 = getelementptr inbounds double, double* %0, i64 %36
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %39
%41 = fadd <2 x double> %39, <double -1.000000e+00, double -1.000000e+00>
%42 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %41
%43 = fadd <2 x double> %40, %42
%44 = getelementptr inbounds double, double* %1, i64 %36
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> %43, <2 x double>* %45
%46 = add nuw i64 %25, 4
%47 = add nuw i64 %26, 2
%48 = icmp eq i64 %47, %23
br i1 %48, label %49, label %24
49: ; preds = %24, %15
%50 = phi i64 [ 0, %15 ], [ %46, %24 ]
%51 = icmp eq i64 %20, 0
br i1 %51, label %62, label %52
52: ; preds = %49
%53 = getelementptr inbounds double, double* %0, i64 %50
%54 = bitcast double* %53 to <2 x double>*
%55 = load <2 x double>, <2 x double>* %54
%56 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %55
%57 = fadd <2 x double> %55, <double -1.000000e+00, double -1.000000e+00>
%58 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %57
%59 = fadd <2 x double> %56, %58
%60 = getelementptr inbounds double, double* %1, i64 %50
%61 = bitcast double* %60 to <2 x double>*
store <2 x double> %59, <2 x double>* %61
br label %62
62: ; preds = %49, %52
%63 = icmp eq i64 %16, %7
br i1 %63, label %66, label %64
64: ; preds = %9, %5, %62
%65 = phi i64 [ 0, %9 ], [ 0, %5 ], [ %16, %62 ]
br label %67
66: ; preds = %67, %62, %3
ret void
67: ; preds = %64, %67
%68 = phi i64 [ %76, %67 ], [ %65, %64 ]
%69 = getelementptr inbounds double, double* %0, i64 %68
%70 = load double, double* %69
%71 = fdiv double 1.000000e+00, %70
%72 = fadd double %70, -1.000000e+00
%73 = fdiv double 1.000000e+00, %72
%74 = fadd double %71, %73
%75 = getelementptr inbounds double, double* %1, i64 %68
store double %74, double* %75
%76 = add nuw nsw i64 %68, 1
%77 = icmp eq i64 %76, %7
br i1 %77, label %66, label %67
}