; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Grid.ll (ZNK6R2Grid9GridValueEdd)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%class.R2Grid = type { %class.R2Affine, %class.R2Affine, double, ptr, [2 x i32], i32, i32 }
%class.R2Affine = type <{ %class.R2Transformation, %class.R3Matrix, i32, [4 x i8] }>
%class.R2Transformation = type { ptr }
%class.R3Matrix = type { [3 x [3 x double]] }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK6R2Grid9GridValueEdd(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1, double noundef %2) #3 align 2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca double, align 8
  %22 = alloca double, align 8
  %23 = alloca double, align 8
  %24 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  %25 = load ptr, ptr %5, align 8
  %26 = load double, ptr %6, align 8, !tbaa !9
  %27 = fcmp olt double %26, 0.000000e+00
  br i1 %27, label %36, label %28

28:                                               ; preds = %3
  %29 = load double, ptr %6, align 8, !tbaa !9
  %30 = getelementptr inbounds %class.R2Grid, ptr %25, i32 0, i32 4
  %31 = getelementptr inbounds [2 x i32], ptr %30, i64 0, i64 0
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = sub nsw i32 %32, 1
  %34 = sitofp i32 %33 to double
  %35 = fcmp ogt double %29, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %28, %3
  store double 0.000000e+00, ptr %4, align 8
  br label %162

37:                                               ; preds = %28
  %38 = load double, ptr %7, align 8, !tbaa !9
  %39 = fcmp olt double %38, 0.000000e+00
  br i1 %39, label %48, label %40

40:                                               ; preds = %37
  %41 = load double, ptr %7, align 8, !tbaa !9
  %42 = getelementptr inbounds %class.R2Grid, ptr %25, i32 0, i32 4
  %43 = getelementptr inbounds [2 x i32], ptr %42, i64 0, i64 1
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = sub nsw i32 %44, 1
  %46 = sitofp i32 %45 to double
  %47 = fcmp ogt double %41, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %40, %37
  store double 0.000000e+00, ptr %4, align 8
  br label %162

49:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %50 = load double, ptr %6, align 8, !tbaa !9
  %51 = fptosi double %50 to i32
  store i32 %51, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %52 = load double, ptr %7, align 8, !tbaa !9
  %53 = fptosi double %52 to i32
  store i32 %53, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %54 = load i32, ptr %8, align 4, !tbaa !11
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %56 = load i32, ptr %9, align 4, !tbaa !11
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %11, align 4, !tbaa !11
  %58 = load i32, ptr %10, align 4, !tbaa !11
  %59 = getelementptr inbounds %class.R2Grid, ptr %25, i32 0, i32 4
  %60 = getelementptr inbounds [2 x i32], ptr %59, i64 0, i64 0
  %61 = load i32, ptr %60, align 8, !tbaa !11
  %62 = icmp sge i32 %58, %61
  br i1 %62, label %63, label %65

63:                                               ; preds = %49
  %64 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %64, ptr %10, align 4, !tbaa !11
  br label %65

65:                                               ; preds = %63, %49
  %66 = load i32, ptr %11, align 4, !tbaa !11
  %67 = getelementptr inbounds %class.R2Grid, ptr %25, i32 0, i32 4
  %68 = getelementptr inbounds [2 x i32], ptr %67, i64 0, i64 1
  %69 = load i32, ptr %68, align 4, !tbaa !11
  %70 = icmp sge i32 %66, %69
  br i1 %70, label %71, label %73

71:                                               ; preds = %65
  %72 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %72, ptr %11, align 4, !tbaa !11
  br label %73

