; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes (R3MeshSearchTree)

; 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.R3Point = type { [3 x double] }
%struct.R3MeshIntersection = type { i32, ptr, ptr, ptr, %class.R3Point, double }
%class.R3MeshSearchTree = type { ptr, ptr, i32, i32 }

@R3null_point = external global %class.R3Point, align 8

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZNK16R3MeshSearchTree4BBoxEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK16R3MeshSearchTree16FindIntersectionERK5R3RayR18R3MeshIntersectiondRdPFiRK7R3PointRK8R3VectorP6R3MeshP10R3MeshFacePvESG_P20R3MeshSearchTreeNodeRK5R3Box(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(64), double noundef, ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(56)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16R3MeshSearchTree16FindIntersectionERK5R3RayR18R3MeshIntersectionddPFiRK7R3PointRK8R3VectorP6R3MeshP10R3MeshFacePvESF_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(64) %2, double noundef %3, double noundef %4, ptr noundef %5, ptr noundef %6) #2 align 2 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store double %3, ptr %11, align 8, !tbaa !9
  store double %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  store ptr %6, ptr %14, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.R3MeshIntersection, ptr %16, i32 0, i32 0
  store i32 0, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.R3MeshIntersection, ptr %18, i32 0, i32 1
  store ptr null, ptr %19, align 8, !tbaa !15
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.R3MeshIntersection, ptr %20, i32 0, i32 2
  store ptr null, ptr %21, align 8, !tbaa !16
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.R3MeshIntersection, ptr %22, i32 0, i32 3
  store ptr null, ptr %23, align 8, !tbaa !17
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.R3MeshIntersection, ptr %24, i32 0, i32 4
  %26 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %25, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.R3MeshIntersection, ptr %27, i32 0, i32 5
  store double 0.000000e+00, ptr %28, align 8, !tbaa !18
  %29 = getelementptr inbounds %class.R3MeshSearchTree, ptr %15, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %31 = icmp ne ptr %30, null
  br i1 %31, label %33, label %32

32:                                               ; preds = %7
  br label %45

33:                                               ; preds = %7
  %34 = getelementptr inbounds %class.R3MeshSearchTree, ptr %15, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !22
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %34, align 4, !tbaa !22
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load double, ptr %11, align 8, !tbaa !9
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = getelementptr inbounds %class.R3MeshSearchTree, ptr %15, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !19
  %44 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNK16R3MeshSearchTree4BBoxEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  call void @_ZNK16R3MeshSearchTree16FindIntersectionERK5R3RayR18R3MeshIntersectiondRdPFiRK7R3PointRK8R3VectorP6R3MeshP10R3MeshFacePvESG_P20R3MeshSearchTreeNodeRK5R3Box(ptr noundef nonnull align 8 dereferenceable(24) %15, ptr noundef nonnull align 8 dereferenceable(48) %37, ptr noundef nonnull align 8 dereferenceable(64) %38, double noundef %39, ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef %40, ptr noundef %41, ptr noundef %43, ptr noundef nonnull align 8 dereferenceable(56) %44)
  br label %45

45:                                               ; preds = %33, %32
  ret void
}

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

!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 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS18R3MeshIntersection", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !10, i64 56}
!13 = !{!"_ZTS10R3MeshType", !7, i64 0}
!14 = !{!"_ZTS7R3Point", !7, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, i64 16}
!17 = !{!12, !6, i64 24}
!18 = !{!12, !10, i64 56}
!19 = !{!20, !6, i64 8}
!20 = !{!"_ZTS16R3MeshSearchTree", !6, i64 0, !6, i64 8, !21, i64 16, !21, i64 20}
!21 = !{!"int", !7, i64 0}
!22 = !{!20, !21, i64 20}


; 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"

%class.R3Point = type { [3 x double] }

@R3null_point = external global %class.R3Point, align 8

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZNK16R3MeshSearchTree4BBoxEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK16R3MeshSearchTree16FindIntersectionERK5R3RayR18R3MeshIntersectiondRdPFiRK7R3PointRK8R3VectorP6R3MeshP10R3MeshFacePvESG_P20R3MeshSearchTreeNodeRK5R3Box(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(64), double noundef, ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16R3MeshSearchTree16FindIntersectionERK5R3RayR18R3MeshIntersectionddPFiRK7R3PointRK8R3VectorP6R3MeshP10R3MeshFacePvESF_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(64) %2, double noundef %3, double noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #2 align 2 {
  %8 = alloca double, align 8
  store double %4, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %2, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %2, i64 8
  %10 = getelementptr inbounds i8, ptr %2, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %9, i8 0, i64 24, i1 false)
  %11 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %10, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  %12 = getelementptr inbounds i8, ptr %2, i64 56
  store double 0.000000e+00, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %20, label %15

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %0, i64 20
  %17 = load i32, ptr %16, align 4, !tbaa !18
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !18
  %19 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNK16R3MeshSearchTree4BBoxEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  call void @_ZNK16R3MeshSearchTree16FindIntersectionERK5R3RayR18R3MeshIntersectiondRdPFiRK7R3PointRK8R3VectorP6R3MeshP10R3MeshFacePvESG_P20R3MeshSearchTreeNodeRK5R3Box(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(64) %2, double noundef %3, ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef %5, ptr noundef %6, ptr noundef nonnull %14, ptr noundef nonnull align 8 dereferenceable(56) %19)
  br label %20

20:                                               ; preds = %7, %15
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { inlinehint 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" }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS18R3MeshIntersection", !11, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !13, i64 32, !6, i64 56}
!11 = !{!"_ZTS10R3MeshType", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"_ZTS7R3Point", !7, i64 0}
!14 = !{!10, !6, i64 56}
!15 = !{!16, !12, i64 8}
!16 = !{!"_ZTS16R3MeshSearchTree", !12, i64 0, !12, i64 8, !17, i64 16, !17, i64 20}
!17 = !{!"int", !7, i64 0}
!18 = !{!16, !17, i64 20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass