; LLVM IR from DanEngelbrecht/longtail :: lib/brotli/ext/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, i64, i32, i32, i32, i32, i32, i32, [4 x i32], i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, %struct.HuffmanTreeGroup, %struct.HuffmanTreeGroup, %struct.HuffmanTreeGroup, ptr, ptr, i32, i32, [3 x i64], i64, [3 x i64], [6 x i64], i64, i64, i64, ptr, ptr, i64, i64, i64, [65 x i32], i32, i32, i8, ptr, ptr, ptr, i64, i32, i32, i32, i32, i32, i32, i64, ptr, ptr, ptr, ptr, [8 x i32], %union.anon.0 }
%struct.BrotliBitReader = type { i64, i64, ptr, ptr, ptr }
%union.anon = type { i64 }
%struct.HuffmanTreeGroup = type { ptr, ptr, i16, i16, i16 }
%union.anon.0 = type { %struct.BrotliMetablockBodyArena }
%struct.BrotliMetablockBodyArena = type { [544 x i8], [544 x i64] }

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

; 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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 48}
!12 = !{!"BrotliDecoderStateStruct", !13, i64 0, !13, i64 4, !14, i64 8, !6, i64 48, !6, i64 56, !6, i64 64, !7, i64 72, !10, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !7, i64 112, !13, i64 128, !13, i64 132, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !15, i64 184, !15, i64 208, !15, i64 232, !6, i64 256, !6, i64 264, !13, i64 272, !13, i64 276, !7, i64 280, !10, i64 304, !7, i64 312, !7, i64 336, !10, i64 384, !10, i64 392, !10, i64 400, !6, i64 408, !6, i64 416, !10, i64 424, !10, i64 432, !10, i64 440, !7, i64 448, !13, i64 708, !13, i64 712, !7, i64 716, !6, i64 720, !6, i64 728, !6, i64 736, !10, i64 744, !13, i64 752, !13, i64 756, !13, i64 760, !13, i64 764, !13, i64 768, !13, i64 772, !13, i64 772, !13, i64 772, !13, i64 772, !13, i64 772, !13, i64 772, !13, i64 772, !13, i64 773, !10, i64 776, !6, i64 784, !6, i64 792, !6, i64 800, !6, i64 808, !7, i64 816, !7, i64 848}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!"", !6, i64 0, !6, i64 8, !16, i64 16, !16, i64 18, !16, i64 20}
!16 = !{!"short", !7, i64 0}
!17 = !{!12, !6, i64 64}
!18 = !{!15, !16, i64 16}
!19 = !{!15, !16, i64 18}
!20 = !{!15, !16, i64 20}
!21 = !{!15, !6, i64 0}
!22 = !{!15, !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"

; Function Attrs: nounwind uwtable
define hidden range(i32 0, 2) i32 @BrotliDecoderHuffmanTreeGroupInit(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = shl i64 %3, 2
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %reass.add = add i64 %6, 1512
  %reass.mul = mul i64 %reass.add, %4
  %11 = tail call ptr %8(ptr noundef %10, i64 noundef %reass.mul) #1
  %12 = trunc i64 %2 to i16
  %13 = getelementptr inbounds i8, ptr %1, i64 16
  store i16 %12, ptr %13, align 8, !tbaa !16
  %14 = trunc i64 %3 to i16
  %15 = getelementptr inbounds i8, ptr %1, i64 18
  store i16 %14, ptr %15, align 2, !tbaa !17
  %16 = trunc i64 %4 to i16
  %17 = getelementptr inbounds i8, ptr %1, i64 20
  store i16 %16, ptr %17, align 4, !tbaa !18
  store ptr %11, ptr %1, align 8, !tbaa !19
  %18 = getelementptr inbounds ptr, ptr %11, i64 %4
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %18, ptr %19, align 8, !tbaa !20
  %20 = icmp ne ptr %11, null
  %21 = zext i1 %20 to i32
  ret i32 %21
}

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, !12, i64 48}
!6 = !{!"BrotliDecoderStateStruct", !7, i64 0, !7, i64 4, !10, i64 8, !12, i64 48, !12, i64 56, !12, i64 64, !8, i64 72, !11, i64 80, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !8, i64 112, !7, i64 128, !7, i64 132, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !13, i64 184, !13, i64 208, !13, i64 232, !12, i64 256, !12, i64 264, !7, i64 272, !7, i64 276, !8, i64 280, !11, i64 304, !8, i64 312, !8, i64 336, !11, i64 384, !11, i64 392, !11, i64 400, !12, i64 408, !12, i64 416, !11, i64 424, !11, i64 432, !11, i64 440, !8, i64 448, !7, i64 708, !7, i64 712, !8, i64 716, !12, i64 720, !12, i64 728, !12, i64 736, !11, i64 744, !7, i64 752, !7, i64 756, !7, i64 760, !7, i64 764, !7, i64 768, !7, i64 772, !7, i64 772, !7, i64 772, !7, i64 772, !7, i64 772, !7, i64 772, !7, i64 772, !7, i64 773, !11, i64 776, !12, i64 784, !12, i64 792, !12, i64 800, !12, i64 808, !8, i64 816, !8, i64 848}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 8, !14, i64 16, !14, i64 18, !14, i64 20}
!14 = !{!"short", !8, i64 0}
!15 = !{!6, !12, i64 64}
!16 = !{!13, !14, i64 16}
!17 = !{!13, !14, i64 18}
!18 = !{!13, !14, i64 20}
!19 = !{!13, !12, i64 0}
!20 = !{!13, !12, i64 8}


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