; LLVM IR from DanEngelbrecht/longtail :: lib/brotli/ext/enc (metablock)

; 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.MetaBlockSplit = type { %struct.BlockSplit, %struct.BlockSplit, %struct.BlockSplit, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64 }
%struct.BlockSplit = type { i64, i64, ptr, ptr, i64, i64 }
%struct.HistogramLiteral = type { [256 x i32], i64, double }
%struct.HistogramCommand = type { [704 x i32], i64, double }
%struct.HistogramDistance = type { [544 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: nounwind uwtable
define hidden void @BrotliOptimizeHistograms(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca [704 x i8], align 16
  %6 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 704, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %7

7:                                                ; preds = %22, %2
  %8 = load i64, ptr %6, align 8, !tbaa !11
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.MetaBlockSplit, ptr %9, i32 0, i32 8
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %12 = icmp ult i64 %8, %11
  br i1 %12, label %13, label %25

13:                                               ; preds = %7
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.MetaBlockSplit, ptr %14, i32 0, i32 7
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = load i64, ptr %6, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.HistogramLiteral, ptr %16, i64 %17
  %19 = getelementptr inbounds %struct.HistogramLiteral, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [256 x i32], ptr %19, i64 0, i64 0
  %21 = getelementptr inbounds [704 x i8], ptr %5, i64 0, i64 0
  call void @BrotliOptimizeHuffmanCountsForRle(i64 noundef 256, ptr noundef %20, ptr noundef %21)
  br label %22

22:                                               ; preds = %13
  %23 = load i64, ptr %6, align 8, !tbaa !11
  %24 = add i64 %23, 1
  store i64 %24, ptr %6, align 8, !tbaa !11
  br label %7, !llvm.loop !17

25:                                               ; preds = %7
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %41, %25
  %27 = load i64, ptr %6, align 8, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.MetaBlockSplit, ptr %28, i32 0, i32 10
  %30 = load i64, ptr %29, align 8, !tbaa !19
  %31 = icmp ult i64 %27, %30
  br i1 %31, label %32, label %44

32:                                               ; preds = %26
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.MetaBlockSplit, ptr %33, i32 0, i32 9
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = load i64, ptr %6, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.HistogramCommand, ptr %35, i64 %36
  %38 = getelementptr inbounds %struct.HistogramCommand, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds [704 x i32], ptr %38, i64 0, i64 0
  %40 = getelementptr inbounds [704 x i8], ptr %5, i64 0, i64 0
  call void @BrotliOptimizeHuffmanCountsForRle(i64 noundef 704, ptr noundef %39, ptr noundef %40)
  br label %41

41:                                               ; preds = %32
  %42 = load i64, ptr %6, align 8, !tbaa !11
  %43 = add i64 %42, 1
  store i64 %43, ptr %6, align 8, !tbaa !11
  br label %26, !llvm.loop !21

44:                                               ; preds = %26
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %45

45:                                               ; preds = %62, %44
  %46 = load i64, ptr %6, align 8, !tbaa !11
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.MetaBlockSplit, ptr %47, i32 0, i32 12
  %49 = load i64, ptr %48, align 8, !tbaa !22
  %50 = icmp ult i64 %46, %49
  br i1 %50, label %51, label %65

51:                                               ; preds = %45
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = zext i32 %52 to i64
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.MetaBlockSplit, ptr %54, i32 0, i32 11
  %56 = load ptr, ptr %55, align 8, !tbaa !23
  %57 = load i64, ptr %6, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.HistogramDistance, ptr %56, i64 %57
  %59 = getelementptr inbounds %struct.HistogramDistance, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds [544 x i32], ptr %59, i64 0, i64 0
  %61 = getelementptr inbounds [704 x i8], ptr %5, i64 0, i64 0
  call void @BrotliOptimizeHuffmanCountsForRle(i64 noundef %53, ptr noundef %60, ptr noundef %61)
  br label %62

62:                                               ; preds = %51
  %63 = load i64, ptr %6, align 8, !tbaa !11
  %64 = add i64 %63, 1
  store i64 %64, ptr %6, align 8, !tbaa !11
  br label %45, !llvm.loop !24

65:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 704, ptr %5) #3
  ret void
}

declare hidden void @BrotliOptimizeHuffmanCountsForRle(i64 noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 184}
!14 = !{!"MetaBlockSplit", !15, i64 0, !15, i64 48, !15, i64 96, !10, i64 144, !12, i64 152, !10, i64 160, !12, i64 168, !10, i64 176, !12, i64 184, !10, i64 192, !12, i64 200, !10, i64 208, !12, i64 216}
!15 = !{!"BlockSplit", !12, i64 0, !12, i64 8, !10, i64 16, !10, i64 24, !12, i64 32, !12, i64 40}
!16 = !{!14, !10, i64 176}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!14, !12, i64 200}
!20 = !{!14, !10, i64 192}
!21 = distinct !{!21, !18}
!22 = !{!14, !12, i64 216}
!23 = !{!14, !10, i64 208}
!24 = distinct !{!24, !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"

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

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

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

; Function Attrs: nounwind uwtable
define hidden void @BrotliOptimizeHistograms(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca [704 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 704, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %1, i64 184
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %.preheader15, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 176
  br label %10

.preheader15:                                     ; preds = %10, %2
  %7 = getelementptr inbounds i8, ptr %1, i64 200
  %8 = load i64, ptr %7, align 8, !tbaa !12
  %.not21 = icmp eq i64 %8, 0
  br i1 %.not21, label %.preheader, label %.lr.ph18

.lr.ph18:                                         ; preds = %.preheader15
  %9 = getelementptr inbounds i8, ptr %1, i64 192
  br label %20

10:                                               ; preds = %.lr.ph, %10
  %.016 = phi i64 [ 0, %.lr.ph ], [ %13, %10 ]
  %11 = load ptr, ptr %6, align 8, !tbaa !13
  %12 = getelementptr inbounds %struct.HistogramLiteral, ptr %11, i64 %.016
  call void @BrotliOptimizeHuffmanCountsForRle(i64 noundef 256, ptr noundef %12, ptr noundef nonnull %3) #3
  %13 = add nuw i64 %.016, 1
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %10, label %.preheader15, !llvm.loop !14

.preheader:                                       ; preds = %20, %.preheader15
  %16 = getelementptr inbounds i8, ptr %1, i64 216
  %17 = load i64, ptr %16, align 8, !tbaa !16
  %.not22 = icmp eq i64 %17, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph20

.lr.ph20:                                         ; preds = %.preheader
  %18 = zext i32 %0 to i64
  %19 = getelementptr inbounds i8, ptr %1, i64 208
  br label %26

20:                                               ; preds = %.lr.ph18, %20
  %.117 = phi i64 [ 0, %.lr.ph18 ], [ %23, %20 ]
  %21 = load ptr, ptr %9, align 8, !tbaa !17
  %22 = getelementptr inbounds %struct.HistogramCommand, ptr %21, i64 %.117
  call void @BrotliOptimizeHuffmanCountsForRle(i64 noundef 704, ptr noundef %22, ptr noundef nonnull %3) #3
  %23 = add nuw i64 %.117, 1
  %24 = load i64, ptr %7, align 8, !tbaa !12
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %20, label %.preheader, !llvm.loop !18

26:                                               ; preds = %.lr.ph20, %26
  %.219 = phi i64 [ 0, %.lr.ph20 ], [ %29, %26 ]
  %27 = load ptr, ptr %19, align 8, !tbaa !19
  %28 = getelementptr inbounds %struct.HistogramDistance, ptr %27, i64 %.219
  call void @BrotliOptimizeHuffmanCountsForRle(i64 noundef %18, ptr noundef %28, ptr noundef nonnull %3) #3
  %29 = add nuw i64 %.219, 1
  %30 = load i64, ptr %16, align 8, !tbaa !16
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %26, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %26, %.preheader
  call void @llvm.lifetime.end.p0(i64 704, ptr nonnull %3) #3
  ret void
}

declare hidden void @BrotliOptimizeHuffmanCountsForRle(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { "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, !8, i64 184}
!6 = !{!"MetaBlockSplit", !7, i64 0, !7, i64 48, !7, i64 96, !11, i64 144, !8, i64 152, !11, i64 160, !8, i64 168, !11, i64 176, !8, i64 184, !11, i64 192, !8, i64 200, !11, i64 208, !8, i64 216}
!7 = !{!"BlockSplit", !8, i64 0, !8, i64 8, !11, i64 16, !11, i64 24, !8, i64 32, !8, i64 40}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!6, !8, i64 200}
!13 = !{!6, !11, i64 176}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !8, i64 216}
!17 = !{!6, !11, i64 192}
!18 = distinct !{!18, !15}
!19 = !{!6, !11, i64 208}
!20 = distinct !{!20, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass