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

; 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::Scan_Buf" = type { [16384 x i32], [16384 x ptr] }

; 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: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6basisu9ResamplerD2Ev(ptr noundef nonnull align 8 dereferenceable(116) %0) unnamed_addr #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %5 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 8
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  call void @free(ptr noundef %6) #3
  %7 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 8
  store ptr null, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 9
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %15

11:                                               ; preds = %1
  %12 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 9
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  call void @free(ptr noundef %13) #3
  %14 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 9
  store ptr null, ptr %14, align 8, !tbaa !16
  br label %15

15:                                               ; preds = %11, %1
  %16 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 10
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %31

19:                                               ; preds = %15
  %20 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 12
  %21 = load i8, ptr %20, align 8, !tbaa !18, !range !19, !noundef !20
  %22 = trunc i8 %21 to i1
  br i1 %22, label %31, label %23

23:                                               ; preds = %19
  %24 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 10
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = getelementptr inbounds %"struct.basisu::Resampler::Contrib_List", ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  call void @free(ptr noundef %27) #3
  %28 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 10
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  call void @free(ptr noundef %29) #3
  %30 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 10
  store ptr null, ptr %30, align 8, !tbaa !17
  br label %31

31:                                               ; preds = %23, %19, %15
  %32 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 11
  %33 = load ptr, ptr %32, align 8, !tbaa !24
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %47

35:                                               ; preds = %31
  %36 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 13
  %37 = load i8, ptr %36, align 1, !tbaa !25, !range !19, !noundef !20
  %38 = trunc i8 %37 to i1
  br i1 %38, label %47, label %39

39:                                               ; preds = %35
  %40 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 11
  %41 = load ptr, ptr %40, align 8, !tbaa !24
  %42 = getelementptr inbounds %"struct.basisu::Resampler::Contrib_List", ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !21
  call void @free(ptr noundef %43) #3
  %44 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 11
  %45 = load ptr, ptr %44, align 8, !tbaa !24
  call void @free(ptr noundef %45) #3
  %46 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 11
  store ptr null, ptr %46, align 8, !tbaa !24
  br label %47

47:                                               ; preds = %39, %35, %31
  %48 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 16
  %49 = load ptr, ptr %48, align 8, !tbaa !26
  call void @free(ptr noundef %49) #3
  %50 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 16
  store ptr null, ptr %50, align 8, !tbaa !26
  %51 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 17
  %52 = load ptr, ptr %51, align 8, !tbaa !27
  call void @free(ptr noundef %52) #3
  %53 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 17
  store ptr null, ptr %53, align 8, !tbaa !27
  %54 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 18
  %55 = load ptr, ptr %54, align 8, !tbaa !28
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %76

57:                                               ; preds = %47
  store i32 0, ptr %3, align 4, !tbaa !29
  br label %58

58:                                               ; preds = %69, %57
  %59 = load i32, ptr %3, align 4, !tbaa !29
  %60 = icmp slt i32 %59, 16384
  br i1 %60, label %61, label %72

61:                                               ; preds = %58
  %62 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 18
  %63 = load ptr, ptr %62, align 8, !tbaa !28
  %64 = getelementptr inbounds %"struct.basisu::Resampler::Scan_Buf", ptr %63, i32 0, i32 1
  %65 = load i32, ptr %3, align 4, !tbaa !29
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [16384 x ptr], ptr %64, i64 0, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  call void @free(ptr noundef %68) #3
  br label %69

69:                                               ; preds = %61
  %70 = load i32, ptr %3, align 4, !tbaa !29
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %3, align 4, !tbaa !29
  br label %58, !llvm.loop !30

72:                                               ; preds = %58
  %73 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 18
  %74 = load ptr, ptr %73, align 8, !tbaa !28
  call void @free(ptr noundef %74) #3
  %75 = getelementptr inbounds %"class.basisu::Resampler", ptr %4, i32 0, i32 18
  store ptr null, ptr %75, align 8, !tbaa !28
  br label %76

76:                                               ; preds = %72, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 32}
!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, !6, i64 40}
!17 = !{!10, !6, i64 48}
!18 = !{!10, !13, i64 64}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!22, !6, i64 8}
!22 = !{!"_ZTSN6basisu9Resampler12Contrib_ListE", !23, i64 0, !6, i64 8}
!23 = !{!"short", !7, i64 0}
!24 = !{!10, !6, i64 56}
!25 = !{!10, !13, i64 65}
!26 = !{!10, !6, i64 72}
!27 = !{!10, !6, i64 80}
!28 = !{!10, !6, i64 88}
!29 = !{!11, !11, i64 0}
!30 = distinct !{!30, !31}
!31 = !{!"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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6basisu9ResamplerD2Ev(ptr nocapture noundef nonnull align 8 dereferenceable(116) %0) unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @free(ptr noundef %3) #2
  store ptr null, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !15
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %1
  tail call void @free(ptr noundef nonnull %5) #2
  store ptr null, ptr %4, align 8, !tbaa !15
  br label %7

7:                                                ; preds = %6, %1
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %.not6 = icmp eq ptr %9, null
  br i1 %.not6, label %18, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = load i8, ptr %11, align 8, !tbaa !17, !range !18, !noundef !19
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %18, label %14

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %9, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  tail call void @free(ptr noundef %16) #2
  %17 = load ptr, ptr %8, align 8, !tbaa !16
  tail call void @free(ptr noundef %17) #2
  store ptr null, ptr %8, align 8, !tbaa !16
  br label %18

18:                                               ; preds = %14, %10, %7
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load ptr, ptr %19, align 8, !tbaa !23
  %.not7 = icmp eq ptr %20, null
  br i1 %.not7, label %29, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %0, i64 65
  %23 = load i8, ptr %22, align 1, !tbaa !24, !range !18, !noundef !19
  %24 = trunc nuw i8 %23 to i1
  br i1 %24, label %29, label %25

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %20, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  tail call void @free(ptr noundef %27) #2
  %28 = load ptr, ptr %19, align 8, !tbaa !23
  tail call void @free(ptr noundef %28) #2
  store ptr null, ptr %19, align 8, !tbaa !23
  br label %29

29:                                               ; preds = %25, %21, %18
  %30 = getelementptr inbounds i8, ptr %0, i64 72
  %31 = load ptr, ptr %30, align 8, !tbaa !25
  tail call void @free(ptr noundef %31) #2
  store ptr null, ptr %30, align 8, !tbaa !25
  %32 = getelementptr inbounds i8, ptr %0, i64 80
  %33 = load ptr, ptr %32, align 8, !tbaa !26
  tail call void @free(ptr noundef %33) #2
  store ptr null, ptr %32, align 8, !tbaa !26
  %34 = getelementptr inbounds i8, ptr %0, i64 88
  %35 = load ptr, ptr %34, align 8, !tbaa !27
  %.not8 = icmp eq ptr %35, null
  br i1 %.not8, label %42, label %.preheader

.preheader:                                       ; preds = %29, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader ], [ 0, %29 ]
  %36 = load ptr, ptr %34, align 8, !tbaa !27
  %37 = getelementptr inbounds i8, ptr %36, i64 65536
  %38 = getelementptr inbounds [16384 x ptr], ptr %37, i64 0, i64 %indvars.iv
  %39 = load ptr, ptr %38, align 8, !tbaa !28
  tail call void @free(ptr noundef %39) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 16384
  br i1 %exitcond.not, label %40, label %.preheader, !llvm.loop !29

40:                                               ; preds = %.preheader
  %41 = load ptr, ptr %34, align 8, !tbaa !27
  tail call void @free(ptr noundef %41) #2
  store ptr null, ptr %34, align 8, !tbaa !27
  br label %42

42:                                               ; preds = %40, %29
  ret void
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 = { 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, !11, i64 32}
!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, !11, i64 40}
!16 = !{!6, !11, i64 48}
!17 = !{!6, !12, i64 64}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!21, !11, i64 8}
!21 = !{!"_ZTSN6basisu9Resampler12Contrib_ListE", !22, i64 0, !11, i64 8}
!22 = !{!"short", !8, i64 0}
!23 = !{!6, !11, i64 56}
!24 = !{!6, !12, i64 65}
!25 = !{!6, !11, i64 72}
!26 = !{!6, !11, i64 80}
!27 = !{!6, !11, i64 88}
!28 = !{!11, !11, i64 0}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass