; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN6basisu23palette_index_reorderer9pick_sideEjjPFfjjPvES1_f(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, float noundef %5) #3 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca float, align 4
  %20 = alloca float, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store float %5, ptr %12, align 4, !tbaa !11
  %21 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store float 0.000000e+00, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %66, %6
  %23 = load i32, ptr %16, align 4, !tbaa !9
  %24 = getelementptr inbounds %"class.basisu::palette_index_reorderer", ptr %21, i32 0, i32 2
  %25 = call noundef i32 @_ZNK6basisu6vectorIjE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %24)
  %26 = icmp ult i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %69

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = getelementptr inbounds %"class.basisu::palette_index_reorderer", ptr %21, i32 0, i32 2
  %31 = load i32, ptr %16, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjEixEm(ptr noundef nonnull align 8 dereferenceable(16) %30, i64 noundef %32)
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = call noundef i32 @_ZNK6basisu23palette_index_reorderer8get_histEiii(ptr noundef nonnull align 8 dereferenceable(80) %21, i32 noundef %29, i32 noundef %34, i32 noundef %35)
  store i32 %36, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %37 = getelementptr inbounds %"class.basisu::palette_index_reorderer", ptr %21, i32 0, i32 2
  %38 = call noundef i32 @_ZNK6basisu6vectorIjE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %37)
  %39 = add nsw i32 %38, 1
  %40 = load i32, ptr %16, align 4, !tbaa !9
  %41 = add i32 %40, 1
  %42 = mul i32 2, %41
  %43 = sub i32 %39, %42
  store i32 %43, ptr %18, align 4, !tbaa !9
  %44 = load i32, ptr %18, align 4, !tbaa !9
  %45 = load i32, ptr %17, align 4, !tbaa !9
  %46 = mul nsw i32 %44, %45
  %47 = sitofp i32 %46 to float
  %48 = load float, ptr %13, align 4, !tbaa !11
  %49 = fadd float %48, %47
  store float %49, ptr %13, align 4, !tbaa !11
  %50 = load i32, ptr %18, align 4, !tbaa !9
  %51 = icmp sge i32 %50, 0
  br i1 %51, label %52, label %58

52:                                               ; preds = %28
  %53 = load i32, ptr %18, align 4, !tbaa !9
  %54 = load i32, ptr %17, align 4, !tbaa !9
  %55 = mul nsw i32 %53, %54
  %56 = load i32, ptr %14, align 4, !tbaa !9
  %57 = add nsw i32 %56, %55
  store i32 %57, ptr %14, align 4, !tbaa !9
  br label %65

58:                                               ; preds = %28
  %59 = load i32, ptr %18, align 4, !tbaa !9
  %60 = sub nsw i32 0, %59
  %61 = load i32, ptr %17, align 4, !tbaa !9
  %62 = mul nsw i32 %60, %61
  %63 = load i32, ptr %15, align 4, !tbaa !9
  %64 = add nsw i32 %63, %62
  store i32 %64, ptr %15, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %58, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %16, align 4, !tbaa !9
  %68 = add i32 %67, 1
  store i32 %68, ptr %16, align 4, !tbaa !9
  br label %22, !llvm.loop !13

69:                                               ; preds = %27
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %106

72:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %73 = load float, ptr %12, align 4, !tbaa !11
  %74 = fsub float 1.000000e+00, %73
  %75 = load float, ptr %12, align 4, !tbaa !11
  %76 = fadd float 1.000000e+00, %75
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = getelementptr inbounds %"class.basisu::palette_index_reorderer", ptr %21, i32 0, i32 2
  %80 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjE5frontEv(ptr noundef nonnull align 8 dereferenceable(16) %79)
  %81 = load i32, ptr %80, align 4, !tbaa !9
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = call noundef float %77(i32 noundef %78, i32 noundef %81, ptr noundef %82)
  %84 = call noundef float @_ZN6basisu4lerpIffEET_S1_S1_T0_(float noundef %74, float noundef %76, float noundef %83)
  store float %84, ptr %19, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  %85 = load float, ptr %12, align 4, !tbaa !11
  %86 = fsub float 1.000000e+00, %85
  %87 = load float, ptr %12, align 4, !tbaa !11
  %88 = fadd float 1.000000e+00, %87
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = load i32, ptr %9, align 4, !tbaa !9
  %91 = getelementptr inbounds %"class.basisu::palette_index_reorderer", ptr %21, i32 0, i32 2
  %92 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjE4backEv(ptr noundef nonnull align 8 dereferenceable(16) %91)
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = load ptr, ptr %11, align 8, !tbaa !5
  %95 = call noundef float %89(i32 noundef %90, i32 noundef %93, ptr noundef %94)
  %96 = call noundef float @_ZN6basisu4lerpIffEET_S1_S1_T0_(float noundef %86, float noundef %88, float noundef %95)
  store float %96, ptr %20, align 4, !tbaa !11
  %97 = load float, ptr %19, align 4, !tbaa !11
  %98 = load i32, ptr %14, align 4, !tbaa !9
  %99 = sitofp i32 %98 to float
  %100 = load float, ptr %20, align 4, !tbaa !11
  %101 = load i32, ptr %15, align 4, !tbaa !9
  %102 = sitofp i32 %101 to float
  %103 = fmul float %100, %102
  %104 = fneg float %103
  %105 = call float @llvm.fmuladd.f32(float %97, float %99, float %104)
  store float %105, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  br label %106

106:                                              ; preds = %72, %69
  %107 = load float, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  ret float %107
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZN6basisu4lerpIffEET_S1_S1_T0_(float noundef, float noundef, float noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN6basisu23palette_index_reorderer9pick_sideEjjPFfjjPvES1_f(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1, i32 noundef %2, ptr noundef readonly %3, ptr noundef %4, float noundef %5) local_unnamed_addr #2 align 2 {
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = tail call noundef i32 @_ZNK6basisu6vectorIjE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %.not46 = icmp eq i32 %8, 0
  br i1 %.not46, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %9 = sitofp i32 %.133 to float
  %10 = sitofp i32 %.135 to float
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %6
  %.034.lcssa = phi float [ 0.000000e+00, %6 ], [ %10, %._crit_edge.loopexit ]
  %.032.lcssa = phi float [ 0.000000e+00, %6 ], [ %9, %._crit_edge.loopexit ]
  %.0.lcssa = phi float [ 0.000000e+00, %6 ], [ %20, %._crit_edge.loopexit ]
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %41, label %27

.lr.ph:                                           ; preds = %6, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %6 ]
  %.042 = phi float [ %20, %.lr.ph ], [ 0.000000e+00, %6 ]
  %.03241 = phi i32 [ %.133, %.lr.ph ], [ 0, %6 ]
  %.03440 = phi i32 [ %.135, %.lr.ph ], [ 0, %6 ]
  %11 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjEixEm(ptr noundef nonnull align 8 dereferenceable(16) %7, i64 noundef %indvars.iv)
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = tail call noundef i32 @_ZNK6basisu23palette_index_reorderer8get_histEiii(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %2, i32 noundef %12, i32 noundef %1)
  %14 = tail call noundef i32 @_ZNK6basisu6vectorIjE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %15 = trunc nuw i64 %indvars.iv to i32
  %.neg47 = xor i32 %15, -1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.neg48 = shl i32 %.neg47, 1
  %16 = or disjoint i32 %.neg48, 1
  %17 = add i32 %16, %14
  %18 = mul i32 %17, %13
  %19 = sitofp i32 %18 to float
  %20 = fadd float %.042, %19
  %21 = icmp sgt i32 %17, -1
  %22 = select i1 %21, i32 0, i32 %18
  %.135 = sub i32 %.03440, %22
  %23 = select i1 %21, i32 %18, i32 0
  %.133 = add nsw i32 %23, %.03241
  %24 = tail call noundef i32 @_ZNK6basisu6vectorIjE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %25 = zext i32 %24 to i64
  %26 = icmp ult i64 %indvars.iv.next, %25
  br i1 %26, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

27:                                               ; preds = %._crit_edge
  %28 = fsub float 1.000000e+00, %5
  %29 = fadd float %5, 1.000000e+00
  %30 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjE5frontEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = tail call noundef float %3(i32 noundef %2, i32 noundef %31, ptr noundef %4)
  %33 = tail call noundef float @_ZN6basisu4lerpIffEET_S1_S1_T0_(float noundef %28, float noundef %29, float noundef %32)
  %34 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjE4backEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = tail call noundef float %3(i32 noundef %2, i32 noundef %35, ptr noundef %4)
  %37 = tail call noundef float @_ZN6basisu4lerpIffEET_S1_S1_T0_(float noundef %28, float noundef %29, float noundef %36)
  %38 = fneg float %37
  %39 = fmul float %.034.lcssa, %38
  %40 = tail call float @llvm.fmuladd.f32(float %33, float %.032.lcssa, float %39)
  br label %41

41:                                               ; preds = %27, %._crit_edge
  %.1 = phi float [ %40, %27 ], [ %.0.lcssa, %._crit_edge ]
  ret float %.1
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjE5frontEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN6basisu6vectorIjE4backEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZN6basisu4lerpIffEET_S1_S1_T0_(float noundef, float noundef, float noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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" }

!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}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass