; LLVM IR from DanEngelbrecht/longtail :: lib/brotli/ext/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, 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, ptr noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca double, align 8
  %18 = alloca i64, align 8
  %19 = alloca double, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  store ptr %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %83, %7
  %21 = load i64, ptr %15, align 8, !tbaa !9
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %86

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %25 = load i64, ptr %15, align 8, !tbaa !9
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = load ptr, ptr %14, align 8, !tbaa !5
  %29 = getelementptr inbounds i32, ptr %28, i64 0
  %30 = load i32, ptr %29, align 4, !tbaa !11
  br label %37

31:                                               ; preds = %24
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = sub i64 %33, 1
  %35 = getelementptr inbounds i32, ptr %32, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %31, %27
  %38 = phi i32 [ %30, %27 ], [ %36, %31 ]
  store i32 %38, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load i64, ptr %15, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.HistogramCommand, ptr %39, i64 %40
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = load i32, ptr %16, align 4, !tbaa !11
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %struct.HistogramCommand, ptr %42, i64 %44
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = call double @BrotliHistogramBitCostDistanceCommand(ptr noundef %41, ptr noundef %45, ptr noundef %46)
  store double %47, ptr %17, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %75, %37
  %49 = load i64, ptr %18, align 8, !tbaa !9
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %52, label %78

52:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i64, ptr %15, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.HistogramCommand, ptr %53, i64 %54
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load i64, ptr %18, align 8, !tbaa !9
  %59 = getelementptr inbounds i32, ptr %57, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !11
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds %struct.HistogramCommand, ptr %56, i64 %61
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = call double @BrotliHistogramBitCostDistanceCommand(ptr noundef %55, ptr noundef %62, ptr noundef %63)
  store double %64, ptr %19, align 8, !tbaa !13
  %65 = load double, ptr %19, align 8, !tbaa !13
  %66 = load double, ptr %17, align 8, !tbaa !13
  %67 = fcmp olt double %65, %66
  br i1 %67, label %68, label %74

68:                                               ; preds = %52
  %69 = load double, ptr %19, align 8, !tbaa !13
  store double %69, ptr %17, align 8, !tbaa !13
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = load i64, ptr %18, align 8, !tbaa !9
  %72 = getelementptr inbounds i32, ptr %70, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !11
  store i32 %73, ptr %16, align 4, !tbaa !11
  br label %74

74:                                               ; preds = %68, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  br label %75

75:                                               ; preds = %74
  %76 = load i64, ptr %18, align 8, !tbaa !9
  %77 = add i64 %76, 1
  store i64 %77, ptr %18, align 8, !tbaa !9
  br label %48, !llvm.loop !15

78:                                               ; preds = %48
  %79 = load i32, ptr %16, align 4, !tbaa !11
  %80 = load ptr, ptr %14, align 8, !tbaa !5
  %81 = load i64, ptr %15, align 8, !tbaa !9
  %82 = getelementptr inbounds i32, ptr %80, i64 %81
  store i32 %79, ptr %82, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %83

83:                                               ; preds = %78
  %84 = load i64, ptr %15, align 8, !tbaa !9
  %85 = add i64 %84, 1
  store i64 %85, ptr %15, align 8, !tbaa !9
  br label %20, !llvm.loop !17

86:                                               ; preds = %20
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %87

87:                                               ; preds = %99, %86
  %88 = load i64, ptr %15, align 8, !tbaa !9
  %89 = load i64, ptr %11, align 8, !tbaa !9
  %90 = icmp ult i64 %88, %89
  br i1 %90, label %91, label %102

91:                                               ; preds = %87
  %92 = load ptr, ptr %12, align 8, !tbaa !5
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = load i64, ptr %15, align 8, !tbaa !9
  %95 = getelementptr inbounds i32, ptr %93, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !11
  %97 = zext i32 %96 to i64
  %98 = getelementptr inbounds %struct.HistogramCommand, ptr %92, i64 %97
  call void @HistogramClearCommand(ptr noundef %98)
  br label %99

99:                                               ; preds = %91
  %100 = load i64, ptr %15, align 8, !tbaa !9
  %101 = add i64 %100, 1
  store i64 %101, ptr %15, align 8, !tbaa !9
  br label %87, !llvm.loop !18

102:                                              ; preds = %87
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %103

103:                                              ; preds = %118, %102
  %104 = load i64, ptr %15, align 8, !tbaa !9
  %105 = load i64, ptr %9, align 8, !tbaa !9
  %106 = icmp ult i64 %104, %105
  br i1 %106, label %107, label %121

107:                                              ; preds = %103
  %108 = load ptr, ptr %12, align 8, !tbaa !5
  %109 = load ptr, ptr %14, align 8, !tbaa !5
  %110 = load i64, ptr %15, align 8, !tbaa !9
  %111 = getelementptr inbounds i32, ptr %109, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !11
  %113 = zext i32 %112 to i64
  %114 = getelementptr inbounds %struct.HistogramCommand, ptr %108, i64 %113
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  %116 = load i64, ptr %15, align 8, !tbaa !9
  %117 = getelementptr inbounds %struct.HistogramCommand, ptr %115, i64 %116
  call void @HistogramAddHistogramCommand(ptr noundef %114, ptr noundef %117)
  br label %118

118:                                              ; preds = %107
  %119 = load i64, ptr %15, align 8, !tbaa !9
  %120 = add i64 %119, 1
  store i64 %120, ptr %15, align 8, !tbaa !9
  br label %103, !llvm.loop !19

121:                                              ; preds = %103
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #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, 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 noundef %5, ptr nocapture noundef %6) local_unnamed_addr #1 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.preheader49, label %.lr.ph55

.lr.ph55:                                         ; preds = %7
  %.not59 = icmp eq i64 %3, 0
  br i1 %.not59, label %.lr.ph55.split.preheader, label %.lr.ph.us

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

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

20:                                               ; preds = %.lr.ph.us, %29
  %.04252.us = phi i64 [ 0, %.lr.ph.us ], [ %30, %29 ]
  %.04351.us = phi double [ %19, %.lr.ph.us ], [ %.144.us, %29 ]
  %.04550.us = phi i32 [ %15, %.lr.ph.us ], [ %.146.us, %29 ]
  %21 = getelementptr inbounds i32, ptr %2, i64 %.04252.us
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds %struct.HistogramCommand, ptr %4, i64 %23
  %25 = tail call double @BrotliHistogramBitCostDistanceCommand(ptr noundef %16, ptr noundef %24, ptr noundef %5)
  %26 = fcmp olt double %25, %.04351.us
  br i1 %26, label %27, label %29

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

29:                                               ; preds = %27, %20
  %.146.us = phi i32 [ %28, %27 ], [ %.04550.us, %20 ]
  %.144.us = phi double [ %25, %27 ], [ %.04351.us, %20 ]
  %30 = add nuw i64 %.04252.us, 1
  %exitcond.not = icmp eq i64 %30, %3
  br i1 %exitcond.not, label %._crit_edge.us, label %20, !llvm.loop !9

._crit_edge.us:                                   ; preds = %29
  store i32 %.146.us, ptr %13, align 4, !tbaa !5
  %31 = add nuw i64 %.053.us, 1
  %exitcond63.not = icmp eq i64 %31, %1
  br i1 %exitcond63.not, label %.lr.ph.preheader, label %.lr.ph.us, !llvm.loop !11

.preheader49:                                     ; preds = %.lr.ph55.split, %7
  %.not60 = icmp eq i64 %3, 0
  br i1 %.not60, label %.preheader, label %.lr.ph.preheader

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

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

.preheader:                                       ; preds = %.lr.ph, %.preheader49
  br i1 %.not, label %._crit_edge, label %.lr.ph58.preheader

.lr.ph58.preheader:                               ; preds = %.lr.ph55.split.preheader, %.preheader
  br label %.lr.ph58

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

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

._crit_edge:                                      ; preds = %.lr.ph58, %.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