; LLVM IR from jdeokkim/ferox :: src (rigid_body)

; 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.frVector2_ = type { float, float }
%struct.frTransform_ = type { %struct.frVector2_, %struct.anon, float }
%struct.anon = type { float, float }
%struct.frRay_ = type { %struct.frVector2_, %struct.frVector2_, float }
%struct.frRaycastHit_ = type { ptr, %struct.frVector2_, %struct.frVector2_, float, i8 }
%struct.frBody_ = type { %struct.frMotionData_, %struct.frTransform_, ptr, i32, i32, %struct.frAABB_, ptr }
%struct.frMotionData_ = type { float, float, float, float, %struct.frVector2_, float, float, %struct.frVector2_, float }
%struct.frAABB_ = type { float, float, float, float }

; 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 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: 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @frBodyContainsPoint(ptr noundef %0, <2 x float> %1) #3 {
  %3 = alloca i1, align 1
  %4 = alloca %struct.frVector2_, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.frTransform_, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca i32, align 4
  %13 = alloca %struct.frRay_, align 8
  %14 = alloca %struct.frRaycastHit_, align 8
  %15 = alloca i8, align 1
  store <2 x float> %1, ptr %4, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %71

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.frBody_, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  store ptr %22, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20, ptr %7) #6
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.frBody_, ptr %23, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %24, i64 20, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i32 @frGetShapeType(ptr noundef %25)
  store i32 %26, ptr %8, align 4, !tbaa !20
  %27 = load i32, ptr %8, align 4, !tbaa !20
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %54

29:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %30 = getelementptr inbounds %struct.frVector2_, ptr %4, i32 0, i32 0
  %31 = load float, ptr %30, align 4, !tbaa !21
  %32 = getelementptr inbounds %struct.frTransform_, ptr %7, i32 0, i32 0
  %33 = getelementptr inbounds %struct.frVector2_, ptr %32, i32 0, i32 0
  %34 = load float, ptr %33, align 4, !tbaa !22
  %35 = fsub float %31, %34
  store float %35, ptr %9, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %36 = getelementptr inbounds %struct.frVector2_, ptr %4, i32 0, i32 1
  %37 = load float, ptr %36, align 4, !tbaa !23
  %38 = getelementptr inbounds %struct.frTransform_, ptr %7, i32 0, i32 0
  %39 = getelementptr inbounds %struct.frVector2_, ptr %38, i32 0, i32 1
  %40 = load float, ptr %39, align 4, !tbaa !24
  %41 = fsub float %37, %40
  store float %41, ptr %10, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call float @frGetCircleRadius(ptr noundef %42)
  store float %43, ptr %11, align 4, !tbaa !19
  %44 = load float, ptr %9, align 4, !tbaa !19
  %45 = load float, ptr %9, align 4, !tbaa !19
  %46 = load float, ptr %10, align 4, !tbaa !19
  %47 = load float, ptr %10, align 4, !tbaa !19
  %48 = fmul float %46, %47
  %49 = call float @llvm.fmuladd.f32(float %44, float %45, float %48)
  %50 = load float, ptr %11, align 4, !tbaa !19
  %51 = load float, ptr %11, align 4, !tbaa !19
  %52 = fmul float %50, %51
  %53 = fcmp ole float %49, %52
  store i1 %53, ptr %3, align 1
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %70

54:                                               ; preds = %19
  %55 = load i32, ptr %8, align 4, !tbaa !20
  %56 = icmp eq i32 %55, 2
  br i1 %56, label %57, label %69

57:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 20, ptr %13) #6
  %58 = getelementptr inbounds %struct.frRay_, ptr %13, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %58, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !25
  %59 = getelementptr inbounds %struct.frRay_, ptr %13, i32 0, i32 1
  %60 = getelementptr inbounds %struct.frVector2_, ptr %59, i32 0, i32 0
  store float 1.000000e+00, ptr %60, align 4, !tbaa !21
  %61 = getelementptr inbounds %struct.frVector2_, ptr %59, i32 0, i32 1
  store float 0.000000e+00, ptr %61, align 4, !tbaa !23
  %62 = getelementptr inbounds %struct.frRay_, ptr %13, i32 0, i32 2
  store float 0x47EFFFFFE0000000, ptr %62, align 4, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #6
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #6
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call zeroext i1 @frComputeRaycast(ptr noundef %63, ptr noundef byval(%struct.frRay_) align 8 %13, ptr noundef %14)
  %65 = zext i1 %64 to i8
  store i8 %65, ptr %15, align 1, !tbaa !28
  %66 = getelementptr inbounds %struct.frRaycastHit_, ptr %14, i32 0, i32 4
  %67 = load i8, ptr %66, align 4, !tbaa !30, !range !32, !noundef !33
  %68 = trunc i8 %67 to i1
  store i1 %68, ptr %3, align 1
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 20, ptr %13) #6
  br label %70

69:                                               ; preds = %54
  store i1 false, ptr %3, align 1
  store i32 1, ptr %12, align 4
  br label %70

70:                                               ; preds = %69, %57, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 20, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %71

71:                                               ; preds = %70, %18
  %72 = load i1, ptr %3, align 1
  ret i1 %72
}

declare i32 @frGetShapeType(ptr noundef) #4

declare float @frGetCircleRadius(ptr noundef) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #5

declare zeroext i1 @frComputeRaycast(ptr noundef, ptr noundef byval(%struct.frRay_) align 8, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !6, i64 64}
!10 = !{!"frBody_", !11, i64 0, !14, i64 44, !6, i64 64, !16, i64 72, !16, i64 76, !17, i64 80, !6, i64 96}
!11 = !{!"frMotionData_", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !13, i64 16, !12, i64 24, !12, i64 28, !13, i64 32, !12, i64 40}
!12 = !{!"float", !7, i64 0}
!13 = !{!"frVector2_", !12, i64 0, !12, i64 4}
!14 = !{!"frTransform_", !13, i64 0, !15, i64 8, !12, i64 16}
!15 = !{!"", !12, i64 0, !12, i64 4}
!16 = !{!"int", !7, i64 0}
!17 = !{!"frAABB_", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!18 = !{i64 0, i64 4, !19, i64 4, i64 4, !19, i64 8, i64 4, !19, i64 12, i64 4, !19, i64 16, i64 4, !19}
!19 = !{!12, !12, i64 0}
!20 = !{!16, !16, i64 0}
!21 = !{!13, !12, i64 0}
!22 = !{!14, !12, i64 0}
!23 = !{!13, !12, i64 4}
!24 = !{!14, !12, i64 4}
!25 = !{i64 0, i64 4, !19, i64 4, i64 4, !19}
!26 = !{!27, !12, i64 16}
!27 = !{!"frRay_", !13, i64 0, !13, i64 8, !12, i64 16}
!28 = !{!29, !29, i64 0}
!29 = !{!"_Bool", !7, i64 0}
!30 = !{!31, !29, i64 28}
!31 = !{!"frRaycastHit_", !6, i64 0, !13, i64 8, !13, i64 16, !12, i64 24, !29, i64 28}
!32 = !{i8 0, i8 2}
!33 = !{}


; 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.frRay_ = type { %struct.frVector2_, %struct.frVector2_, float }
%struct.frVector2_ = type { float, float }
%struct.frRaycastHit_ = type { ptr, %struct.frVector2_, %struct.frVector2_, float, i8 }

; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @frBodyContainsPoint(ptr noundef %0, <2 x float> %1) local_unnamed_addr #2 {
  %3 = alloca %struct.frRay_, align 8
  %4 = alloca %struct.frRaycastHit_, align 8
  %5 = icmp eq ptr %0, null
  br i1 %5, label %26, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 44
  %.sroa.0.0.copyload = load float, ptr %9, align 4, !tbaa !17
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 48
  %.sroa.4.0.copyload = load float, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !17
  %10 = tail call i32 @frGetShapeType(ptr noundef %8) #5
  switch i32 %10, label %26 [
    i32 1, label %11
    i32 2, label %19
  ]

11:                                               ; preds = %6
  %.sroa.013.0.vec.extract = extractelement <2 x float> %1, i64 0
  %12 = fsub float %.sroa.013.0.vec.extract, %.sroa.0.0.copyload
  %.sroa.013.4.vec.extract = extractelement <2 x float> %1, i64 1
  %13 = fsub float %.sroa.013.4.vec.extract, %.sroa.4.0.copyload
  %14 = tail call float @frGetCircleRadius(ptr noundef %8) #5
  %15 = fmul float %13, %13
  %16 = tail call float @llvm.fmuladd.f32(float %12, float %12, float %15)
  %17 = fmul float %14, %14
  %18 = fcmp ole float %16, %17
  br label %26

19:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %3) #5
  store <2 x float> %1, ptr %3, align 8
  %20 = getelementptr inbounds i8, ptr %3, i64 8
  store <2 x float> <float 1.000000e+00, float 0.000000e+00>, ptr %20, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %3, i64 16
  store float 0x47EFFFFFE0000000, ptr %21, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %4, i8 0, i64 32, i1 false)
  %22 = call zeroext i1 @frComputeRaycast(ptr noundef nonnull %0, ptr noundef nonnull byval(%struct.frRay_) align 8 %3, ptr noundef nonnull %4) #5
  %23 = getelementptr inbounds i8, ptr %4, i64 28
  %24 = load i8, ptr %23, align 4, !tbaa !20, !range !23, !noundef !24
  %25 = trunc nuw i8 %24 to i1
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %3) #5
  br label %26

26:                                               ; preds = %11, %19, %6, %2
  %.1 = phi i1 [ false, %2 ], [ %18, %11 ], [ %25, %19 ], [ false, %6 ]
  ret i1 %.1
}

declare i32 @frGetShapeType(ptr noundef) local_unnamed_addr #3

declare float @frGetCircleRadius(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #4

declare zeroext i1 @frComputeRaycast(ptr noundef, ptr noundef byval(%struct.frRay_) align 8, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nounwind 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 = { "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !14, i64 64}
!6 = !{!"frBody_", !7, i64 0, !12, i64 44, !14, i64 64, !15, i64 72, !15, i64 76, !16, i64 80, !14, i64 96}
!7 = !{!"frMotionData_", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !11, i64 16, !8, i64 24, !8, i64 28, !11, i64 32, !8, i64 40}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"frVector2_", !8, i64 0, !8, i64 4}
!12 = !{!"frTransform_", !11, i64 0, !13, i64 8, !8, i64 16}
!13 = !{!"", !8, i64 0, !8, i64 4}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!"int", !9, i64 0}
!16 = !{!"frAABB_", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12}
!17 = !{!8, !8, i64 0}
!18 = !{!19, !8, i64 16}
!19 = !{!"frRay_", !11, i64 0, !11, i64 8, !8, i64 16}
!20 = !{!21, !22, i64 28}
!21 = !{!"frRaycastHit_", !14, i64 0, !11, i64 8, !11, i64 16, !8, i64 24, !22, i64 28}
!22 = !{!"_Bool", !9, i64 0}
!23 = !{i8 0, i8 2}
!24 = !{}


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