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

; 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.RGBDSurface = type { ptr, ptr, i32, %class.RNArray, i32, i32, i32, ptr, ptr, %class.R2Box, i32, ptr, ptr, ptr }
%class.RNArray = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.R2Box = type { %class.R2Solid, %class.R2Point, %class.R2Point }
%class.R2Solid = type { %class.R2Shape }
%class.R2Shape = type { ptr }
%class.R2Point = type { [2 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 uwtable
declare dso_local noundef double @_ZNK5R2Box7XLengthEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK5R2Box7YLengthEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11RGBDSurface20SetWorldTexelSpacingEd(ptr noundef nonnull align 8 dereferenceable(144) %0, double noundef %1) unnamed_addr #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = load double, ptr %4, align 8, !tbaa !9
  %9 = fcmp ogt double %8, 0.000000e+00
  br i1 %9, label %10, label %23

10:                                               ; preds = %2
  %11 = getelementptr inbounds %class.RGBDSurface, ptr %7, i32 0, i32 9
  %12 = call noundef double @_ZNK5R2Box7XLengthEv(ptr noundef nonnull align 8 dereferenceable(40) %11)
  %13 = load double, ptr %4, align 8, !tbaa !9
  %14 = fdiv double %12, %13
  %15 = fptosi double %14 to i32
  %16 = getelementptr inbounds %class.RGBDSurface, ptr %7, i32 0, i32 4
  store i32 %15, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds %class.RGBDSurface, ptr %7, i32 0, i32 9
  %18 = call noundef double @_ZNK5R2Box7YLengthEv(ptr noundef nonnull align 8 dereferenceable(40) %17)
  %19 = load double, ptr %4, align 8, !tbaa !9
  %20 = fdiv double %18, %19
  %21 = fptosi double %20 to i32
  %22 = getelementptr inbounds %class.RGBDSurface, ptr %7, i32 0, i32 5
  store i32 %21, ptr %22, align 4, !tbaa !20
  br label %23

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

24:                                               ; preds = %41, %23
  %25 = load i32, ptr %5, align 4, !tbaa !21
  %26 = call noundef i32 @_ZNK11RGBDSurface9NChannelsEv(ptr noundef nonnull align 8 dereferenceable(144) %7)
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %30 = load i32, ptr %5, align 4, !tbaa !21
  %31 = call noundef ptr @_ZNK11RGBDSurface7ChannelEi(ptr noundef nonnull align 8 dereferenceable(144) %7, i32 noundef %30)
  store ptr %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %40

34:                                               ; preds = %29
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.RGBDSurface, ptr %7, i32 0, i32 4
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %class.RGBDSurface, ptr %7, i32 0, i32 5
  %39 = load i32, ptr %38, align 4, !tbaa !20
  call void @_ZN6R2Grid8ResampleEii(ptr noundef nonnull align 8 dereferenceable(208) %35, i32 noundef %37, i32 noundef %39)
  br label %40

40:                                               ; preds = %34, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %5, align 4, !tbaa !21
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !21
  br label %24, !llvm.loop !22

44:                                               ; preds = %28
  %45 = load ptr, ptr %7, align 8, !tbaa !24
  %46 = getelementptr inbounds ptr, ptr %45, i64 29
  %47 = load ptr, ptr %46, align 8
  call void %47(ptr noundef nonnull align 8 dereferenceable(144) %7)
  ret void
}

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

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

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 = { 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 = { "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, !13, i64 40}
!12 = !{!"_ZTS11RGBDSurface", !6, i64 8, !13, i64 16, !14, i64 24, !13, i64 40, !13, i64 44, !13, i64 48, !6, i64 56, !6, i64 64, !16, i64 72, !13, i64 112, !6, i64 120, !6, i64 128, !6, i64 136}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS7RNArrayIP6R2GridE", !15, i64 0}
!15 = !{!"_ZTS8RNVArray", !6, i64 0, !13, i64 8, !13, i64 12}
!16 = !{!"_ZTS5R2Box", !17, i64 0, !19, i64 8, !19, i64 24}
!17 = !{!"_ZTS7R2Solid", !18, i64 0}
!18 = !{!"_ZTS7R2Shape"}
!19 = !{!"_ZTS7R2Point", !7, i64 0}
!20 = !{!12, !13, i64 44}
!21 = !{!13, !13, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!25, !25, i64 0}
!25 = !{!"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 uwtable
declare dso_local noundef double @_ZNK5R2Box7XLengthEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK5R2Box7YLengthEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11RGBDSurface20SetWorldTexelSpacingEd(ptr noundef nonnull align 8 dereferenceable(144) %0, double noundef %1) unnamed_addr #2 align 2 {
  %3 = fcmp ogt double %1, 0.000000e+00
  br i1 %3, label %4, label %14

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 72
  %6 = tail call noundef double @_ZNK5R2Box7XLengthEv(ptr noundef nonnull align 8 dereferenceable(40) %5)
  %7 = fdiv double %6, %1
  %8 = fptosi double %7 to i32
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %8, ptr %9, align 8, !tbaa !5
  %10 = tail call noundef double @_ZNK5R2Box7YLengthEv(ptr noundef nonnull align 8 dereferenceable(40) %5)
  %11 = fdiv double %10, %1
  %12 = fptosi double %11 to i32
  %13 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %12, ptr %13, align 4, !tbaa !17
  br label %14

14:                                               ; preds = %4, %2
  %15 = tail call noundef i32 @_ZNK11RGBDSurface9NChannelsEv(ptr noundef nonnull align 8 dereferenceable(144) %0)
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %14
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = getelementptr inbounds i8, ptr %0, i64 44
  br label %22

._crit_edge:                                      ; preds = %27, %14
  %19 = load ptr, ptr %0, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %19, i64 232
  %21 = load ptr, ptr %20, align 8
  tail call void %21(ptr noundef nonnull align 8 dereferenceable(144) %0)
  ret void

22:                                               ; preds = %.lr.ph, %27
  %.010 = phi i32 [ 0, %.lr.ph ], [ %28, %27 ]
  %23 = tail call noundef ptr @_ZNK11RGBDSurface7ChannelEi(ptr noundef nonnull align 8 dereferenceable(144) %0, i32 noundef %.010)
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %27, label %24

24:                                               ; preds = %22
  %25 = load i32, ptr %17, align 8, !tbaa !5
  %26 = load i32, ptr %18, align 4, !tbaa !17
  tail call void @_ZN6R2Grid8ResampleEii(ptr noundef nonnull align 8 dereferenceable(208) %23, i32 noundef %25, i32 noundef %26)
  br label %27

27:                                               ; preds = %24, %22
  %28 = add nuw nsw i32 %.010, 1
  %29 = tail call noundef i32 @_ZNK11RGBDSurface9NChannelsEv(ptr noundef nonnull align 8 dereferenceable(144) %0)
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %22, label %._crit_edge, !llvm.loop !20
}

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

declare void @_ZN6R2Grid8ResampleEii(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, 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 = { 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" }

!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 = !{!"_ZTS11RGBDSurface", !7, i64 8, !10, i64 16, !11, i64 24, !10, i64 40, !10, i64 44, !10, i64 48, !7, i64 56, !7, i64 64, !13, i64 72, !10, i64 112, !7, i64 120, !7, i64 128, !7, i64 136}
!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 = !{!"_ZTS5R2Box", !14, i64 0, !16, i64 8, !16, i64 24}
!14 = !{!"_ZTS7R2Solid", !15, i64 0}
!15 = !{!"_ZTS7R2Shape"}
!16 = !{!"_ZTS7R2Point", !8, i64 0}
!17 = !{!6, !10, i64 44}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !9, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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