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

; 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 nounwind uwtable
declare dso_local noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #1 align 2

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

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

15:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %54

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %17 = getelementptr inbounds %struct.d2PolygonShape, ptr %9, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = load i32, ptr %5, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %struct.d2Vec2, ptr %18, i64 %20
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %21, i64 8, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %22 = getelementptr inbounds %struct.d2PolygonShape, ptr %9, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = load i32, ptr %5, align 4, !tbaa !11
  %25 = add nsw i32 %24, 1
  %26 = getelementptr inbounds %struct.d2PolygonShape, ptr %9, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = srem i32 %25, %27
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.d2Vec2, ptr %23, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %30, i64 8, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %31 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %7)
  %32 = fcmp ogt float %31, 0.000000e+00
  br i1 %32, label %33, label %35

33:                                               ; preds = %16
  %34 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %7)
  br label %38

35:                                               ; preds = %16
  %36 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %7)
  %37 = fneg float %36
  br label %38

38:                                               ; preds = %35, %33
  %39 = phi float [ %34, %33 ], [ %37, %35 ]
  store float %39, ptr %8, align 4, !tbaa !9
  %40 = load float, ptr %8, align 4, !tbaa !9
  %41 = call noundef float @_ZNK6d2Vec23DotERKS_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %6)
  %42 = call noundef float @_ZNK6d2Vec23DotERKS_(ptr noundef nonnull align 4 dereferenceable(8) %7, ptr noundef nonnull align 4 dereferenceable(8) %7)
  %43 = fadd float %41, %42
  %44 = call noundef float @_ZNK6d2Vec23DotERKS_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %7)
  %45 = fadd float %43, %44
  %46 = load float, ptr %3, align 4, !tbaa !9
  %47 = call float @llvm.fmuladd.f32(float %40, float %45, float %46)
  store float %47, ptr %3, align 4, !tbaa !9
  %48 = load float, ptr %8, align 4, !tbaa !9
  %49 = load float, ptr %4, align 4, !tbaa !9
  %50 = fadd float %49, %48
  store float %50, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %51

51:                                               ; preds = %38
  %52 = load i32, ptr %5, align 4, !tbaa !11
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !11
  br label %10, !llvm.loop !18

54:                                               ; preds = %15
  %55 = load float, ptr %3, align 4, !tbaa !9
  %56 = fdiv float %55, 6.000000e+00
  %57 = load float, ptr %4, align 4, !tbaa !9
  %58 = fdiv float %56, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret float %58
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #4

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_ZNK14d2PolygonShape18GetMomentOfInertiaEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0) unnamed_addr #1 align 2 {
  %2 = alloca %struct.d2Vec2, align 8
  %3 = alloca %struct.d2Vec2, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %10, %1
  %.011.lcssa = phi float [ 0.000000e+00, %1 ], [ %31, %10 ]
  %.0.lcssa = phi float [ 0.000000e+00, %1 ], [ %30, %10 ]
  %8 = fdiv float %.0.lcssa, 6.000000e+00
  %9 = fdiv float %8, %.011.lcssa
  ret float %9

10:                                               ; preds = %.lr.ph, %10
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %10 ]
  %11 = phi i32 [ %5, %.lr.ph ], [ %32, %10 ]
  %.014 = phi float [ 0.000000e+00, %.lr.ph ], [ %30, %10 ]
  %.01112 = phi float [ 0.000000e+00, %.lr.ph ], [ %31, %10 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %12 = load ptr, ptr %7, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.d2Vec2, ptr %12, i64 %indvars.iv
  %14 = load i64, ptr %13, align 4
  store i64 %14, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = trunc nuw nsw i64 %indvars.iv.next to i32
  %16 = srem i32 %15, %11
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds %struct.d2Vec2, ptr %12, i64 %17
  %19 = load i64, ptr %18, align 4
  store i64 %19, ptr %3, align 8
  %20 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %3)
  %21 = fcmp ogt float %20, 0.000000e+00
  %22 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %3)
  %23 = fneg float %22
  %24 = select i1 %21, float %22, float %23
  %25 = call noundef float @_ZNK6d2Vec23DotERKS_(ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %2)
  %26 = call noundef float @_ZNK6d2Vec23DotERKS_(ptr noundef nonnull align 4 dereferenceable(8) %3, ptr noundef nonnull align 4 dereferenceable(8) %3)
  %27 = fadd float %25, %26
  %28 = call noundef float @_ZNK6d2Vec23DotERKS_(ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %3)
  %29 = fadd float %27, %28
  %30 = call float @llvm.fmuladd.f32(float %24, float %29, float %.014)
  %31 = fadd float %.01112, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %32 = load i32, ptr %4, align 8, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next, %33
  br i1 %34, label %10, label %._crit_edge, !llvm.loop !14
}

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass