; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder (basisu_enc)

; 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::palette_index_reorderer" = type { %"class.basisu::vector.18", %"class.basisu::vector.18", %"class.basisu::vector.18", %"class.basisu::vector.18", %"class.basisu::vector.18" }
%"class.basisu::vector.18" = type { ptr, i32, i32 }

; 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 void @_ZN6basisu6vectorIjE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i1 noundef zeroext) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6basisu23palette_index_reorderer12prepare_histEjjPKj(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  %12 = getelementptr inbounds %"class.basisu::palette_index_reorderer", ptr %11, i32 0, i32 0
  call void @_ZN6basisu6vectorIjE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(16) %12, i64 noundef 0, i1 noundef zeroext false)
  %13 = getelementptr inbounds %"class.basisu::palette_index_reorderer", ptr %11, i32 0, i32 0
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = mul i32 %14, %15
  %17 = zext i32 %16 to i64
  call void @_ZN6basisu6vectorIjE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(16) %13, i64 noundef %17, i1 noundef zeroext false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %59, %4
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %62

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  store i32 %28, ptr %10, align 4, !tbaa !9
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = sub i32 %31, 1
  %33 = icmp ult i32 %30, %32
  br i1 %33, label %34, label %41

34:                                               ; preds = %23
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = add i32 %36, 1
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %35, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  br label %42

41:                                               ; preds = %23
  br label %42

42:                                               ; preds = %41, %34
  %43 = phi i32 [ %40, %34 ], [ -1, %41 ]
  %44 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN6basisu23palette_index_reorderer8inc_histEiii(ptr noundef nonnull align 8 dereferenceable(80) %11, i32 noundef %29, i32 noundef %43, i32 noundef %44)
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = icmp ugt i32 %46, 0
  br i1 %47, label %48, label %55

48:                                               ; preds = %42
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = sub i32 %50, 1
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %49, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  br label %56

55:                                               ; preds = %42
  br label %56

56:                                               ; preds = %55, %48
  %57 = phi i32 [ %54, %48 ], [ -1, %55 ]
  %58 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN6basisu23palette_index_reorderer8inc_histEiii(ptr noundef nonnull align 8 dereferenceable(80) %11, i32 noundef %45, i32 noundef %57, i32 noundef %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %59

59:                                               ; preds = %56
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = add i32 %60, 1
  store i32 %61, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !11

62:                                               ; preds = %22
  ret void
}

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

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 = { 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 = { 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 = distinct !{!11, !12}
!12 = !{!"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: inlinehint mustprogress uwtable
declare dso_local void @_ZN6basisu6vectorIjE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i1 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6basisu23palette_index_reorderer12prepare_histEjjPKj(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #1 align 2 {
  tail call void @_ZN6basisu6vectorIjE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef 0, i1 noundef zeroext false)
  %5 = mul i32 %1, %1
  %6 = zext i32 %5 to i64
  tail call void @_ZN6basisu6vectorIjE6resizeEmb(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %6, i1 noundef zeroext false)
  %.not20 = icmp eq i32 %2, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %7 = add i32 %2, -1
  %8 = zext i32 %7 to i64
  %wide.trip.count = zext i32 %2 to i64
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %13, label %10

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %3, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %.lr.ph, %10
  %14 = phi i32 [ %12, %10 ], [ -1, %.lr.ph ]
  tail call void @_ZN6basisu23palette_index_reorderer8inc_histEiii(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %9, i32 noundef %14, i32 noundef %1)
  tail call void @_ZN6basisu23palette_index_reorderer8inc_histEiii(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %9, i32 noundef -1, i32 noundef %1)
  %exitcond.peel.not = icmp eq i32 %2, 1
  br i1 %exitcond.peel.not, label %._crit_edge, label %.peel.next

.peel.next:                                       ; preds = %13
  %invariant.gep = getelementptr inbounds i8, ptr %3, i64 4
  %invariant.gep24 = getelementptr i8, ptr %3, i64 -4
  br label %15

._crit_edge:                                      ; preds = %21, %13, %4
  ret void

15:                                               ; preds = %.peel.next, %21
  %indvars.iv = phi i64 [ 1, %.peel.next ], [ %indvars.iv.next, %21 ]
  %16 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp ult i64 %indvars.iv, %8
  br i1 %18, label %19, label %21

19:                                               ; preds = %15
  %gep = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv
  %20 = load i32, ptr %gep, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %15, %19
  %22 = phi i32 [ %20, %19 ], [ -1, %15 ]
  tail call void @_ZN6basisu23palette_index_reorderer8inc_histEiii(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %17, i32 noundef %22, i32 noundef %1)
  %gep25 = getelementptr i32, ptr %invariant.gep24, i64 %indvars.iv
  %23 = load i32, ptr %gep25, align 4, !tbaa !5
  tail call void @_ZN6basisu23palette_index_reorderer8inc_histEiii(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %17, i32 noundef %23, i32 noundef %1)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !9
}

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

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}


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