; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3Grid.ll (ZN6R3Grid16PercentileFilterEdd)

; 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.R3Grid = type { %class.R3Affine, %class.R3Affine, double, double, ptr, [3 x i32], i32, i32, i32 }
%class.R3Affine = type { %class.R3Transformation, %class.R4Matrix, %class.R4Matrix, %class.RNFlags }
%class.R3Transformation = type { ptr }
%class.R4Matrix = type { [4 x [4 x double]] }
%class.RNFlags = type { i64 }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [8 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

declare void @_Z7RNAbortPKcz(ptr noundef, ...) #2

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #4

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

declare noundef i32 @_Z16RNCompareScalarsPKvS0_(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R3Grid9GridValueEiii(ptr noundef nonnull align 8 dereferenceable(592), i32 noundef, i32 noundef, i32 noundef) #5 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592)) #6 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592)) #6 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592)) #6 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592), i32 noundef, i32 noundef, i32 noundef, double noundef) #5 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Grid16PercentileFilterEdd(ptr noundef nonnull align 8 dereferenceable(592) %0, double noundef %1, double noundef %2) #7 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca %class.R3Grid, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  %28 = alloca i32, align 4
  %29 = alloca i32, align 4
  %30 = alloca i32, align 4
  %31 = alloca i32, align 4
  %32 = alloca double, align 8
  %33 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 592, ptr %7) #8
  call void @_ZN6R3GridC1ERKS_(ptr noundef nonnull align 8 dereferenceable(592) %7, ptr noundef nonnull align 8 dereferenceable(592) %34)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #8
  %35 = load double, ptr %5, align 8, !tbaa !9
  %36 = load double, ptr %5, align 8, !tbaa !9
  %37 = fmul double %35, %36
  store double %37, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %38 = load double, ptr %5, align 8, !tbaa !9
  %39 = fptosi double %38 to i32
  store i32 %39, ptr %9, align 4, !tbaa !11
  %40 = load i32, ptr %9, align 4, !tbaa !11
  %41 = icmp sge i32 %40, 0
  br i1 %41, label %48, label %42

42:                                               ; preds = %3
  invoke void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.14, i32 noundef 962, ptr noundef @.str.2)
          to label %43 unwind label %44

43:                                               ; preds = %42
  br label %48

44:                                               ; preds = %42
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %10, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %11, align 4
  br label %322

48:                                               ; preds = %43, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  %49 = load i32, ptr %9, align 4, !tbaa !11
  %50 = mul nsw i32 2, %49
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %9, align 4, !tbaa !11
  %53 = mul nsw i32 2, %52
  %54 = add nsw i32 %53, 1
  %55 = mul nsw i32 %51, %54
  %56 = load i32, ptr %9, align 4, !tbaa !11
  %57 = mul nsw i32 2, %56
  %58 = add nsw i32 %57, 1
  %59 = mul nsw i32 %55, %58
  store i32 %59, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #8
  %60 = load i32, ptr %12, align 4, !tbaa !11
  %61 = sext i32 %60 to i64
  %62 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %61, i64 8)
  %63 = extractvalue { i64, i1 } %62, 1
  %64 = extractvalue { i64, i1 } %62, 0
  %65 = select i1 %63, i64 -1, i64 %64
  %66 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %65) #9
          to label %67 unwind label %72

67:                                               ; preds = %48
  store ptr %66, ptr %13, align 8, !tbaa !5
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %76, label %70

70:                                               ; preds = %67
  invoke void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.15, i32 noundef 965, ptr noundef @.str.2)
          to label %71 unwind label %72

71:                                               ; preds = %70
  br label %76

72:                                               ; preds = %70, %48
  %73 = landingpad { ptr, i32 }
          cleanup
  %74 = extractvalue { ptr, i32 } %73, 0
  store ptr %74, ptr %10, align 8
  %75 = extractvalue { ptr, i32 } %73, 1
  store i32 %75, ptr %11, align 4
  br label %321

76:                                               ; preds = %71, %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #8
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %77

77:                                               ; preds = %312, %76
  %78 = load i32, ptr %14, align 4, !tbaa !11
  %79 = invoke noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %80 unwind label %83

80:                                               ; preds = %77
  %81 = icmp slt i32 %78, %79
  br i1 %81, label %87, label %82

82:                                               ; preds = %80
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  br label %316

83:                                               ; preds = %77
  %84 = landingpad { ptr, i32 }
          cleanup
  %85 = extractvalue { ptr, i32 } %84, 0
  store ptr %85, ptr %10, align 8
  %86 = extractvalue { ptr, i32 } %84, 1
  store i32 %86, ptr %11, align 4
  br label %315

87:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #8
  store i32 0, ptr %16, align 4, !tbaa !11
  br label %88

88:                                               ; preds = %307, %87
  %89 = load i32, ptr %16, align 4, !tbaa !11
  %90 = invoke noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %91 unwind label %94

91:                                               ; preds = %88
  %92 = icmp slt i32 %89, %90
  br i1 %92, label %98, label %93

93:                                               ; preds = %91
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  br label %311

94:                                               ; preds = %88
  %95 = landingpad { ptr, i32 }
          cleanup
  %96 = extractvalue { ptr, i32 } %95, 0
  store ptr %96, ptr %10, align 8
  %97 = extractvalue { ptr, i32 } %95, 1
  store i32 %97, ptr %11, align 4
  br label %310

98:                                               ; preds = %91
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #8
  store i32 0, ptr %17, align 4, !tbaa !11
  br label %99

99:                                               ; preds = %301, %98
  %100 = load i32, ptr %17, align 4, !tbaa !11
  %101 = invoke noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %102 unwind label %105

102:                                              ; preds = %99
  %103 = icmp slt i32 %100, %101
  br i1 %103, label %109, label %104

104:                                              ; preds = %102
  store i32 8, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  br label %306

105:                                              ; preds = %99
  %106 = landingpad { ptr, i32 }
          cleanup
  %107 = extractvalue { ptr, i32 } %106, 0
  store ptr %107, ptr %10, align 8
  %108 = extractvalue { ptr, i32 } %106, 1
  store i32 %108, ptr %11, align 4
  br label %305

109:                                              ; preds = %102
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #8
  store i32 0, ptr %18, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #8
  %110 = load i32, ptr %14, align 4, !tbaa !11
  %111 = load i32, ptr %9, align 4, !tbaa !11
  %112 = sub nsw i32 %110, %111
  store i32 %112, ptr %19, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #8
  %113 = load i32, ptr %14, align 4, !tbaa !11
  %114 = load i32, ptr %9, align 4, !tbaa !11
  %115 = add nsw i32 %113, %114
  store i32 %115, ptr %20, align 4, !tbaa !11
  %116 = load i32, ptr %19, align 4, !tbaa !11
  %117 = icmp slt i32 %116, 0
  br i1 %117, label %118, label %119

118:                                              ; preds = %109
  store i32 0, ptr %19, align 4, !tbaa !11
  br label %119

119:                                              ; preds = %118, %109
  %120 = load i32, ptr %20, align 4, !tbaa !11
  %121 = invoke noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %122 unwind label %128

122:                                              ; preds = %119
  %123 = icmp sge i32 %120, %121
  br i1 %123, label %124, label %132

124:                                              ; preds = %122
  %125 = invoke noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %126 unwind label %128

126:                                              ; preds = %124
  %127 = sub nsw i32 %125, 1
  store i32 %127, ptr %20, align 4, !tbaa !11
  br label %132

128:                                              ; preds = %265, %260, %124, %119
  %129 = landingpad { ptr, i32 }
          cleanup
  %130 = extractvalue { ptr, i32 } %129, 0
  store ptr %130, ptr %10, align 8
  %131 = extractvalue { ptr, i32 } %129, 1
  store i32 %131, ptr %11, align 4
  br label %304

132:                                              ; preds = %126, %122
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #8
  %133 = load i32, ptr %19, align 4, !tbaa !11
  store i32 %133, ptr %21, align 4, !tbaa !11
  br label %134

134:                                              ; preds = %253, %132
  %135 = load i32, ptr %21, align 4, !tbaa !11
  %136 = load i32, ptr %20, align 4, !tbaa !11
  %137 = icmp sle i32 %135, %136
  br i1 %137, label %139, label %138

138:                                              ; preds = %134
  store i32 11, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #8
  br label %257

139:                                              ; preds = %134
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #8
  %140 = load i32, ptr %21, align 4, !tbaa !11
  %141 = load i32, ptr %14, align 4, !tbaa !11
  %142 = sub nsw i32 %140, %141
  store i32 %142, ptr %22, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #8
  %143 = load i32, ptr %16, align 4, !tbaa !11
  %144 = load i32, ptr %9, align 4, !tbaa !11
  %145 = sub nsw i32 %143, %144
  store i32 %145, ptr %23, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #8
  %146 = load i32, ptr %16, align 4, !tbaa !11
  %147 = load i32, ptr %9, align 4, !tbaa !11
  %148 = add nsw i32 %146, %147
  store i32 %148, ptr %24, align 4, !tbaa !11
  %149 = load i32, ptr %23, align 4, !tbaa !11
  %150 = icmp slt i32 %149, 0
  br i1 %150, label %151, label %152

151:                                              ; preds = %139
  store i32 0, ptr %23, align 4, !tbaa !11
  br label %152

152:                                              ; preds = %151, %139
  %153 = load i32, ptr %24, align 4, !tbaa !11
  %154 = invoke noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %155 unwind label %161

155:                                              ; preds = %152
  %156 = icmp sge i32 %153, %154
  br i1 %156, label %157, label %165

157:                                              ; preds = %155
  %158 = invoke noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %159 unwind label %161

159:                                              ; preds = %157
  %160 = sub nsw i32 %158, 1
  store i32 %160, ptr %24, align 4, !tbaa !11
  br label %165

161:                                              ; preds = %157, %152
  %162 = landingpad { ptr, i32 }
          cleanup
  %163 = extractvalue { ptr, i32 } %162, 0
  store ptr %163, ptr %10, align 8
  %164 = extractvalue { ptr, i32 } %162, 1
  store i32 %164, ptr %11, align 4
  br label %256

165:                                              ; preds = %159, %155
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #8
  %166 = load i32, ptr %23, align 4, !tbaa !11
  store i32 %166, ptr %25, align 4, !tbaa !11
  br label %167

167:                                              ; preds = %248, %165
  %168 = load i32, ptr %25, align 4, !tbaa !11
  %169 = load i32, ptr %24, align 4, !tbaa !11
  %170 = icmp sle i32 %168, %169
  br i1 %170, label %172, label %171

171:                                              ; preds = %167
  store i32 14, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #8
  br label %252

172:                                              ; preds = %167
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #8
  %173 = load i32, ptr %25, align 4, !tbaa !11
  %174 = load i32, ptr %16, align 4, !tbaa !11
  %175 = sub nsw i32 %173, %174
  store i32 %175, ptr %26, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #8
  %176 = load i32, ptr %17, align 4, !tbaa !11
  %177 = load i32, ptr %9, align 4, !tbaa !11
  %178 = sub nsw i32 %176, %177
  store i32 %178, ptr %27, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %28) #8
  %179 = load i32, ptr %17, align 4, !tbaa !11
  %180 = load i32, ptr %9, align 4, !tbaa !11
  %181 = add nsw i32 %179, %180
  store i32 %181, ptr %28, align 4, !tbaa !11
  %182 = load i32, ptr %27, align 4, !tbaa !11
  %183 = icmp slt i32 %182, 0
  br i1 %183, label %184, label %185

184:                                              ; preds = %172
  store i32 0, ptr %27, align 4, !tbaa !11
  br label %185

185:                                              ; preds = %184, %172
  %186 = load i32, ptr %28, align 4, !tbaa !11
  %187 = invoke noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %188 unwind label %194

188:                                              ; preds = %185
  %189 = icmp sge i32 %186, %187
  br i1 %189, label %190, label %198

190:                                              ; preds = %188
  %191 = invoke noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %34)
          to label %192 unwind label %194

192:                                              ; preds = %190
  %193 = sub nsw i32 %191, 1
  store i32 %193, ptr %28, align 4, !tbaa !11
  br label %198

194:                                              ; preds = %190, %185
  %195 = landingpad { ptr, i32 }
          cleanup
  %196 = extractvalue { ptr, i32 } %195, 0
  store ptr %196, ptr %10, align 8
  %197 = extractvalue { ptr, i32 } %195, 1
  store i32 %197, ptr %11, align 4
  br label %251

198:                                              ; preds = %192, %188
  call void @llvm.lifetime.start.p0(i64 4, ptr %29) #8
  %199 = load i32, ptr %27, align 4, !tbaa !11
  store i32 %199, ptr %29, align 4, !tbaa !11
  br label %200

200:                                              ; preds = %240, %198
  %201 = load i32, ptr %29, align 4, !tbaa !11
  %202 = load i32, ptr %28, align 4, !tbaa !11
  %203 = icmp sle i32 %201, %202
  br i1 %203, label %205, label %204

204:                                              ; preds = %200
  store i32 17, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %29) #8
  br label %247

