; LLVM IR from niessner/Matterport :: code/gaps/pkgs/RGBD/RGBDImage.ll (ZN9RGBDImage10SetNPixelsEii)

; 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.RGBDImage = type { ptr, ptr, i32, %class.RNArray, i32, i32, %class.R3Affine, %class.R3Matrix, %class.R3Box, i32, ptr, ptr, ptr, i32, i32 }
%class.RNArray = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.R3Affine = type { %class.R3Transformation, %class.R4Matrix, %class.R4Matrix, %class.RNFlags }
%class.R3Transformation = type { ptr }
%class.R4Matrix = type { [4 x [4 x double]] }
%class.RNFlags = type { i64 }
%class.R3Matrix = type { [3 x [3 x double]] }
%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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9RGBDImage10SetNPixelsEii(ptr noundef nonnull align 8 dereferenceable(488) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = getelementptr inbounds %class.RGBDImage, ptr %9, i32 0, i32 4
  store i32 %10, ptr %11, align 8, !tbaa !11
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = getelementptr inbounds %class.RGBDImage, ptr %9, i32 0, i32 5
  store i32 %12, ptr %13, align 4, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %31, %3
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = getelementptr inbounds %class.RGBDImage, ptr %9, i32 0, i32 3
  %17 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %16)
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %34

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %21 = getelementptr inbounds %class.RGBDImage, ptr %9, i32 0, i32 3
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = call noundef ptr @_ZNK7RNArrayIP6R2GridE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %21, i32 noundef %22)
  store ptr %23, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %30

26:                                               ; preds = %20
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN6R2Grid8ResampleEii(ptr noundef nonnull align 8 dereferenceable(208) %27, i32 noundef %28, i32 noundef %29)
  br label %30

30:                                               ; preds = %26, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !26

34:                                               ; preds = %19
  %35 = load ptr, ptr %9, align 8, !tbaa !28
  %36 = getelementptr inbounds ptr, ptr %35, i64 39
  %37 = load ptr, ptr %36, align 8
  call void %37(ptr noundef nonnull align 8 dereferenceable(488) %9)
  ret void
}

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

declare void @_ZN6R2Grid8ResampleEii(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = { 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 = !{!12, !10, i64 40}
!12 = !{!"_ZTS9RGBDImage", !6, i64 8, !10, i64 16, !13, i64 24, !10, i64 40, !10, i64 44, !15, i64 48, !20, i64 320, !21, i64 392, !10, i64 448, !6, i64 456, !6, i64 464, !6, i64 472, !10, i64 480, !10, i64 484}
!13 = !{!"_ZTS7RNArrayIP6R2GridE", !14, i64 0}
!14 = !{!"_ZTS8RNVArray", !6, i64 0, !10, i64 8, !10, i64 12}
!15 = !{!"_ZTS8R3Affine", !16, i64 0, !17, i64 8, !17, i64 136, !18, i64 264}
!16 = !{!"_ZTS16R3Transformation"}
!17 = !{!"_ZTS8R4Matrix", !7, i64 0}
!18 = !{!"_ZTS7RNFlags", !19, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"_ZTS8R3Matrix", !7, i64 0}
!21 = !{!"_ZTS5R3Box", !22, i64 0, !24, i64 8, !24, i64 32}
!22 = !{!"_ZTS7R3Solid", !23, i64 0}
!23 = !{!"_ZTS7R3Shape"}
!24 = !{!"_ZTS7R3Point", !7, i64 0}
!25 = !{!12, !10, i64 44}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!29, !29, i64 0}
!29 = !{!"vtable pointer", !8, i64 0}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9RGBDImage10SetNPixelsEii(ptr noundef nonnull align 8 dereferenceable(488) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %1, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %2, ptr %5, align 4, !tbaa !23
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %14, %3
  %9 = load ptr, ptr %0, align 8, !tbaa !24
  %10 = getelementptr inbounds i8, ptr %9, i64 312
  %11 = load ptr, ptr %10, align 8
  tail call void %11(ptr noundef nonnull align 8 dereferenceable(488) %0)
  ret void

.lr.ph:                                           ; preds = %3, %14
  %.010 = phi i32 [ %15, %14 ], [ 0, %3 ]
  %12 = tail call noundef ptr @_ZNK7RNArrayIP6R2GridE3KthEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef %.010)
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %14, label %13

13:                                               ; preds = %.lr.ph
  tail call void @_ZN6R2Grid8ResampleEii(ptr noundef nonnull align 8 dereferenceable(208) %12, i32 noundef %1, i32 noundef %2)
  br label %14

14:                                               ; preds = %13, %.lr.ph
  %15 = add nuw nsw i32 %.010, 1
  %16 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !26
}

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

declare void @_ZN6R2Grid8ResampleEii(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef) local_unnamed_addr #2

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

!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, !10, i64 40}
!6 = !{!"_ZTS9RGBDImage", !7, i64 8, !10, i64 16, !11, i64 24, !10, i64 40, !10, i64 44, !13, i64 48, !18, i64 320, !19, i64 392, !10, i64 448, !7, i64 456, !7, i64 464, !7, i64 472, !10, i64 480, !10, i64 484}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS7RNArrayIP6R2GridE", !12, i64 0}
!12 = !{!"_ZTS8RNVArray", !7, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!"_ZTS8R3Affine", !14, i64 0, !15, i64 8, !15, i64 136, !16, i64 264}
!14 = !{!"_ZTS16R3Transformation"}
!15 = !{!"_ZTS8R4Matrix", !8, i64 0}
!16 = !{!"_ZTS7RNFlags", !17, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = !{!"_ZTS8R3Matrix", !8, i64 0}
!19 = !{!"_ZTS5R3Box", !20, i64 0, !22, i64 8, !22, i64 32}
!20 = !{!"_ZTS7R3Solid", !21, i64 0}
!21 = !{!"_ZTS7R3Shape"}
!22 = !{!"_ZTS7R3Point", !8, i64 0}
!23 = !{!6, !10, i64 44}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !9, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


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