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

; 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: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #1 align 2

; Function Attrs: nounwind
declare void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208)) unnamed_addr #2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9RGBDImage9NChannelsEv(ptr noundef nonnull align 8 dereferenceable(488)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9RGBDImage20ReleaseColorChannelsEv(ptr noundef nonnull align 8 dereferenceable(488) %0) unnamed_addr #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.RGBDImage, ptr %6, i32 0, i32 13
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr %7, align 8, !tbaa !9
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  br label %45

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

13:                                               ; preds = %40, %12
  %14 = load i32, ptr %4, align 4, !tbaa !24
  %15 = icmp sle i32 %14, 2
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %5, align 4
  br label %43

17:                                               ; preds = %13
  %18 = call noundef i32 @_ZNK9RGBDImage9NChannelsEv(ptr noundef nonnull align 8 dereferenceable(488) %6)
  %19 = load i32, ptr %4, align 4, !tbaa !24
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store i32 2, ptr %5, align 4
  br label %43

22:                                               ; preds = %17
  %23 = getelementptr inbounds %class.RGBDImage, ptr %6, i32 0, i32 3
  %24 = load i32, ptr %4, align 4, !tbaa !24
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %23, i32 noundef %24)
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  br label %40

29:                                               ; preds = %22
  %30 = getelementptr inbounds %class.RGBDImage, ptr %6, i32 0, i32 3
  %31 = load i32, ptr %4, align 4, !tbaa !24
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %30, i32 noundef %31)
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %36, label %35

35:                                               ; preds = %29
  call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %33) #5
  call void @_ZdlPvm(ptr noundef %33, i64 noundef 208) #6
  br label %36

36:                                               ; preds = %35, %29
  %37 = getelementptr inbounds %class.RGBDImage, ptr %6, i32 0, i32 3
  %38 = load i32, ptr %4, align 4, !tbaa !24
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %37, i32 noundef %38)
  store ptr null, ptr %39, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %36, %28
  %41 = load i32, ptr %4, align 4, !tbaa !24
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %4, align 4, !tbaa !24
  br label %13, !llvm.loop !25

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

44:                                               ; preds = %43
  store i32 1, ptr %2, align 4
  br label %45

45:                                               ; preds = %44, %11
  %46 = load i32, ptr %2, align 4
  ret i32 %46
}

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 = { nounwind "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 = { nobuiltin nounwind "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 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 #5 = { nounwind }
attributes #6 = { builtin 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, !11, i64 480}
!10 = !{!"_ZTS9RGBDImage", !6, i64 8, !11, i64 16, !12, i64 24, !11, i64 40, !11, i64 44, !14, i64 48, !19, i64 320, !20, i64 392, !11, i64 448, !6, i64 456, !6, i64 464, !6, i64 472, !11, i64 480, !11, i64 484}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS7RNArrayIP6R2GridE", !13, i64 0}
!13 = !{!"_ZTS8RNVArray", !6, i64 0, !11, i64 8, !11, i64 12}
!14 = !{!"_ZTS8R3Affine", !15, i64 0, !16, i64 8, !16, i64 136, !17, i64 264}
!15 = !{!"_ZTS16R3Transformation"}
!16 = !{!"_ZTS8R4Matrix", !7, i64 0}
!17 = !{!"_ZTS7RNFlags", !18, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTS8R3Matrix", !7, i64 0}
!20 = !{!"_ZTS5R3Box", !21, i64 0, !23, i64 8, !23, i64 32}
!21 = !{!"_ZTS7R3Solid", !22, i64 0}
!22 = !{!"_ZTS7R3Shape"}
!23 = !{!"_ZTS7R3Point", !7, i64 0}
!24 = !{!11, !11, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"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"

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

; Function Attrs: nounwind
declare void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208)) unnamed_addr #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9RGBDImage20ReleaseColorChannelsEv(ptr noundef nonnull align 8 dereferenceable(488) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 480
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr %2, align 8, !tbaa !5
  %5 = icmp sgt i32 %3, 1
  br i1 %5, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = tail call noundef i32 @_ZNK9RGBDImage9NChannelsEv(ptr noundef nonnull align 8 dereferenceable(488) %0)
  %.not = icmp sgt i32 %7, 0
  br i1 %.not, label %8, label %.loopexit

8:                                                ; preds = %.preheader
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 0)
  %10 = load ptr, ptr %9, align 8, !tbaa !23
  %.not9 = icmp eq ptr %10, null
  br i1 %.not9, label %18, label %11

11:                                               ; preds = %8
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 0)
  %13 = load ptr, ptr %12, align 8, !tbaa !23
  %14 = icmp eq ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  tail call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %13) #4
  tail call void @_ZdlPvm(ptr noundef nonnull %13, i64 noundef 208) #5
  br label %16

16:                                               ; preds = %15, %11
  %17 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 0)
  store ptr null, ptr %17, align 8, !tbaa !23
  br label %18

18:                                               ; preds = %8, %16
  %19 = tail call noundef i32 @_ZNK9RGBDImage9NChannelsEv(ptr noundef nonnull align 8 dereferenceable(488) %0)
  %.not.1 = icmp sgt i32 %19, 1
  br i1 %.not.1, label %20, label %.loopexit

20:                                               ; preds = %18
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 1)
  %22 = load ptr, ptr %21, align 8, !tbaa !23
  %.not9.1 = icmp eq ptr %22, null
  br i1 %.not9.1, label %30, label %23

23:                                               ; preds = %20
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 1)
  %25 = load ptr, ptr %24, align 8, !tbaa !23
  %26 = icmp eq ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  tail call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %25) #4
  tail call void @_ZdlPvm(ptr noundef nonnull %25, i64 noundef 208) #5
  br label %28

28:                                               ; preds = %27, %23
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 1)
  store ptr null, ptr %29, align 8, !tbaa !23
  br label %30

30:                                               ; preds = %28, %20
  %31 = tail call noundef i32 @_ZNK9RGBDImage9NChannelsEv(ptr noundef nonnull align 8 dereferenceable(488) %0)
  %.not.2 = icmp sgt i32 %31, 2
  br i1 %.not.2, label %32, label %.loopexit

32:                                               ; preds = %30
  %33 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 2)
  %34 = load ptr, ptr %33, align 8, !tbaa !23
  %.not9.2 = icmp eq ptr %34, null
  br i1 %.not9.2, label %.loopexit, label %35

35:                                               ; preds = %32
  %36 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 2)
  %37 = load ptr, ptr %36, align 8, !tbaa !23
  %38 = icmp eq ptr %37, null
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  tail call void @_ZN6R2GridD1Ev(ptr noundef nonnull align 8 dereferenceable(208) %37) #4
  tail call void @_ZdlPvm(ptr noundef nonnull %37, i64 noundef 208) #5
  br label %40

40:                                               ; preds = %39, %35
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP6R2GridEixEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef 2)
  store ptr null, ptr %41, align 8, !tbaa !23
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %18, %30, %40, %32, %1
  ret i32 1
}

attributes #0 = { 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 = { nounwind "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 = { nobuiltin nounwind "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 = { nounwind }
attributes #5 = { builtin 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, !10, i64 480}
!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 = !{!7, !7, i64 0}


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