; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Graphics/R3Frustum.ll (ZNK9R3Frustum10IntersectsERK5R3Box)

; 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.R3Frustum = type { %class.R3Camera, [2 x [3 x %class.R3Halfspace]] }
%class.R3Camera = type { %class.R3CoordSystem, double, double, double, double, double, ptr }
%class.R3CoordSystem = type { %class.R3Point, %class.R3Triad }
%class.R3Point = type { [3 x double] }
%class.R3Triad = type { [3 x %class.R3Vector] }
%class.R3Vector = type { [3 x double] }
%class.R3Halfspace = type { %class.R3Plane }
%class.R3Plane = type { %class.R3Vector, double }

; 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 @_ZNK9R3Frustum10IntersectsERK5R3Box(ptr noundef nonnull align 8 dereferenceable(336) %0, ptr noundef nonnull align 8 dereferenceable(56) %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 i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %38, %2
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 2
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  br label %41

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %15

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

18:                                               ; preds = %15
  store i32 5, ptr %7, align 4
  br label %35

19:                                               ; preds = %15
  %20 = getelementptr inbounds %struct.R3Frustum, ptr %9, i32 0, i32 1
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2 x [3 x %class.R3Halfspace]], ptr %20, i64 0, i64 %22
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [3 x %class.R3Halfspace], ptr %23, i64 0, i64 %25
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32) %26, ptr noundef nonnull align 8 dereferenceable(56) %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %19
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %35

31:                                               ; preds = %19
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %8, align 4, !tbaa !9
  br label %15, !llvm.loop !11

35:                                               ; preds = %30, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %36 = load i32, ptr %7, align 4
  switch i32 %36, label %41 [
    i32 5, label %37
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !9
  br label %10, !llvm.loop !13

41:                                               ; preds = %35, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %42 = load i32, ptr %7, align 4
  switch i32 %42, label %46 [
    i32 2, label %43
    i32 1, label %44
  ]

43:                                               ; preds = %41
  store i32 1, ptr %3, align 4
  br label %44

44:                                               ; preds = %43, %41
  %45 = load i32, ptr %3, align 4
  ret i32 %45

46:                                               ; preds = %41
  unreachable
}

declare noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(56)) #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 = { "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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 i32 @_ZNK9R3Frustum10IntersectsERK5R3Box(ptr noundef nonnull align 8 dereferenceable(336) %0, ptr noundef nonnull align 8 dereferenceable(56) %1) local_unnamed_addr #0 align 2 {
.preheader:
  %2 = getelementptr inbounds i8, ptr %0, i64 144
  %3 = tail call noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(56) %1)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.loopexit.loopexit, label %4

4:                                                ; preds = %.preheader
  %5 = getelementptr inbounds i8, ptr %0, i64 176
  %6 = tail call noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32) %5, ptr noundef nonnull align 8 dereferenceable(56) %1)
  %.not.1 = icmp eq i32 %6, 0
  br i1 %.not.1, label %.loopexit.loopexit, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 208
  %9 = tail call noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 8 dereferenceable(56) %1)
  %.not.2 = icmp eq i32 %9, 0
  br i1 %.not.2, label %.loopexit.loopexit, label %.preheader.1

.preheader.1:                                     ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 240
  %11 = tail call noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32) %10, ptr noundef nonnull align 8 dereferenceable(56) %1)
  %.not.123 = icmp eq i32 %11, 0
  br i1 %.not.123, label %.loopexit.loopexit, label %12

12:                                               ; preds = %.preheader.1
  %13 = getelementptr inbounds i8, ptr %0, i64 272
  %14 = tail call noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32) %13, ptr noundef nonnull align 8 dereferenceable(56) %1)
  %.not.1.1 = icmp eq i32 %14, 0
  br i1 %.not.1.1, label %.loopexit.loopexit, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 304
  %17 = tail call noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32) %16, ptr noundef nonnull align 8 dereferenceable(56) %1)
  %.not.2.1 = icmp eq i32 %17, 0
  br i1 %.not.2.1, label %.loopexit.loopexit, label %.loopexit

.loopexit.loopexit:                               ; preds = %15, %12, %.preheader.1, %7, %4, %.preheader
  br label %.loopexit

.loopexit:                                        ; preds = %15, %.loopexit.loopexit
  %spec.select = phi i32 [ 0, %.loopexit.loopexit ], [ 1, %15 ]
  ret i32 %spec.select
}

declare noundef i32 @_Z12R3IntersectsRK11R3HalfspaceRK5R3Box(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1

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 = { "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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass