; LLVM IR from jdeokkim/ferox :: src (geometry)

; 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.frVector2_ = type { float, float }
%struct.frShape_ = type { i32, %union.frShapeData_, %struct.frMaterial_, float }
%union.frShapeData_ = type { %struct.anon.0 }
%struct.anon.0 = type { %struct.frVertices_, %struct.frVertices_ }
%struct.frVertices_ = type { [8 x %struct.frVector2_], i32 }
%struct.frMaterial_ = type { float, float, float }
%struct.anon = type { float }

; 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) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local float @frGetShapeMass(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local float @frGetShapeInertia(ptr noundef %0) #3 {
  %2 = alloca float, align 4
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.frVector2_, align 4
  %11 = alloca %struct.frVector2_, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %22, label %16

16:                                               ; preds = %1
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.frShape_, ptr %17, i32 0, i32 2
  %19 = getelementptr inbounds %struct.frMaterial_, ptr %18, i32 0, i32 0
  %20 = load float, ptr %19, align 4, !tbaa !9
  %21 = fcmp ole float %20, 0.000000e+00
  br i1 %21, label %22, label %23

22:                                               ; preds = %16, %1
  store float 0.000000e+00, ptr %2, align 4
  br label %109

23:                                               ; preds = %16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.frShape_, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !14
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %40

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.frShape_, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %struct.anon, ptr %30, i32 0, i32 0
  %32 = load float, ptr %31, align 4, !tbaa !15
  store float %32, ptr %4, align 4, !tbaa !16
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call float @frGetShapeMass(ptr noundef %33)
  %35 = fmul float 5.000000e-01, %34
  %36 = load float, ptr %4, align 4, !tbaa !16
  %37 = load float, ptr %4, align 4, !tbaa !16
  %38 = fmul float %36, %37
  %39 = fmul float %35, %38
  store float %39, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %109

40:                                               ; preds = %23
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.frShape_, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = icmp eq i32 %43, 2
  br i1 %44, label %45, label %108

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store float 0.000000e+00, ptr %5, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store float 0.000000e+00, ptr %6, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.frShape_, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.anon.0, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds %struct.frVertices_, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !15
  store i32 %50, ptr %7, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %51 = load i32, ptr %7, align 4, !tbaa !17
  %52 = sub nsw i32 %51, 1
  store i32 %52, ptr %8, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !17
  br label %53

53:                                               ; preds = %94, %45
  %54 = load i32, ptr %9, align 4, !tbaa !17
  %55 = load i32, ptr %7, align 4, !tbaa !17
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %98

58:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.frShape_, ptr %59, i32 0, i32 1
  %61 = getelementptr inbounds %struct.anon.0, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.frVertices_, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %8, align 4, !tbaa !17
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [8 x %struct.frVector2_], ptr %62, i64 0, i64 %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %65, i64 8, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.frShape_, ptr %66, i32 0, i32 1
  %68 = getelementptr inbounds %struct.anon.0, ptr %67, i32 0, i32 0
  %69 = getelementptr inbounds %struct.frVertices_, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %9, align 4, !tbaa !17
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [8 x %struct.frVector2_], ptr %69, i64 0, i64 %71
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %72, i64 8, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %73 = load <2 x float>, ptr %10, align 4
  %74 = load <2 x float>, ptr %11, align 4
  %75 = call float @frVector2Cross(<2 x float> %73, <2 x float> %74)
  store float %75, ptr %12, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  %76 = load <2 x float>, ptr %10, align 4
  %77 = load <2 x float>, ptr %10, align 4
  %78 = call float @frVector2Dot(<2 x float> %76, <2 x float> %77)
  %79 = load <2 x float>, ptr %10, align 4
  %80 = load <2 x float>, ptr %11, align 4
  %81 = call float @frVector2Dot(<2 x float> %79, <2 x float> %80)
  %82 = fadd float %78, %81
  %83 = load <2 x float>, ptr %11, align 4
  %84 = load <2 x float>, ptr %11, align 4
  %85 = call float @frVector2Dot(<2 x float> %83, <2 x float> %84)
  %86 = fadd float %82, %85
  store float %86, ptr %13, align 4, !tbaa !16
  %87 = load float, ptr %12, align 4, !tbaa !16
  %88 = load float, ptr %13, align 4, !tbaa !16
  %89 = load float, ptr %5, align 4, !tbaa !16
  %90 = call float @llvm.fmuladd.f32(float %87, float %88, float %89)
  store float %90, ptr %5, align 4, !tbaa !16
  %91 = load float, ptr %12, align 4, !tbaa !16
  %92 = load float, ptr %6, align 4, !tbaa !16
  %93 = fadd float %92, %91
  store float %93, ptr %6, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %94

94:                                               ; preds = %58
  %95 = load i32, ptr %9, align 4, !tbaa !17
  store i32 %95, ptr %8, align 4, !tbaa !17
  %96 = load i32, ptr %9, align 4, !tbaa !17
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %9, align 4, !tbaa !17
  br label %53, !llvm.loop !19

98:                                               ; preds = %57
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.frShape_, ptr %99, i32 0, i32 2
  %101 = getelementptr inbounds %struct.frMaterial_, ptr %100, i32 0, i32 0
  %102 = load float, ptr %101, align 4, !tbaa !9
  %103 = load float, ptr %5, align 4, !tbaa !16
  %104 = load float, ptr %6, align 4, !tbaa !16
  %105 = fmul float 6.000000e+00, %104
  %106 = fdiv float %103, %105
  %107 = fmul float %102, %106
  store float %107, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %109

108:                                              ; preds = %40
  store float 0.000000e+00, ptr %2, align 4
  br label %109

109:                                              ; preds = %108, %98, %28, %22
  %110 = load float, ptr %2, align 4
  ret float %110
}

; Function Attrs: alwaysinline nounwind uwtable
declare float @frVector2Cross(<2 x float>, <2 x float>) #4

; Function Attrs: alwaysinline nounwind uwtable
declare float @frVector2Dot(<2 x float>, <2 x float>) #4

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { nounwind 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 = { alwaysinline nounwind 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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/C++ TBAA"}
!9 = !{!10, !13, i64 140}
!10 = !{!"frShape_", !11, i64 0, !7, i64 4, !12, i64 140, !13, i64 152}
!11 = !{!"int", !7, i64 0}
!12 = !{!"frMaterial_", !13, i64 0, !13, i64 4, !13, i64 8}
!13 = !{!"float", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!13, !13, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{i64 0, i64 4, !16, i64 4, i64 4, !16}
!19 = distinct !{!19, !20}
!20 = !{!"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.frVector2_ = type { float, float }

; Function Attrs: nounwind uwtable
declare dso_local float @frGetShapeMass(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local float @frGetShapeInertia(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %39, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 140
  %5 = load float, ptr %4, align 4, !tbaa !5
  %6 = fcmp ugt float %5, 0.000000e+00
  br i1 %6, label %7, label %39

7:                                                ; preds = %3
  %8 = load i32, ptr %0, align 4, !tbaa !12
  switch i32 %8, label %39 [
    i32 1, label %9
    i32 2, label %16
  ]

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load float, ptr %10, align 4, !tbaa !13
  %12 = tail call float @frGetShapeMass(ptr noundef nonnull %0)
  %13 = fmul float %12, 5.000000e-01
  %14 = fmul float %11, %11
  %15 = fmul float %14, %13
  br label %39

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %0, i64 4
  %18 = getelementptr inbounds i8, ptr %0, i64 68
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %16
  %21 = add nsw i32 %19, -1
  %wide.trip.count = zext nneg i32 %19 to i64
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load float, ptr %4, align 4, !tbaa !5
  %22 = fmul float %37, 6.000000e+00
  %23 = fdiv float %36, %22
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %16
  %24 = phi float [ %5, %16 ], [ %.pre, %._crit_edge.loopexit ]
  %25 = phi float [ 0x7FF8000000000000, %16 ], [ %23, %._crit_edge.loopexit ]
  %26 = fmul float %25, %24
  br label %39

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.03342 = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %36, %.lr.ph ]
  %.03441 = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %37, %.lr.ph ]
  %.03540 = phi i32 [ %21, %.lr.ph.preheader ], [ %38, %.lr.ph ]
  %27 = sext i32 %.03540 to i64
  %28 = getelementptr inbounds [8 x %struct.frVector2_], ptr %17, i64 0, i64 %27
  %.sroa.06.0.copyload = load <2 x float>, ptr %28, align 4
  %29 = getelementptr inbounds [8 x %struct.frVector2_], ptr %17, i64 0, i64 %indvars.iv
  %.sroa.0.0.copyload = load <2 x float>, ptr %29, align 4
  %30 = tail call float @frVector2Cross(<2 x float> %.sroa.06.0.copyload, <2 x float> %.sroa.0.0.copyload)
  %31 = tail call float @frVector2Dot(<2 x float> %.sroa.06.0.copyload, <2 x float> %.sroa.06.0.copyload)
  %32 = tail call float @frVector2Dot(<2 x float> %.sroa.06.0.copyload, <2 x float> %.sroa.0.0.copyload)
  %33 = fadd float %31, %32
  %34 = tail call float @frVector2Dot(<2 x float> %.sroa.0.0.copyload, <2 x float> %.sroa.0.0.copyload)
  %35 = fadd float %33, %34
  %36 = tail call float @llvm.fmuladd.f32(float %30, float %35, float %.03342)
  %37 = fadd float %.03441, %30
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %38 = trunc nuw nsw i64 %indvars.iv to i32
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

39:                                               ; preds = %7, %1, %3, %._crit_edge, %9
  %.0 = phi float [ %15, %9 ], [ %26, %._crit_edge ], [ 0.000000e+00, %3 ], [ 0.000000e+00, %1 ], [ 0.000000e+00, %7 ]
  ret float %.0
}

; Function Attrs: alwaysinline nounwind uwtable
declare float @frVector2Cross(<2 x float>, <2 x float>) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare float @frVector2Dot(<2 x float>, <2 x float>) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { nounwind 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 #2 = { alwaysinline nounwind 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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 140}
!6 = !{!"frShape_", !7, i64 0, !8, i64 4, !10, i64 140, !11, i64 152}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"frMaterial_", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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