#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(double);
void transformGrid_KK(int n, double *x, double *w) {
  int i;
  double ln2 = log(2.0);
  double x_i, w_i;
  for (i = 0; i < n; i++) {
    x_i = 1.0 - log(1.0 - x[i]) / ln2;
    w_i = w[i] / (ln2 * (1.0 - x[i]));
    x[i] = x_i;
    w[i] = w_i;
  }
}


x86 assembly (clang, -O0):
<transformGrid_KK>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  0xed5(%rip),%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e1 <transformGrid_KK+0xd1>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  0xeb0(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
divsd  -0x28(%rbp),%xmm1
movsd  0xe96(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  0xe6b(%rip),%xmm2
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <transformGrid_KK+0x2c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transformGrid_KK>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1188 <transformGrid_KK+0x78>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  0xec8(%rip),%xmm0
subsd  (%r12,%rbx,8),%xmm0
call   1030 <log@plt>
movsd  0xebd(%rip),%xmm3
divsd  %xmm3,%xmm0
movsd  0xea9(%rip),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movsd  (%r14,%rbx,8),%xmm0
subsd  (%r12,%rbx,8),%xmm2
mulsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm1,(%r12,%rbx,8)
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <transformGrid_KK+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @transformGrid_KK(i32 %0, double* nocapture %1, double* nocapture %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %23
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %21, %7 ]
%9 = getelementptr inbounds double, double* %1, i64 %8
%10 = load double, double* %9
%11 = fsub double 1.000000e+00, %10
%12 = tail call double @log(double %11)
%13 = fdiv double %12, 0x3FE62E42FEFA39EF
%14 = fsub double 1.000000e+00, %13
%15 = getelementptr inbounds double, double* %2, i64 %8
%16 = load double, double* %15
%17 = load double, double* %9
%18 = fsub double 1.000000e+00, %17
%19 = fmul double %18, 0x3FE62E42FEFA39EF
%20 = fdiv double %16, %19
store double %14, double* %9
store double %20, double* %15
%21 = add nuw nsw i64 %8, 1
%22 = icmp eq i64 %21, %6
br i1 %22, label %23, label %7
23: ; preds = %7, %3
ret void
}