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

; 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.5 }
%union.anon.5 = type { <4 x float> }
%"class.JPH::PlaneShape" = type { %"class.JPH::Shape.base", %"class.JPH::Plane", %"class.JPH::RefConst", float, %"class.JPH::AABox" }
%"class.JPH::Shape.base" = type <{ ptr, %"class.JPH::RefTarget.4", [4 x i8], i64, i8, i8 }>
%"class.JPH::RefTarget.4" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::Plane" = type { %"class.JPH::Vec4" }
%"class.JPH::Vec4" = type { %union.anon.3 }
%union.anon.3 = type { <4 x float> }
%"class.JPH::RefConst" = type { ptr }
%"class.JPH::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"struct.JPH::RayCastT" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"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: mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH5Plane9GetNormalEv(ptr noundef nonnull align 16 dereferenceable(16)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH10PlaneShape7CastRayERKNS_7RayCastERKNS_17SubShapeIDCreatorERNS_13RayCastResultE(ptr noundef nonnull align 16 dereferenceable(96) %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 #1 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 i32, align 4
  %13 = alloca float, align 4
  %14 = alloca %"class.JPH::Vec3", align 16
  %15 = alloca float, 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
  %16 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %17 = getelementptr inbounds %"class.JPH::PlaneShape", ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.JPH::RayCastT", ptr %18, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %11, ptr align 16 %19, i64 16, i1 false), !tbaa.struct !9
  %20 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %21 = load double, ptr %20, align 16
  %22 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %23 = load double, ptr %22, align 8
  %24 = call noundef float @_ZNK3JPH5Plane14SignedDistanceENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(16) %17, double %21, double %23)
  store float %24, ptr %10, align 4, !tbaa !11
  %25 = load float, ptr %10, align 4, !tbaa !11
  %26 = fcmp ole float %25, 0.000000e+00
  br i1 %26, label %27, label %34

27:                                               ; preds = %4
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %28, i32 0, i32 1
  store float 0.000000e+00, ptr %29, align 4, !tbaa !13
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8) %30)
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.JPH::RayCastResult", ptr %32, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %33, ptr align 4 %31, i64 4, i1 false), !tbaa.struct !17
  store i1 true, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %77

34:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.JPH::RayCastT", ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds %"class.JPH::PlaneShape", ptr %16, i32 0, i32 1
  %38 = call { double, double } @_ZNK3JPH5Plane9GetNormalEv(ptr noundef nonnull align 16 dereferenceable(16) %37)
  %39 = getelementptr inbounds %"class.JPH::Vec3", ptr %14, i32 0, i32 0
  %40 = getelementptr inbounds %union.anon.5, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds { double, double }, ptr %40, i32 0, i32 0
  %42 = extractvalue { double, double } %38, 0
  store double %42, ptr %41, align 16
  %43 = getelementptr inbounds { double, double }, ptr %40, i32 0, i32 1
  %44 = extractvalue { double, double } %38, 1
  store double %44, ptr %43, align 8
  %45 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %46 = load double, ptr %45, align 16
  %47 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %48 = load double, ptr %47, align 8
  %49 = call noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16) %36, double %46, double %48)
  store float %49, ptr %13, align 4, !tbaa !11
  %50 = load float, ptr %13, align 4, !tbaa !11
  %51 = fcmp oeq float %50, 0.000000e+00
  br i1 %51, label %52, label %53

52:                                               ; preds = %34
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %76

53:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %54 = load float, ptr %10, align 4, !tbaa !11
  %55 = fneg float %54
  %56 = load float, ptr %13, align 4, !tbaa !11
  %57 = fdiv float %55, %56
  store float %57, ptr %15, align 4, !tbaa !11
  %58 = load float, ptr %15, align 4, !tbaa !11
  %59 = fcmp oge float %58, 0.000000e+00
  br i1 %59, label %60, label %74

60:                                               ; preds = %53
  %61 = load float, ptr %15, align 4, !tbaa !11
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %62, i32 0, i32 1
  %64 = load float, ptr %63, align 4, !tbaa !13
  %65 = fcmp olt float %61, %64
  br i1 %65, label %66, label %74

66:                                               ; preds = %60
  %67 = load float, ptr %15, align 4, !tbaa !11
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %68, i32 0, i32 1
  store float %67, ptr %69, align 4, !tbaa !13
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8) %70)
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds %"class.JPH::RayCastResult", ptr %72, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %73, ptr align 4 %71, i64 4, i1 false), !tbaa.struct !17
  store i1 true, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %75

74:                                               ; preds = %60, %53
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %75

75:                                               ; preds = %74, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %76

76:                                               ; preds = %75, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %77

77:                                               ; preds = %76, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %78 = load i1, ptr %5, align 1
  ret i1 %78
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNK3JPH5Plane14SignedDistanceENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(16), double, double) #1 align 2

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #4 = { alwaysinline 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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !12, i64 4}
!14 = !{!"_ZTSN3JPH20BroadPhaseCastResultE", !15, i64 0, !12, i64 4}
!15 = !{!"_ZTSN3JPH6BodyIDE", !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{i64 0, i64 4, !18}
!18 = !{!16, !16, 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
declare dso_local { double, double } @_ZNK3JPH5Plane9GetNormalEv(ptr noundef nonnull align 16 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH10PlaneShape7CastRayERKNS_7RayCastERKNS_17SubShapeIDCreatorERNS_13RayCastResultE(ptr noundef nonnull align 16 dereferenceable(96) %0, ptr noundef nonnull 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 {
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %.sroa.05.0.copyload = load double, ptr %1, align 16
  %.sroa.26.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 8
  %.sroa.26.0.copyload = load double, ptr %.sroa.26.0..sroa_idx, align 8, !tbaa !5
  %6 = tail call noundef float @_ZNK3JPH5Plane14SignedDistanceENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(16) %5, double %.sroa.05.0.copyload, double %.sroa.26.0.copyload)
  %7 = fcmp ugt float %6, 0.000000e+00
  br i1 %7, label %10, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %3, i64 4
  store float 0.000000e+00, ptr %9, align 4, !tbaa !8
  br label %.sink.split

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %1, i64 16
  %12 = tail call { double, double } @_ZNK3JPH5Plane9GetNormalEv(ptr noundef nonnull align 16 dereferenceable(16) %5)
  %13 = extractvalue { double, double } %12, 0
  %14 = extractvalue { double, double } %12, 1
  %15 = tail call noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16) %11, double %13, double %14)
  %16 = fcmp oeq float %15, 0.000000e+00
  br i1 %16, label %29, label %17

17:                                               ; preds = %10
  %18 = fneg float %6
  %19 = fdiv float %18, %15
  %20 = fcmp ult float %19, 0.000000e+00
  br i1 %20, label %29, label %21

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %3, i64 4
  %23 = load float, ptr %22, align 4, !tbaa !8
  %24 = fcmp olt float %19, %23
  br i1 %24, label %25, label %29

25:                                               ; preds = %21
  store float %19, ptr %22, align 4, !tbaa !8
  br label %.sink.split

.sink.split:                                      ; preds = %8, %25
  %26 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %27 = getelementptr inbounds i8, ptr %3, i64 8
  %28 = load i32, ptr %26, align 4, !tbaa !13
  store i32 %28, ptr %27, align 4, !tbaa !13
  br label %29

29:                                               ; preds = %.sink.split, %10, %17, %21
  %.2 = phi i1 [ false, %10 ], [ false, %21 ], [ false, %17 ], [ true, %.sink.split ]
  ret i1 %.2
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNK3JPH5Plane14SignedDistanceENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(16), double, double) local_unnamed_addr #0 align 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 #1 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) 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 = { 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 #2 = { alwaysinline 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, !12, i64 4}
!9 = !{!"_ZTSN3JPH20BroadPhaseCastResultE", !10, i64 0, !12, i64 4}
!10 = !{!"_ZTSN3JPH6BodyIDE", !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"float", !6, i64 0}
!13 = !{!11, !11, i64 0}


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