73:                                               ; preds = %71, %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %74 = load double, ptr %6, align 8, !tbaa !9
  %75 = load i32, ptr %8, align 4, !tbaa !11
  %76 = sitofp i32 %75 to double
  %77 = fsub double %74, %76
  store double %77, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %78 = load double, ptr %7, align 8, !tbaa !9
  %79 = load i32, ptr %9, align 4, !tbaa !11
  %80 = sitofp i32 %79 to double
  %81 = fsub double %78, %80
  store double %81, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %82 = load i32, ptr %8, align 4, !tbaa !11
  %83 = load i32, ptr %9, align 4, !tbaa !11
  %84 = call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %25, i32 noundef %82, i32 noundef %83)
  store double %84, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %85 = load i32, ptr %8, align 4, !tbaa !11
  %86 = load i32, ptr %11, align 4, !tbaa !11
  %87 = call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %25, i32 noundef %85, i32 noundef %86)
  store double %87, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %88 = load i32, ptr %10, align 4, !tbaa !11
  %89 = load i32, ptr %9, align 4, !tbaa !11
  %90 = call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %25, i32 noundef %88, i32 noundef %89)
  store double %90, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %91 = load i32, ptr %10, align 4, !tbaa !11
  %92 = load i32, ptr %11, align 4, !tbaa !11
  %93 = call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %25, i32 noundef %91, i32 noundef %92)
  store double %93, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %94 = load double, ptr %12, align 8, !tbaa !9
  %95 = fsub double 1.000000e+00, %94
  %96 = load double, ptr %13, align 8, !tbaa !9
  %97 = fsub double 1.000000e+00, %96
  %98 = fmul double %95, %97
  store double %98, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %99 = load double, ptr %12, align 8, !tbaa !9
  %100 = fsub double 1.000000e+00, %99
  %101 = load double, ptr %13, align 8, !tbaa !9
  %102 = fmul double %100, %101
  store double %102, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %103 = load double, ptr %12, align 8, !tbaa !9
  %104 = load double, ptr %13, align 8, !tbaa !9
  %105 = fsub double 1.000000e+00, %104
  %106 = fmul double %103, %105
  store double %106, ptr %20, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %107 = load double, ptr %12, align 8, !tbaa !9
  %108 = load double, ptr %13, align 8, !tbaa !9
  %109 = fmul double %107, %108
  store double %109, ptr %21, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  store double 0.000000e+00, ptr %22, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  store double 0.000000e+00, ptr %23, align 8, !tbaa !9
  %110 = load double, ptr %14, align 8, !tbaa !9
  %111 = fcmp une double %110, -3.210000e+02
  br i1 %111, label %112, label %120

112:                                              ; preds = %73
  %113 = load double, ptr %18, align 8, !tbaa !9
  %114 = load double, ptr %14, align 8, !tbaa !9
  %115 = load double, ptr %22, align 8, !tbaa !9
  %116 = call double @llvm.fmuladd.f64(double %113, double %114, double %115)
  store double %116, ptr %22, align 8, !tbaa !9
  %117 = load double, ptr %18, align 8, !tbaa !9
  %118 = load double, ptr %23, align 8, !tbaa !9
  %119 = fadd double %118, %117
  store double %119, ptr %23, align 8, !tbaa !9
  br label %120

120:                                              ; preds = %112, %73
  %121 = load double, ptr %15, align 8, !tbaa !9
  %122 = fcmp une double %121, -3.210000e+02
  br i1 %122, label %123, label %131

123:                                              ; preds = %120
  %124 = load double, ptr %19, align 8, !tbaa !9
  %125 = load double, ptr %15, align 8, !tbaa !9
  %126 = load double, ptr %22, align 8, !tbaa !9
  %127 = call double @llvm.fmuladd.f64(double %124, double %125, double %126)
  store double %127, ptr %22, align 8, !tbaa !9
  %128 = load double, ptr %19, align 8, !tbaa !9
  %129 = load double, ptr %23, align 8, !tbaa !9
  %130 = fadd double %129, %128
  store double %130, ptr %23, align 8, !tbaa !9
  br label %131

131:                                              ; preds = %123, %120
  %132 = load double, ptr %16, align 8, !tbaa !9
  %133 = fcmp une double %132, -3.210000e+02
  br i1 %133, label %134, label %142

134:                                              ; preds = %131
  %135 = load double, ptr %20, align 8, !tbaa !9
  %136 = load double, ptr %16, align 8, !tbaa !9
  %137 = load double, ptr %22, align 8, !tbaa !9
  %138 = call double @llvm.fmuladd.f64(double %135, double %136, double %137)
  store double %138, ptr %22, align 8, !tbaa !9
  %139 = load double, ptr %20, align 8, !tbaa !9
  %140 = load double, ptr %23, align 8, !tbaa !9
  %141 = fadd double %140, %139
  store double %141, ptr %23, align 8, !tbaa !9
  br label %142

142:                                              ; preds = %134, %131
  %143 = load double, ptr %17, align 8, !tbaa !9
  %144 = fcmp une double %143, -3.210000e+02
  br i1 %144, label %145, label %153

145:                                              ; preds = %142
  %146 = load double, ptr %21, align 8, !tbaa !9
  %147 = load double, ptr %17, align 8, !tbaa !9
  %148 = load double, ptr %22, align 8, !tbaa !9
  %149 = call double @llvm.fmuladd.f64(double %146, double %147, double %148)
  store double %149, ptr %22, align 8, !tbaa !9
  %150 = load double, ptr %21, align 8, !tbaa !9
  %151 = load double, ptr %23, align 8, !tbaa !9
  %152 = fadd double %151, %150
  store double %152, ptr %23, align 8, !tbaa !9
  br label %153

153:                                              ; preds = %145, %142
  %154 = load double, ptr %23, align 8, !tbaa !9
  %155 = fcmp oeq double %154, 0.000000e+00
  br i1 %155, label %156, label %157

156:                                              ; preds = %153
  store double -3.210000e+02, ptr %4, align 8
  store i32 1, ptr %24, align 4
  br label %161

157:                                              ; preds = %153
  %158 = load double, ptr %22, align 8, !tbaa !9
  %159 = load double, ptr %23, align 8, !tbaa !9
  %160 = fdiv double %158, %159
  store double %160, ptr %4, align 8
  store i32 1, ptr %24, align 4
  br label %161

161:                                              ; preds = %157, %156
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %162

162:                                              ; preds = %161, %48, %36
  %163 = load double, ptr %4, align 8
  ret double %163
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK6R2Grid9GridValueEdd(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1, double noundef %2) local_unnamed_addr #2 align 2 {
  %4 = fcmp olt double %1, 0.000000e+00
  br i1 %4, label %55, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 192
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = add nsw i32 %7, -1
  %9 = sitofp i32 %8 to double
  %10 = fcmp olt double %9, %1
  %11 = fcmp olt double %2, 0.000000e+00
  %or.cond = or i1 %11, %10
  br i1 %or.cond, label %55, label %12

12:                                               ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 196
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  %16 = sitofp i32 %15 to double
  %17 = fcmp olt double %16, %2
  br i1 %17, label %55, label %18

18:                                               ; preds = %12
  %19 = insertelement <2 x double> poison, double %1, i64 0
  %20 = insertelement <2 x double> %19, double %2, i64 1
  %21 = fptosi <2 x double> %20 to <2 x i32>
  %22 = extractelement <2 x i32> %21, i64 0
  %23 = add nsw i32 %22, 1
  %24 = extractelement <2 x i32> %21, i64 1
  %25 = add nsw i32 %24, 1
  %.not = icmp slt i32 %23, %7
  %spec.select = select i1 %.not, i32 %23, i32 %22
  %.not76 = icmp slt i32 %25, %14
  %.067 = select i1 %.not76, i32 %25, i32 %24
  %26 = sitofp <2 x i32> %21 to <2 x double>
  %27 = fsub <2 x double> %20, %26
  %28 = tail call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %22, i32 noundef %24)
  %29 = tail call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %22, i32 noundef %.067)
  %30 = tail call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %spec.select, i32 noundef %24)
  %31 = tail call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %spec.select, i32 noundef %.067)
  %32 = fsub <2 x double> <double 1.000000e+00, double 1.000000e+00>, %27
  %33 = extractelement <2 x double> %32, i64 0
  %34 = extractelement <2 x double> %27, i64 1
  %35 = fmul double %33, %34
  %36 = extractelement <2 x double> %32, i64 1
  %37 = extractelement <2 x double> %27, i64 0
  %38 = fmul double %37, %36
  %39 = fmul double %37, %34
  %40 = fcmp une double %28, -3.210000e+02
  %41 = fmul double %33, %36
  %42 = tail call double @llvm.fmuladd.f64(double %41, double %28, double 0.000000e+00)
  %43 = fadd double %41, 0.000000e+00
  %.060 = select i1 %40, double %42, double 0.000000e+00
  %.0 = select i1 %40, double %43, double 0.000000e+00
  %44 = fcmp une double %29, -3.210000e+02
  %45 = tail call double @llvm.fmuladd.f64(double %35, double %29, double %.060)
  %46 = fadd double %35, %.0
  %.161 = select i1 %44, double %45, double %.060
  %.1 = select i1 %44, double %46, double %.0
  %47 = fcmp une double %30, -3.210000e+02
  %48 = tail call double @llvm.fmuladd.f64(double %38, double %30, double %.161)
  %49 = fadd double %38, %.1
  %.262 = select i1 %47, double %48, double %.161
  %.2 = select i1 %47, double %49, double %.1
  %50 = fcmp une double %31, -3.210000e+02
  %51 = tail call double @llvm.fmuladd.f64(double %39, double %31, double %.262)
  %52 = fadd double %39, %.2
  %.363 = select i1 %50, double %51, double %.262
  %.3 = select i1 %50, double %52, double %.2
  %53 = fcmp oeq double %.3, 0.000000e+00
  %54 = fdiv double %.363, %.3
  %.064 = select i1 %53, double -3.210000e+02, double %54
  br label %55

55:                                               ; preds = %12, %3, %5, %18
  %.165 = phi double [ %.064, %18 ], [ 0.000000e+00, %5 ], [ 0.000000e+00, %3 ], [ 0.000000e+00, %12 ]
  ret double %.165
}

attributes #0 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass