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

; 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.RNInterval = type { double, 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 void @_ZNK11R3SceneNode7NFacetsEv(ptr dead_on_unwind noalias writable sret(%class.RNInterval) align 8 %0, ptr noundef nonnull align 8 dereferenceable(432) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %class.RNInterval, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %class.RNInterval, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca %class.RNInterval, align 8
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8
  call void @_ZN10RNIntervalC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %0, double noundef 0.000000e+00, double noundef 0.000000e+00)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %25, %2
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = call noundef i32 @_ZNK11R3SceneNode9NElementsEv(ptr noundef nonnull align 8 dereferenceable(432) %15)
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = call noundef ptr @_ZNK11R3SceneNode7ElementEi(ptr noundef nonnull align 8 dereferenceable(432) %15, i32 noundef %22)
  store ptr %23, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZNK14R3SceneElement7NFacetsEv(ptr dead_on_unwind writable sret(%class.RNInterval) align 8 %7, ptr noundef nonnull align 8 dereferenceable(96) %24)
  call void @_ZN10RNIntervalpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %7)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %25

25:                                               ; preds = %21
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %5, align 4, !tbaa !9
  br label %16, !llvm.loop !11

28:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %44, %28
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = call noundef i32 @_ZNK11R3SceneNode11NReferencesEv(ptr noundef nonnull align 8 dereferenceable(432) %15)
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %47

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = call noundef ptr @_ZNK11R3SceneNode9ReferenceEi(ptr noundef nonnull align 8 dereferenceable(432) %15, i32 noundef %35)
  store ptr %36, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = call noundef ptr @_ZNK16R3SceneReference15ReferencedSceneEv(ptr noundef nonnull align 8 dereferenceable(48) %37)
  store ptr %38, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %43

41:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZNK7R3Scene7NFacetsEv(ptr dead_on_unwind writable sret(%class.RNInterval) align 8 %11, ptr noundef nonnull align 8 dereferenceable(352) %42)
  call void @_ZN10RNIntervalpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %11)
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  br label %43

43:                                               ; preds = %41, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !9
  br label %29, !llvm.loop !13

47:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %57, %47
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = call noundef i32 @_ZNK11R3SceneNode9NChildrenEv(ptr noundef nonnull align 8 dereferenceable(432) %15)
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %53, label %52

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

53:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = call noundef ptr @_ZNK11R3SceneNode5ChildEi(ptr noundef nonnull align 8 dereferenceable(432) %15, i32 noundef %54)
  store ptr %55, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  call void @_ZNK11R3SceneNode7NFacetsEv(ptr dead_on_unwind writable sret(%class.RNInterval) align 8 %14, ptr noundef nonnull align 8 dereferenceable(432) %56)
  call void @_ZN10RNIntervalpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %14)
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %57

57:                                               ; preds = %53
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %12, align 4, !tbaa !9
  br label %48, !llvm.loop !14

60:                                               ; preds = %52
  ret void
}

declare void @_ZN10RNIntervalC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK11R3SceneNode9NElementsEv(ptr noundef nonnull align 8 dereferenceable(432)) #3 align 2

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

declare void @_ZNK14R3SceneElement7NFacetsEv(ptr dead_on_unwind writable sret(%class.RNInterval) align 8, ptr noundef nonnull align 8 dereferenceable(96)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10RNIntervalpLERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK11R3SceneNode11NReferencesEv(ptr noundef nonnull align 8 dereferenceable(432)) #3 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK16R3SceneReference15ReferencedSceneEv(ptr noundef nonnull align 8 dereferenceable(48)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK7R3Scene7NFacetsEv(ptr dead_on_unwind noalias writable sret(%class.RNInterval) align 8, ptr noundef nonnull align 8 dereferenceable(352)) #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK11R3SceneNode9NChildrenEv(ptr noundef nonnull align 8 dereferenceable(432)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK11R3SceneNode5ChildEi(ptr noundef nonnull align 8 dereferenceable(432), i32 noundef) #4 align 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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

%class.RNInterval = type { double, double }

; 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 uwtable
define dso_local void @_ZNK11R3SceneNode7NFacetsEv(ptr dead_on_unwind noalias nonnull writable sret(%class.RNInterval) align 8 %0, ptr noundef nonnull align 8 dereferenceable(432) %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %class.RNInterval, align 8
  %4 = alloca %class.RNInterval, align 8
  %5 = alloca %class.RNInterval, align 8
  tail call void @_ZN10RNIntervalC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %0, double noundef 0.000000e+00, double noundef 0.000000e+00)
  %6 = tail call noundef i32 @_ZNK11R3SceneNode9NElementsEv(ptr noundef nonnull align 8 dereferenceable(432) %1)
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %.preheader17

.preheader17:                                     ; preds = %.lr.ph, %2
  %8 = call noundef i32 @_ZNK11R3SceneNode11NReferencesEv(ptr noundef nonnull align 8 dereferenceable(432) %1)
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph20, label %.preheader

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.018 = phi i32 [ %11, %.lr.ph ], [ 0, %2 ]
  %10 = call noundef ptr @_ZNK11R3SceneNode7ElementEi(ptr noundef nonnull align 8 dereferenceable(432) %1, i32 noundef %.018)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  call void @_ZNK14R3SceneElement7NFacetsEv(ptr dead_on_unwind nonnull writable sret(%class.RNInterval) align 8 %3, ptr noundef nonnull align 8 dereferenceable(96) %10)
  call void @_ZN10RNIntervalpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %3)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  %11 = add nuw nsw i32 %.018, 1
  %12 = call noundef i32 @_ZNK11R3SceneNode9NElementsEv(ptr noundef nonnull align 8 dereferenceable(432) %1)
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %.lr.ph, label %.preheader17, !llvm.loop !5

.preheader:                                       ; preds = %19, %.preheader17
  %14 = call noundef i32 @_ZNK11R3SceneNode9NChildrenEv(ptr noundef nonnull align 8 dereferenceable(432) %1)
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph22, label %._crit_edge

.lr.ph20:                                         ; preds = %.preheader17, %19
  %.01519 = phi i32 [ %20, %19 ], [ 0, %.preheader17 ]
  %16 = call noundef ptr @_ZNK11R3SceneNode9ReferenceEi(ptr noundef nonnull align 8 dereferenceable(432) %1, i32 noundef %.01519)
  %17 = call noundef ptr @_ZNK16R3SceneReference15ReferencedSceneEv(ptr noundef nonnull align 8 dereferenceable(48) %16)
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %19, label %18

18:                                               ; preds = %.lr.ph20
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  call void @_ZNK7R3Scene7NFacetsEv(ptr dead_on_unwind nonnull writable sret(%class.RNInterval) align 8 %4, ptr noundef nonnull align 8 dereferenceable(352) %17)
  call void @_ZN10RNIntervalpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %4)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  br label %19

19:                                               ; preds = %18, %.lr.ph20
  %20 = add nuw nsw i32 %.01519, 1
  %21 = call noundef i32 @_ZNK11R3SceneNode11NReferencesEv(ptr noundef nonnull align 8 dereferenceable(432) %1)
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %.lr.ph20, label %.preheader, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph22, %.preheader
  ret void

.lr.ph22:                                         ; preds = %.preheader, %.lr.ph22
  %.01421 = phi i32 [ %24, %.lr.ph22 ], [ 0, %.preheader ]
  %23 = call noundef ptr @_ZNK11R3SceneNode5ChildEi(ptr noundef nonnull align 8 dereferenceable(432) %1, i32 noundef %.01421)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  call void @_ZNK11R3SceneNode7NFacetsEv(ptr dead_on_unwind nonnull writable sret(%class.RNInterval) align 8 %5, ptr noundef nonnull align 8 dereferenceable(432) %23)
  call void @_ZN10RNIntervalpLERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %5)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  %24 = add nuw nsw i32 %.01421, 1
  %25 = call noundef i32 @_ZNK11R3SceneNode9NChildrenEv(ptr noundef nonnull align 8 dereferenceable(432) %1)
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %.lr.ph22, label %._crit_edge, !llvm.loop !8
}

declare void @_ZN10RNIntervalC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK11R3SceneNode9NElementsEv(ptr noundef nonnull align 8 dereferenceable(432)) local_unnamed_addr #3 align 2

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

declare void @_ZNK14R3SceneElement7NFacetsEv(ptr dead_on_unwind writable sret(%class.RNInterval) align 8, ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10RNIntervalpLERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK11R3SceneNode11NReferencesEv(ptr noundef nonnull align 8 dereferenceable(432)) local_unnamed_addr #3 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK16R3SceneReference15ReferencedSceneEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK7R3Scene7NFacetsEv(ptr dead_on_unwind noalias writable sret(%class.RNInterval) align 8, ptr noundef nonnull align 8 dereferenceable(352)) local_unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK11R3SceneNode9NChildrenEv(ptr noundef nonnull align 8 dereferenceable(432)) local_unnamed_addr #3 align 2

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

attributes #0 = { mustprogress 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 = { 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 #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"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


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