; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Collision/Shape (SphereShape)

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

%"class.JPH::Vec3" = type { %union.anon.4 }
%union.anon.4 = type { <4 x float> }
%"struct.JPH::RayCastT" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::SphereShape" = type { %"class.JPH::ConvexShape.base", float }
%"class.JPH::ConvexShape.base" = type <{ %"class.JPH::Shape.base", [6 x i8], %"class.JPH::RefConst", float }>
%"class.JPH::Shape.base" = type <{ ptr, %"class.JPH::RefTarget.3", [4 x i8], i64, i8, i8 }>
%"class.JPH::RefTarget.3" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::RefConst" = type { ptr }
%"class.JPH::BroadPhaseCastResult" = type { %"class.JPH::BodyID", float }
%"class.JPH::BodyID" = type { i32 }
%"class.JPH::RayCastResult" = type { %"class.JPH::BroadPhaseCastResult", %"class.JPH::SubShapeID" }
%"class.JPH::SubShapeID" = type { i32 }

; 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: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZN3JPH4Vec35sZeroEv() #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH11SphereShape7CastRayERKNS_7RayCastERKNS_17SubShapeIDCreatorERNS_13RayCastResultE(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 16 dereferenceable(32) %1, ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(12) %3) unnamed_addr #3 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca float, align 4
  %11 = alloca %"class.JPH::Vec3", align 16
  %12 = alloca %"class.JPH::Vec3", align 16
  %13 = alloca %"class.JPH::Vec3", align 16
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.JPH::RayCastT", ptr %16, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %11, ptr align 16 %17, i64 16, i1 false), !tbaa.struct !9
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.JPH::RayCastT", ptr %18, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %12, ptr align 16 %19, i64 16, i1 false), !tbaa.struct !9
  %20 = call { double, double } @_ZN3JPH4Vec35sZeroEv()
  %21 = getelementptr inbounds %"class.JPH::Vec3", ptr %13, i32 0, i32 0
  %22 = getelementptr inbounds %union.anon.4, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds { double, double }, ptr %22, i32 0, i32 0
  %24 = extractvalue { double, double } %20, 0
  store double %24, ptr %23, align 16
  %25 = getelementptr inbounds { double, double }, ptr %22, i32 0, i32 1
  %26 = extractvalue { double, double } %20, 1
  store double %26, ptr %25, align 8
  %27 = getelementptr inbounds %"class.JPH::SphereShape", ptr %15, i32 0, i32 1
  %28 = load float, ptr %27, align 4, !tbaa !11
  %29 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %30 = load double, ptr %29, align 16
  %31 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %32 = load double, ptr %31, align 8
  %33 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %34 = load double, ptr %33, align 16
  %35 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %36 = load double, ptr %35, align 8
  %37 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  %38 = load double, ptr %37, align 16
  %39 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  %40 = load double, ptr %39, align 8
  %41 = call noundef float @_ZN3JPH9RaySphereENS_4Vec3ES0_S0_f(double %30, double %32, double %34, double %36, double %38, double %40, float noundef %28)
  store float %41, ptr %10, align 4, !tbaa !24
  %42 = load float, ptr %10, align 4, !tbaa !24
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %43, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !25
  %46 = fcmp olt float %42, %45
  br i1 %46, label %47, label %55

47:                                               ; preds = %4
  %48 = load float, ptr %10, align 4, !tbaa !24
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %49, i32 0, i32 1
  store float %48, ptr %50, align 4, !tbaa !25
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8) %51)
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.JPH::RayCastResult", ptr %53, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %54, ptr align 4 %52, i64 4, i1 false), !tbaa.struct !28
  store i1 true, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %56

55:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %56

56:                                               ; preds = %55, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  %57 = load i1, ptr %5, align 1
  ret i1 %57
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZN3JPH9RaySphereENS_4Vec3ES0_S0_f(double, double, double, double, double, double, float noundef) #4

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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"="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 #4 = { alwaysinline 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 #5 = { 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 #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++ TBAA"}
!9 = !{i64 0, i64 16, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !23, i64 44}
!12 = !{!"_ZTSN3JPH11SphereShapeE", !13, i64 0, !23, i64 44}
!13 = !{!"_ZTSN3JPH11ConvexShapeE", !14, i64 0, !22, i64 32, !23, i64 40}
!14 = !{!"_ZTSN3JPH5ShapeE", !15, i64 8, !19, i64 16, !20, i64 24, !21, i64 25}
!15 = !{!"_ZTSN3JPH9RefTargetINS_5ShapeEEE", !16, i64 0}
!16 = !{!"_ZTSSt6atomicIjE", !17, i64 0}
!17 = !{!"_ZTSSt13__atomic_baseIjE", !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"_ZTSN3JPH10EShapeTypeE", !7, i64 0}
!21 = !{!"_ZTSN3JPH13EShapeSubTypeE", !7, i64 0}
!22 = !{!"_ZTSN3JPH8RefConstINS_15PhysicsMaterialEEE", !6, i64 0}
!23 = !{!"float", !7, i64 0}
!24 = !{!23, !23, i64 0}
!25 = !{!26, !23, i64 4}
!26 = !{!"_ZTSN3JPH20BroadPhaseCastResultE", !27, i64 0, !23, i64 4}
!27 = !{!"_ZTSN3JPH6BodyIDE", !18, i64 0}
!28 = !{i64 0, i64 4, !29}
!29 = !{!18, !18, i64 0}


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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZN3JPH4Vec35sZeroEv() local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH11SphereShape7CastRayERKNS_7RayCastERKNS_17SubShapeIDCreatorERNS_13RayCastResultE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %0, ptr nocapture noundef nonnull readonly align 16 dereferenceable(32) %1, ptr noundef nonnull align 4 dereferenceable(8) %2, ptr nocapture noundef nonnull align 4 dereferenceable(12) %3) unnamed_addr #1 align 2 {
  %.sroa.03.0.copyload = load double, ptr %1, align 16
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 8
  %.sroa.24.0.copyload = load double, ptr %.sroa.24.0..sroa_idx, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %.sroa.01.0.copyload = load double, ptr %5, align 16
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 24
  %.sroa.22.0.copyload = load double, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !5
  %6 = tail call { double, double } @_ZN3JPH4Vec35sZeroEv()
  %7 = extractvalue { double, double } %6, 0
  %8 = extractvalue { double, double } %6, 1
  %9 = getelementptr inbounds i8, ptr %0, i64 44
  %10 = load float, ptr %9, align 4, !tbaa !8
  %11 = tail call noundef float @_ZN3JPH9RaySphereENS_4Vec3ES0_S0_f(double %.sroa.03.0.copyload, double %.sroa.24.0.copyload, double %.sroa.01.0.copyload, double %.sroa.22.0.copyload, double %7, double %8, float noundef %10)
  %12 = getelementptr inbounds i8, ptr %3, i64 4
  %13 = load float, ptr %12, align 4, !tbaa !22
  %14 = fcmp olt float %11, %13
  br i1 %14, label %15, label %19

15:                                               ; preds = %4
  store float %11, ptr %12, align 4, !tbaa !22
  %16 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %17 = getelementptr inbounds i8, ptr %3, i64 8
  %18 = load i32, ptr %16, align 4, !tbaa !25
  store i32 %18, ptr %17, align 4, !tbaa !25
  br label %19

19:                                               ; preds = %4, %15
  ret i1 %14
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZN3JPH9RaySphereENS_4Vec3ES0_S0_f(double, double, double, double, double, double, float noundef) local_unnamed_addr #2

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

attributes #0 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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 = { 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 = { alwaysinline 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 = { 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" }

!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, !21, i64 44}
!9 = !{!"_ZTSN3JPH11SphereShapeE", !10, i64 0, !21, i64 44}
!10 = !{!"_ZTSN3JPH11ConvexShapeE", !11, i64 0, !19, i64 32, !21, i64 40}
!11 = !{!"_ZTSN3JPH5ShapeE", !12, i64 8, !16, i64 16, !17, i64 24, !18, i64 25}
!12 = !{!"_ZTSN3JPH9RefTargetINS_5ShapeEEE", !13, i64 0}
!13 = !{!"_ZTSSt6atomicIjE", !14, i64 0}
!14 = !{!"_ZTSSt13__atomic_baseIjE", !15, i64 0}
!15 = !{!"int", !6, i64 0}
!16 = !{!"long", !6, i64 0}
!17 = !{!"_ZTSN3JPH10EShapeTypeE", !6, i64 0}
!18 = !{!"_ZTSN3JPH13EShapeSubTypeE", !6, i64 0}
!19 = !{!"_ZTSN3JPH8RefConstINS_15PhysicsMaterialEEE", !20, i64 0}
!20 = !{!"any pointer", !6, i64 0}
!21 = !{!"float", !6, i64 0}
!22 = !{!23, !21, i64 4}
!23 = !{!"_ZTSN3JPH20BroadPhaseCastResultE", !24, i64 0, !21, i64 4}
!24 = !{!"_ZTSN3JPH6BodyIDE", !15, i64 0}
!25 = !{!15, !15, i64 0}


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