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

; 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.R2Vector = type { [2 x double] }
%class.R2Polygon = type <{ %class.R2Solid, ptr, i32, [4 x i8], %class.R2Box, i32, [4 x i8] }>
%class.R2Solid = type { %class.R2Shape }
%class.R2Shape = type { ptr }
%class.R2Box = type { %class.R2Solid, %class.R2Point, %class.R2Point }
%class.R2Point = type { [2 x double] }

@RN_EPSILON = external global double, align 8
@RN_PI = external constant double, align 8

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

declare noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2

declare void @_ZmiRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Vector) align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #3 align 2

declare noundef double @_ZNK8R2Vector6LengthEv(ptr noundef nonnull align 8 dereferenceable(16)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8RNIsZerodd(double noundef, double noundef) #3

declare noundef double @_Z15R2InteriorAngleRK8R2VectorS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK9R2Polygon9CurvatureEid(ptr noundef nonnull align 8 dereferenceable(68) %0, i32 noundef %1, double noundef %2) #4 align 2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca double, align 8
  %16 = alloca i32, align 4
  %17 = alloca %class.R2Vector, align 8
  %18 = alloca %class.R2Vector, 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 double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !11
  %25 = load ptr, ptr %5, align 8
  %26 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = icmp slt i32 %27, 3
  br i1 %28, label %29, label %30

29:                                               ; preds = %3
  store double 0.000000e+00, ptr %4, align 8
  br label %217

30:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %31 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  %35 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !13
  %37 = add nsw i32 %34, %36
  %38 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !13
  %40 = srem i32 %37, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %class.R2Point, ptr %32, i64 %41
  store ptr %42, ptr %8, align 8, !tbaa !5
  %43 = load double, ptr %7, align 8, !tbaa !11
  %44 = fcmp ogt double %43, 0.000000e+00
  br i1 %44, label %45, label %96

45:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %46, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !19
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds %class.R2Point, ptr %49, i64 %51
  %53 = call noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16) %47, ptr noundef nonnull align 8 dereferenceable(16) %52)
  store double %53, ptr %10, align 8, !tbaa !11
  %54 = load double, ptr %10, align 8, !tbaa !11
  %55 = load double, ptr %7, align 8, !tbaa !11
  %56 = fcmp olt double %54, %55
  br i1 %56, label %57, label %95

57:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 2, ptr %11, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %90, %57
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %61 = load i32, ptr %60, align 8, !tbaa !13
  %62 = sdiv i32 %61, 3
  %63 = icmp slt i32 %59, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %58
  store i32 2, ptr %12, align 4
  br label %93

65:                                               ; preds = %58
  %66 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = sub nsw i32 %68, %69
  %71 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %72 = load i32, ptr %71, align 8, !tbaa !13
  %73 = add nsw i32 %70, %72
  %74 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %75 = load i32, ptr %74, align 8, !tbaa !13
  %76 = srem i32 %73, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds %class.R2Point, ptr %67, i64 %77
  store ptr %78, ptr %8, align 8, !tbaa !5
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = call noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16) %79, ptr noundef nonnull align 8 dereferenceable(16) %80)
  %82 = load double, ptr %10, align 8, !tbaa !11
  %83 = fadd double %82, %81
  store double %83, ptr %10, align 8, !tbaa !11
  %84 = load double, ptr %10, align 8, !tbaa !11
  %85 = load double, ptr %7, align 8, !tbaa !11
  %86 = fcmp oge double %84, %85
  br i1 %86, label %87, label %88

87:                                               ; preds = %65
  store i32 2, ptr %12, align 4
  br label %93

88:                                               ; preds = %65
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %89, ptr %9, align 8, !tbaa !5
  br label %90

90:                                               ; preds = %88
  %91 = load i32, ptr %11, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %11, align 4, !tbaa !9
  br label %58, !llvm.loop !20

93:                                               ; preds = %87, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %96

