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

; 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.basist::etc1_global_palette_entry_modifier" = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8 }
%"struct.basist::etc1_selector_palette_entry" = type { [16 x i8] }
%"struct.basisu::etc_block" = type { %union.anon.0 }
%union.anon.0 = type { i64 }
%"struct.basisu::pixel_block" = type { [4 x [4 x %"class.basisu::color_rgba"]] }
%"class.basisu::color_rgba" = type { %union.anon }
%union.anon = type { [4 x i8] }

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN6basisu45etc1_global_selector_codebook_find_best_entryERKN6basist29etc1_global_selector_codebookEjPKNS_11pixel_blockEPKNS_9etc_blockERjRNS0_34etc1_global_palette_entry_modifierEbjj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 1 dereferenceable(13) %5, i1 noundef zeroext %6, i32 noundef %7, i32 noundef %8) #0 {
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i8, align 1
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  %20 = alloca i32, align 4
  %21 = alloca %"class.basist::etc1_global_palette_entry_modifier", align 1
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  %25 = alloca %"class.basist::etc1_global_palette_entry_modifier", align 1
  %26 = alloca %"struct.basist::etc1_selector_palette_entry", align 1
  %27 = alloca i64, align 8
  %28 = alloca i32, align 4
  %29 = alloca %"struct.basisu::etc_block", align 8
  %30 = alloca i32, align 4
  %31 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i32 %1, ptr %11, align 4, !tbaa !9
  store ptr %2, ptr %12, align 8, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !5
  store ptr %4, ptr %14, align 8, !tbaa !5
  store ptr %5, ptr %15, align 8, !tbaa !5
  %32 = zext i1 %6 to i8
  store i8 %32, ptr %16, align 1, !tbaa !11
  store i32 %7, ptr %17, align 4, !tbaa !9
  store i32 %8, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  store i64 -1, ptr %19, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #6
  store i32 0, ptr %20, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 13, ptr %21) #6
  call void @_ZN6basist34etc1_global_palette_entry_modifierC2Ej(ptr noundef nonnull align 1 dereferenceable(13) %21, i32 noundef 0)
  %33 = load i32, ptr %17, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %38, label %35

35:                                               ; preds = %9
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call noundef i32 @_ZNK6basist29etc1_global_selector_codebook4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %36)
  store i32 %37, ptr %17, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %35, %9
  %39 = load i32, ptr %18, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  store i32 32768, ptr %18, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %41, %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #6
  store i32 0, ptr %22, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %132, %42
  %44 = load i32, ptr %22, align 4, !tbaa !9
  %45 = load i32, ptr %17, align 4, !tbaa !9
  %46 = icmp ult i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 2, ptr %23, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #6
  br label %135

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #6
  store i32 0, ptr %24, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %128, %48
  %50 = load i32, ptr %24, align 4, !tbaa !9
  %51 = load i32, ptr %18, align 4, !tbaa !9
  %52 = icmp ult i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i32 5, ptr %23, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #6
  br label %131

54:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 13, ptr %25) #6
  %55 = load i32, ptr %24, align 4, !tbaa !9
  call void @_ZN6basist34etc1_global_palette_entry_modifierC2Ej(ptr noundef nonnull align 1 dereferenceable(13) %25, i32 noundef %55)
  call void @llvm.lifetime.start.p0(i64 16, ptr %26) #6
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load i32, ptr %22, align 4, !tbaa !9
  %58 = call { i64, i64 } @_ZNK6basist29etc1_global_selector_codebook9get_entryEjRKNS_34etc1_global_palette_entry_modifierE(ptr noundef nonnull align 8 dereferenceable(16) %56, i32 noundef %57, ptr noundef nonnull align 1 dereferenceable(13) %25)
  %59 = getelementptr inbounds %"struct.basist::etc1_selector_palette_entry", ptr %26, i32 0, i32 0
  %60 = getelementptr inbounds { i64, i64 }, ptr %59, i32 0, i32 0
  %61 = extractvalue { i64, i64 } %58, 0
  store i64 %61, ptr %60, align 1
  %62 = getelementptr inbounds { i64, i64 }, ptr %59, i32 0, i32 1
  %63 = extractvalue { i64, i64 } %58, 1
  store i64 %63, ptr %62, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #6
  store i64 0, ptr %27, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %28) #6
  store i32 0, ptr %28, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %116, %54
  %65 = load i32, ptr %28, align 4, !tbaa !9
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = icmp ult i32 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  store i32 8, ptr %23, align 4
  br label %119

69:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %29) #6
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = load i32, ptr %28, align 4, !tbaa !9
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds %"struct.basisu::etc_block", ptr %70, i64 %72
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %29, ptr align 8 %73, i64 8, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #6
  store i32 0, ptr %30, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %94, %69
  %75 = load i32, ptr %30, align 4, !tbaa !9
  %76 = icmp ult i32 %75, 4
  br i1 %76, label %78, label %77

77:                                               ; preds = %74
  store i32 11, ptr %23, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #6
  br label %97

78:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 4, ptr %31) #6
  store i32 0, ptr %31, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %90, %78
  %80 = load i32, ptr %31, align 4, !tbaa !9
  %81 = icmp ult i32 %80, 4
  br i1 %81, label %83, label %82

82:                                               ; preds = %79
  store i32 14, ptr %23, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %31) #6
  br label %93

83:                                               ; preds = %79
  %84 = load i32, ptr %31, align 4, !tbaa !9
  %85 = load i32, ptr %30, align 4, !tbaa !9
  %86 = load i32, ptr %31, align 4, !tbaa !9
  %87 = load i32, ptr %30, align 4, !tbaa !9
  %88 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %26, i32 noundef %86, i32 noundef %87)
  %89 = zext i8 %88 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %29, i32 noundef %84, i32 noundef %85, i32 noundef %89)
  br label %90

90:                                               ; preds = %83
  %91 = load i32, ptr %31, align 4, !tbaa !9
  %92 = add i32 %91, 1
  store i32 %92, ptr %31, align 4, !tbaa !9
  br label %79, !llvm.loop !17

93:                                               ; preds = %82
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %30, align 4, !tbaa !9
  %96 = add i32 %95, 1
  store i32 %96, ptr %30, align 4, !tbaa !9
  br label %74, !llvm.loop !19

97:                                               ; preds = %77
  %98 = load ptr, ptr %12, align 8, !tbaa !5
  %99 = load i32, ptr %28, align 4, !tbaa !9
  %100 = zext i32 %99 to i64
  %101 = getelementptr inbounds %"struct.basisu::pixel_block", ptr %98, i64 %100
  %102 = call noundef ptr @_ZNK6basisu11pixel_block7get_ptrEv(ptr noundef nonnull align 1 dereferenceable(64) %101)
  %103 = load i8, ptr %16, align 1, !tbaa !11, !range !20, !noundef !21
  %104 = trunc i8 %103 to i1
  %105 = call noundef i64 @_ZNK6basisu9etc_block19evaluate_etc1_errorEPKNS_10color_rgbaEbi(ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef %102, i1 noundef zeroext %104, i32 noundef -1)
  %106 = load i64, ptr %27, align 8, !tbaa !13
  %107 = add i64 %106, %105
  store i64 %107, ptr %27, align 8, !tbaa !13
  %108 = load i64, ptr %27, align 8, !tbaa !13
  %109 = load i64, ptr %19, align 8, !tbaa !13
  %110 = icmp uge i64 %108, %109
  br i1 %110, label %111, label %112

111:                                              ; preds = %97
  store i32 8, ptr %23, align 4
  br label %113

112:                                              ; preds = %97
  store i32 0, ptr %23, align 4
  br label %113

113:                                              ; preds = %112, %111
  call void @llvm.lifetime.end.p0(i64 8, ptr %29) #6
  %114 = load i32, ptr %23, align 4
  switch i32 %114, label %119 [
    i32 0, label %115
  ]

115:                                              ; preds = %113
  br label %116

116:                                              ; preds = %115
  %117 = load i32, ptr %28, align 4, !tbaa !9
  %118 = add i32 %117, 1
  store i32 %118, ptr %28, align 4, !tbaa !9
  br label %64, !llvm.loop !22

119:                                              ; preds = %113, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #6
  br label %120

120:                                              ; preds = %119
  %121 = load i64, ptr %27, align 8, !tbaa !13
  %122 = load i64, ptr %19, align 8, !tbaa !13
  %123 = icmp ult i64 %121, %122
  br i1 %123, label %124, label %127

124:                                              ; preds = %120
  %125 = load i64, ptr %27, align 8, !tbaa !13
  store i64 %125, ptr %19, align 8, !tbaa !13
  %126 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %126, ptr %20, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %21, ptr align 1 %25, i64 13, i1 false), !tbaa.struct !23
  br label %127

127:                                              ; preds = %124, %120
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %26) #6
  call void @llvm.lifetime.end.p0(i64 13, ptr %25) #6
  br label %128

128:                                              ; preds = %127
  %129 = load i32, ptr %24, align 4, !tbaa !9
  %130 = add i32 %129, 1
  store i32 %130, ptr %24, align 4, !tbaa !9
  br label %49, !llvm.loop !24

131:                                              ; preds = %53
  br label %132

132:                                              ; preds = %131
  %133 = load i32, ptr %22, align 4, !tbaa !9
  %134 = add i32 %133, 1
  store i32 %134, ptr %22, align 4, !tbaa !9
  br label %43, !llvm.loop !25

135:                                              ; preds = %47
  %136 = load i32, ptr %20, align 4, !tbaa !9
  %137 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 %136, ptr %137, align 4, !tbaa !9
  %138 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %138, ptr align 1 %21, i64 13, i1 false), !tbaa.struct !23
  %139 = load i64, ptr %19, align 8, !tbaa !13
  store i32 1, ptr %23, align 4
  call void @llvm.lifetime.end.p0(i64 13, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  ret i64 %139
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6basist34etc1_global_palette_entry_modifierC2Ej(ptr noundef nonnull align 1 dereferenceable(13), i32 noundef) unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZNK6basist29etc1_global_selector_codebook9get_entryEjRKNS_34etc1_global_palette_entry_modifierE(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, ptr noundef nonnull align 1 dereferenceable(13)) #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16), i32 noundef, i32 noundef) #4 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef i64 @_ZNK6basisu9etc_block19evaluate_etc1_errorEPKNS_10color_rgbaEbi(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i1 noundef zeroext, i32 noundef) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK6basisu11pixel_block7get_ptrEv(ptr noundef nonnull align 1 dereferenceable(64)) #4 align 2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { "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 #6 = { 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 = !{!"bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{i64 0, i64 8, !16}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = distinct !{!22, !18}
!23 = !{i64 0, i64 1, !16, i64 1, i64 1, !11, i64 2, i64 1, !11, i64 3, i64 1, !11, i64 4, i64 1, !11, i64 5, i64 1, !11, i64 6, i64 1, !11, i64 7, i64 1, !11, i64 8, i64 1, !11, i64 9, i64 1, !11, i64 10, i64 1, !11, i64 11, i64 1, !11, i64 12, i64 1, !16}
!24 = distinct !{!24, !18}
!25 = distinct !{!25, !18}


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

%"class.basist::etc1_global_palette_entry_modifier" = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8 }
%"struct.basist::etc1_selector_palette_entry" = type { [16 x i8] }
%"struct.basisu::etc_block" = type { %union.anon.0 }
%union.anon.0 = type { i64 }
%"struct.basisu::pixel_block" = type { [4 x [4 x %"class.basisu::color_rgba"]] }
%"class.basisu::color_rgba" = type { %union.anon }
%union.anon = type { [4 x i8] }

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN6basisu45etc1_global_selector_codebook_find_best_entryERKN6basist29etc1_global_selector_codebookEjPKNS_11pixel_blockEPKNS_9etc_blockERjRNS0_34etc1_global_palette_entry_modifierEbjj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, ptr noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %4, ptr nocapture noundef nonnull writeonly align 1 dereferenceable(13) %5, i1 noundef zeroext %6, i32 noundef %7, i32 noundef %8) local_unnamed_addr #0 {
  %10 = alloca %"class.basist::etc1_global_palette_entry_modifier", align 1
  %11 = alloca %"class.basist::etc1_global_palette_entry_modifier", align 1
  %12 = alloca %"struct.basist::etc1_selector_palette_entry", align 8
  %13 = alloca %"struct.basisu::etc_block", align 8
  call void @llvm.lifetime.start.p0(i64 13, ptr nonnull %10) #6
  call void @_ZN6basist34etc1_global_palette_entry_modifierC2Ej(ptr noundef nonnull align 1 dereferenceable(13) %10, i32 noundef 0)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %14, label %.thread

.thread:                                          ; preds = %9
  %.not5282 = icmp eq i32 %8, 0
  %spec.store.select83 = select i1 %.not5282, i32 32768, i32 %8
  br label %.preheader54.lr.ph

14:                                               ; preds = %9
  %15 = call noundef i32 @_ZNK6basist29etc1_global_selector_codebook4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %.not52 = icmp eq i32 %8, 0
  %spec.store.select = select i1 %.not52, i32 32768, i32 %8
  %.not72 = icmp eq i32 %15, 0
  br i1 %.not72, label %._crit_edge, label %.preheader54.lr.ph

.preheader54.lr.ph:                               ; preds = %.thread, %14
  %spec.store.select86 = phi i32 [ %spec.store.select83, %.thread ], [ %spec.store.select, %14 ]
  %.05085 = phi i32 [ %7, %.thread ], [ %15, %14 ]
  %16 = getelementptr inbounds i8, ptr %12, i64 8
  %.not73 = icmp eq i32 %1, 0
  br i1 %.not73, label %.preheader54.preheader, label %.preheader54.us.preheader

.preheader54.preheader:                           ; preds = %.preheader54.lr.ph
  %exitcond79.not.peel = icmp eq i32 %spec.store.select86, 1
  br label %.preheader54

.preheader54.us.preheader:                        ; preds = %.preheader54.lr.ph
  %17 = zext i32 %1 to i64
  br label %.preheader54.us

.preheader54.us:                                  ; preds = %.preheader54.us.preheader, %.split.us.us
  %.04467.us = phi i32 [ %63, %.split.us.us ], [ 0, %.preheader54.us.preheader ]
  %.04566.us = phi i32 [ %.2.us.us, %.split.us.us ], [ 0, %.preheader54.us.preheader ]
  %.04765.us = phi i64 [ %.249.us.us, %.split.us.us ], [ -1, %.preheader54.us.preheader ]
  br label %.lr.ph.us.us

.lr.ph.us.us:                                     ; preds = %61, %.preheader54.us
  %.04263.us.us = phi i32 [ 0, %.preheader54.us ], [ %62, %61 ]
  %.14662.us.us = phi i32 [ %.04566.us, %.preheader54.us ], [ %.2.us.us, %61 ]
  %.14861.us.us = phi i64 [ %.04765.us, %.preheader54.us ], [ %.249.us.us, %61 ]
  call void @llvm.lifetime.start.p0(i64 13, ptr nonnull %11) #6
  call void @_ZN6basist34etc1_global_palette_entry_modifierC2Ej(ptr noundef nonnull align 1 dereferenceable(13) %11, i32 noundef %.04263.us.us)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %12) #6
  %18 = call { i64, i64 } @_ZNK6basist29etc1_global_selector_codebook9get_entryEjRKNS_34etc1_global_palette_entry_modifierE(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.04467.us, ptr noundef nonnull align 1 dereferenceable(13) %11)
  %19 = extractvalue { i64, i64 } %18, 0
  store i64 %19, ptr %12, align 8
  %20 = extractvalue { i64, i64 } %18, 1
  store i64 %20, ptr %16, align 8
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %.preheader.us.us, %.lr.ph.us.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader.us.us ], [ 0, %.lr.ph.us.us ]
  %.04157.us.us = phi i64 [ %58, %.preheader.us.us ], [ 0, %.lr.ph.us.us ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %13) #6
  %21 = getelementptr inbounds %"struct.basisu::etc_block", ptr %3, i64 %indvars.iv
  %22 = load i64, ptr %21, align 8, !tbaa !5
  store i64 %22, ptr %13, align 8, !tbaa !5
  %23 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 0, i32 noundef 0)
  %24 = zext i8 %23 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 0, i32 noundef 0, i32 noundef %24)
  %25 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 1, i32 noundef 0)
  %26 = zext i8 %25 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 1, i32 noundef 0, i32 noundef %26)
  %27 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 2, i32 noundef 0)
  %28 = zext i8 %27 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 2, i32 noundef 0, i32 noundef %28)
  %29 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 3, i32 noundef 0)
  %30 = zext i8 %29 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 3, i32 noundef 0, i32 noundef %30)
  %31 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 0, i32 noundef 1)
  %32 = zext i8 %31 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 0, i32 noundef 1, i32 noundef %32)
  %33 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 1, i32 noundef 1)
  %34 = zext i8 %33 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 1, i32 noundef 1, i32 noundef %34)
  %35 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 2, i32 noundef 1)
  %36 = zext i8 %35 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 2, i32 noundef 1, i32 noundef %36)
  %37 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 3, i32 noundef 1)
  %38 = zext i8 %37 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 3, i32 noundef 1, i32 noundef %38)
  %39 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 0, i32 noundef 2)
  %40 = zext i8 %39 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 0, i32 noundef 2, i32 noundef %40)
  %41 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 1, i32 noundef 2)
  %42 = zext i8 %41 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 1, i32 noundef 2, i32 noundef %42)
  %43 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 2, i32 noundef 2)
  %44 = zext i8 %43 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 2, i32 noundef 2, i32 noundef %44)
  %45 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 3, i32 noundef 2)
  %46 = zext i8 %45 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 3, i32 noundef 2, i32 noundef %46)
  %47 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 0, i32 noundef 3)
  %48 = zext i8 %47 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 0, i32 noundef 3, i32 noundef %48)
  %49 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 1, i32 noundef 3)
  %50 = zext i8 %49 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 1, i32 noundef 3, i32 noundef %50)
  %51 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 2, i32 noundef 3)
  %52 = zext i8 %51 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 2, i32 noundef 3, i32 noundef %52)
  %53 = call noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16) %12, i32 noundef 3, i32 noundef 3)
  %54 = zext i8 %53 to i32
  call void @_ZN6basisu9etc_block12set_selectorEjjj(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 3, i32 noundef 3, i32 noundef %54)
  %55 = getelementptr inbounds %"struct.basisu::pixel_block", ptr %2, i64 %indvars.iv
  %56 = call noundef ptr @_ZNK6basisu11pixel_block7get_ptrEv(ptr noundef nonnull align 1 dereferenceable(64) %55)
  %57 = call noundef i64 @_ZNK6basisu9etc_block19evaluate_etc1_errorEPKNS_10color_rgbaEbi(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef %56, i1 noundef zeroext %6, i32 noundef -1)
  %58 = add i64 %57, %.04157.us.us
  %.not53.us.us = icmp ult i64 %58, %.14861.us.us
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %13) #6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %59 = icmp ult i64 %indvars.iv.next, %17
  %or.cond = and i1 %.not53.us.us, %59
  br i1 %or.cond, label %.preheader.us.us, label %._crit_edge.us.us, !llvm.loop !8

._crit_edge.us.us:                                ; preds = %.preheader.us.us
  br i1 %.not53.us.us, label %60, label %61

60:                                               ; preds = %._crit_edge.us.us
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(13) %10, ptr noundef nonnull align 1 dereferenceable(13) %11, i64 13, i1 false), !tbaa.struct !10
  br label %61

61:                                               ; preds = %60, %._crit_edge.us.us
  %.249.us.us = phi i64 [ %58, %60 ], [ %.14861.us.us, %._crit_edge.us.us ]
  %.2.us.us = phi i32 [ %.04467.us, %60 ], [ %.14662.us.us, %._crit_edge.us.us ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %12) #6
  call void @llvm.lifetime.end.p0(i64 13, ptr nonnull %11) #6
  %62 = add nuw i32 %.04263.us.us, 1
  %exitcond.not = icmp eq i32 %62, %spec.store.select86
  br i1 %exitcond.not, label %.split.us.us, label %.lr.ph.us.us, !llvm.loop !13

.split.us.us:                                     ; preds = %61
  %63 = add nuw i32 %.04467.us, 1
  %exitcond77.not = icmp eq i32 %63, %.05085
  br i1 %exitcond77.not, label %._crit_edge, label %.preheader54.us, !llvm.loop !14

.preheader54:                                     ; preds = %.preheader54.preheader, %.split
  %.04467 = phi i32 [ %67, %.split ], [ 0, %.preheader54.preheader ]
  %.04566 = phi i32 [ %.2.peel, %.split ], [ 0, %.preheader54.preheader ]
  %.not74.peel = phi i1 [ true, %.split ], [ false, %.preheader54.preheader ]
  call void @llvm.lifetime.start.p0(i64 13, ptr nonnull %11) #6
  call void @_ZN6basist34etc1_global_palette_entry_modifierC2Ej(ptr noundef nonnull align 1 dereferenceable(13) %11, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %12) #6
  %64 = call { i64, i64 } @_ZNK6basist29etc1_global_selector_codebook9get_entryEjRKNS_34etc1_global_palette_entry_modifierE(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.04467, ptr noundef nonnull align 1 dereferenceable(13) %11)
  br i1 %.not74.peel, label %66, label %65

65:                                               ; preds = %.preheader54
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(13) %10, ptr noundef nonnull align 1 dereferenceable(13) %11, i64 13, i1 false), !tbaa.struct !10
  br label %66

66:                                               ; preds = %65, %.preheader54
  %.2.peel = phi i32 [ %.04467, %65 ], [ %.04566, %.preheader54 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %12) #6
  call void @llvm.lifetime.end.p0(i64 13, ptr nonnull %11) #6
  br i1 %exitcond79.not.peel, label %.split, label %.preheader54.peel.newph

._crit_edge:                                      ; preds = %.split.us.us, %.split, %14
  %.047.lcssa = phi i64 [ -1, %14 ], [ 0, %.split ], [ %.249.us.us, %.split.us.us ]
  %.045.lcssa = phi i32 [ 0, %14 ], [ %.2.peel, %.split ], [ %.2.us.us, %.split.us.us ]
  store i32 %.045.lcssa, ptr %4, align 4, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(13) %5, ptr noundef nonnull align 1 dereferenceable(13) %10, i64 13, i1 false), !tbaa.struct !10
  call void @llvm.lifetime.end.p0(i64 13, ptr nonnull %10) #6
  ret i64 %.047.lcssa

.split:                                           ; preds = %.preheader54.peel.newph, %66
  %67 = add nuw i32 %.04467, 1
  %exitcond80.not = icmp eq i32 %67, %.05085
  br i1 %exitcond80.not, label %._crit_edge, label %.preheader54, !llvm.loop !14

.preheader54.peel.newph:                          ; preds = %66, %.preheader54.peel.newph
  %.04263 = phi i32 [ %69, %.preheader54.peel.newph ], [ 1, %66 ]
  call void @llvm.lifetime.start.p0(i64 13, ptr nonnull %11) #6
  call void @_ZN6basist34etc1_global_palette_entry_modifierC2Ej(ptr noundef nonnull align 1 dereferenceable(13) %11, i32 noundef %.04263)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %12) #6
  %68 = call { i64, i64 } @_ZNK6basist29etc1_global_selector_codebook9get_entryEjRKNS_34etc1_global_palette_entry_modifierE(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.04467, ptr noundef nonnull align 1 dereferenceable(13) %11)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %12) #6
  call void @llvm.lifetime.end.p0(i64 13, ptr nonnull %11) #6
  %69 = add nuw i32 %.04263, 1
  %exitcond79.not = icmp eq i32 %69, %spec.store.select86
  br i1 %exitcond79.not, label %.split, label %.preheader54.peel.newph, !llvm.loop !17
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6basist34etc1_global_palette_entry_modifierC2Ej(ptr noundef nonnull align 1 dereferenceable(13), i32 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK6basist29etc1_global_selector_codebook4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZNK6basist29etc1_global_selector_codebook9get_entryEjRKNS_34etc1_global_palette_entry_modifierE(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, ptr noundef nonnull align 1 dereferenceable(13)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZNK6basist27etc1_selector_palette_entryclEjj(ptr noundef nonnull align 1 dereferenceable(16), i32 noundef, i32 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef i64 @_ZNK6basisu9etc_block19evaluate_etc1_errorEPKNS_10color_rgbaEbi(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i1 noundef zeroext, i32 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK6basisu11pixel_block7get_ptrEv(ptr noundef nonnull align 1 dereferenceable(64)) local_unnamed_addr #4 align 2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { "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 #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{i64 0, i64 1, !5, i64 1, i64 1, !11, i64 2, i64 1, !11, i64 3, i64 1, !11, i64 4, i64 1, !11, i64 5, i64 1, !11, i64 6, i64 1, !11, i64 7, i64 1, !11, i64 8, i64 1, !11, i64 9, i64 1, !11, i64 10, i64 1, !11, i64 11, i64 1, !11, i64 12, i64 1, !5}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !6, i64 0}
!13 = distinct !{!13, !9}
!14 = distinct !{!14, !9}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !6, i64 0}
!17 = distinct !{!17, !9, !18}
!18 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass