; LLVM IR from aap/librw :: src/camera.ll (ZNK2rw6Camera17frustumTestSphereEPKNS_6SphereE)

; 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.rw::Camera" = type { %"struct.rw::ObjectWithFrame", ptr, ptr, %"struct.rw::V2d", %"struct.rw::V2d", float, float, float, i32, %"struct.rw::Matrix", float, float, [6 x %"struct.rw::FrustumPlane"], [8 x %"struct.rw::V3d"], %"struct.rw::BBox", ptr, ptr, %"struct.rw::RawMatrix", %"struct.rw::RawMatrix", ptr, %"struct.rw::LLLink", ptr, ptr, ptr, ptr }
%"struct.rw::ObjectWithFrame" = type { %"struct.rw::Object", %"struct.rw::LLLink", ptr }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }
%"struct.rw::V2d" = type { float, float }
%"struct.rw::Matrix" = type { %"struct.rw::V3d", i32, %"struct.rw::V3d", i32, %"struct.rw::V3d", i32, %"struct.rw::V3d", i32 }
%"struct.rw::V3d" = type { float, float, float }
%"struct.rw::FrustumPlane" = type { %"struct.rw::Plane", i8, i8, i8 }
%"struct.rw::Plane" = type { %"struct.rw::V3d", float }
%"struct.rw::BBox" = type { %"struct.rw::V3d", %"struct.rw::V3d" }
%"struct.rw::RawMatrix" = type { %"struct.rw::V3d", float, %"struct.rw::V3d", float, %"struct.rw::V3d", float, %"struct.rw::V3d", float }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::Sphere" = type { %"struct.rw::V3d", 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK2rw6Camera17frustumTestSphereEPKNS_6SphereE(ptr noundef nonnull align 8 dereferenceable(600) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %12 = getelementptr inbounds %"struct.rw::Camera", ptr %11, i32 0, i32 12
  %13 = getelementptr inbounds [6 x %"struct.rw::FrustumPlane"], ptr %12, i64 0, i64 0
  store ptr %13, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %50, %2
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 6
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 2, ptr %9, align 4
  br label %53

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.rw::FrustumPlane", ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %"struct.rw::Plane", ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.rw::Sphere", ptr %22, i32 0, i32 0
  %24 = call noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12) %21, ptr noundef nonnull align 4 dereferenceable(12) %23)
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.rw::FrustumPlane", ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds %"struct.rw::Plane", ptr %26, i32 0, i32 1
  %28 = load float, ptr %27, align 4, !tbaa !11
  %29 = fsub float %24, %28
  store float %29, ptr %10, align 4, !tbaa !16
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.rw::Sphere", ptr %30, i32 0, i32 1
  %32 = load float, ptr %31, align 4, !tbaa !17
  %33 = load float, ptr %10, align 4, !tbaa !16
  %34 = fcmp olt float %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %47

36:                                               ; preds = %18
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.rw::Sphere", ptr %37, i32 0, i32 1
  %39 = load float, ptr %38, align 4, !tbaa !17
  %40 = load float, ptr %10, align 4, !tbaa !16
  %41 = fneg float %40
  %42 = fcmp ogt float %39, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %36
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %43, %36
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.rw::FrustumPlane", ptr %45, i32 1
  store ptr %46, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %9, align 4
  br label %47

47:                                               ; preds = %44, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %48 = load i32, ptr %9, align 4
  switch i32 %48, label %53 [
    i32 0, label %49
  ]

49:                                               ; preds = %47
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %8, align 4, !tbaa !9
  br label %14, !llvm.loop !19

53:                                               ; preds = %47, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %54 = load i32, ptr %9, align 4
  switch i32 %54, label %57 [
    i32 2, label %55
  ]

55:                                               ; preds = %53
  %56 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %56, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %57

57:                                               ; preds = %55, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %58 = load i32, ptr %3, align 4
  ret i32 %58
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) #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 = { inlinehint 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 #3 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 12}
!12 = !{!"_ZTSN2rw12FrustumPlaneE", !13, i64 0, !7, i64 16, !7, i64 17, !7, i64 18}
!13 = !{!"_ZTSN2rw5PlaneE", !14, i64 0, !15, i64 12}
!14 = !{!"_ZTSN2rw3V3dE", !15, i64 0, !15, i64 4, !15, i64 8}
!15 = !{!"float", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!18, !15, i64 12}
!18 = !{!"_ZTSN2rw6SphereE", !14, i64 0, !15, i64 12}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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 nounwind uwtable
define dso_local noundef i32 @_ZNK2rw6Camera17frustumTestSphereEPKNS_6SphereE(ptr noundef nonnull align 8 dereferenceable(600) %0, ptr noundef nonnull %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 160
  %4 = getelementptr inbounds i8, ptr %1, i64 12
  %5 = tail call noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12) %3, ptr noundef nonnull align 4 dereferenceable(12) %1)
  %6 = getelementptr inbounds i8, ptr %0, i64 172
  %7 = load float, ptr %6, align 4, !tbaa !5
  %8 = fsub float %5, %7
  %9 = load float, ptr %4, align 4, !tbaa !12
  %10 = fcmp uge float %9, %8
  br i1 %10, label %11, label %69

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 180
  %13 = tail call noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12) %12, ptr noundef nonnull align 4 dereferenceable(12) %1)
  %14 = getelementptr inbounds i8, ptr %0, i64 192
  %15 = load float, ptr %14, align 8, !tbaa !5
  %16 = fsub float %13, %15
  %17 = load float, ptr %4, align 4, !tbaa !12
  %18 = fcmp uge float %17, %16
  br i1 %18, label %19, label %69

19:                                               ; preds = %11
  %20 = getelementptr inbounds i8, ptr %0, i64 200
  %21 = tail call noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12) %20, ptr noundef nonnull align 4 dereferenceable(12) %1)
  %22 = getelementptr inbounds i8, ptr %0, i64 212
  %23 = load float, ptr %22, align 4, !tbaa !5
  %24 = fsub float %21, %23
  %25 = load float, ptr %4, align 4, !tbaa !12
  %26 = fcmp uge float %25, %24
  br i1 %26, label %27, label %69

27:                                               ; preds = %19
  %28 = getelementptr inbounds i8, ptr %0, i64 220
  %29 = tail call noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12) %28, ptr noundef nonnull align 4 dereferenceable(12) %1)
  %30 = getelementptr inbounds i8, ptr %0, i64 232
  %31 = load float, ptr %30, align 8, !tbaa !5
  %32 = fsub float %29, %31
  %33 = load float, ptr %4, align 4, !tbaa !12
  %34 = fcmp uge float %33, %32
  br i1 %34, label %35, label %69

35:                                               ; preds = %27
  %36 = getelementptr inbounds i8, ptr %0, i64 240
  %37 = tail call noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12) %36, ptr noundef nonnull align 4 dereferenceable(12) %1)
  %38 = getelementptr inbounds i8, ptr %0, i64 252
  %39 = load float, ptr %38, align 4, !tbaa !5
  %40 = fsub float %37, %39
  %41 = load float, ptr %4, align 4, !tbaa !12
  %42 = fcmp uge float %41, %40
  br i1 %42, label %43, label %69

43:                                               ; preds = %35
  %44 = getelementptr inbounds i8, ptr %0, i64 260
  %45 = tail call noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12) %44, ptr noundef nonnull align 4 dereferenceable(12) %1)
  %46 = getelementptr inbounds i8, ptr %0, i64 272
  %47 = load float, ptr %46, align 8, !tbaa !5
  %48 = fsub float %45, %47
  %49 = load float, ptr %4, align 4, !tbaa !12
  %50 = fcmp uge float %49, %48
  br i1 %50, label %51, label %69

51:                                               ; preds = %43
  %52 = fneg float %40
  %53 = fcmp ogt float %41, %52
  %54 = fneg float %32
  %55 = fcmp ogt float %33, %54
  %56 = fneg float %24
  %57 = fcmp ogt float %25, %56
  %58 = fneg float %16
  %59 = fcmp ogt float %17, %58
  %60 = fneg float %8
  %61 = fcmp ogt float %9, %60
  %62 = or i1 %59, %61
  %63 = or i1 %57, %62
  %64 = or i1 %55, %63
  %65 = or i1 %53, %64
  %66 = fneg float %48
  %67 = fcmp ogt float %49, %66
  %68 = or i1 %67, %65
  %.121.5 = select i1 %68, i32 1, i32 2
  br label %69

69:                                               ; preds = %51, %43, %35, %27, %19, %11, %2
  %spec.select = phi i32 [ 0, %2 ], [ 0, %11 ], [ 0, %19 ], [ 0, %27 ], [ 0, %35 ], [ 0, %43 ], [ %.121.5, %51 ]
  ret i32 %spec.select
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZN2rw3dotERKNS_3V3dES2_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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, !9, i64 12}
!6 = !{!"_ZTSN2rw12FrustumPlaneE", !7, i64 0, !10, i64 16, !10, i64 17, !10, i64 18}
!7 = !{!"_ZTSN2rw5PlaneE", !8, i64 0, !9, i64 12}
!8 = !{!"_ZTSN2rw3V3dE", !9, i64 0, !9, i64 4, !9, i64 8}
!9 = !{!"float", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!13, !9, i64 12}
!13 = !{!"_ZTSN2rw6SphereE", !8, i64 0, !9, i64 12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass