; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Graphics (R3SceneElement)

; 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.RNFlags = type { i64 }
%class.R3SceneElement = type { ptr, ptr, %class.RNArray, i32, %class.R3Box }
%class.RNArray = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.R3Box = type { %class.R3Solid, %class.R3Point, %class.R3Point }
%class.R3Solid = type { %class.R3Shape }
%class.R3Shape = type { ptr }
%class.R3Point = type { [3 x double] }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK14R3SceneElement7NShapesEv(ptr noundef nonnull align 8 dereferenceable(96)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK14R3SceneElement5ShapeEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) #1 align 2

; 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 @_ZNK14R3SceneElement4DrawE7RNFlagsPK7RNArrayIP10R3MaterialE(ptr noundef nonnull align 8 dereferenceable(96) %0, i64 %1, ptr noundef %2) #2 align 2 {
  %4 = alloca %class.RNFlags, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %class.RNFlags, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca %class.RNFlags, align 8
  %12 = getelementptr inbounds %class.RNFlags, ptr %4, i32 0, i32 0
  store i64 %1, ptr %12, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8
  %14 = call noundef i32 @_ZNK14R3SceneElement7NShapesEv(ptr noundef nonnull align 8 dereferenceable(96) %13)
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  br label %71

17:                                               ; preds = %3
  %18 = getelementptr inbounds %class.R3SceneElement, ptr %13, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %53

21:                                               ; preds = %17
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %7, i64 noundef 64)
  %22 = getelementptr inbounds %class.RNFlags, ptr %7, i32 0, i32 0
  %23 = load i64, ptr %22, align 8
  %24 = call noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8) %4, i64 %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %53

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %27 = getelementptr inbounds %class.R3SceneElement, ptr %13, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = call noundef i32 @_ZNK10R3Material10SceneIndexEv(ptr noundef nonnull align 8 dereferenceable(48) %28)
  store i32 %29, ptr %8, align 4, !tbaa !18
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %49

32:                                               ; preds = %26
  %33 = load i32, ptr %8, align 4, !tbaa !18
  %34 = icmp sge i32 %33, 0
  br i1 %34, label %35, label %49

35:                                               ; preds = %32
  %36 = load i32, ptr %8, align 4, !tbaa !18
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %37)
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %40, label %49

40:                                               ; preds = %35
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !18
  %43 = call noundef ptr @_ZNK7RNArrayIP10R3MaterialE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %41, i32 noundef %42)
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %49

45:                                               ; preds = %40
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !18
  %48 = call noundef ptr @_ZNK7RNArrayIP10R3MaterialE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %46, i32 noundef %47)
  call void @_ZNK10R3Material4DrawEi(ptr noundef nonnull align 8 dereferenceable(48) %48, i32 noundef 0)
  br label %52

49:                                               ; preds = %40, %35, %32, %26
  %50 = getelementptr inbounds %class.R3SceneElement, ptr %13, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  call void @_ZNK10R3Material4DrawEi(ptr noundef nonnull align 8 dereferenceable(48) %51, i32 noundef 0)
  br label %52

52:                                               ; preds = %49, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %53

53:                                               ; preds = %52, %21, %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !18
  br label %54

54:                                               ; preds = %68, %53
  %55 = load i32, ptr %9, align 4, !tbaa !18
  %56 = call noundef i32 @_ZNK14R3SceneElement7NShapesEv(ptr noundef nonnull align 8 dereferenceable(96) %13)
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %71

59:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %60 = load i32, ptr %9, align 4, !tbaa !18
  %61 = call noundef ptr @_ZNK14R3SceneElement5ShapeEi(ptr noundef nonnull align 8 dereferenceable(96) %13, i32 noundef %60)
  store ptr %61, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %4, i64 8, i1 false), !tbaa.struct !19
  %63 = getelementptr inbounds %class.RNFlags, ptr %11, i32 0, i32 0
  %64 = load i64, ptr %63, align 8
  %65 = load ptr, ptr %62, align 8, !tbaa !22
  %66 = getelementptr inbounds ptr, ptr %65, i64 21
  %67 = load ptr, ptr %66, align 8
  call void %67(ptr noundef nonnull align 8 dereferenceable(8) %62, i64 %64)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %68

68:                                               ; preds = %59
  %69 = load i32, ptr %9, align 4, !tbaa !18
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %9, align 4, !tbaa !18
  br label %54, !llvm.loop !24

71:                                               ; preds = %58, %16
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8), i64) #1 align 2

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

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

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

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

declare void @_ZNK10R3Material4DrawEi(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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, !6, i64 8}
!10 = !{!"_ZTS14R3SceneElement", !6, i64 0, !6, i64 8, !11, i64 16, !13, i64 32, !14, i64 40}
!11 = !{!"_ZTS7RNArrayIP7R3ShapeE", !12, i64 0}
!12 = !{!"_ZTS8RNVArray", !6, i64 0, !13, i64 8, !13, i64 12}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS5R3Box", !15, i64 0, !17, i64 8, !17, i64 32}
!15 = !{!"_ZTS7R3Solid", !16, i64 0}
!16 = !{!"_ZTS7R3Shape"}
!17 = !{!"_ZTS7R3Point", !7, i64 0}
!18 = !{!13, !13, i64 0}
!19 = !{i64 0, i64 8, !20}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"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.RNFlags = type { i64 }

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK14R3SceneElement7NShapesEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK14R3SceneElement5ShapeEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK14R3SceneElement4DrawE7RNFlagsPK7RNArrayIP10R3MaterialE(ptr noundef nonnull align 8 dereferenceable(96) %0, i64 %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca %class.RNFlags, align 8
  %5 = alloca %class.RNFlags, align 8
  store i64 %1, ptr %4, align 8
  %6 = tail call noundef i32 @_ZNK14R3SceneElement7NShapesEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %28, label %11

11:                                               ; preds = %8
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef 64)
  %12 = load i64, ptr %5, align 8
  %13 = call noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8) %4, i64 %12)
  %.not15 = icmp eq i32 %13, 0
  br i1 %.not15, label %28, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = call noundef i32 @_ZNK10R3Material10SceneIndexEv(ptr noundef nonnull align 8 dereferenceable(48) %15)
  %17 = icmp ne ptr %2, null
  %18 = icmp sgt i32 %16, -1
  %or.cond = and i1 %17, %18
  br i1 %or.cond, label %19, label %26

19:                                               ; preds = %14
  %20 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %21 = icmp slt i32 %16, %20
  br i1 %21, label %22, label %26

22:                                               ; preds = %19
  %23 = call noundef ptr @_ZNK7RNArrayIP10R3MaterialE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %16)
  %.not16 = icmp eq ptr %23, null
  br i1 %.not16, label %26, label %24

24:                                               ; preds = %22
  %25 = call noundef ptr @_ZNK7RNArrayIP10R3MaterialE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %16)
  br label %.sink.split

26:                                               ; preds = %22, %19, %14
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %26, %24
  %.sink = phi ptr [ %25, %24 ], [ %27, %26 ]
  call void @_ZNK10R3Material4DrawEi(ptr noundef nonnull align 8 dereferenceable(48) %.sink, i32 noundef 0)
  br label %28

28:                                               ; preds = %.sink.split, %11, %8
  %29 = call noundef i32 @_ZNK14R3SceneElement7NShapesEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %28, %.lr.ph
  %.017 = phi i32 [ %35, %.lr.ph ], [ 0, %28 ]
  %31 = call noundef ptr @_ZNK14R3SceneElement5ShapeEi(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef %.017)
  %.sroa.0.0.copyload = load i64, ptr %4, align 8, !tbaa !17
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  %33 = getelementptr inbounds i8, ptr %32, i64 168
  %34 = load ptr, ptr %33, align 8
  call void %34(ptr noundef nonnull align 8 dereferenceable(8) %31, i64 %.sroa.0.0.copyload)
  %35 = add nuw nsw i32 %.017, 1
  %36 = call noundef i32 @_ZNK14R3SceneElement7NShapesEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %.lr.ph, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %.lr.ph, %28, %3
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK7RNFlagsixES_(ptr noundef nonnull align 8 dereferenceable(8), i64) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) unnamed_addr #2 align 2

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

; 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 @_ZNK7RNArrayIP10R3MaterialE3KthEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1 align 2

declare void @_ZNK10R3Material4DrawEi(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) local_unnamed_addr #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 = { 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 = { "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, !7, i64 8}
!6 = !{!"_ZTS14R3SceneElement", !7, i64 0, !7, i64 8, !10, i64 16, !12, i64 32, !13, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS7RNArrayIP7R3ShapeE", !11, i64 0}
!11 = !{!"_ZTS8RNVArray", !7, i64 0, !12, i64 8, !12, i64 12}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_ZTS5R3Box", !14, i64 0, !16, i64 8, !16, i64 32}
!14 = !{!"_ZTS7R3Solid", !15, i64 0}
!15 = !{!"_ZTS7R3Shape"}
!16 = !{!"_ZTS7R3Point", !8, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !8, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !9, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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