; LLVM IR from ThePhysicsGuys/Physics3D :: Physics3D/geometry (builtinShapeClasses)

; 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.P3D::Vector.0" = type { %union.anon.1 }
%union.anon.1 = type { [3 x float] }

@_ZN3P3D12ShapeLibrary16wedgeVertexCountE = external constant i32, align 4
@_ZN3P3D12ShapeLibrary13wedgeVerticesE = external global [6 x %"struct.P3D::Vector.0"], align 16

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local { <2 x float>, float } @_ZNK3P3D10WedgeClass19furthestInDirectionERKNS_6VectorIfLm3EEE(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) unnamed_addr #2 align 2 {
  %3 = alloca %"struct.P3D::Vector.0", align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca { <2 x float>, float }, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noundef float @_ZN3P3DmlIffLm3EEEDTplmlixfp_Li0Eixfp0_Li0Emlixfp_Li1Eixfp0_Li1EERKNS_6VectorIT_XT1_EEERKNS2_IT0_XT1_EEE(ptr noundef nonnull align 4 dereferenceable(12) @_ZN3P3D12ShapeLibrary13wedgeVerticesE, ptr noundef nonnull align 4 dereferenceable(12) %11) #3
  store float %12, ptr %6, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 16 @_ZN3P3D12ShapeLibrary13wedgeVerticesE, i64 12, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !13
  br label %13

13:                                               ; preds = %33, %2
  %14 = load i32, ptr %7, align 4, !tbaa !13
  %15 = load i32, ptr @_ZN3P3D12ShapeLibrary16wedgeVertexCountE, align 4, !tbaa !13
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %36

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %19 = load i32, ptr %7, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [6 x %"struct.P3D::Vector.0"], ptr @_ZN3P3D12ShapeLibrary13wedgeVerticesE, i64 0, i64 %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call noundef float @_ZN3P3DmlIffLm3EEEDTplmlixfp_Li0Eixfp0_Li0Emlixfp_Li1Eixfp0_Li1EERKNS_6VectorIT_XT1_EEERKNS2_IT0_XT1_EEE(ptr noundef nonnull align 4 dereferenceable(12) %21, ptr noundef nonnull align 4 dereferenceable(12) %22) #3
  store float %23, ptr %8, align 4, !tbaa !9
  %24 = load float, ptr %8, align 4, !tbaa !9
  %25 = load float, ptr %6, align 4, !tbaa !9
  %26 = fcmp ogt float %24, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %18
  %28 = load float, ptr %8, align 4, !tbaa !9
  store float %28, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !13
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [6 x %"struct.P3D::Vector.0"], ptr @_ZN3P3D12ShapeLibrary13wedgeVerticesE, i64 0, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %31, i64 12, i1 false), !tbaa.struct !11
  br label %32

32:                                               ; preds = %27, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %7, align 4, !tbaa !13
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !13
  br label %13, !llvm.loop !15

36:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %37 = getelementptr inbounds %"struct.P3D::Vector.0", ptr %3, i32 0, i32 0
  %38 = getelementptr inbounds %union.anon.1, ptr %37, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 4 %38, i64 12, i1 false)
  %39 = load { <2 x float>, float }, ptr %9, align 8
  ret { <2 x float>, float } %39
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{i64 0, i64 12, !12}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.P3D::Vector.0" = type { %union.anon.1 }
%union.anon.1 = type { [3 x float] }

@_ZN3P3D12ShapeLibrary16wedgeVertexCountE = external local_unnamed_addr constant i32, align 4
@_ZN3P3D12ShapeLibrary13wedgeVerticesE = external global [6 x %"struct.P3D::Vector.0"], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local { <2 x float>, float } @_ZNK3P3D10WedgeClass19furthestInDirectionERKNS_6VectorIfLm3EEE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(104) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) unnamed_addr #0 align 2 {
  %3 = tail call noundef float @_ZN3P3DmlIffLm3EEEDTplmlixfp_Li0Eixfp0_Li0Emlixfp_Li1Eixfp0_Li1EERKNS_6VectorIT_XT1_EEERKNS2_IT0_XT1_EEE(ptr noundef nonnull align 4 dereferenceable(12) @_ZN3P3D12ShapeLibrary13wedgeVerticesE, ptr noundef nonnull align 4 dereferenceable(12) %1) #1
  %.sroa.09.0.copyload = load <2 x float>, ptr @_ZN3P3D12ShapeLibrary13wedgeVerticesE, align 16
  %.sroa.3.0.copyload = load float, ptr getelementptr inbounds (i8, ptr @_ZN3P3D12ShapeLibrary13wedgeVerticesE, i64 8), align 8, !tbaa !5
  %4 = load i32, ptr @_ZN3P3D12ShapeLibrary16wedgeVertexCountE, align 4, !tbaa !8
  %5 = icmp sgt i32 %4, 1
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %10, %2
  %.sroa.09.0.lcssa = phi <2 x float> [ %.sroa.09.0.copyload, %2 ], [ %.sroa.09.1, %10 ]
  %.sroa.3.0.lcssa = phi float [ %.sroa.3.0.copyload, %2 ], [ %.sroa.3.1, %10 ]
  %.fca.0.insert = insertvalue { <2 x float>, float } poison, <2 x float> %.sroa.09.0.lcssa, 0
  %.fca.1.insert = insertvalue { <2 x float>, float } %.fca.0.insert, float %.sroa.3.0.lcssa, 1
  ret { <2 x float>, float } %.fca.1.insert

.lr.ph:                                           ; preds = %.lr.ph.preheader, %10
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %10 ]
  %.sroa.3.017 = phi float [ %.sroa.3.0.copyload, %.lr.ph.preheader ], [ %.sroa.3.1, %10 ]
  %.sroa.09.016 = phi <2 x float> [ %.sroa.09.0.copyload, %.lr.ph.preheader ], [ %.sroa.09.1, %10 ]
  %.015 = phi float [ %3, %.lr.ph.preheader ], [ %.1, %10 ]
  %6 = getelementptr inbounds [6 x %"struct.P3D::Vector.0"], ptr @_ZN3P3D12ShapeLibrary13wedgeVerticesE, i64 0, i64 %indvars.iv
  %7 = tail call noundef float @_ZN3P3DmlIffLm3EEEDTplmlixfp_Li0Eixfp0_Li0Emlixfp_Li1Eixfp0_Li1EERKNS_6VectorIT_XT1_EEERKNS2_IT0_XT1_EEE(ptr noundef nonnull align 4 dereferenceable(12) %6, ptr noundef nonnull align 4 dereferenceable(12) %1) #1
  %8 = fcmp ogt float %7, %.015
  br i1 %8, label %9, label %10

9:                                                ; preds = %.lr.ph
  %.sroa.09.0.copyload10 = load <2 x float>, ptr %6, align 4
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  %.sroa.3.0.copyload11 = load float, ptr %.sroa.3.0..sroa_idx, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %9, %.lr.ph
  %.1 = phi float [ %7, %9 ], [ %.015, %.lr.ph ]
  %.sroa.09.1 = phi <2 x float> [ %.sroa.09.0.copyload10, %9 ], [ %.sroa.09.016, %.lr.ph ]
  %.sroa.3.1 = phi float [ %.sroa.3.0.copyload11, %9 ], [ %.sroa.3.017, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZN3P3DmlIffLm3EEEDTplmlixfp_Li0Eixfp0_Li0Emlixfp_Li1Eixfp0_Li1EERKNS_6VectorIT_XT1_EEERKNS2_IT0_XT1_EEE(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #0

attributes #0 = { 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 #1 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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