205:                                              ; preds = %200
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #8
  %206 = load i32, ptr %29, align 4, !tbaa !11
  %207 = load i32, ptr %17, align 4, !tbaa !11
  %208 = sub nsw i32 %206, %207
  store i32 %208, ptr %30, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %31) #8
  %209 = load i32, ptr %30, align 4, !tbaa !11
  %210 = load i32, ptr %30, align 4, !tbaa !11
  %211 = mul nsw i32 %209, %210
  %212 = load i32, ptr %26, align 4, !tbaa !11
  %213 = load i32, ptr %26, align 4, !tbaa !11
  %214 = mul nsw i32 %212, %213
  %215 = add nsw i32 %211, %214
  %216 = load i32, ptr %22, align 4, !tbaa !11
  %217 = load i32, ptr %22, align 4, !tbaa !11
  %218 = mul nsw i32 %216, %217
  %219 = add nsw i32 %215, %218
  store i32 %219, ptr %31, align 4, !tbaa !11
  %220 = load i32, ptr %31, align 4, !tbaa !11
  %221 = sitofp i32 %220 to double
  %222 = load double, ptr %8, align 8, !tbaa !9
  %223 = fcmp ogt double %221, %222
  br i1 %223, label %224, label %225

224:                                              ; preds = %205
  store i32 19, ptr %15, align 4
  br label %237

225:                                              ; preds = %205
  call void @llvm.lifetime.start.p0(i64 8, ptr %32) #8
  %226 = load i32, ptr %29, align 4, !tbaa !11
  %227 = load i32, ptr %25, align 4, !tbaa !11
  %228 = load i32, ptr %21, align 4, !tbaa !11
  %229 = invoke noundef double @_ZNK6R3Grid9GridValueEiii(ptr noundef nonnull align 8 dereferenceable(592) %7, i32 noundef %226, i32 noundef %227, i32 noundef %228)
          to label %230 unwind label %243

230:                                              ; preds = %225
  store double %229, ptr %32, align 8, !tbaa !9
  %231 = load double, ptr %32, align 8, !tbaa !9
  %232 = load ptr, ptr %13, align 8, !tbaa !5
  %233 = load i32, ptr %18, align 4, !tbaa !11
  %234 = add nsw i32 %233, 1
  store i32 %234, ptr %18, align 4, !tbaa !11
  %235 = sext i32 %233 to i64
  %236 = getelementptr inbounds double, ptr %232, i64 %235
  store double %231, ptr %236, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %32) #8
  store i32 0, ptr %15, align 4
  br label %237

237:                                              ; preds = %230, %224
  call void @llvm.lifetime.end.p0(i64 4, ptr %31) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #8
  %238 = load i32, ptr %15, align 4
  switch i32 %238, label %328 [
    i32 0, label %239
    i32 19, label %240
  ]

239:                                              ; preds = %237
  br label %240

240:                                              ; preds = %239, %237
  %241 = load i32, ptr %29, align 4, !tbaa !11
  %242 = add nsw i32 %241, 1
  store i32 %242, ptr %29, align 4, !tbaa !11
  br label %200, !llvm.loop !13

243:                                              ; preds = %225
  %244 = landingpad { ptr, i32 }
          cleanup
  %245 = extractvalue { ptr, i32 } %244, 0
  store ptr %245, ptr %10, align 8
  %246 = extractvalue { ptr, i32 } %244, 1
  store i32 %246, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %32) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %31) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %29) #8
  br label %251

247:                                              ; preds = %204
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #8
  br label %248

248:                                              ; preds = %247
  %249 = load i32, ptr %25, align 4, !tbaa !11
  %250 = add nsw i32 %249, 1
  store i32 %250, ptr %25, align 4, !tbaa !11
  br label %167, !llvm.loop !15

251:                                              ; preds = %243, %194
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #8
  br label %256

252:                                              ; preds = %171
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #8
  br label %253

253:                                              ; preds = %252
  %254 = load i32, ptr %21, align 4, !tbaa !11
  %255 = add nsw i32 %254, 1
  store i32 %255, ptr %21, align 4, !tbaa !11
  br label %134, !llvm.loop !16

256:                                              ; preds = %251, %161
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #8
  br label %304

257:                                              ; preds = %138
  %258 = load i32, ptr %18, align 4, !tbaa !11
  %259 = icmp eq i32 %258, 0
  br i1 %259, label %260, label %265

260:                                              ; preds = %257
  %261 = load i32, ptr %17, align 4, !tbaa !11
  %262 = load i32, ptr %16, align 4, !tbaa !11
  %263 = load i32, ptr %14, align 4, !tbaa !11
  invoke void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %34, i32 noundef %261, i32 noundef %262, i32 noundef %263, double noundef 0.000000e+00)
          to label %264 unwind label %128

264:                                              ; preds = %260
  br label %300

265:                                              ; preds = %257
  %266 = load ptr, ptr %13, align 8, !tbaa !5
  %267 = load i32, ptr %18, align 4, !tbaa !11
  %268 = sext i32 %267 to i64
  invoke void @qsort(ptr noundef %266, i64 noundef %268, i64 noundef 8, ptr noundef @_Z16RNCompareScalarsPKvS0_)
          to label %269 unwind label %128

269:                                              ; preds = %265
  call void @llvm.lifetime.start.p0(i64 4, ptr %33) #8
  %270 = load double, ptr %6, align 8, !tbaa !9
  %271 = load i32, ptr %18, align 4, !tbaa !11
  %272 = sitofp i32 %271 to double
  %273 = fmul double %270, %272
  %274 = fptosi double %273 to i32
  store i32 %274, ptr %33, align 4, !tbaa !11
  %275 = load i32, ptr %33, align 4, !tbaa !11
  %276 = icmp slt i32 %275, 0
  br i1 %276, label %277, label %278

277:                                              ; preds = %269
  store i32 0, ptr %33, align 4, !tbaa !11
  br label %286

278:                                              ; preds = %269
  %279 = load i32, ptr %33, align 4, !tbaa !11
  %280 = load i32, ptr %18, align 4, !tbaa !11
  %281 = icmp sge i32 %279, %280
  br i1 %281, label %282, label %285

282:                                              ; preds = %278
  %283 = load i32, ptr %18, align 4, !tbaa !11
  %284 = sub nsw i32 %283, 1
  store i32 %284, ptr %33, align 4, !tbaa !11
  br label %285

285:                                              ; preds = %282, %278
  br label %286

286:                                              ; preds = %285, %277
  %287 = load i32, ptr %17, align 4, !tbaa !11
  %288 = load i32, ptr %16, align 4, !tbaa !11
  %289 = load i32, ptr %14, align 4, !tbaa !11
  %290 = load ptr, ptr %13, align 8, !tbaa !5
  %291 = load i32, ptr %33, align 4, !tbaa !11
  %292 = sext i32 %291 to i64
  %293 = getelementptr inbounds double, ptr %290, i64 %292
  %294 = load double, ptr %293, align 8, !tbaa !9
  invoke void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %34, i32 noundef %287, i32 noundef %288, i32 noundef %289, double noundef %294)
          to label %295 unwind label %296

295:                                              ; preds = %286
  call void @llvm.lifetime.end.p0(i64 4, ptr %33) #8
  br label %300

296:                                              ; preds = %286
  %297 = landingpad { ptr, i32 }
          cleanup
  %298 = extractvalue { ptr, i32 } %297, 0
  store ptr %298, ptr %10, align 8
  %299 = extractvalue { ptr, i32 } %297, 1
  store i32 %299, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %33) #8
  br label %304

300:                                              ; preds = %295, %264
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #8
  br label %301

301:                                              ; preds = %300
  %302 = load i32, ptr %17, align 4, !tbaa !11
  %303 = add nsw i32 %302, 1
  store i32 %303, ptr %17, align 4, !tbaa !11
  br label %99, !llvm.loop !17

304:                                              ; preds = %296, %256, %128
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #8
  br label %305

305:                                              ; preds = %304, %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  br label %310

306:                                              ; preds = %104
  br label %307

307:                                              ; preds = %306
  %308 = load i32, ptr %16, align 4, !tbaa !11
  %309 = add nsw i32 %308, 1
  store i32 %309, ptr %16, align 4, !tbaa !11
  br label %88, !llvm.loop !18

310:                                              ; preds = %305, %94
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  br label %315

311:                                              ; preds = %93
  br label %312

312:                                              ; preds = %311
  %313 = load i32, ptr %14, align 4, !tbaa !11
  %314 = add nsw i32 %313, 1
  store i32 %314, ptr %14, align 4, !tbaa !11
  br label %77, !llvm.loop !19

315:                                              ; preds = %310, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  br label %321

316:                                              ; preds = %82
  %317 = load ptr, ptr %13, align 8, !tbaa !5
  %318 = icmp eq ptr %317, null
  br i1 %318, label %320, label %319

319:                                              ; preds = %316
  call void @_ZdaPv(ptr noundef %317) #10
  br label %320

320:                                              ; preds = %319, %316
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  call void @_ZN6R3GridD1Ev(ptr noundef nonnull align 8 dereferenceable(592) %7) #8
  call void @llvm.lifetime.end.p0(i64 592, ptr %7) #8
  ret void

321:                                              ; preds = %315, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  br label %322

322:                                              ; preds = %321, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  call void @_ZN6R3GridD1Ev(ptr noundef nonnull align 8 dereferenceable(592) %7) #8
  call void @llvm.lifetime.end.p0(i64 592, ptr %7) #8
  br label %323

323:                                              ; preds = %322
  %324 = load ptr, ptr %10, align 8
  %325 = load i32, ptr %11, align 4
  %326 = insertvalue { ptr, i32 } poison, ptr %324, 0
  %327 = insertvalue { ptr, i32 } %326, i32 %325, 1
  resume { ptr, i32 } %327

328:                                              ; preds = %237
  unreachable
}

declare void @_ZN6R3GridC1ERKS_(ptr, ptr)

declare void @_ZN6R3GridD1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nobuiltin allocsize(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 = { "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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nobuiltin nounwind "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 #5 = { 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 #6 = { inlinehint mustprogress nounwind 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { builtin allocsize(0) }
attributes #10 = { builtin 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}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}


; 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"

%class.R3Grid = type { %class.R3Affine, %class.R3Affine, double, double, ptr, [3 x i32], i32, i32, i32 }
%class.R3Affine = type { %class.R3Transformation, %class.R4Matrix, %class.R4Matrix, %class.RNFlags }
%class.R3Transformation = type { ptr }
%class.R4Matrix = type { [4 x [4 x double]] }
%class.RNFlags = type { i64 }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [7 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

declare void @_Z7RNAbortPKcz(ptr noundef, ...) local_unnamed_addr #1

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #4

declare noundef i32 @_Z16RNCompareScalarsPKvS0_(ptr noundef, ptr noundef) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592)) local_unnamed_addr #6 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592)) local_unnamed_addr #6 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592)) local_unnamed_addr #6 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592), i32 noundef, i32 noundef, i32 noundef, double noundef) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Grid16PercentileFilterEdd(ptr noundef nonnull align 8 dereferenceable(592) %0, double noundef %1, double noundef %2) local_unnamed_addr #7 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %class.R3Grid, align 8
  call void @llvm.lifetime.start.p0(i64 592, ptr nonnull %4) #9
  call void @_ZN6R3GridC1ERKS_(ptr noundef nonnull align 8 dereferenceable(592) %4, ptr noundef nonnull align 8 dereferenceable(592) %0)
  %5 = fmul double %1, %1
  %6 = fptosi double %1 to i32
  %7 = icmp sgt i32 %6, -1
  br i1 %7, label %11, label %8

8:                                                ; preds = %3
  invoke void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.14, i32 noundef 962, ptr noundef nonnull @.str.2)
          to label %11 unwind label %9

9:                                                ; preds = %8
  %10 = landingpad { ptr, i32 }
          cleanup
  br label %102

11:                                               ; preds = %8, %3
  %12 = shl nsw i32 %6, 1
  %13 = or disjoint i32 %12, 1
  %14 = mul nsw i32 %13, %13
  %15 = mul nsw i32 %14, %13
  %16 = sext i32 %15 to i64
  %17 = icmp slt i32 %15, 0
  %18 = shl nsw i64 %16, 3
  %19 = select i1 %17, i64 -1, i64 %18
  %20 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %19) #10
          to label %.preheader117 unwind label %23

.preheader117:                                    ; preds = %11
  %21 = call noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.preheader116, label %._crit_edge144

23:                                               ; preds = %11
  %24 = landingpad { ptr, i32 }
          cleanup
  br label %102

.preheader116:                                    ; preds = %.preheader117, %._crit_edge142
  %.091143 = phi i32 [ %33, %._crit_edge142 ], [ 0, %.preheader117 ]
  %25 = call noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.preheader.lr.ph, label %._crit_edge142

.preheader.lr.ph:                                 ; preds = %.preheader116
  %27 = sub nsw i32 %.091143, %6
  %28 = add nsw i32 %.091143, %6
  %spec.store.select = call i32 @llvm.smax.i32(i32 %27, i32 0)
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge140
  %.096141 = phi i32 [ 0, %.preheader.lr.ph ], [ %36, %._crit_edge140 ]
  %29 = call noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph139, label %._crit_edge140

.lr.ph139:                                        ; preds = %.preheader
  %31 = sub nsw i32 %.096141, %6
  %32 = add nsw i32 %.096141, %6
  %spec.store.select1 = call i32 @llvm.smax.i32(i32 %31, i32 0)
  br label %39

._crit_edge142:                                   ; preds = %._crit_edge140, %.preheader116
  %33 = add nuw nsw i32 %.091143, 1
  %34 = call noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %.preheader116, label %._crit_edge144, !llvm.loop !5

._crit_edge140:                                   ; preds = %98, %.preheader
  %36 = add nuw nsw i32 %.096141, 1
  %37 = call noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %.preheader, label %._crit_edge142, !llvm.loop !7

39:                                               ; preds = %.lr.ph139, %98
  %.0102138 = phi i32 [ 0, %.lr.ph139 ], [ %99, %98 ]
  %40 = call noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %.not = icmp slt i32 %28, %40
  br i1 %.not, label %46, label %41

41:                                               ; preds = %39
  %42 = call noundef i32 @_ZNK6R3Grid11ZResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %43 = add nsw i32 %42, -1
  br label %46

44:                                               ; preds = %85, %._crit_edge136.thread
  %45 = landingpad { ptr, i32 }
          cleanup
  br label %102

46:                                               ; preds = %41, %39
  %.098 = phi i32 [ %43, %41 ], [ %28, %39 ]
  %.not107131 = icmp sgt i32 %spec.store.select, %.098
  br i1 %.not107131, label %._crit_edge136.thread, label %.lr.ph135

.lr.ph135:                                        ; preds = %46
  %47 = sub nsw i32 %.0102138, %6
  %48 = add nsw i32 %.0102138, %6
  %spec.store.select2 = call i32 @llvm.smax.i32(i32 %47, i32 0)
  br label %50

._crit_edge136:                                   ; preds = %._crit_edge129
  %49 = icmp eq i32 %.1100.lcssa, 0
  br i1 %49, label %._crit_edge136.thread, label %85

50:                                               ; preds = %.lr.ph135, %._crit_edge129
  %.097133 = phi i32 [ %spec.store.select, %.lr.ph135 ], [ %58, %._crit_edge129 ]
  %.099132 = phi i32 [ 0, %.lr.ph135 ], [ %.1100.lcssa, %._crit_edge129 ]
  %51 = sub nsw i32 %.097133, %.091143
  %52 = call noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %.not109 = icmp slt i32 %32, %52
  br i1 %.not109, label %56, label %53

53:                                               ; preds = %50
  %54 = call noundef i32 @_ZNK6R3Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %55 = add nsw i32 %54, -1
  br label %56

56:                                               ; preds = %53, %50
  %.095 = phi i32 [ %55, %53 ], [ %32, %50 ]
  %.not110124 = icmp sgt i32 %spec.store.select1, %.095
  br i1 %.not110124, label %._crit_edge129, label %.lr.ph128

.lr.ph128:                                        ; preds = %56
  %57 = mul nsw i32 %51, %51
  br label %59

._crit_edge129:                                   ; preds = %._crit_edge, %56
  %.1100.lcssa = phi i32 [ %.099132, %56 ], [ %.2101.lcssa, %._crit_edge ]
  %58 = add nuw nsw i32 %.097133, 1
  %.not107.not = icmp slt i32 %.097133, %.098
  br i1 %.not107.not, label %50, label %._crit_edge136, !llvm.loop !8

59:                                               ; preds = %.lr.ph128, %._crit_edge
  %.094126 = phi i32 [ %spec.store.select1, %.lr.ph128 ], [ %68, %._crit_edge ]
  %.1100125 = phi i32 [ %.099132, %.lr.ph128 ], [ %.2101.lcssa, %._crit_edge ]
  %60 = sub nsw i32 %.094126, %.096141
  %61 = call noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %.not111 = icmp slt i32 %48, %61
  br i1 %.not111, label %65, label %62

62:                                               ; preds = %59
  %63 = call noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %64 = add nsw i32 %63, -1
  br label %65

65:                                               ; preds = %62, %59
  %.093 = phi i32 [ %64, %62 ], [ %48, %59 ]
  %.not112121 = icmp sgt i32 %spec.store.select2, %.093
  br i1 %.not112121, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %65
  %66 = mul nsw i32 %60, %60
  %67 = add nuw nsw i32 %66, %57
  br label %69

._crit_edge:                                      ; preds = %81, %65
  %.2101.lcssa = phi i32 [ %.1100125, %65 ], [ %.3, %81 ]
  %68 = add nuw nsw i32 %.094126, 1
  %.not110.not = icmp slt i32 %.094126, %.095
  br i1 %.not110.not, label %59, label %._crit_edge129, !llvm.loop !9

69:                                               ; preds = %.lr.ph, %81
  %.092123 = phi i32 [ %spec.store.select2, %.lr.ph ], [ %82, %81 ]
  %.2101122 = phi i32 [ %.1100125, %.lr.ph ], [ %.3, %81 ]
  %70 = sub nsw i32 %.092123, %.0102138
  %71 = mul nsw i32 %70, %70
  %72 = add nuw nsw i32 %67, %71
  %73 = uitofp nneg i32 %72 to double
  %74 = fcmp olt double %5, %73
  br i1 %74, label %81, label %75

75:                                               ; preds = %69
  %76 = invoke noundef double @_ZNK6R3Grid9GridValueEiii(ptr noundef nonnull align 8 dereferenceable(592) %4, i32 noundef %.092123, i32 noundef %.094126, i32 noundef %.097133)
          to label %77 unwind label %83

77:                                               ; preds = %75
  %78 = add nsw i32 %.2101122, 1
  %79 = sext i32 %.2101122 to i64
  %80 = getelementptr inbounds double, ptr %20, i64 %79
  store double %76, ptr %80, align 8, !tbaa !10
  br label %81

81:                                               ; preds = %69, %77
  %.3 = phi i32 [ %78, %77 ], [ %.2101122, %69 ]
  %82 = add nuw nsw i32 %.092123, 1
  %.not112.not = icmp slt i32 %.092123, %.093
  br i1 %.not112.not, label %69, label %._crit_edge, !llvm.loop !14

83:                                               ; preds = %75
  %84 = landingpad { ptr, i32 }
          cleanup
  br label %102

._crit_edge136.thread:                            ; preds = %46, %._crit_edge136
  invoke void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %.0102138, i32 noundef %.096141, i32 noundef %.091143, double noundef 0.000000e+00)
          to label %98 unwind label %44

85:                                               ; preds = %._crit_edge136
  %86 = sext i32 %.1100.lcssa to i64
  invoke void @qsort(ptr noundef nonnull %20, i64 noundef %86, i64 noundef 8, ptr noundef nonnull @_Z16RNCompareScalarsPKvS0_)
          to label %87 unwind label %44

87:                                               ; preds = %85
  %88 = sitofp i32 %.1100.lcssa to double
  %89 = fmul double %88, %2
  %90 = fptosi double %89 to i32
  %91 = icmp slt i32 %90, 0
  %.not108 = icmp sgt i32 %.1100.lcssa, %90
  %92 = add nsw i32 %.1100.lcssa, -1
  %spec.select = select i1 %.not108, i32 %90, i32 %92
  %.0 = select i1 %91, i32 0, i32 %spec.select
  %93 = sext i32 %.0 to i64
  %94 = getelementptr inbounds double, ptr %20, i64 %93
  %95 = load double, ptr %94, align 8, !tbaa !10
  invoke void @_ZN6R3Grid12SetGridValueEiiid(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %.0102138, i32 noundef %.096141, i32 noundef %.091143, double noundef %95)
          to label %98 unwind label %96

96:                                               ; preds = %87
  %97 = landingpad { ptr, i32 }
          cleanup
  br label %102

98:                                               ; preds = %87, %._crit_edge136.thread
  %99 = add nuw nsw i32 %.0102138, 1
  %100 = call noundef i32 @_ZNK6R3Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(592) %0)
  %101 = icmp slt i32 %99, %100
  br i1 %101, label %39, label %._crit_edge140, !llvm.loop !15

._crit_edge144:                                   ; preds = %._crit_edge142, %.preheader117
  call void @_ZdaPv(ptr noundef nonnull %20) #11
  call void @_ZN6R3GridD1Ev(ptr noundef nonnull align 8 dereferenceable(592) %4) #9
  call void @llvm.lifetime.end.p0(i64 592, ptr nonnull %4) #9
  ret void

102:                                              ; preds = %23, %96, %83, %44, %9
  %.pn.pn.pn = phi { ptr, i32 } [ %10, %9 ], [ %24, %23 ], [ %84, %83 ], [ %45, %44 ], [ %97, %96 ]
  call void @_ZN6R3GridD1Ev(ptr noundef nonnull align 8 dereferenceable(592) %4) #9
  call void @llvm.lifetime.end.p0(i64 592, ptr nonnull %4) #9
  resume { ptr, i32 } %.pn.pn.pn
}

declare void @_ZN6R3GridC1ERKS_(ptr, ptr) local_unnamed_addr

declare void @_ZN6R3GridD1Ev(ptr) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #8

attributes #0 = { nobuiltin allocsize(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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nobuiltin nounwind "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 = { nofree "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 #5 = { 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 #6 = { inlinehint mustprogress nounwind 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 #7 = { 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 #8 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #9 = { nounwind }
attributes #10 = { builtin allocsize(0) }
attributes #11 = { builtin 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}
!9 = distinct !{!9, !6}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = distinct !{!14, !6}
!15 = distinct !{!15, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass