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

; 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]] }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.13 = 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) #4 align 2

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid16PercentileFilterEdd(ptr noundef nonnull align 8 dereferenceable(208) %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.R2Grid, 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 double, align 8
  %28 = 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
  %29 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 208, ptr %7) #8
  call void @_ZN6R2GridC1ERKS_(ptr noundef nonnull align 8 dereferenceable(208) %7, ptr noundef nonnull align 8 dereferenceable(208) %29)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #8
  %30 = load double, ptr %5, align 8, !tbaa !9
  %31 = load double, ptr %5, align 8, !tbaa !9
  %32 = fmul double %30, %31
  store double %32, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %33 = load double, ptr %5, align 8, !tbaa !9
  %34 = fptosi double %33 to i32
  store i32 %34, ptr %9, align 4, !tbaa !11
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = icmp sge i32 %35, 0
  br i1 %36, label %43, label %37

37:                                               ; preds = %3
  invoke void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.12, i32 noundef 1045, ptr noundef @.str.2)
          to label %38 unwind label %39

38:                                               ; preds = %37
  br label %43

39:                                               ; preds = %37
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %10, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %11, align 4
  br label %264

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

58:                                               ; preds = %43
  store ptr %57, ptr %13, align 8, !tbaa !5
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %67, label %61

61:                                               ; preds = %58
  invoke void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.13, i32 noundef 1048, ptr noundef @.str.2)
          to label %62 unwind label %63

62:                                               ; preds = %61
  br label %67

63:                                               ; preds = %61, %43
  %64 = landingpad { ptr, i32 }
          cleanup
  %65 = extractvalue { ptr, i32 } %64, 0
  store ptr %65, ptr %10, align 8
  %66 = extractvalue { ptr, i32 } %64, 1
  store i32 %66, ptr %11, align 4
  br label %263

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

68:                                               ; preds = %254, %67
  %69 = load i32, ptr %14, align 4, !tbaa !11
  %70 = invoke noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %29)
          to label %71 unwind label %74

71:                                               ; preds = %68
  %72 = icmp slt i32 %69, %70
  br i1 %72, label %78, label %73

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

74:                                               ; preds = %68
  %75 = landingpad { ptr, i32 }
          cleanup
  %76 = extractvalue { ptr, i32 } %75, 0
  store ptr %76, ptr %10, align 8
  %77 = extractvalue { ptr, i32 } %75, 1
  store i32 %77, ptr %11, align 4
  br label %257

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

79:                                               ; preds = %249, %78
  %80 = load i32, ptr %16, align 4, !tbaa !11
  %81 = invoke noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %29)
          to label %82 unwind label %85

82:                                               ; preds = %79
  %83 = icmp slt i32 %80, %81
  br i1 %83, label %89, label %84

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

85:                                               ; preds = %89, %79
  %86 = landingpad { ptr, i32 }
          cleanup
  %87 = extractvalue { ptr, i32 } %86, 0
  store ptr %87, ptr %10, align 8
  %88 = extractvalue { ptr, i32 } %86, 1
  store i32 %88, ptr %11, align 4
  br label %252

89:                                               ; preds = %82
  %90 = load i32, ptr %16, align 4, !tbaa !11
  %91 = load i32, ptr %14, align 4, !tbaa !11
  %92 = invoke noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %29, i32 noundef %90, i32 noundef %91)
          to label %93 unwind label %85

93:                                               ; preds = %89
  %94 = fcmp une double %92, -3.210000e+02
  br i1 %94, label %95, label %248

95:                                               ; preds = %93
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #8
  store i32 0, ptr %17, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #8
  %96 = load i32, ptr %14, align 4, !tbaa !11
  %97 = load i32, ptr %9, align 4, !tbaa !11
  %98 = sub nsw i32 %96, %97
  store i32 %98, ptr %18, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #8
  %99 = load i32, ptr %14, align 4, !tbaa !11
  %100 = load i32, ptr %9, align 4, !tbaa !11
  %101 = add nsw i32 %99, %100
  store i32 %101, ptr %19, align 4, !tbaa !11
  %102 = load i32, ptr %18, align 4, !tbaa !11
  %103 = icmp slt i32 %102, 0
  br i1 %103, label %104, label %105

104:                                              ; preds = %95
  store i32 0, ptr %18, align 4, !tbaa !11
  br label %105

105:                                              ; preds = %104, %95
  %106 = load i32, ptr %19, align 4, !tbaa !11
  %107 = invoke noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %29)
          to label %108 unwind label %114

108:                                              ; preds = %105
  %109 = icmp sge i32 %106, %107
  br i1 %109, label %110, label %118

110:                                              ; preds = %108
  %111 = invoke noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %29)
          to label %112 unwind label %114

112:                                              ; preds = %110
  %113 = sub nsw i32 %111, 1
  store i32 %113, ptr %19, align 4, !tbaa !11
  br label %118

114:                                              ; preds = %212, %208, %110, %105
  %115 = landingpad { ptr, i32 }
          cleanup
  %116 = extractvalue { ptr, i32 } %115, 0
  store ptr %116, ptr %10, align 8
  %117 = extractvalue { ptr, i32 } %115, 1
  store i32 %117, ptr %11, align 4
  br label %247

118:                                              ; preds = %112, %108
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #8
  %119 = load i32, ptr %18, align 4, !tbaa !11
  store i32 %119, ptr %20, align 4, !tbaa !11
  br label %120

120:                                              ; preds = %201, %118
  %121 = load i32, ptr %20, align 4, !tbaa !11
  %122 = load i32, ptr %19, align 4, !tbaa !11
  %123 = icmp sle i32 %121, %122
  br i1 %123, label %125, label %124

124:                                              ; preds = %120
  store i32 8, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #8
  br label %205

125:                                              ; preds = %120
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #8
  %126 = load i32, ptr %16, align 4, !tbaa !11
  %127 = load i32, ptr %9, align 4, !tbaa !11
  %128 = sub nsw i32 %126, %127
  store i32 %128, ptr %21, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #8
  %129 = load i32, ptr %16, align 4, !tbaa !11
  %130 = load i32, ptr %9, align 4, !tbaa !11
  %131 = add nsw i32 %129, %130
  store i32 %131, ptr %22, align 4, !tbaa !11
  %132 = load i32, ptr %21, align 4, !tbaa !11
  %133 = icmp slt i32 %132, 0
  br i1 %133, label %134, label %135

134:                                              ; preds = %125
  store i32 0, ptr %21, align 4, !tbaa !11
  br label %135

135:                                              ; preds = %134, %125
  %136 = load i32, ptr %22, align 4, !tbaa !11
  %137 = invoke noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %29)
          to label %138 unwind label %144

138:                                              ; preds = %135
  %139 = icmp sge i32 %136, %137
  br i1 %139, label %140, label %148

140:                                              ; preds = %138
  %141 = invoke noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %29)
          to label %142 unwind label %144

142:                                              ; preds = %140
  %143 = sub nsw i32 %141, 1
  store i32 %143, ptr %22, align 4, !tbaa !11
  br label %148

144:                                              ; preds = %140, %135
  %145 = landingpad { ptr, i32 }
          cleanup
  %146 = extractvalue { ptr, i32 } %145, 0
  store ptr %146, ptr %10, align 8
  %147 = extractvalue { ptr, i32 } %145, 1
  store i32 %147, ptr %11, align 4
  br label %204

148:                                              ; preds = %142, %138
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #8
  %149 = load i32, ptr %20, align 4, !tbaa !11
  %150 = load i32, ptr %14, align 4, !tbaa !11
  %151 = sub nsw i32 %149, %150
  store i32 %151, ptr %23, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #8
  %152 = load i32, ptr %21, align 4, !tbaa !11
  store i32 %152, ptr %24, align 4, !tbaa !11
  br label %153

153:                                              ; preds = %197, %148
  %154 = load i32, ptr %24, align 4, !tbaa !11
  %155 = load i32, ptr %22, align 4, !tbaa !11
  %156 = icmp sle i32 %154, %155
  br i1 %156, label %158, label %157

157:                                              ; preds = %153
  store i32 11, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #8
  br label %200

158:                                              ; preds = %153
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #8
  %159 = load i32, ptr %24, align 4, !tbaa !11
  %160 = load i32, ptr %16, align 4, !tbaa !11
  %161 = sub nsw i32 %159, %160
  store i32 %161, ptr %25, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #8
  %162 = load i32, ptr %25, align 4, !tbaa !11
  %163 = load i32, ptr %25, align 4, !tbaa !11
  %164 = mul nsw i32 %162, %163
  %165 = load i32, ptr %23, align 4, !tbaa !11
  %166 = load i32, ptr %23, align 4, !tbaa !11
  %167 = mul nsw i32 %165, %166
  %168 = add nsw i32 %164, %167
  store i32 %168, ptr %26, align 4, !tbaa !11
  %169 = load i32, ptr %26, align 4, !tbaa !11
  %170 = sitofp i32 %169 to double
  %171 = load double, ptr %8, align 8, !tbaa !9
  %172 = fcmp ogt double %170, %171
  br i1 %172, label %173, label %174

173:                                              ; preds = %158
  store i32 13, ptr %15, align 4
  br label %194

174:                                              ; preds = %158
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #8
  %175 = load i32, ptr %24, align 4, !tbaa !11
  %176 = load i32, ptr %20, align 4, !tbaa !11
  %177 = invoke noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %7, i32 noundef %175, i32 noundef %176)
          to label %178 unwind label %182

178:                                              ; preds = %174
  store double %177, ptr %27, align 8, !tbaa !9
  %179 = load double, ptr %27, align 8, !tbaa !9
  %180 = fcmp oeq double %179, -3.210000e+02
  br i1 %180, label %181, label %186

181:                                              ; preds = %178
  store i32 13, ptr %15, align 4
  br label %193

182:                                              ; preds = %174
  %183 = landingpad { ptr, i32 }
          cleanup
  %184 = extractvalue { ptr, i32 } %183, 0
  store ptr %184, ptr %10, align 8
  %185 = extractvalue { ptr, i32 } %183, 1
  store i32 %185, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #8
  br label %204

186:                                              ; preds = %178
  %187 = load double, ptr %27, align 8, !tbaa !9
  %188 = load ptr, ptr %13, align 8, !tbaa !5
  %189 = load i32, ptr %17, align 4, !tbaa !11
  %190 = add nsw i32 %189, 1
  store i32 %190, ptr %17, align 4, !tbaa !11
  %191 = sext i32 %189 to i64
  %192 = getelementptr inbounds double, ptr %188, i64 %191
  store double %187, ptr %192, align 8, !tbaa !9
  store i32 0, ptr %15, align 4
  br label %193

193:                                              ; preds = %186, %181
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #8
  br label %194

194:                                              ; preds = %193, %173
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #8
  %195 = load i32, ptr %15, align 4
  switch i32 %195, label %270 [
    i32 0, label %196
    i32 13, label %197
  ]

196:                                              ; preds = %194
  br label %197

197:                                              ; preds = %196, %194
  %198 = load i32, ptr %24, align 4, !tbaa !11
  %199 = add nsw i32 %198, 1
  store i32 %199, ptr %24, align 4, !tbaa !11
  br label %153, !llvm.loop !13

200:                                              ; preds = %157
  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 %201

201:                                              ; preds = %200
  %202 = load i32, ptr %20, align 4, !tbaa !11
  %203 = add nsw i32 %202, 1
  store i32 %203, ptr %20, align 4, !tbaa !11
  br label %120, !llvm.loop !15

204:                                              ; preds = %182, %144
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #8
  br label %247

205:                                              ; preds = %124
  %206 = load i32, ptr %17, align 4, !tbaa !11
  %207 = icmp eq i32 %206, 0
  br i1 %207, label %208, label %212

208:                                              ; preds = %205
  %209 = load i32, ptr %16, align 4, !tbaa !11
  %210 = load i32, ptr %14, align 4, !tbaa !11
  invoke void @_ZN6R2Grid12SetGridValueEiid(ptr noundef nonnull align 8 dereferenceable(208) %29, i32 noundef %209, i32 noundef %210, double noundef -3.210000e+02)
          to label %211 unwind label %114

211:                                              ; preds = %208
  br label %246

212:                                              ; preds = %205
  %213 = load ptr, ptr %13, align 8, !tbaa !5
  %214 = load i32, ptr %17, align 4, !tbaa !11
  %215 = sext i32 %214 to i64
  invoke void @qsort(ptr noundef %213, i64 noundef %215, i64 noundef 8, ptr noundef @_Z16RNCompareScalarsPKvS0_)
          to label %216 unwind label %114

216:                                              ; preds = %212
  call void @llvm.lifetime.start.p0(i64 4, ptr %28) #8
  %217 = load double, ptr %6, align 8, !tbaa !9
  %218 = load i32, ptr %17, align 4, !tbaa !11
  %219 = sitofp i32 %218 to double
  %220 = fmul double %217, %219
  %221 = fptosi double %220 to i32
  store i32 %221, ptr %28, align 4, !tbaa !11
  %222 = load i32, ptr %28, align 4, !tbaa !11
  %223 = icmp slt i32 %222, 0
  br i1 %223, label %224, label %225

224:                                              ; preds = %216
  store i32 0, ptr %28, align 4, !tbaa !11
  br label %233

225:                                              ; preds = %216
  %226 = load i32, ptr %28, align 4, !tbaa !11
  %227 = load i32, ptr %17, align 4, !tbaa !11
  %228 = icmp sge i32 %226, %227
  br i1 %228, label %229, label %232

229:                                              ; preds = %225
  %230 = load i32, ptr %17, align 4, !tbaa !11
  %231 = sub nsw i32 %230, 1
  store i32 %231, ptr %28, align 4, !tbaa !11
  br label %232

232:                                              ; preds = %229, %225
  br label %233

233:                                              ; preds = %232, %224
  %234 = load i32, ptr %16, align 4, !tbaa !11
  %235 = load i32, ptr %14, align 4, !tbaa !11
  %236 = load ptr, ptr %13, align 8, !tbaa !5
  %237 = load i32, ptr %28, align 4, !tbaa !11
  %238 = sext i32 %237 to i64
  %239 = getelementptr inbounds double, ptr %236, i64 %238
  %240 = load double, ptr %239, align 8, !tbaa !9
  invoke void @_ZN6R2Grid12SetGridValueEiid(ptr noundef nonnull align 8 dereferenceable(208) %29, i32 noundef %234, i32 noundef %235, double noundef %240)
          to label %241 unwind label %242

241:                                              ; preds = %233
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #8
  br label %246

242:                                              ; preds = %233
  %243 = landingpad { ptr, i32 }
          cleanup
  %244 = extractvalue { ptr, i32 } %243, 0
  store ptr %244, ptr %10, align 8
  %245 = extractvalue { ptr, i32 } %243, 1
  store i32 %245, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #8
  br label %247

246:                                              ; preds = %241, %211
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  br label %248

247:                                              ; preds = %242, %204, %114
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  br label %252

248:                                              ; preds = %246, %93
  br label %249

249:                                              ; preds = %248
  %250 = load i32, ptr %16, align 4, !tbaa !11
  %251 = add nsw i32 %250, 1
  store i32 %251, ptr %16, align 4, !tbaa !11
  br label %79, !llvm.loop !16

252:                                              ; preds = %247, %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  br label %257

253:                                              ; preds = %84
  br label %254

254:                                              ; preds = %253
  %255 = load i32, ptr %14, align 4, !tbaa !11
  %256 = add nsw i32 %255, 1
  store i32 %256, ptr %14, align 4, !tbaa !11
  br label %68, !llvm.loop !17

257:                                              ; preds = %252, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  br label %263

258:                                              ; preds = %73
  %259 = load ptr, ptr %13, align 8, !tbaa !5
  %260 = icmp eq ptr %259, null
  br i1 %260, label %262, label %261

261:                                              ; preds = %258
  call void @_ZdaPv(ptr noundef %259) #10
  br label %262

262:                                              ; preds = %261, %258
  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 @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %7) #8
  call void @llvm.lifetime.end.p0(i64 208, ptr %7) #8
  ret void

263:                                              ; preds = %257, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  br label %264

264:                                              ; preds = %263, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %7) #8
  call void @llvm.lifetime.end.p0(i64 208, ptr %7) #8
  br label %265

265:                                              ; preds = %264
  %266 = load ptr, ptr %10, align 8
  %267 = load i32, ptr %11, align 4
  %268 = insertvalue { ptr, i32 } poison, ptr %266, 0
  %269 = insertvalue { ptr, i32 } %268, i32 %267, 1
  resume { ptr, i32 } %269

270:                                              ; preds = %194
  unreachable
}

declare void @_ZN6R2GridC1ERKS_(ptr, ptr)

declare void @_ZN6R2GridD1Ev(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 = { 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 #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 = { 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 #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}


; 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.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]] }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.12 = 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #3 align 2

; 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 #4 align 2

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2Grid16PercentileFilterEdd(ptr noundef nonnull align 8 dereferenceable(208) %0, double noundef %1, double noundef %2) local_unnamed_addr #7 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %class.R2Grid, align 8
  call void @llvm.lifetime.start.p0(i64 208, ptr nonnull %4) #9
  call void @_ZN6R2GridC1ERKS_(ptr noundef nonnull align 8 dereferenceable(208) %4, ptr noundef nonnull align 8 dereferenceable(208) %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.12, i32 noundef 1045, ptr noundef nonnull @.str.2)
          to label %11 unwind label %9

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

11:                                               ; preds = %8, %3
  %12 = shl nsw i32 %6, 1
  %13 = or disjoint i32 %12, 1
  %14 = mul nsw i32 %13, %13
  %15 = zext nneg i32 %14 to i64
  %16 = shl nuw nsw i64 %15, 3
  %17 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %16) #10
          to label %.preheader96 unwind label %20

.preheader96:                                     ; preds = %11
  %18 = call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.preheader, label %._crit_edge113

20:                                               ; preds = %11
  %21 = landingpad { ptr, i32 }
          cleanup
  br label %90

.preheader:                                       ; preds = %.preheader96, %._crit_edge111
  %.074112 = phi i32 [ %26, %._crit_edge111 ], [ 0, %.preheader96 ]
  %22 = call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph110, label %._crit_edge111

.lr.ph110:                                        ; preds = %.preheader
  %24 = sub nsw i32 %.074112, %6
  %25 = add nsw i32 %.074112, %6
  %spec.store.select = call i32 @llvm.smax.i32(i32 %24, i32 0)
  br label %31

._crit_edge111:                                   ; preds = %86, %.preheader
  %26 = add nuw nsw i32 %.074112, 1
  %27 = call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %.preheader, label %._crit_edge113, !llvm.loop !5

29:                                               ; preds = %31
  %30 = landingpad { ptr, i32 }
          cleanup
  br label %90

31:                                               ; preds = %.lr.ph110, %86
  %.083109 = phi i32 [ 0, %.lr.ph110 ], [ %87, %86 ]
  %32 = invoke noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %.083109, i32 noundef %.074112)
          to label %33 unwind label %29

33:                                               ; preds = %31
  %34 = fcmp une double %32, -3.210000e+02
  br i1 %34, label %35, label %86

35:                                               ; preds = %33
  %36 = call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %.not = icmp slt i32 %25, %36
  br i1 %.not, label %42, label %37

37:                                               ; preds = %35
  %38 = call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %39 = add nsw i32 %38, -1
  br label %42

40:                                               ; preds = %73, %._crit_edge107.thread
  %41 = landingpad { ptr, i32 }
          cleanup
  br label %90

42:                                               ; preds = %37, %35
  %.078 = phi i32 [ %39, %37 ], [ %25, %35 ]
  %.not88102 = icmp sgt i32 %spec.store.select, %.078
  br i1 %.not88102, label %._crit_edge107.thread, label %.lr.ph106

.lr.ph106:                                        ; preds = %42
  %43 = sub nsw i32 %.083109, %6
  %44 = add nsw i32 %.083109, %6
  %spec.store.select1 = call i32 @llvm.smax.i32(i32 %43, i32 0)
  br label %46

._crit_edge107:                                   ; preds = %._crit_edge
  %45 = icmp eq i32 %.180.lcssa, 0
  br i1 %45, label %._crit_edge107.thread, label %73

46:                                               ; preds = %.lr.ph106, %._crit_edge
  %.077104 = phi i32 [ %spec.store.select, %.lr.ph106 ], [ %54, %._crit_edge ]
  %.079103 = phi i32 [ 0, %.lr.ph106 ], [ %.180.lcssa, %._crit_edge ]
  %47 = call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %.not90 = icmp slt i32 %44, %47
  br i1 %.not90, label %51, label %48

48:                                               ; preds = %46
  %49 = call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %50 = add nsw i32 %49, -1
  br label %51

51:                                               ; preds = %48, %46
  %.076 = phi i32 [ %50, %48 ], [ %44, %46 ]
  %.not9199 = icmp sgt i32 %spec.store.select1, %.076
  br i1 %.not9199, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %51
  %52 = sub nsw i32 %.077104, %.074112
  %53 = mul nsw i32 %52, %52
  br label %55

._crit_edge:                                      ; preds = %71, %51
  %.180.lcssa = phi i32 [ %.079103, %51 ], [ %.382, %71 ]
  %54 = add nuw nsw i32 %.077104, 1
  %.not88.not = icmp slt i32 %.077104, %.078
  br i1 %.not88.not, label %46, label %._crit_edge107, !llvm.loop !7

55:                                               ; preds = %.lr.ph, %71
  %.075101 = phi i32 [ %spec.store.select1, %.lr.ph ], [ %72, %71 ]
  %.180100 = phi i32 [ %.079103, %.lr.ph ], [ %.382, %71 ]
  %56 = sub nsw i32 %.075101, %.083109
  %57 = mul nsw i32 %56, %56
  %58 = add nuw nsw i32 %57, %53
  %59 = uitofp nneg i32 %58 to double
  %60 = fcmp olt double %5, %59
  br i1 %60, label %71, label %61

61:                                               ; preds = %55
  %62 = invoke noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %4, i32 noundef %.075101, i32 noundef %.077104)
          to label %63 unwind label %65

63:                                               ; preds = %61
  %64 = fcmp oeq double %62, -3.210000e+02
  br i1 %64, label %71, label %67

65:                                               ; preds = %61
  %66 = landingpad { ptr, i32 }
          cleanup
  br label %90

67:                                               ; preds = %63
  %68 = add nsw i32 %.180100, 1
  %69 = sext i32 %.180100 to i64
  %70 = getelementptr inbounds double, ptr %17, i64 %69
  store double %62, ptr %70, align 8, !tbaa !8
  br label %71

71:                                               ; preds = %67, %63, %55
  %.382 = phi i32 [ %.180100, %55 ], [ %68, %67 ], [ %.180100, %63 ]
  %72 = add nuw nsw i32 %.075101, 1
  %.not91.not = icmp slt i32 %.075101, %.076
  br i1 %.not91.not, label %55, label %._crit_edge, !llvm.loop !12

._crit_edge107.thread:                            ; preds = %42, %._crit_edge107
  invoke void @_ZN6R2Grid12SetGridValueEiid(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %.083109, i32 noundef %.074112, double noundef -3.210000e+02)
          to label %86 unwind label %40

73:                                               ; preds = %._crit_edge107
  %74 = sext i32 %.180.lcssa to i64
  invoke void @qsort(ptr noundef nonnull %17, i64 noundef %74, i64 noundef 8, ptr noundef nonnull @_Z16RNCompareScalarsPKvS0_)
          to label %75 unwind label %40

75:                                               ; preds = %73
  %76 = sitofp i32 %.180.lcssa to double
  %77 = fmul double %76, %2
  %78 = fptosi double %77 to i32
  %79 = icmp slt i32 %78, 0
  %.not89 = icmp sgt i32 %.180.lcssa, %78
  %80 = add nsw i32 %.180.lcssa, -1
  %spec.select = select i1 %.not89, i32 %78, i32 %80
  %.0 = select i1 %79, i32 0, i32 %spec.select
  %81 = sext i32 %.0 to i64
  %82 = getelementptr inbounds double, ptr %17, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !8
  invoke void @_ZN6R2Grid12SetGridValueEiid(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %.083109, i32 noundef %.074112, double noundef %83)
          to label %86 unwind label %84

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

86:                                               ; preds = %._crit_edge107.thread, %75, %33
  %87 = add nuw nsw i32 %.083109, 1
  %88 = call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %89 = icmp slt i32 %87, %88
  br i1 %89, label %31, label %._crit_edge111, !llvm.loop !13

._crit_edge113:                                   ; preds = %._crit_edge111, %.preheader96
  call void @_ZdaPv(ptr noundef nonnull %17) #11
  call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %4) #9
  call void @llvm.lifetime.end.p0(i64 208, ptr nonnull %4) #9
  ret void

90:                                               ; preds = %20, %40, %65, %84, %29, %9
  %.pn.pn.pn.pn = phi { ptr, i32 } [ %10, %9 ], [ %21, %20 ], [ %30, %29 ], [ %66, %65 ], [ %41, %40 ], [ %85, %84 ]
  call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %4) #9
  call void @llvm.lifetime.end.p0(i64 208, ptr nonnull %4) #9
  resume { ptr, i32 } %.pn.pn.pn.pn
}

declare void @_ZN6R2GridC1ERKS_(ptr, ptr) local_unnamed_addr

declare void @_ZN6R2GridD1Ev(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 = { 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 #4 = { 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 #5 = { 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 #6 = { 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 #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 = !{!9, !9, i64 0}
!9 = !{!"double", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = distinct !{!12, !6}
!13 = distinct !{!13, !6}


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