double get_tolerance_for_BZ_reduction(double rec_lattice[3][3],
                                      const int mesh[3]) {
  int i, j;
  double tolerance;
  double length[3];
  for (i = 0; i < 3; i++) {
    length[i] = 0;
    for (j = 0; j < 3; j++) {
      length[i] += rec_lattice[j][i] * rec_lattice[j][i];
    }
    length[i] /= mesh[i] * mesh[i];
  }
  tolerance = length[0];
  for (i = 1; i < 3; i++) {
    if (tolerance < length[i]) {
      tolerance = length[i];
    }
  }
  tolerance *= 0.01;
  return tolerance;
}


x86 assembly (clang, -O0):
<get_tolerance_for_BZ_reduction>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11ce <get_tolerance_for_BZ_reduction+0xce>
movslq -0x14(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    1191 <get_tolerance_for_BZ_reduction+0x91>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movslq -0x14(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <get_tolerance_for_BZ_reduction+0x31>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
imul   (%rcx,%rdx,4),%eax
cvtsi2sd %eax,%xmm1
movslq -0x14(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1113 <get_tolerance_for_BZ_reduction+0x13>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1224 <get_tolerance_for_BZ_reduction+0x124>
movsd  -0x20(%rbp),%xmm1
movslq -0x14(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1211 <get_tolerance_for_BZ_reduction+0x111>
movslq -0x14(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1216 <get_tolerance_for_BZ_reduction+0x116>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11df <get_tolerance_for_BZ_reduction+0xdf>
movsd  0xdd4(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tolerance_for_BZ_reduction>:
movupd (%rdi),%xmm0
mulpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
addpd  %xmm0,%xmm1
movupd 0x18(%rdi),%xmm0
mulpd  %xmm0,%xmm0
addpd  %xmm1,%xmm0
movupd 0x30(%rdi),%xmm1
mulpd  %xmm1,%xmm1
addpd  %xmm0,%xmm1
movq   (%rsi),%xmm0
pshufd $0xf5,%xmm0,%xmm2
pmuludq %xmm0,%xmm0
pmuludq %xmm2,%xmm2
punpckldq %xmm2,%xmm0
cvtdq2pd %xmm0,%xmm0
divpd  %xmm0,%xmm1
movsd  0x10(%rdi),%xmm0
mulsd  %xmm0,%xmm0
pxor   %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x28(%rdi),%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
movsd  0x40(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
mov    0x8(%rsi),%eax
imul   %eax,%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
divsd  %xmm2,%xmm0
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
maxsd  %xmm1,%xmm2
maxsd  %xmm2,%xmm0
mulsd  0xe65(%rip),%xmm0
ret

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

LLVM IR (-O2):
define double @get_tolerance_for_BZ_reduction([3 x double]* nocapture %0, i32* nocapture %1) {
%3 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 0
%4 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 0
%5 = bitcast [3 x double]* %0 to <2 x double>*
%6 = load <2 x double>, <2 x double>* %5
%7 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %6, <2 x double> %6, <2 x double> zeroinitializer)
%8 = bitcast double* %3 to <2 x double>*
%9 = load <2 x double>, <2 x double>* %8
%10 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %9, <2 x double> %9, <2 x double> %7)
%11 = bitcast double* %4 to <2 x double>*
%12 = load <2 x double>, <2 x double>* %11
%13 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %12, <2 x double> %12, <2 x double> %10)
%14 = bitcast i32* %1 to <2 x i32>*
%15 = load <2 x i32>, <2 x i32>* %14
%16 = mul nsw <2 x i32> %15, %15
%17 = sitofp <2 x i32> %16 to <2 x double>
%18 = fdiv <2 x double> %13, %17
%19 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 2
%20 = load double, double* %19
%21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double 0.000000e+00)
%22 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 2
%23 = load double, double* %22
%24 = tail call double @llvm.fmuladd.f64(double %23, double %23, double %21)
%25 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 2
%26 = load double, double* %25
%27 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %24)
%28 = getelementptr inbounds i32, i32* %1, i64 2
%29 = load i32, i32* %28
%30 = mul nsw i32 %29, %29
%31 = sitofp i32 %30 to double
%32 = fdiv double %27, %31
%33 = extractelement <2 x double> %18, i64 0
%34 = extractelement <2 x double> %18, i64 1
%35 = fcmp olt double %33, %34
%36 = select i1 %35, double %34, double %33
%37 = fcmp olt double %36, %32
%38 = select i1 %37, double %32, double %36
%39 = fmul double %38, 1.000000e-02
ret double %39
}