#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 calc_gamma2(double, double);
double sqrt(double);
void lock_accelerate(const double *a, const double *b, double *c,
                     const char *lock, int n) {
  int i;
  double r_norm2 = 0;
  double v_norm2 = 0;
  for (i = 0; i < n; i++)
    if (!lock[i]) {
      double r = b[i] - a[i];
      double v = c[i] - b[i] - r;
      r_norm2 += r * r;
      v_norm2 += v * v;
    }
  double gamma2 = calc_gamma2(r_norm2, v_norm2);
  double gamma = -sqrt(gamma2);
  int zeroing = 0;
  for (i = 0; i < n; i++)
    if (!lock[i]) {
      double r = b[i] - a[i];
      double v = c[i] - b[i] - r;
      double new_val = a[i] - 2 * gamma * r + gamma2 * v;
      if (new_val <= 1e-300) {
        zeroing += (c[i] > 1e-300);
        new_val = c[i] / 10;
      }
      c[i] = new_val;
    }
}


x86 assembly (clang, -O0):
<lock_accelerate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1202 <lock_accelerate+0xe2>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11ef <lock_accelerate+0xcf>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11f4 <lock_accelerate+0xd4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1156 <lock_accelerate+0x36>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1040 <calc_gamma2@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1030 <sqrt@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    137d <lock_accelerate+0x25d>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    136a <lock_accelerate+0x24a>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
subsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xd48(%rip),%xmm1
mulsd  -0x58(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xcf8(%rip),%xmm0
ucomisd -0x78(%rbp),%xmm0
jb     1358 <lock_accelerate+0x238>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xcd8(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
add    -0x5c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xcc1(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    136f <lock_accelerate+0x24f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    124a <lock_accelerate+0x12a>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lock_accelerate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %r8d,%ebp
xorpd  %xmm1,%xmm1
test   %r8d,%r8d
jle    1187 <lock_accelerate+0x67>
xor    %eax,%eax
jmp    1159 <lock_accelerate+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    %rax,%rbp
je     1187 <lock_accelerate+0x67>
cmpb   $0x0,(%rbx,%rax,1)
jne    1150 <lock_accelerate+0x30>
movsd  (%r15,%rax,8),%xmm0
movsd  (%r14,%rax,8),%xmm2
subsd  %xmm0,%xmm2
subsd  (%r12,%rax,8),%xmm0
subsd  %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
mulpd  %xmm2,%xmm2
addpd  %xmm2,%xmm1
jmp    1150 <lock_accelerate+0x30>
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
call   1040 <calc_gamma2@plt>
movapd %xmm0,%xmm7
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm7
jb     11b3 <lock_accelerate+0x93>
xorps  %xmm0,%xmm0
sqrtsd %xmm7,%xmm0
test   %r13d,%r13d
jg     11cb <lock_accelerate+0xab>
jmp    1247 <lock_accelerate+0x127>
movapd %xmm7,%xmm0
movsd  %xmm7,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm7
test   %r13d,%r13d
jle    1247 <lock_accelerate+0x127>
addsd  %xmm0,%xmm0
xor    %eax,%eax
movsd  0xe27(%rip),%xmm1
movsd  0xe27(%rip),%xmm2
jmp    11ff <lock_accelerate+0xdf>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm4,(%r14,%rax,8)
add    $0x1,%rax
cmp    %rax,%rbp
je     1247 <lock_accelerate+0x127>
cmpb   $0x0,(%rbx,%rax,1)
jne    11f6 <lock_accelerate+0xd6>
movsd  (%r15,%rax,8),%xmm5
movsd  (%r12,%rax,8),%xmm6
movsd  (%r14,%rax,8),%xmm3
movapd %xmm3,%xmm4
subsd  %xmm5,%xmm4
subsd  %xmm6,%xmm5
subsd  %xmm5,%xmm4
mulsd  %xmm0,%xmm5
addsd  %xmm6,%xmm5
mulsd  %xmm7,%xmm4
addsd  %xmm5,%xmm4
ucomisd %xmm4,%xmm1
jb     11f0 <lock_accelerate+0xd0>
divsd  %xmm2,%xmm3
movapd %xmm3,%xmm4
jmp    11f0 <lock_accelerate+0xd0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @lock_accelerate(double* %0, double* %1, double* %2, i8* %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca double
%20 = alloca double
%21 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store i32 0, i32* %11
br label %22
22: ; preds = %67, %5
%23 = load i32, i32* %11
%24 = load i32, i32* %10
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %70
26: ; preds = %22
%27 = load i8*, i8** %9
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %66, label %33
33: ; preds = %26
%34 = load double*, double** %7
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
%39 = load double*, double** %6
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = fsub double %38, %43
store double %44, double* %14
%45 = load double*, double** %8
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = load double*, double** %7
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = fsub double %49, %54
%56 = load double, double* %14
%57 = fsub double %55, %56
store double %57, double* %15
%58 = load double, double* %14
%59 = load double, double* %14
%60 = load double, double* %12
%61 = call double @llvm.fmuladd.f64(double %58, double %59, double %60)
store double %61, double* %12
%62 = load double, double* %15
%63 = load double, double* %15
%64 = load double, double* %13
%65 = call double @llvm.fmuladd.f64(double %62, double %63, double %64)
store double %65, double* %13
br label %66
66: ; preds = %33, %26
br label %67
67: ; preds = %66
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
br label %22
70: ; preds = %22
%71 = load double, double* %12
%72 = load double, double* %13
%73 = call double @calc_gamma2(double %71, double %72)
store double %73, double* %16
%74 = load double, double* %16
%75 = call double @sqrt(double %74)
%76 = fneg double %75
store double %76, double* %17
store i32 0, i32* %18
store i32 0, i32* %11
br label %77
77: ; preds = %151, %70
%78 = load i32, i32* %11
%79 = load i32, i32* %10
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %154
81: ; preds = %77
%82 = load i8*, i8** %9
%83 = load i32, i32* %11
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i8, i8* %85
%87 = icmp ne i8 %86, 0
br i1 %87, label %150, label %88
88: ; preds = %81
%89 = load double*, double** %7
%90 = load i32, i32* %11
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds double, double* %89, i64 %91
%93 = load double, double* %92
%94 = load double*, double** %6
%95 = load i32, i32* %11
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds double, double* %94, i64 %96
%98 = load double, double* %97
%99 = fsub double %93, %98
store double %99, double* %19
%100 = load double*, double** %8
%101 = load i32, i32* %11
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %100, i64 %102
%104 = load double, double* %103
%105 = load double*, double** %7
%106 = load i32, i32* %11
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double, double* %105, i64 %107
%109 = load double, double* %108
%110 = fsub double %104, %109
%111 = load double, double* %19
%112 = fsub double %110, %111
store double %112, double* %20
%113 = load double*, double** %6
%114 = load i32, i32* %11
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds double, double* %113, i64 %115
%117 = load double, double* %116
%118 = load double, double* %17
%119 = fmul double 2.000000e+00, %118
%120 = load double, double* %19
%121 = fneg double %119
%122 = call double @llvm.fmuladd.f64(double %121, double %120, double %117)
%123 = load double, double* %16
%124 = load double, double* %20
%125 = call double @llvm.fmuladd.f64(double %123, double %124, double %122)
store double %125, double* %21
%126 = load double, double* %21
%127 = fcmp ole double %126, 1.000000e-300
br i1 %127, label %128, label %144
128: ; preds = %88
%129 = load double*, double** %8
%130 = load i32, i32* %11
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds double, double* %129, i64 %131
%133 = load double, double* %132
%134 = fcmp ogt double %133, 1.000000e-300
%135 = zext i1 %134 to i32
%136 = load i32, i32* %18
%137 = add nsw i32 %136, %135
store i32 %137, i32* %18
%138 = load double*, double** %8
%139 = load i32, i32* %11
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds double, double* %138, i64 %140
%142 = load double, double* %141
%143 = fdiv double %142, 1.000000e+01
store double %143, double* %21
br label %144
144: ; preds = %128, %88
%145 = load double, double* %21
%146 = load double*, double** %8
%147 = load i32, i32* %11
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds double, double* %146, i64 %148
store double %145, double* %149
br label %150
150: ; preds = %144, %81
br label %151
151: ; preds = %150
%152 = load i32, i32* %11
%153 = add nsw i32 %152, 1
store i32 %153, i32* %11
br label %77
154: ; preds = %77
ret void
}

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