; LLVM IR from DanEngelbrecht/longtail :: lib/brotli/ext/dec (decode)

; 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] }
%struct.BrotliSharedDictionaryStruct = type { i32, [15 x i64], [15 x ptr], i32, [64 x i8], i8, [64 x ptr], [64 x ptr], i8, ptr, i8, ptr, ptr, ptr, ptr, ptr }

; 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 dso_local i32 @BrotliDecoderAttachDictionary(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %13, i32 0, i32 59
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !18
  %18 = zext i32 %17 to i64
  store i64 %18, ptr %11, align 8, !tbaa !11
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !20
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %69

24:                                               ; preds = %4
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %25, i32 0, i32 59
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = load i64, ptr %8, align 8, !tbaa !11
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = call i32 @BrotliSharedDictionaryAttach(ptr noundef %27, i32 noundef %28, i64 noundef %29, ptr noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %24
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %69

34:                                               ; preds = %24
  %35 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %35, ptr %10, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %65, %34
  %37 = load i64, ptr %10, align 8, !tbaa !11
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %38, i32 0, i32 59
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !18
  %43 = zext i32 %42 to i64
  %44 = icmp ult i64 %37, %43
  br i1 %44, label %45, label %68

45:                                               ; preds = %36
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %47, i32 0, i32 59
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %49, i32 0, i32 2
  %51 = load i64, ptr %10, align 8, !tbaa !11
  %52 = getelementptr inbounds [15 x ptr], ptr %50, i64 0, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %54, i32 0, i32 59
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  %57 = getelementptr inbounds %struct.BrotliSharedDictionaryStruct, ptr %56, i32 0, i32 1
  %58 = load i64, ptr %10, align 8, !tbaa !11
  %59 = getelementptr inbounds [15 x i64], ptr %57, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = call i32 @AttachCompoundDictionary(ptr noundef %46, ptr noundef %53, i64 noundef %60)
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %64, label %63

63:                                               ; preds = %45
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %69

64:                                               ; preds = %45
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %10, align 8, !tbaa !11
  %67 = add i64 %66, 1
  store i64 %67, ptr %10, align 8, !tbaa !11
  br label %36, !llvm.loop !21

68:                                               ; preds = %36
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %69

69:                                               ; preds = %68, %63, %33, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %70 = load i32, ptr %5, align 4
  ret i32 %70
}

declare i32 @BrotliSharedDictionaryAttach(ptr noundef, i32 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @AttachCompoundDictionary(ptr noundef, ptr noundef, i64 noundef) #1

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


; 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 dso_local range(i32 0, 2) i32 @BrotliDecoderAttachDictionary(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 800
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %.loopexit

7:                                                ; preds = %4
  %8 = load ptr, ptr %5, align 8, !tbaa !15
  %9 = load i32, ptr %8, align 8, !tbaa !16
  %10 = tail call i32 @BrotliSharedDictionaryAttach(ptr noundef nonnull %8, i32 noundef %1, i64 noundef %2, ptr noundef %3) #2
  %.not16 = icmp eq i32 %10, 0
  br i1 %.not16, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %7
  %11 = load ptr, ptr %5, align 8, !tbaa !15
  %12 = load i32, ptr %11, align 8, !tbaa !16
  %13 = icmp ult i32 %9, %12
  br i1 %13, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %14 = zext i32 %9 to i64
  br label %.lr.ph

15:                                               ; preds = %.lr.ph
  %16 = add nuw nsw i64 %.01518, 1
  %17 = load ptr, ptr %5, align 8, !tbaa !15
  %18 = load i32, ptr %17, align 8, !tbaa !16
  %19 = zext i32 %18 to i64
  %20 = icmp ult i64 %16, %19
  br i1 %20, label %.lr.ph, label %.loopexit, !llvm.loop !18

.lr.ph:                                           ; preds = %.lr.ph.preheader, %15
  %21 = phi ptr [ %17, %15 ], [ %11, %.lr.ph.preheader ]
  %.01518 = phi i64 [ %16, %15 ], [ %14, %.lr.ph.preheader ]
  %22 = getelementptr inbounds i8, ptr %21, i64 128
  %23 = getelementptr inbounds [15 x ptr], ptr %22, i64 0, i64 %.01518
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  %25 = getelementptr inbounds i8, ptr %21, i64 8
  %26 = getelementptr inbounds [15 x i64], ptr %25, i64 0, i64 %.01518
  %27 = load i64, ptr %26, align 8, !tbaa !21
  %28 = tail call i32 @AttachCompoundDictionary(ptr noundef nonnull %0, ptr noundef %24, i64 noundef %27)
  %.not17 = icmp eq i32 %28, 0
  br i1 %.not17, label %.loopexit, label %15

.loopexit:                                        ; preds = %.lr.ph, %15, %.preheader, %7, %4
  %.0 = phi i32 [ 0, %4 ], [ 0, %7 ], [ 1, %.preheader ], [ 0, %.lr.ph ], [ 1, %15 ]
  ret i32 %.0
}

declare i32 @BrotliSharedDictionaryAttach(ptr noundef, i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @AttachCompoundDictionary(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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 = { "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 }

!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, !7, i64 0}
!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 800}
!16 = !{!17, !7, i64 0}
!17 = !{!"BrotliSharedDictionaryStruct", !7, i64 0, !8, i64 8, !8, i64 128, !7, i64 248, !8, i64 252, !8, i64 316, !8, i64 320, !8, i64 832, !8, i64 1344, !12, i64 1352, !8, i64 1360, !12, i64 1368, !12, i64 1376, !12, i64 1384, !12, i64 1392, !12, i64 1400}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !12, i64 0}
!21 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass