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

; 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.12 }
%union.anon.12 = type { <4 x float> }
%"struct.JPH::RayCastT" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::CapsuleShape" = type { %"class.JPH::ConvexShape.base", float, float, [4 x i8] }
%"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.11", [4 x i8], i64, i8, i8 }>
%"class.JPH::RefTarget.11" = 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH12CapsuleShape7CastRayERKNS_7RayCastERKNS_17SubShapeIDCreatorERNS_13RayCastResultE(ptr noundef nonnull align 8 dereferenceable(56) %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 #2 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 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
  %14 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.JPH::RayCastT", ptr %15, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %11, ptr align 16 %16, i64 16, i1 false), !tbaa.struct !9
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.JPH::RayCastT", ptr %17, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %12, ptr align 16 %18, i64 16, i1 false), !tbaa.struct !9
  %19 = getelementptr inbounds %"class.JPH::CapsuleShape", ptr %14, i32 0, i32 2
  %20 = load float, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %"class.JPH::CapsuleShape", ptr %14, i32 0, i32 1
  %22 = load float, ptr %21, align 4, !tbaa !24
  %23 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %24 = load double, ptr %23, align 16
  %25 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %26 = load double, ptr %25, align 8
  %27 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %28 = load double, ptr %27, align 16
  %29 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %30 = load double, ptr %29, align 8
  %31 = call noundef float @_ZN3JPH10RayCapsuleENS_4Vec3ES0_ff(double %24, double %26, double %28, double %30, float noundef %20, float noundef %22)
  store float %31, ptr %10, align 4, !tbaa !25
  %32 = load float, ptr %10, align 4, !tbaa !25
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %33, i32 0, i32 1
  %35 = load float, ptr %34, align 4, !tbaa !26
  %36 = fcmp olt float %32, %35
  br i1 %36, label %37, label %45

37:                                               ; preds = %4
  %38 = load float, ptr %10, align 4, !tbaa !25
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %39, i32 0, i32 1
  store float %38, ptr %40, align 4, !tbaa !26
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8) %41)
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.JPH::RayCastResult", ptr %43, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %44, ptr align 4 %42, i64 4, i1 false), !tbaa.struct !29
  store i1 true, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %46

45:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %46

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 #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 = !{i64 0, i64 16, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !23, i64 48}
!12 = !{!"_ZTSN3JPH12CapsuleShapeE", !13, i64 0, !23, i64 44, !23, i64 48}
!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 = !{!12, !23, i64 44}
!25 = !{!23, !23, i64 0}
!26 = !{!27, !23, i64 4}
!27 = !{!"_ZTSN3JPH20BroadPhaseCastResultE", !28, i64 0, !23, i64 4}
!28 = !{!"_ZTSN3JPH6BodyIDE", !18, i64 0}
!29 = !{i64 0, i64 4, !30}
!30 = !{!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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH12CapsuleShape7CastRayERKNS_7RayCastERKNS_17SubShapeIDCreatorERNS_13RayCastResultE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(56) %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 #0 align 2 {
  %.sroa.01.0.copyload = load double, ptr %1, align 16
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 8
  %.sroa.22.0.copyload = load double, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %.sroa.0.0.copyload = load double, ptr %5, align 16
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 24
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load float, ptr %6, align 8, !tbaa !8
  %8 = getelementptr inbounds i8, ptr %0, i64 44
  %9 = load float, ptr %8, align 4, !tbaa !22
  %10 = tail call noundef float @_ZN3JPH10RayCapsuleENS_4Vec3ES0_ff(double %.sroa.01.0.copyload, double %.sroa.22.0.copyload, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload, float noundef %7, float noundef %9)
  %11 = getelementptr inbounds i8, ptr %3, i64 4
  %12 = load float, ptr %11, align 4, !tbaa !23
  %13 = fcmp olt float %10, %12
  br i1 %13, label %14, label %18

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

18:                                               ; preds = %4, %14
  ret i1 %13
}

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

; 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 #2 align 2

attributes #0 = { 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 #1 = { 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 #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" }

!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 48}
!9 = !{!"_ZTSN3JPH12CapsuleShapeE", !10, i64 0, !21, i64 44, !21, i64 48}
!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 = !{!9, !21, i64 44}
!23 = !{!24, !21, i64 4}
!24 = !{!"_ZTSN3JPH20BroadPhaseCastResultE", !25, i64 0, !21, i64 4}
!25 = !{!"_ZTSN3JPH6BodyIDE", !15, i64 0}
!26 = !{!15, !15, i64 0}


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