96:                                               ; preds = %95, %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %97 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 1
  %98 = load ptr, ptr %97, align 8, !tbaa !19
  %99 = load i32, ptr %6, align 4, !tbaa !9
  %100 = add nsw i32 %99, 1
  %101 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %102 = load i32, ptr %101, align 8, !tbaa !13
  %103 = srem i32 %100, %102
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds %class.R2Point, ptr %98, i64 %104
  store ptr %105, ptr %13, align 8, !tbaa !5
  %106 = load double, ptr %7, align 8, !tbaa !11
  %107 = fcmp ogt double %106, 0.000000e+00
  br i1 %107, label %108, label %156

108:                                              ; preds = %96
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %109 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %109, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %110 = load ptr, ptr %13, align 8, !tbaa !5
  %111 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 1
  %112 = load ptr, ptr %111, align 8, !tbaa !19
  %113 = load i32, ptr %6, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds %class.R2Point, ptr %112, i64 %114
  %116 = call noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16) %110, ptr noundef nonnull align 8 dereferenceable(16) %115)
  store double %116, ptr %15, align 8, !tbaa !11
  %117 = load double, ptr %15, align 8, !tbaa !11
  %118 = load double, ptr %7, align 8, !tbaa !11
  %119 = fcmp olt double %117, %118
  br i1 %119, label %120, label %155

120:                                              ; preds = %108
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  store i32 2, ptr %16, align 4, !tbaa !9
  br label %121

121:                                              ; preds = %150, %120
  %122 = load i32, ptr %16, align 4, !tbaa !9
  %123 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %124 = load i32, ptr %123, align 8, !tbaa !13
  %125 = sdiv i32 %124, 3
  %126 = icmp slt i32 %122, %125
  br i1 %126, label %128, label %127

127:                                              ; preds = %121
  store i32 5, ptr %12, align 4
  br label %153

128:                                              ; preds = %121
  %129 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 1
  %130 = load ptr, ptr %129, align 8, !tbaa !19
  %131 = load i32, ptr %6, align 4, !tbaa !9
  %132 = load i32, ptr %16, align 4, !tbaa !9
  %133 = add nsw i32 %131, %132
  %134 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 2
  %135 = load i32, ptr %134, align 8, !tbaa !13
  %136 = srem i32 %133, %135
  %137 = sext i32 %136 to i64
  %138 = getelementptr inbounds %class.R2Point, ptr %130, i64 %137
  store ptr %138, ptr %13, align 8, !tbaa !5
  %139 = load ptr, ptr %13, align 8, !tbaa !5
  %140 = load ptr, ptr %14, align 8, !tbaa !5
  %141 = call noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16) %139, ptr noundef nonnull align 8 dereferenceable(16) %140)
  %142 = load double, ptr %15, align 8, !tbaa !11
  %143 = fadd double %142, %141
  store double %143, ptr %15, align 8, !tbaa !11
  %144 = load double, ptr %15, align 8, !tbaa !11
  %145 = load double, ptr %7, align 8, !tbaa !11
  %146 = fcmp oge double %144, %145
  br i1 %146, label %147, label %148

147:                                              ; preds = %128
  store i32 5, ptr %12, align 4
  br label %153

148:                                              ; preds = %128
  %149 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %149, ptr %14, align 8, !tbaa !5
  br label %150

150:                                              ; preds = %148
  %151 = load i32, ptr %16, align 4, !tbaa !9
  %152 = add nsw i32 %151, 1
  store i32 %152, ptr %16, align 4, !tbaa !9
  br label %121, !llvm.loop !22

153:                                              ; preds = %147, %127
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  br label %154

154:                                              ; preds = %153
  br label %155

155:                                              ; preds = %154, %108
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %156

156:                                              ; preds = %155, %96
  call void @llvm.lifetime.start.p0(i64 16, ptr %17) #5
  %157 = load ptr, ptr %8, align 8, !tbaa !5
  %158 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 1
  %159 = load ptr, ptr %158, align 8, !tbaa !19
  %160 = load i32, ptr %6, align 4, !tbaa !9
  %161 = sext i32 %160 to i64
  %162 = getelementptr inbounds %class.R2Point, ptr %159, i64 %161
  call void @_ZmiRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Vector) align 8 %17, ptr noundef nonnull align 8 dereferenceable(16) %157, ptr noundef nonnull align 8 dereferenceable(16) %162)
  call void @llvm.lifetime.start.p0(i64 16, ptr %18) #5
  %163 = load ptr, ptr %13, align 8, !tbaa !5
  %164 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 1
  %165 = load ptr, ptr %164, align 8, !tbaa !19
  %166 = load i32, ptr %6, align 4, !tbaa !9
  %167 = sext i32 %166 to i64
  %168 = getelementptr inbounds %class.R2Point, ptr %165, i64 %167
  call void @_ZmiRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Vector) align 8 %18, ptr noundef nonnull align 8 dereferenceable(16) %163, ptr noundef nonnull align 8 dereferenceable(16) %168)
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %169 = call noundef double @_ZNK8R2Vector6LengthEv(ptr noundef nonnull align 8 dereferenceable(16) %17)
  store double %169, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %170 = call noundef double @_ZNK8R2Vector6LengthEv(ptr noundef nonnull align 8 dereferenceable(16) %18)
  store double %170, ptr %20, align 8, !tbaa !11
  %171 = load double, ptr %19, align 8, !tbaa !11
  %172 = load double, ptr @RN_EPSILON, align 8, !tbaa !11
  %173 = call noundef i32 @_Z8RNIsZerodd(double noundef %171, double noundef %172)
  %174 = icmp ne i32 %173, 0
  br i1 %174, label %180, label %175

175:                                              ; preds = %156
  %176 = load double, ptr %20, align 8, !tbaa !11
  %177 = load double, ptr @RN_EPSILON, align 8, !tbaa !11
  %178 = call noundef i32 @_Z8RNIsZerodd(double noundef %176, double noundef %177)
  %179 = icmp ne i32 %178, 0
  br i1 %179, label %180, label %181

180:                                              ; preds = %175, %156
  store double -1.000000e+00, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %216

181:                                              ; preds = %175
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %182 = call noundef double @_Z15R2InteriorAngleRK8R2VectorS1_(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef nonnull align 8 dereferenceable(16) %18)
  store double %182, ptr %21, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  %183 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16) %17, i32 noundef 0)
  %184 = load double, ptr %183, align 8, !tbaa !11
  %185 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16) %18, i32 noundef 1)
  %186 = load double, ptr %185, align 8, !tbaa !11
  %187 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16) %17, i32 noundef 1)
  %188 = load double, ptr %187, align 8, !tbaa !11
  %189 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16) %18, i32 noundef 0)
  %190 = load double, ptr %189, align 8, !tbaa !11
  %191 = fmul double %188, %190
  %192 = fneg double %191
  %193 = call double @llvm.fmuladd.f64(double %184, double %186, double %192)
  store double %193, ptr %22, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #5
  %194 = load double, ptr %22, align 8, !tbaa !11
  %195 = fcmp ogt double %194, 0.000000e+00
  %196 = zext i1 %195 to i64
  %197 = select i1 %195, i32 -1, i32 1
  %198 = sitofp i32 %197 to double
  store double %198, ptr %23, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #5
  %199 = load double, ptr %23, align 8, !tbaa !11
  %200 = load double, ptr @RN_PI, align 8, !tbaa !11
  %201 = load double, ptr %21, align 8, !tbaa !11
  %202 = fsub double %200, %201
  %203 = fmul double %199, %202
  %204 = load double, ptr %19, align 8, !tbaa !11
  %205 = load double, ptr %20, align 8, !tbaa !11
  %206 = fadd double %204, %205
  %207 = fdiv double %203, %206
  store double %207, ptr %24, align 8, !tbaa !11
  %208 = getelementptr inbounds %class.R2Polygon, ptr %25, i32 0, i32 5
  %209 = load i32, ptr %208, align 8, !tbaa !23
  %210 = icmp ne i32 %209, 0
  br i1 %210, label %211, label %214

211:                                              ; preds = %181
  %212 = load double, ptr %24, align 8, !tbaa !11
  %213 = fneg double %212
  store double %213, ptr %24, align 8, !tbaa !11
  br label %214

214:                                              ; preds = %211, %181
  %215 = load double, ptr %24, align 8, !tbaa !11
  store double %215, ptr %4, align 8
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  br label %216

216:                                              ; preds = %214, %180
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %217

217:                                              ; preds = %216, %29
  %218 = load double, ptr %4, align 8
  ret double %218
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 #4 = { 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"_ZTS9R2Polygon", !15, i64 0, !6, i64 8, !10, i64 16, !17, i64 24, !10, i64 64}
!15 = !{!"_ZTS7R2Solid", !16, i64 0}
!16 = !{!"_ZTS7R2Shape"}
!17 = !{!"_ZTS5R2Box", !15, i64 0, !18, i64 8, !18, i64 24}
!18 = !{!"_ZTS7R2Point", !7, i64 0}
!19 = !{!14, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}
!23 = !{!14, !10, i64 64}


; 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.R2Vector = type { [2 x double] }
%class.R2Point = type { [2 x double] }

@RN_EPSILON = external local_unnamed_addr global double, align 8
@RN_PI = external local_unnamed_addr constant double, align 8

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

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

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

declare noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

declare void @_ZmiRK7R2PointS1_(ptr dead_on_unwind writable sret(%class.R2Vector) align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #3 align 2

declare noundef double @_ZNK8R2Vector6LengthEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8RNIsZerodd(double noundef, double noundef) local_unnamed_addr #3

declare noundef double @_Z15R2InteriorAngleRK8R2VectorS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK9R2Polygon9CurvatureEid(ptr nocapture noundef nonnull readonly align 8 dereferenceable(68) %0, i32 noundef %1, double noundef %2) local_unnamed_addr #4 align 2 {
  %4 = alloca %class.R2Vector, align 8
  %5 = alloca %class.R2Vector, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp slt i32 %7, 3
  br i1 %8, label %106, label %9

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = add nsw i32 %1, -1
  %13 = add nsw i32 %12, %7
  %14 = srem i32 %13, %7
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds %class.R2Point, ptr %11, i64 %15
  %17 = fcmp ogt double %2, 0.000000e+00
  br i1 %17, label %22, label %.thread73

.thread73:                                        ; preds = %9
  %18 = add nsw i32 %1, 1
  %19 = srem i32 %18, %7
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %class.R2Point, ptr %11, i64 %20
  %.pre = sext i32 %1 to i64
  br label %.loopexit

22:                                               ; preds = %9
  %23 = sext i32 %1 to i64
  %24 = getelementptr inbounds %class.R2Point, ptr %11, i64 %23
  %25 = tail call noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16) %16, ptr noundef nonnull align 8 dereferenceable(16) %24)
  %26 = fcmp olt double %25, %2
  br i1 %26, label %.preheader75, label %.thread

.preheader75:                                     ; preds = %22
  %27 = load i32, ptr %6, align 8, !tbaa !5
  %28 = icmp sgt i32 %27, 8
  br i1 %28, label %.lr.ph, label %._crit_edge

.thread:                                          ; preds = %22
  %29 = add nsw i32 %1, 1
  %30 = load i32, ptr %6, align 8, !tbaa !5
  %31 = srem i32 %29, %30
  br label %49

32:                                               ; preds = %.lr.ph
  %33 = add nuw nsw i32 %.05376, 1
  %34 = sdiv i32 %.pre.pre, 3
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader75, %32
  %36 = phi i32 [ %.pre.pre, %32 ], [ %27, %.preheader75 ]
  %.04978 = phi ptr [ %42, %32 ], [ %16, %.preheader75 ]
  %.05277 = phi double [ %44, %32 ], [ %25, %.preheader75 ]
  %.05376 = phi i32 [ %33, %32 ], [ 2, %.preheader75 ]
  %37 = load ptr, ptr %10, align 8, !tbaa !15
  %38 = sub i32 %1, %.05376
  %39 = add nsw i32 %38, %36
  %40 = srem i32 %39, %36
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %class.R2Point, ptr %37, i64 %41
  %43 = tail call noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16) %42, ptr noundef nonnull align 8 dereferenceable(16) %.04978)
  %44 = fadd double %.05277, %43
  %45 = fcmp ult double %44, %2
  %.pre.pre = load i32, ptr %6, align 8, !tbaa !5
  br i1 %45, label %32, label %._crit_edge

._crit_edge:                                      ; preds = %32, %.lr.ph, %.preheader75
  %46 = phi i32 [ %27, %.preheader75 ], [ %.pre.pre, %.lr.ph ], [ %.pre.pre, %32 ]
  %.3 = phi ptr [ %16, %.preheader75 ], [ %42, %.lr.ph ], [ %42, %32 ]
  %47 = add nsw i32 %1, 1
  %48 = srem i32 %47, %46
  br label %49

49:                                               ; preds = %._crit_edge, %.thread
  %.sink91 = phi i32 [ %48, %._crit_edge ], [ %31, %.thread ]
  %.372 = phi ptr [ %.3, %._crit_edge ], [ %16, %.thread ]
  %.sink = load ptr, ptr %10, align 8, !tbaa !15
  %50 = sext i32 %.sink91 to i64
  %51 = getelementptr inbounds %class.R2Point, ptr %.sink, i64 %50
  %52 = getelementptr inbounds %class.R2Point, ptr %.sink, i64 %23
  %53 = tail call noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16) %51, ptr noundef nonnull align 8 dereferenceable(16) %52)
  %54 = fcmp olt double %53, %2
  %55 = load i32, ptr %6, align 8
  %56 = icmp sgt i32 %55, 8
  %or.cond = select i1 %54, i1 %56, i1 false
  br i1 %or.cond, label %.lr.ph84, label %.loopexit

57:                                               ; preds = %.lr.ph84
  %58 = add nuw nsw i32 %.05483, 1
  %59 = load i32, ptr %6, align 8, !tbaa !5
  %60 = sdiv i32 %59, 3
  %61 = icmp slt i32 %58, %60
  br i1 %61, label %.lr.ph84, label %.loopexit, !llvm.loop !18

.lr.ph84:                                         ; preds = %49, %57
  %62 = phi i32 [ %59, %57 ], [ %55, %49 ]
  %.05483 = phi i32 [ %58, %57 ], [ 2, %49 ]
  %.05582 = phi double [ %69, %57 ], [ %53, %49 ]
  %.05681 = phi ptr [ %67, %57 ], [ %51, %49 ]
  %63 = load ptr, ptr %10, align 8, !tbaa !15
  %64 = add nsw i32 %.05483, %1
  %65 = srem i32 %64, %62
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %class.R2Point, ptr %63, i64 %66
  %68 = tail call noundef double @_Z10R2DistanceRK7R2PointS1_(ptr noundef nonnull align 8 dereferenceable(16) %67, ptr noundef nonnull align 8 dereferenceable(16) %.05681)
  %69 = fadd double %.05582, %68
  %70 = fcmp ult double %69, %2
  br i1 %70, label %57, label %.loopexit

.loopexit:                                        ; preds = %57, %.lr.ph84, %.thread73, %49
  %.pre-phi = phi i64 [ %.pre, %.thread73 ], [ %23, %49 ], [ %23, %.lr.ph84 ], [ %23, %57 ]
  %.371 = phi ptr [ %16, %.thread73 ], [ %.372, %49 ], [ %.372, %.lr.ph84 ], [ %.372, %57 ]
  %.360 = phi ptr [ %21, %.thread73 ], [ %51, %49 ], [ %67, %.lr.ph84 ], [ %67, %57 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  %71 = load ptr, ptr %10, align 8, !tbaa !15
  %72 = getelementptr inbounds %class.R2Point, ptr %71, i64 %.pre-phi
  call void @_ZmiRK7R2PointS1_(ptr dead_on_unwind nonnull writable sret(%class.R2Vector) align 8 %4, ptr noundef nonnull align 8 dereferenceable(16) %.371, ptr noundef nonnull align 8 dereferenceable(16) %72)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  %73 = load ptr, ptr %10, align 8, !tbaa !15
  %74 = getelementptr inbounds %class.R2Point, ptr %73, i64 %.pre-phi
  call void @_ZmiRK7R2PointS1_(ptr dead_on_unwind nonnull writable sret(%class.R2Vector) align 8 %5, ptr noundef nonnull align 8 dereferenceable(16) %.360, ptr noundef nonnull align 8 dereferenceable(16) %74)
  %75 = call noundef double @_ZNK8R2Vector6LengthEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  %76 = call noundef double @_ZNK8R2Vector6LengthEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %77 = load double, ptr @RN_EPSILON, align 8, !tbaa !19
  %78 = call noundef i32 @_Z8RNIsZerodd(double noundef %75, double noundef %77)
  %.not = icmp eq i32 %78, 0
  br i1 %.not, label %79, label %105

79:                                               ; preds = %.loopexit
  %80 = load double, ptr @RN_EPSILON, align 8, !tbaa !19
  %81 = call noundef i32 @_Z8RNIsZerodd(double noundef %76, double noundef %80)
  %.not68 = icmp eq i32 %81, 0
  br i1 %.not68, label %82, label %105

82:                                               ; preds = %79
  %83 = call noundef double @_Z15R2InteriorAngleRK8R2VectorS1_(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %5)
  %84 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef 0)
  %85 = load double, ptr %84, align 8, !tbaa !19
  %86 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef 1)
  %87 = load double, ptr %86, align 8, !tbaa !19
  %88 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef 1)
  %89 = load double, ptr %88, align 8, !tbaa !19
  %90 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8R2VectorixEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef 0)
  %91 = load double, ptr %90, align 8, !tbaa !19
  %92 = fneg double %89
  %93 = fmul double %91, %92
  %94 = call double @llvm.fmuladd.f64(double %85, double %87, double %93)
  %95 = fcmp ogt double %94, 0.000000e+00
  %96 = load double, ptr @RN_PI, align 8, !tbaa !19
  %97 = fsub double %96, %83
  %98 = fneg double %97
  %99 = select i1 %95, double %98, double %97
  %100 = fadd double %75, %76
  %101 = fdiv double %99, %100
  %102 = getelementptr inbounds i8, ptr %0, i64 64
  %103 = load i32, ptr %102, align 8, !tbaa !21
  %.not69 = icmp eq i32 %103, 0
  %104 = fneg double %101
  %.0 = select i1 %.not69, double %101, double %104
  br label %105

105:                                              ; preds = %.loopexit, %79, %82
  %.048 = phi double [ %.0, %82 ], [ -1.000000e+00, %79 ], [ -1.000000e+00, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  br label %106

106:                                              ; preds = %3, %105
  %.1 = phi double [ %.048, %105 ], [ 0.000000e+00, %3 ]
  ret double %.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 #4 = { 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 = { 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, !12, i64 16}
!6 = !{!"_ZTS9R2Polygon", !7, i64 0, !9, i64 8, !12, i64 16, !13, i64 24, !12, i64 64}
!7 = !{!"_ZTS7R2Solid", !8, i64 0}
!8 = !{!"_ZTS7R2Shape"}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"_ZTS5R2Box", !7, i64 0, !14, i64 8, !14, i64 24}
!14 = !{!"_ZTS7R2Point", !10, i64 0}
!15 = !{!6, !9, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !10, i64 0}
!21 = !{!6, !12, i64 64}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass