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

; 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.R3Mesh = type { ptr, %class.RNArray, %class.RNArray.0, %class.RNArray.1, ptr, ptr, ptr, [128 x i8], %class.R3Box, ptr }
%class.RNArray = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.RNArray.0 = type { %class.RNVArray }
%class.RNArray.1 = type { %class.RNVArray }
%class.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }
%class.R3Shape = type { ptr }

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

; 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

declare void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1

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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK7RNArrayIP10R3MeshFaceEixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN18R3MeshIntersectionC2Ev(ptr noundef nonnull align 8 dereferenceable(64)) unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZN18R3MeshIntersectionaSERKS_(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef nonnull align 8 dereferenceable(64)) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6R3Mesh18ClosestPointOnFaceEPK10R3MeshFaceRK7R3PointP18R3MeshIntersection(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(272), ptr noundef, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #3 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6R3Mesh12ClosestPointERK7R3PointP18R3MeshIntersection(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(272) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef %3) #3 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca %struct.R3MeshIntersection, align 8
  %13 = alloca %class.R3Point, align 8
  %14 = alloca double, align 8
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8
  call void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store double 0x47EFFFFFE0000000, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %49, %4
  %17 = load i32, ptr %10, align 4, !tbaa !11
  %18 = getelementptr inbounds %class.R3Mesh, ptr %15, i32 0, i32 3
  %19 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %18)
  %20 = icmp slt i32 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %52

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %23 = getelementptr inbounds %class.R3Mesh, ptr %15, i32 0, i32 3
  %24 = load i32, ptr %10, align 4, !tbaa !11
  %25 = call noundef ptr @_ZNK7RNArrayIP10R3MeshFaceEixEi(ptr noundef nonnull align 8 dereferenceable(16) %23, i32 noundef %24)
  store ptr %25, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %12) #5
  call void @_ZN18R3MeshIntersectionC2Ev(ptr noundef nonnull align 8 dereferenceable(64) %12)
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %31

30:                                               ; preds = %22
  br label %32

31:                                               ; preds = %22
  br label %32

32:                                               ; preds = %31, %30
  %33 = phi ptr [ %12, %30 ], [ null, %31 ]
  call void @_ZNK6R3Mesh18ClosestPointOnFaceEPK10R3MeshFaceRK7R3PointP18R3MeshIntersection(ptr dead_on_unwind writable sret(%class.R3Point) align 8 %13, ptr noundef nonnull align 8 dereferenceable(272) %15, ptr noundef %26, ptr noundef nonnull align 8 dereferenceable(24) %27, ptr noundef %33)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = call noundef double @_Z17R3SquaredDistanceRK7R3PointS1_(ptr noundef nonnull align 8 dereferenceable(24) %13, ptr noundef nonnull align 8 dereferenceable(24) %34)
  store double %35, ptr %14, align 8, !tbaa !9
  %36 = load double, ptr %14, align 8, !tbaa !9
  %37 = load double, ptr %9, align 8, !tbaa !9
  %38 = fcmp olt double %36, %37
  br i1 %38, label %39, label %48

39:                                               ; preds = %32
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %45

42:                                               ; preds = %39
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZN18R3MeshIntersectionaSERKS_(ptr noundef nonnull align 8 dereferenceable(64) %43, ptr noundef nonnull align 8 dereferenceable(64) %12)
  br label %45

45:                                               ; preds = %42, %39
  %46 = load double, ptr %14, align 8, !tbaa !9
  store double %46, ptr %9, align 8, !tbaa !9
  %47 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %13)
  br label %48

48:                                               ; preds = %45, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %10, align 4, !tbaa !11
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %10, align 4, !tbaa !11
  br label %16, !llvm.loop !13

52:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #4 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%class.R3Point = type { [3 x double] }
%struct.R3MeshIntersection = type { i32, ptr, ptr, ptr, %class.R3Point, double }

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

; 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

declare void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1

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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK7RNArrayIP10R3MeshFaceEixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN18R3MeshIntersectionC2Ev(ptr noundef nonnull align 8 dereferenceable(64)) unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZN18R3MeshIntersectionaSERKS_(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6R3Mesh18ClosestPointOnFaceEPK10R3MeshFaceRK7R3PointP18R3MeshIntersection(ptr dead_on_unwind noalias writable sret(%class.R3Point) align 8, ptr noundef nonnull align 8 dereferenceable(272), ptr noundef, ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #3 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6R3Mesh12ClosestPointERK7R3PointP18R3MeshIntersection(ptr dead_on_unwind noalias nonnull writable sret(%class.R3Point) align 8 %0, ptr noundef nonnull align 8 dereferenceable(272) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef %3) local_unnamed_addr #3 align 2 {
  %5 = alloca %struct.R3MeshIntersection, align 8
  %6 = alloca %class.R3Point, align 8
  tail call void @_ZN7R3PointC1ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) @R3null_point)
  %7 = getelementptr inbounds i8, ptr %1, i64 40
  %8 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %.not = icmp eq ptr %3, null
  %. = select i1 %.not, ptr null, ptr %5
  br i1 %.not, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %15
  %.016.us = phi double [ %.1.us, %15 ], [ 0x47EFFFFFE0000000, %.lr.ph ]
  %.01215.us = phi i32 [ %16, %15 ], [ 0, %.lr.ph ]
  %10 = call noundef ptr @_ZNK7RNArrayIP10R3MeshFaceEixEi(ptr noundef nonnull align 8 dereferenceable(16) %7, i32 noundef %.01215.us)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #5
  call void @_ZN18R3MeshIntersectionC2Ev(ptr noundef nonnull align 8 dereferenceable(64) %5)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #5
  call void @_ZNK6R3Mesh18ClosestPointOnFaceEPK10R3MeshFaceRK7R3PointP18R3MeshIntersection(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %6, ptr noundef nonnull align 8 dereferenceable(272) %1, ptr noundef %10, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef %.)
  %11 = call noundef double @_Z17R3SquaredDistanceRK7R3PointS1_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %2)
  %12 = fcmp olt double %11, %.016.us
  br i1 %12, label %13, label %15

13:                                               ; preds = %.lr.ph.split.us
  %14 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %6)
  br label %15

15:                                               ; preds = %13, %.lr.ph.split.us
  %.1.us = phi double [ %11, %13 ], [ %.016.us, %.lr.ph.split.us ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #5
  %16 = add nuw nsw i32 %.01215.us, 1
  %17 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %25, %15, %4
  ret void

.lr.ph.split:                                     ; preds = %.lr.ph, %25
  %.016 = phi double [ %.1, %25 ], [ 0x47EFFFFFE0000000, %.lr.ph ]
  %.01215 = phi i32 [ %26, %25 ], [ 0, %.lr.ph ]
  %19 = call noundef ptr @_ZNK7RNArrayIP10R3MeshFaceEixEi(ptr noundef nonnull align 8 dereferenceable(16) %7, i32 noundef %.01215)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #5
  call void @_ZN18R3MeshIntersectionC2Ev(ptr noundef nonnull align 8 dereferenceable(64) %5)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #5
  call void @_ZNK6R3Mesh18ClosestPointOnFaceEPK10R3MeshFaceRK7R3PointP18R3MeshIntersection(ptr dead_on_unwind nonnull writable sret(%class.R3Point) align 8 %6, ptr noundef nonnull align 8 dereferenceable(272) %1, ptr noundef %19, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef %.)
  %20 = call noundef double @_Z17R3SquaredDistanceRK7R3PointS1_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %2)
  %21 = fcmp olt double %20, %.016
  br i1 %21, label %22, label %25

22:                                               ; preds = %.lr.ph.split
  %23 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZN18R3MeshIntersectionaSERKS_(ptr noundef nonnull align 8 dereferenceable(64) %3, ptr noundef nonnull align 8 dereferenceable(64) %5)
  %24 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7R3PointaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %6)
  br label %25

25:                                               ; preds = %22, %.lr.ph.split
  %.1 = phi double [ %20, %22 ], [ %.016, %.lr.ph.split ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #5
  %26 = add nuw nsw i32 %.01215, 1
  %27 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %.lr.ph.split, label %._crit_edge, !llvm.loop !5
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #4 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass