; LLVM IR from itchio/go-brotli :: dec (state)

; 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.BrotliDecoderStateStruct = type { i32, i32, %struct.BrotliBitReader, ptr, ptr, ptr, %union.anon, i32, i32, i32, i32, i32, i32, i32, [4 x i32], i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.HuffmanTreeGroup, %struct.HuffmanTreeGroup, %struct.HuffmanTreeGroup, ptr, ptr, i32, i32, i32, i32, [3 x i32], [3 x i32], [6 x i32], i32, i32, i32, i32, ptr, ptr, i8, i32, i32, i32, i32, i64, i64, i32, i32, i32, [32 x %struct.HuffmanCode], ptr, [720 x i16], [32 x i32], [18 x i8], [16 x i16], i32, ptr, i32, i32, i32, [646 x %struct.HuffmanCode], i32, [65 x i32], i32, i32, i32, i32, i32, i32, i32, i16, i32, i32, i32, ptr, ptr, ptr, [8 x i32] }
%struct.BrotliBitReader = type { i64, i32, ptr, i64 }
%union.anon = type { i64 }
%struct.HuffmanTreeGroup = type { ptr, ptr, i16, i16 }
%struct.HuffmanCode = type { i8, i16 }

@kMaxHuffmanTableSize = external hidden constant [23 x i16], align 16

; Function Attrs: nounwind uwtable
define hidden i32 @BrotliDecoderHuffmanTreeGroupInit(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = add i32 %13, 31
  %15 = lshr i32 %14, 5
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [23 x i16], ptr @kMaxHuffmanTableSize, i64 0, i64 %16
  %18 = load i16, ptr %17, align 2, !tbaa !11
  %19 = zext i16 %18 to i64
  store i64 %19, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = mul i64 4, %21
  %23 = load i64, ptr %9, align 8, !tbaa !13
  %24 = mul i64 %22, %23
  store i64 %24, ptr %10, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = mul i64 8, %26
  store i64 %27, ptr %11, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %31, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = load i64, ptr %10, align 8, !tbaa !13
  %35 = load i64, ptr %11, align 8, !tbaa !13
  %36 = add i64 %34, %35
  %37 = call ptr %30(ptr noundef %33, i64 noundef %36)
  store ptr %37, ptr %12, align 8, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = trunc i32 %38 to i16
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.HuffmanTreeGroup, ptr %40, i32 0, i32 2
  store i16 %39, ptr %41, align 8, !tbaa !20
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = trunc i32 %42 to i16
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.HuffmanTreeGroup, ptr %44, i32 0, i32 3
  store i16 %43, ptr %45, align 2, !tbaa !21
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.HuffmanTreeGroup, ptr %47, i32 0, i32 0
  store ptr %46, ptr %48, align 8, !tbaa !22
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.HuffmanTreeGroup, ptr %53, i32 0, i32 1
  store ptr %52, ptr %54, align 8, !tbaa !23
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  %57 = xor i1 %56, true
  %58 = xor i1 %57, true
  %59 = zext i1 %58 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i32 %59
}

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

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 40}
!16 = !{!"BrotliDecoderStateStruct", !10, i64 0, !10, i64 4, !17, i64 8, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !7, i64 100, !10, i64 116, !10, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !18, i64 184, !18, i64 208, !18, i64 232, !6, i64 256, !6, i64 264, !10, i64 272, !10, i64 276, !10, i64 280, !10, i64 284, !7, i64 288, !7, i64 300, !7, i64 312, !10, i64 336, !10, i64 340, !10, i64 344, !10, i64 348, !6, i64 352, !6, i64 360, !7, i64 368, !10, i64 372, !10, i64 376, !10, i64 380, !10, i64 384, !14, i64 392, !14, i64 400, !10, i64 408, !10, i64 412, !10, i64 416, !7, i64 420, !6, i64 552, !7, i64 560, !7, i64 2000, !7, i64 2128, !7, i64 2146, !10, i64 2180, !6, i64 2184, !10, i64 2192, !10, i64 2196, !10, i64 2200, !7, i64 2204, !10, i64 4788, !7, i64 4792, !10, i64 5052, !10, i64 5056, !10, i64 5060, !10, i64 5064, !10, i64 5068, !10, i64 5072, !10, i64 5076, !10, i64 5080, !10, i64 5080, !10, i64 5080, !10, i64 5080, !10, i64 5080, !10, i64 5080, !10, i64 5084, !10, i64 5088, !10, i64 5092, !6, i64 5096, !6, i64 5104, !6, i64 5112, !7, i64 5120}
!17 = !{!"", !14, i64 0, !10, i64 8, !6, i64 16, !14, i64 24}
!18 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 18}
!19 = !{!16, !6, i64 56}
!20 = !{!18, !12, i64 16}
!21 = !{!18, !12, i64 18}
!22 = !{!18, !6, i64 0}
!23 = !{!18, !6, i64 8}


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

@kMaxHuffmanTableSize = external hidden local_unnamed_addr constant [23 x i16], align 16

; Function Attrs: nounwind uwtable
define hidden range(i32 0, 2) i32 @BrotliDecoderHuffmanTreeGroupInit(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add i32 %2, 31
  %6 = lshr i32 %5, 5
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds [23 x i16], ptr @kMaxHuffmanTableSize, i64 0, i64 %7
  %9 = load i16, ptr %8, align 2, !tbaa !5
  %10 = zext i16 %9 to i64
  %11 = zext i32 %3 to i64
  %12 = shl nuw nsw i64 %10, 2
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %0, i64 56
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %reass.add = add nuw nsw i64 %12, 8
  %reass.mul = mul nuw nsw i64 %reass.add, %11
  %17 = tail call ptr %14(ptr noundef %16, i64 noundef %reass.mul) #1
  %18 = trunc i32 %2 to i16
  %19 = getelementptr inbounds i8, ptr %1, i64 16
  store i16 %18, ptr %19, align 8, !tbaa !17
  %20 = trunc i32 %3 to i16
  %21 = getelementptr inbounds i8, ptr %1, i64 18
  store i16 %20, ptr %21, align 2, !tbaa !18
  store ptr %17, ptr %1, align 8, !tbaa !19
  %22 = getelementptr inbounds ptr, ptr %17, i64 %11
  %23 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %22, ptr %23, align 8, !tbaa !20
  %24 = icmp ne ptr %17, null
  %25 = zext i1 %24 to i32
  ret i32 %25
}

attributes #0 = { 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 }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !14, i64 40}
!10 = !{!"BrotliDecoderStateStruct", !11, i64 0, !11, i64 4, !12, i64 8, !14, i64 40, !14, i64 48, !14, i64 56, !7, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !7, i64 100, !11, i64 116, !11, i64 120, !14, i64 128, !14, i64 136, !14, i64 144, !14, i64 152, !14, i64 160, !14, i64 168, !14, i64 176, !15, i64 184, !15, i64 208, !15, i64 232, !14, i64 256, !14, i64 264, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !7, i64 288, !7, i64 300, !7, i64 312, !11, i64 336, !11, i64 340, !11, i64 344, !11, i64 348, !14, i64 352, !14, i64 360, !7, i64 368, !11, i64 372, !11, i64 376, !11, i64 380, !11, i64 384, !13, i64 392, !13, i64 400, !11, i64 408, !11, i64 412, !11, i64 416, !7, i64 420, !14, i64 552, !7, i64 560, !7, i64 2000, !7, i64 2128, !7, i64 2146, !11, i64 2180, !14, i64 2184, !11, i64 2192, !11, i64 2196, !11, i64 2200, !7, i64 2204, !11, i64 4788, !7, i64 4792, !11, i64 5052, !11, i64 5056, !11, i64 5060, !11, i64 5064, !11, i64 5068, !11, i64 5072, !11, i64 5076, !11, i64 5080, !11, i64 5080, !11, i64 5080, !11, i64 5080, !11, i64 5080, !11, i64 5080, !11, i64 5084, !11, i64 5088, !11, i64 5092, !14, i64 5096, !14, i64 5104, !14, i64 5112, !7, i64 5120}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !13, i64 0, !11, i64 8, !14, i64 16, !13, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!"", !14, i64 0, !14, i64 8, !6, i64 16, !6, i64 18}
!16 = !{!10, !14, i64 56}
!17 = !{!15, !6, i64 16}
!18 = !{!15, !6, i64 18}
!19 = !{!15, !14, i64 0}
!20 = !{!15, !14, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass