; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder/basisu_resampler.ll (ZN6basisu9Resampler8get_lineEv)

; 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.basisu::Resampler" = type <{ i32, i32, i32, i32, i32, i32, i32, [4 x i8], ptr, ptr, ptr, ptr, i8, i8, i8, [5 x i8], ptr, ptr, ptr, i32, i32, i32, float, float, [4 x i8] }>
%"struct.basisu::Resampler::Contrib_List" = type { i16, ptr }
%"struct.basisu::Resampler::Contrib" = type { float, i16 }

; 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 void @_ZN6basisu9Resampler10resample_yEPf(ptr noundef nonnull align 8 dereferenceable(116), ptr noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN6basisuL21resampler_range_checkEii(i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN6basisu9Resampler8get_lineEv(ptr noundef nonnull align 8 dereferenceable(116) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %7 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 20
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 5
  %10 = load i32, ptr %9, align 4, !tbaa !16
  %11 = icmp eq i32 %8, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %63

13:                                               ; preds = %1
  store i32 0, ptr %4, align 4, !tbaa !17
  br label %14

14:                                               ; preds = %52, %13
  %15 = load i32, ptr %4, align 4, !tbaa !17
  %16 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 11
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 20
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %"struct.basisu::Resampler::Contrib_List", ptr %17, i64 %20
  %22 = getelementptr inbounds %"struct.basisu::Resampler::Contrib_List", ptr %21, i32 0, i32 0
  %23 = load i16, ptr %22, align 8, !tbaa !19
  %24 = zext i16 %23 to i32
  %25 = icmp slt i32 %15, %24
  br i1 %25, label %26, label %55

26:                                               ; preds = %14
  %27 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 17
  %28 = load ptr, ptr %27, align 8, !tbaa !22
  %29 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 11
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 20
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %"struct.basisu::Resampler::Contrib_List", ptr %30, i64 %33
  %35 = getelementptr inbounds %"struct.basisu::Resampler::Contrib_List", ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !23
  %37 = load i32, ptr %4, align 4, !tbaa !17
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %"struct.basisu::Resampler::Contrib", ptr %36, i64 %38
  %40 = getelementptr inbounds %"struct.basisu::Resampler::Contrib", ptr %39, i32 0, i32 1
  %41 = load i16, ptr %40, align 4, !tbaa !24
  %42 = zext i16 %41 to i32
  %43 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 3
  %44 = load i32, ptr %43, align 4, !tbaa !26
  %45 = call noundef i32 @_ZN6basisuL21resampler_range_checkEii(i32 noundef %42, i32 noundef %44)
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %28, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !27
  %49 = icmp ne i8 %48, 0
  br i1 %49, label %51, label %50

50:                                               ; preds = %26
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %63

51:                                               ; preds = %26
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %4, align 4, !tbaa !17
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %4, align 4, !tbaa !17
  br label %14, !llvm.loop !28

55:                                               ; preds = %14
  %56 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 8
  %57 = load ptr, ptr %56, align 8, !tbaa !30
  call void @_ZN6basisu9Resampler10resample_yEPf(ptr noundef nonnull align 8 dereferenceable(116) %6, ptr noundef %57)
  %58 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 20
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %58, align 4, !tbaa !9
  %61 = getelementptr inbounds %"class.basisu::Resampler", ptr %6, i32 0, i32 8
  %62 = load ptr, ptr %61, align 8, !tbaa !30
  store ptr %62, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %63

63:                                               ; preds = %55, %50, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %64 = load ptr, ptr %2, align 8
  ret ptr %64
}

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 = { 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 = { 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 100}
!10 = !{!"_ZTSN6basisu9ResamplerE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !12, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !13, i64 64, !13, i64 65, !13, i64 66, !6, i64 72, !6, i64 80, !6, i64 88, !11, i64 96, !11, i64 100, !14, i64 104, !15, i64 108, !15, i64 112}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN6basisu9Resampler11Boundary_OpE", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN6basisu9Resampler6StatusE", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!10, !11, i64 20}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !6, i64 56}
!19 = !{!20, !21, i64 0}
!20 = !{!"_ZTSN6basisu9Resampler12Contrib_ListE", !21, i64 0, !6, i64 8}
!21 = !{!"short", !7, i64 0}
!22 = !{!10, !6, i64 80}
!23 = !{!20, !6, i64 8}
!24 = !{!25, !21, i64 4}
!25 = !{!"_ZTSN6basisu9Resampler7ContribE", !15, i64 0, !21, i64 4}
!26 = !{!10, !11, i64 12}
!27 = !{!7, !7, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!10, !6, i64 32}


; 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"

%"struct.basisu::Resampler::Contrib_List" = type { i16, ptr }
%"struct.basisu::Resampler::Contrib" = type { float, i16 }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6basisu9Resampler10resample_yEPf(ptr noundef nonnull align 8 dereferenceable(116), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN6basisuL21resampler_range_checkEii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN6basisu9Resampler8get_lineEv(ptr noundef nonnull align 8 dereferenceable(116) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 100
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 20
  %5 = load i32, ptr %4, align 4, !tbaa !15
  %6 = icmp eq i32 %3, %5
  br i1 %6, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  %8 = load ptr, ptr %7, align 8, !tbaa !16
  %9 = sext i32 %3 to i64
  %10 = getelementptr inbounds %"struct.basisu::Resampler::Contrib_List", ptr %8, i64 %9
  %11 = load i16, ptr %10, align 8, !tbaa !17
  %.not6 = icmp eq i16 %11, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  %13 = getelementptr inbounds i8, ptr %0, i64 12
  br label %22

14:                                               ; preds = %22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = load ptr, ptr %7, align 8, !tbaa !16
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds %"struct.basisu::Resampler::Contrib_List", ptr %15, i64 %17
  %19 = load i16, ptr %18, align 8, !tbaa !17
  %20 = zext i16 %19 to i64
  %21 = icmp ult i64 %indvars.iv.next, %20
  br i1 %21, label %22, label %._crit_edge, !llvm.loop !20

22:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %23 = phi ptr [ %10, %.lr.ph ], [ %18, %14 ]
  %24 = load ptr, ptr %12, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %23, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !23
  %27 = getelementptr inbounds %"struct.basisu::Resampler::Contrib", ptr %26, i64 %indvars.iv, i32 1
  %28 = load i16, ptr %27, align 4, !tbaa !24
  %29 = zext i16 %28 to i32
  %30 = load i32, ptr %13, align 4, !tbaa !26
  %31 = tail call noundef i32 @_ZN6basisuL21resampler_range_checkEii(i32 noundef %29, i32 noundef %30)
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %24, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !27
  %.not = icmp eq i8 %34, 0
  br i1 %.not, label %.loopexit, label %14

._crit_edge:                                      ; preds = %14, %.preheader
  %35 = getelementptr inbounds i8, ptr %0, i64 32
  %36 = load ptr, ptr %35, align 8, !tbaa !28
  tail call void @_ZN6basisu9Resampler10resample_yEPf(ptr noundef nonnull align 8 dereferenceable(116) %0, ptr noundef %36)
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  %39 = load ptr, ptr %35, align 8, !tbaa !28
  br label %.loopexit

.loopexit:                                        ; preds = %22, %1, %._crit_edge
  %.04 = phi ptr [ %39, %._crit_edge ], [ null, %1 ], [ null, %22 ]
  ret ptr %.04
}

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

!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 100}
!6 = !{!"_ZTSN6basisu9ResamplerE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !12, i64 64, !12, i64 65, !12, i64 66, !11, i64 72, !11, i64 80, !11, i64 88, !7, i64 96, !7, i64 100, !13, i64 104, !14, i64 108, !14, i64 112}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN6basisu9Resampler11Boundary_OpE", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!"_ZTSN6basisu9Resampler6StatusE", !8, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = !{!6, !7, i64 20}
!16 = !{!6, !11, i64 56}
!17 = !{!18, !19, i64 0}
!18 = !{!"_ZTSN6basisu9Resampler12Contrib_ListE", !19, i64 0, !11, i64 8}
!19 = !{!"short", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!6, !11, i64 80}
!23 = !{!18, !11, i64 8}
!24 = !{!25, !19, i64 4}
!25 = !{!"_ZTSN6basisu9Resampler7ContribE", !14, i64 0, !19, i64 4}
!26 = !{!6, !7, i64 12}
!27 = !{!8, !8, i64 0}
!28 = !{!6, !11, i64 32}


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