; LLVM IR from Sopiro/Muli :: src/collision/simplex.ll (ZNK4muli7Simplex15GetClosestPointEv)

; 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.muli::Vec2" = type { float, float }
%"struct.muli::Simplex" = type { i32, [3 x %"struct.muli::SupportPoint"], float }
%"struct.muli::SupportPoint" = type { %"struct.muli::Point", %"struct.muli::Point", %"struct.muli::Vec2", float }
%"struct.muli::Point" = type { %"struct.muli::Vec2", i32 }

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@_ZN4muli4Vec24zeroE = external dso_local constant %"struct.muli::Vec2", align 4
@__PRETTY_FUNCTION__._ZNK4muli7Simplex15GetClosestPointEv = external hidden unnamed_addr constant [44 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK4muli7Simplex15GetClosestPointEv(ptr noundef nonnull align 4 dereferenceable(116) %0) #2 align 2 {
  %2 = alloca %"struct.muli::Vec2", align 4
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca %"struct.muli::Vec2", align 4
  %6 = alloca %"struct.muli::Vec2", align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"struct.muli::Simplex", ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !9
  switch i32 %9, label %40 [
    i32 1, label %10
    i32 2, label %14
    i32 3, label %39
  ]

10:                                               ; preds = %1
  %11 = getelementptr inbounds %"struct.muli::Simplex", ptr %7, i32 0, i32 1
  %12 = getelementptr inbounds [3 x %"struct.muli::SupportPoint"], ptr %11, i64 0, i64 0
  %13 = getelementptr inbounds %"struct.muli::SupportPoint", ptr %12, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %13, i64 8, i1 false), !tbaa.struct !13
  br label %41

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %15 = getelementptr inbounds %"struct.muli::Simplex", ptr %7, i32 0, i32 2
  %16 = load float, ptr %15, align 4, !tbaa !15
  %17 = fdiv float 1.000000e+00, %16
  store float %17, ptr %4, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %18 = load float, ptr %4, align 4, !tbaa !14
  %19 = getelementptr inbounds %"struct.muli::Simplex", ptr %7, i32 0, i32 1
  %20 = getelementptr inbounds [3 x %"struct.muli::SupportPoint"], ptr %19, i64 0, i64 0
  %21 = getelementptr inbounds %"struct.muli::SupportPoint", ptr %20, i32 0, i32 3
  %22 = load float, ptr %21, align 4, !tbaa !16
  %23 = fmul float %18, %22
  %24 = getelementptr inbounds %"struct.muli::Simplex", ptr %7, i32 0, i32 1
  %25 = getelementptr inbounds [3 x %"struct.muli::SupportPoint"], ptr %24, i64 0, i64 0
  %26 = getelementptr inbounds %"struct.muli::SupportPoint", ptr %25, i32 0, i32 2
  %27 = call <2 x float> @_ZN4mulimlEfRKNS_4Vec2E(float noundef %23, ptr noundef nonnull align 4 dereferenceable(8) %26)
  store <2 x float> %27, ptr %5, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %28 = load float, ptr %4, align 4, !tbaa !14
  %29 = getelementptr inbounds %"struct.muli::Simplex", ptr %7, i32 0, i32 1
  %30 = getelementptr inbounds [3 x %"struct.muli::SupportPoint"], ptr %29, i64 0, i64 1
  %31 = getelementptr inbounds %"struct.muli::SupportPoint", ptr %30, i32 0, i32 3
  %32 = load float, ptr %31, align 4, !tbaa !16
  %33 = fmul float %28, %32
  %34 = getelementptr inbounds %"struct.muli::Simplex", ptr %7, i32 0, i32 1
  %35 = getelementptr inbounds [3 x %"struct.muli::SupportPoint"], ptr %34, i64 0, i64 1
  %36 = getelementptr inbounds %"struct.muli::SupportPoint", ptr %35, i32 0, i32 2
  %37 = call <2 x float> @_ZN4mulimlEfRKNS_4Vec2E(float noundef %33, ptr noundef nonnull align 4 dereferenceable(8) %36)
  store <2 x float> %37, ptr %6, align 4
  %38 = call <2 x float> @_ZN4muliplERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8) %5, ptr noundef nonnull align 4 dereferenceable(8) %6)
  store <2 x float> %38, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %41

39:                                               ; preds = %1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 @_ZN4muli4Vec24zeroE, i64 8, i1 false), !tbaa.struct !13
  br label %41

40:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 47, ptr noundef @__PRETTY_FUNCTION__._ZNK4muli7Simplex15GetClosestPointEv) #6
  unreachable

41:                                               ; preds = %39, %14, %10
  %42 = load <2 x float>, ptr %2, align 4
  ret <2 x float> %42
}

; 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: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4muliplERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4mulimlEfRKNS_4Vec2E(float noundef, ptr noundef nonnull align 4 dereferenceable(8)) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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"="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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { noreturn 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, !11, i64 0}
!10 = !{!"_ZTSN4muli7SimplexE", !11, i64 0, !7, i64 4, !12, i64 112}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !14}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 112}
!16 = !{!17, !12, i64 32}
!17 = !{!"_ZTSN4muli12SupportPointE", !18, i64 0, !18, i64 12, !19, i64 24, !12, i64 32}
!18 = !{!"_ZTSN4muli5PointE", !19, i64 0, !11, i64 8}
!19 = !{!"_ZTSN4muli4Vec2E", !12, i64 0, !12, i64 4}


; 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.muli::Vec2" = type { float, float }

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@_ZN4muli4Vec24zeroE = external dso_local local_unnamed_addr constant %"struct.muli::Vec2", align 4
@__PRETTY_FUNCTION__._ZNK4muli7Simplex15GetClosestPointEv = external hidden unnamed_addr constant [44 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK4muli7Simplex15GetClosestPointEv(ptr noundef nonnull align 4 dereferenceable(116) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca %"struct.muli::Vec2", align 8
  %3 = alloca %"struct.muli::Vec2", align 8
  %4 = load i32, ptr %0, align 4, !tbaa !5
  switch i32 %4, label %23 [
    i32 1, label %5
    i32 2, label %7
    i32 3, label %22
  ]

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 28
  %.sroa.0.0.copyload = load <2 x float>, ptr %6, align 4
  br label %24

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 112
  %9 = load float, ptr %8, align 4, !tbaa !11
  %10 = fdiv float 1.000000e+00, %9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %11 = getelementptr inbounds i8, ptr %0, i64 36
  %12 = load float, ptr %11, align 4, !tbaa !12
  %13 = fmul float %10, %12
  %14 = getelementptr inbounds i8, ptr %0, i64 28
  %15 = tail call <2 x float> @_ZN4mulimlEfRKNS_4Vec2E(float noundef %13, ptr noundef nonnull align 4 dereferenceable(8) %14)
  store <2 x float> %15, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %16 = getelementptr inbounds i8, ptr %0, i64 72
  %17 = load float, ptr %16, align 4, !tbaa !12
  %18 = fmul float %10, %17
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  %20 = tail call <2 x float> @_ZN4mulimlEfRKNS_4Vec2E(float noundef %18, ptr noundef nonnull align 4 dereferenceable(8) %19)
  store <2 x float> %20, ptr %3, align 8
  %21 = call <2 x float> @_ZN4muliplERKNS_4Vec2ES2_(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 %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br label %24

22:                                               ; preds = %1
  %.sroa.0.0.copyload3 = load <2 x float>, ptr @_ZN4muli4Vec24zeroE, align 4
  br label %24

23:                                               ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 47, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK4muli7Simplex15GetClosestPointEv) #5
  unreachable

24:                                               ; preds = %22, %7, %5
  %.sroa.0.0 = phi <2 x float> [ %.sroa.0.0.copyload3, %22 ], [ %21, %7 ], [ %.sroa.0.0.copyload, %5 ]
  ret <2 x float> %.sroa.0.0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4muliplERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4mulimlEfRKNS_4Vec2E(float noundef, ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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"="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 = { inlinehint 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 = { nounwind }
attributes #5 = { noreturn 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, !7, i64 0}
!6 = !{!"_ZTSN4muli7SimplexE", !7, i64 0, !8, i64 4, !10, i64 112}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!6, !10, i64 112}
!12 = !{!13, !10, i64 32}
!13 = !{!"_ZTSN4muli12SupportPointE", !14, i64 0, !14, i64 12, !15, i64 24, !10, i64 32}
!14 = !{!"_ZTSN4muli5PointE", !15, i64 0, !7, i64 8}
!15 = !{!"_ZTSN4muli4Vec2E", !10, i64 0, !10, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass