; LLVM IR from SOHNE/Dura2D :: src/collision/d2Shape.ll (ZNK14d2PolygonShape15PolygonCentroidEv)

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

%struct.d2Vec2 = type { float, float }
%struct.d2PolygonShape = type { %struct.d2Shape, float, float, i32, ptr, ptr }
%struct.d2Shape = type { ptr }

; 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: mustprogress uwtable
declare dso_local noundef float @_ZNK14d2PolygonShape11PolygonAreaEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK14d2PolygonShape15PolygonCentroidEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #3 align 2 {
  %2 = alloca %struct.d2Vec2, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.d2Vec2, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.d2Vec2, align 4
  %8 = alloca %struct.d2Vec2, align 4
  %9 = alloca %struct.d2Vec2, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @_ZN6d2Vec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8) %4, float noundef 0.000000e+00, float noundef 0.000000e+00)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %47, %1
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = getelementptr inbounds %struct.d2PolygonShape, ptr %10, i32 0, i32 3
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  %20 = getelementptr inbounds %struct.d2PolygonShape, ptr %10, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = srem i32 %19, %21
  store i32 %22, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %23 = getelementptr inbounds %struct.d2PolygonShape, ptr %10, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.d2Vec2, ptr %24, i64 %26
  %28 = getelementptr inbounds %struct.d2PolygonShape, ptr %10, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.d2Vec2, ptr %29, i64 %31
  %33 = call <2 x float> @_ZNK6d2Vec2plERKS_(ptr noundef nonnull align 4 dereferenceable(8) %27, ptr noundef nonnull align 4 dereferenceable(8) %32)
  store <2 x float> %33, ptr %8, align 4
  %34 = getelementptr inbounds %struct.d2PolygonShape, ptr %10, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds %struct.d2Vec2, ptr %35, i64 %37
  %39 = getelementptr inbounds %struct.d2PolygonShape, ptr %10, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.d2Vec2, ptr %40, i64 %42
  %44 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %38, ptr noundef nonnull align 4 dereferenceable(8) %43)
  %45 = call <2 x float> @_ZNK6d2Vec2mlEf(ptr noundef nonnull align 4 dereferenceable(8) %8, float noundef %44)
  store <2 x float> %45, ptr %7, align 4
  %46 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZN6d2Vec2pLERKS_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(8) %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %47

47:                                               ; preds = %17
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %5, align 4, !tbaa !9
  br label %11, !llvm.loop !16

50:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %51 = call <2 x float> @_ZNK6d2Vec2dvEf(ptr noundef nonnull align 4 dereferenceable(8) %4, float noundef 6.000000e+00)
  store <2 x float> %51, ptr %9, align 4
  %52 = call noundef float @_ZNK14d2PolygonShape11PolygonAreaEv(ptr noundef nonnull align 8 dereferenceable(40) %10)
  %53 = call <2 x float> @_ZNK6d2Vec2dvEf(ptr noundef nonnull align 4 dereferenceable(8) %9, float noundef %52)
  store <2 x float> %53, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %54 = load <2 x float>, ptr %2, align 4
  ret <2 x float> %54
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6d2Vec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #2 align 2

declare <2 x float> @_ZNK6d2Vec2plERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #4

declare <2 x float> @_ZNK6d2Vec2mlEf(ptr noundef nonnull align 4 dereferenceable(8), float noundef) #4

declare noundef nonnull align 4 dereferenceable(8) ptr @_ZN6d2Vec2pLERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #4

declare <2 x float> @_ZNK6d2Vec2dvEf(ptr noundef nonnull align 4 dereferenceable(8), float noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 #3 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { "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, !10, i64 16}
!12 = !{!"_ZTS14d2PolygonShape", !13, i64 0, !14, i64 8, !14, i64 12, !10, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!"_ZTS7d2Shape"}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !6, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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

%struct.d2Vec2 = type { float, float }

; 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 uwtable
declare dso_local noundef float @_ZNK14d2PolygonShape11PolygonAreaEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK14d2PolygonShape15PolygonCentroidEv(ptr noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #3 align 2 {
  %2 = alloca %struct.d2Vec2, align 4
  %3 = alloca %struct.d2Vec2, align 8
  %4 = alloca %struct.d2Vec2, align 8
  %5 = alloca %struct.d2Vec2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @_ZN6d2Vec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8) %2, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  br label %13

._crit_edge:                                      ; preds = %13, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %10 = call <2 x float> @_ZNK6d2Vec2dvEf(ptr noundef nonnull align 4 dereferenceable(8) %2, float noundef 6.000000e+00)
  store <2 x float> %10, ptr %5, align 8
  %11 = call noundef float @_ZNK14d2PolygonShape11PolygonAreaEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %12 = call <2 x float> @_ZNK6d2Vec2dvEf(ptr noundef nonnull align 4 dereferenceable(8) %5, float noundef %11)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret <2 x float> %12

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %14 = phi i32 [ %7, %.lr.ph ], [ %28, %13 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = trunc nuw nsw i64 %indvars.iv.next to i32
  %16 = srem i32 %15, %14
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %17 = load ptr, ptr %9, align 8, !tbaa !13
  %18 = getelementptr inbounds %struct.d2Vec2, ptr %17, i64 %indvars.iv
  %19 = zext nneg i32 %16 to i64
  %20 = getelementptr inbounds %struct.d2Vec2, ptr %17, i64 %19
  %21 = call <2 x float> @_ZNK6d2Vec2plERKS_(ptr noundef nonnull align 4 dereferenceable(8) %18, ptr noundef nonnull align 4 dereferenceable(8) %20)
  store <2 x float> %21, ptr %4, align 8
  %22 = load ptr, ptr %9, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct.d2Vec2, ptr %22, i64 %indvars.iv
  %24 = getelementptr inbounds %struct.d2Vec2, ptr %22, i64 %19
  %25 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %23, ptr noundef nonnull align 4 dereferenceable(8) %24)
  %26 = call <2 x float> @_ZNK6d2Vec2mlEf(ptr noundef nonnull align 4 dereferenceable(8) %4, float noundef %25)
  store <2 x float> %26, ptr %3, align 8
  %27 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZN6d2Vec2pLERKS_(ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  %28 = load i32, ptr %6, align 8, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %indvars.iv.next, %29
  br i1 %30, label %13, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6d2Vec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #2 align 2

declare <2 x float> @_ZNK6d2Vec2plERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #4

declare <2 x float> @_ZNK6d2Vec2mlEf(ptr noundef nonnull align 4 dereferenceable(8), float noundef) local_unnamed_addr #4

declare noundef nonnull align 4 dereferenceable(8) ptr @_ZN6d2Vec2pLERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #4

declare <2 x float> @_ZNK6d2Vec2dvEf(ptr noundef nonnull align 4 dereferenceable(8), float noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 #3 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { "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, !11, i64 16}
!6 = !{!"_ZTS14d2PolygonShape", !7, i64 0, !8, i64 8, !8, i64 12, !11, i64 16, !12, i64 24, !12, i64 32}
!7 = !{!"_ZTS7d2Shape"}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!6, !12, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass