#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 ddot1(int, double *, double *);
void diagonalScaling(int n, double e[], double v[], double gv[], double r[]) {
  int i;
  double vr, vgv;
  vr = 1.0 / ddot1(n, v, r);
  vgv = 1.0 / ddot1(n, v, gv);
  for (i = 0; i < n; i++) {
    e[i] += -r[i] * r[i] * vr + gv[i] * gv[i] * vgv;
    if (e[i] <= 1e-6)
      e[i] = 1.0;
  }
}


x86 assembly (clang, -O0):
<diagonalScaling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <ddot1@plt>
movaps %xmm0,%xmm1
movsd  0xeba(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <ddot1@plt>
movaps %xmm0,%xmm1
movsd  0xe96(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1238 <diagonalScaling+0x128>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  -0x38(%rbp),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xe03(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jb     1225 <diagonalScaling+0x115>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xde0(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    122a <diagonalScaling+0x11a>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117a <diagonalScaling+0x6a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diagonalScaling>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rdx,%rsi
mov    %r8,%rdx
call   1030 <ddot1@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <ddot1@plt>
test   %ebp,%ebp
jle    1298 <diagonalScaling+0x188>
movsd  0xea8(%rip),%xmm1
movapd %xmm1,%xmm2
divsd  0x8(%rsp),%xmm2
divsd  %xmm0,%xmm1
mov    %ebp,%eax
cmp    $0x1,%ebp
jne    1174 <diagonalScaling+0x64>
xor    %ecx,%ecx
jmp    1231 <diagonalScaling+0x121>
lea    (%rbx,%rax,8),%rcx
lea    (%r14,%rax,8),%rdx
cmp    %rbx,%rdx
seta   %dil
lea    (%r15,%rax,8),%rdx
cmp    %r14,%rcx
seta   %r8b
cmp    %rbx,%rdx
seta   %dl
cmp    %r15,%rcx
seta   %sil
xor    %ecx,%ecx
test   %r8b,%dil
jne    1231 <diagonalScaling+0x121>
and    %sil,%dl
jne    1231 <diagonalScaling+0x121>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd %xmm1,%xmm0
unpcklpd %xmm1,%xmm0
movapd %xmm2,%xmm3
unpcklpd %xmm2,%xmm3
xor    %edx,%edx
movapd 0xe42(%rip),%xmm4
movapd 0xe4a(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
movupd (%r14,%rdx,8),%xmm6
mulpd  %xmm6,%xmm6
mulpd  %xmm3,%xmm6
movupd (%r15,%rdx,8),%xmm7
mulpd  %xmm7,%xmm7
mulpd  %xmm0,%xmm7
subpd  %xmm6,%xmm7
movupd (%rbx,%rdx,8),%xmm6
addpd  %xmm7,%xmm6
movapd %xmm6,%xmm7
cmpnlepd %xmm4,%xmm7
andpd  %xmm7,%xmm6
andnpd %xmm5,%xmm7
orpd   %xmm6,%xmm7
movupd %xmm7,(%rbx,%rdx,8)
add    $0x2,%rdx
cmp    %rdx,%rcx
jne    11e0 <diagonalScaling+0xd0>
cmp    %rax,%rcx
je     1298 <diagonalScaling+0x188>
movsd  0xdcf(%rip),%xmm0
movsd  0xdbf(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%r14,%rcx,8),%xmm4
mulsd  %xmm4,%xmm4
movsd  (%r15,%rcx,8),%xmm5
mulsd  %xmm5,%xmm5
mulsd  %xmm1,%xmm5
mulsd  %xmm2,%xmm4
subsd  %xmm4,%xmm5
addsd  (%rbx,%rcx,8),%xmm5
movapd %xmm5,%xmm4
cmpnlesd %xmm0,%xmm4
andpd  %xmm4,%xmm5
andnpd %xmm3,%xmm4
orpd   %xmm5,%xmm4
movlpd %xmm4,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1250 <diagonalScaling+0x140>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @diagonalScaling(i32 %0, double* %1, double* %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
%14 = load i32, i32* %6
%15 = load double*, double** %8
%16 = load double*, double** %10
%17 = call double @ddot1(i32 %14, double* %15, double* %16)
%18 = fdiv double 1.000000e+00, %17
store double %18, double* %12
%19 = load i32, i32* %6
%20 = load double*, double** %8
%21 = load double*, double** %9
%22 = call double @ddot1(i32 %19, double* %20, double* %21)
%23 = fdiv double 1.000000e+00, %22
store double %23, double* %13
store i32 0, i32* %11
br label %24
24: ; preds = %74, %5
%25 = load i32, i32* %11
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %77
28: ; preds = %24
%29 = load double*, double** %10
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = fneg double %33
%35 = load double*, double** %10
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = fmul double %34, %39
%41 = load double, double* %12
%42 = load double*, double** %9
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = load double*, double** %9
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = fmul double %46, %51
%53 = load double, double* %13
%54 = fmul double %52, %53
%55 = call double @llvm.fmuladd.f64(double %40, double %41, double %54)
%56 = load double*, double** %7
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = fadd double %60, %55
store double %61, double* %59
%62 = load double*, double** %7
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
%66 = load double, double* %65
%67 = fcmp ole double %66, 0x3EB0C6F7A0B5ED8D
br i1 %67, label %68, label %73
68: ; preds = %28
%69 = load double*, double** %7
%70 = load i32, i32* %11
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
store double 1.000000e+00, double* %72
br label %73
73: ; preds = %68, %28
br label %74
74: ; preds = %73
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
br label %24
77: ; preds = %24
ret void
}

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