; LLVM IR from itchio/go-brotli :: enc (cluster)

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

%struct.HistogramCommand = type { [704 x i32], i64, double }

; 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: alwaysinline nounwind uwtable
declare hidden void @HistogramAddHistogramCommand(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden double @BrotliHistogramBitCostDistanceCommand(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define hidden void @BrotliHistogramRemapCommand(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  %16 = alloca i64, align 8
  %17 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %79, %6
  %19 = load i64, ptr %13, align 8, !tbaa !9
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %22, label %82

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %23 = load i64, ptr %13, align 8, !tbaa !9
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = getelementptr inbounds i32, ptr %26, i64 0
  %28 = load i32, ptr %27, align 4, !tbaa !11
  br label %35

29:                                               ; preds = %22
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = load i64, ptr %13, align 8, !tbaa !9
  %32 = sub i64 %31, 1
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %29, %25
  %36 = phi i32 [ %28, %25 ], [ %34, %29 ]
  store i32 %36, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i64, ptr %13, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.HistogramCommand, ptr %37, i64 %38
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = load i32, ptr %14, align 4, !tbaa !11
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds %struct.HistogramCommand, ptr %40, i64 %42
  %44 = call double @BrotliHistogramBitCostDistanceCommand(ptr noundef %39, ptr noundef %43)
  store double %44, ptr %15, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %45

45:                                               ; preds = %71, %35
  %46 = load i64, ptr %16, align 8, !tbaa !9
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = icmp ult i64 %46, %47
  br i1 %48, label %49, label %74

49:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %13, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.HistogramCommand, ptr %50, i64 %51
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load i64, ptr %16, align 8, !tbaa !9
  %56 = getelementptr inbounds i32, ptr %54, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !11
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds %struct.HistogramCommand, ptr %53, i64 %58
  %60 = call double @BrotliHistogramBitCostDistanceCommand(ptr noundef %52, ptr noundef %59)
  store double %60, ptr %17, align 8, !tbaa !13
  %61 = load double, ptr %17, align 8, !tbaa !13
  %62 = load double, ptr %15, align 8, !tbaa !13
  %63 = fcmp olt double %61, %62
  br i1 %63, label %64, label %70

64:                                               ; preds = %49
  %65 = load double, ptr %17, align 8, !tbaa !13
  store double %65, ptr %15, align 8, !tbaa !13
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load i64, ptr %16, align 8, !tbaa !9
  %68 = getelementptr inbounds i32, ptr %66, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !11
  store i32 %69, ptr %14, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %64, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %71

71:                                               ; preds = %70
  %72 = load i64, ptr %16, align 8, !tbaa !9
  %73 = add i64 %72, 1
  store i64 %73, ptr %16, align 8, !tbaa !9
  br label %45, !llvm.loop !15

74:                                               ; preds = %45
  %75 = load i32, ptr %14, align 4, !tbaa !11
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = load i64, ptr %13, align 8, !tbaa !9
  %78 = getelementptr inbounds i32, ptr %76, i64 %77
  store i32 %75, ptr %78, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %79

79:                                               ; preds = %74
  %80 = load i64, ptr %13, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %13, align 8, !tbaa !9
  br label %18, !llvm.loop !17

82:                                               ; preds = %18
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %83

83:                                               ; preds = %95, %82
  %84 = load i64, ptr %13, align 8, !tbaa !9
  %85 = load i64, ptr %10, align 8, !tbaa !9
  %86 = icmp ult i64 %84, %85
  br i1 %86, label %87, label %98

87:                                               ; preds = %83
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = load i64, ptr %13, align 8, !tbaa !9
  %91 = getelementptr inbounds i32, ptr %89, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !11
  %93 = zext i32 %92 to i64
  %94 = getelementptr inbounds %struct.HistogramCommand, ptr %88, i64 %93
  call void @HistogramClearCommand(ptr noundef %94)
  br label %95

95:                                               ; preds = %87
  %96 = load i64, ptr %13, align 8, !tbaa !9
  %97 = add i64 %96, 1
  store i64 %97, ptr %13, align 8, !tbaa !9
  br label %83, !llvm.loop !18

98:                                               ; preds = %83
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %99

99:                                               ; preds = %114, %98
  %100 = load i64, ptr %13, align 8, !tbaa !9
  %101 = load i64, ptr %8, align 8, !tbaa !9
  %102 = icmp ult i64 %100, %101
  br i1 %102, label %103, label %117

103:                                              ; preds = %99
  %104 = load ptr, ptr %11, align 8, !tbaa !5
  %105 = load ptr, ptr %12, align 8, !tbaa !5
  %106 = load i64, ptr %13, align 8, !tbaa !9
  %107 = getelementptr inbounds i32, ptr %105, i64 %106
  %108 = load i32, ptr %107, align 4, !tbaa !11
  %109 = zext i32 %108 to i64
  %110 = getelementptr inbounds %struct.HistogramCommand, ptr %104, i64 %109
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = load i64, ptr %13, align 8, !tbaa !9
  %113 = getelementptr inbounds %struct.HistogramCommand, ptr %111, i64 %112
  call void @HistogramAddHistogramCommand(ptr noundef %110, ptr noundef %113)
  br label %114

114:                                              ; preds = %103
  %115 = load i64, ptr %13, align 8, !tbaa !9
  %116 = add i64 %115, 1
  store i64 %116, ptr %13, align 8, !tbaa !9
  br label %99, !llvm.loop !19

117:                                              ; preds = %99
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @HistogramClearCommand(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


; 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.HistogramCommand = type { [704 x i32], i64, double }

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @HistogramAddHistogramCommand(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden double @BrotliHistogramBitCostDistanceCommand(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define hidden void @BrotliHistogramRemapCommand(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr noundef %4, ptr nocapture noundef %5) local_unnamed_addr #1 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.preheader47, label %.lr.ph53

.lr.ph53:                                         ; preds = %6
  %.not57 = icmp eq i64 %3, 0
  br i1 %.not57, label %.lr.ph53.split.preheader, label %.lr.ph.us

.lr.ph53.split.preheader:                         ; preds = %.lr.ph53
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds %struct.HistogramCommand, ptr %4, i64 %8
  %10 = tail call double @BrotliHistogramBitCostDistanceCommand(ptr noundef %0, ptr noundef %9)
  store i32 %7, ptr %5, align 4, !tbaa !5
  %exitcond62.peel.not = icmp eq i64 %1, 1
  br i1 %exitcond62.peel.not, label %.lr.ph56.preheader, label %.lr.ph53.split

.lr.ph.us:                                        ; preds = %.lr.ph53, %._crit_edge.us
  %.051.us = phi i64 [ %30, %._crit_edge.us ], [ 0, %.lr.ph53 ]
  %11 = icmp eq i64 %.051.us, 0
  %12 = getelementptr i32, ptr %5, i64 %.051.us
  %13 = getelementptr i8, ptr %12, i64 -4
  %.in.us = select i1 %11, ptr %5, ptr %13
  %14 = load i32, ptr %.in.us, align 4, !tbaa !5
  %15 = getelementptr inbounds %struct.HistogramCommand, ptr %0, i64 %.051.us
  %16 = zext i32 %14 to i64
  %17 = getelementptr inbounds %struct.HistogramCommand, ptr %4, i64 %16
  %18 = tail call double @BrotliHistogramBitCostDistanceCommand(ptr noundef %15, ptr noundef %17)
  br label %19

19:                                               ; preds = %.lr.ph.us, %28
  %.04050.us = phi i64 [ 0, %.lr.ph.us ], [ %29, %28 ]
  %.04149.us = phi double [ %18, %.lr.ph.us ], [ %.142.us, %28 ]
  %.04348.us = phi i32 [ %14, %.lr.ph.us ], [ %.144.us, %28 ]
  %20 = getelementptr inbounds i32, ptr %2, i64 %.04050.us
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds %struct.HistogramCommand, ptr %4, i64 %22
  %24 = tail call double @BrotliHistogramBitCostDistanceCommand(ptr noundef %15, ptr noundef %23)
  %25 = fcmp olt double %24, %.04149.us
  br i1 %25, label %26, label %28

26:                                               ; preds = %19
  %27 = load i32, ptr %20, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %26, %19
  %.144.us = phi i32 [ %27, %26 ], [ %.04348.us, %19 ]
  %.142.us = phi double [ %24, %26 ], [ %.04149.us, %19 ]
  %29 = add nuw i64 %.04050.us, 1
  %exitcond.not = icmp eq i64 %29, %3
  br i1 %exitcond.not, label %._crit_edge.us, label %19, !llvm.loop !9

._crit_edge.us:                                   ; preds = %28
  store i32 %.144.us, ptr %12, align 4, !tbaa !5
  %30 = add nuw i64 %.051.us, 1
  %exitcond61.not = icmp eq i64 %30, %1
  br i1 %exitcond61.not, label %.lr.ph.preheader, label %.lr.ph.us, !llvm.loop !11

.preheader47:                                     ; preds = %.lr.ph53.split, %6
  %.not58 = icmp eq i64 %3, 0
  br i1 %.not58, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %._crit_edge.us, %.preheader47
  br label %.lr.ph

.lr.ph53.split:                                   ; preds = %.lr.ph53.split.preheader, %.lr.ph53.split
  %.051 = phi i64 [ %38, %.lr.ph53.split ], [ 1, %.lr.ph53.split.preheader ]
  %31 = getelementptr i32, ptr %5, i64 %.051
  %32 = getelementptr i8, ptr %31, i64 -4
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = getelementptr inbounds %struct.HistogramCommand, ptr %0, i64 %.051
  %35 = zext i32 %33 to i64
  %36 = getelementptr inbounds %struct.HistogramCommand, ptr %4, i64 %35
  %37 = tail call double @BrotliHistogramBitCostDistanceCommand(ptr noundef nonnull %34, ptr noundef %36)
  store i32 %33, ptr %31, align 4, !tbaa !5
  %38 = add nuw i64 %.051, 1
  %exitcond62.not = icmp eq i64 %38, %1
  br i1 %exitcond62.not, label %.preheader47, label %.lr.ph53.split, !llvm.loop !12

.preheader:                                       ; preds = %.lr.ph, %.preheader47
  br i1 %.not, label %._crit_edge, label %.lr.ph56.preheader

.lr.ph56.preheader:                               ; preds = %.lr.ph53.split.preheader, %.preheader
  br label %.lr.ph56

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.154 = phi i64 [ %43, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %39 = getelementptr inbounds i32, ptr %2, i64 %.154
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds %struct.HistogramCommand, ptr %4, i64 %41
  tail call void @HistogramClearCommand(ptr noundef %42)
  %43 = add nuw i64 %.154, 1
  %exitcond64.not = icmp eq i64 %43, %3
  br i1 %exitcond64.not, label %.preheader, label %.lr.ph, !llvm.loop !14

.lr.ph56:                                         ; preds = %.lr.ph56.preheader, %.lr.ph56
  %.255 = phi i64 [ %49, %.lr.ph56 ], [ 0, %.lr.ph56.preheader ]
  %44 = getelementptr inbounds i32, ptr %5, i64 %.255
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds %struct.HistogramCommand, ptr %4, i64 %46
  %48 = getelementptr inbounds %struct.HistogramCommand, ptr %0, i64 %.255
  tail call void @HistogramAddHistogramCommand(ptr noundef %47, ptr noundef %48)
  %49 = add nuw i64 %.255, 1
  %exitcond65.not = icmp eq i64 %49, %1
  br i1 %exitcond65.not, label %._crit_edge, label %.lr.ph56, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph56, %.preheader
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @HistogramClearCommand(ptr noundef) local_unnamed_addr #0

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


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