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

; 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.SharedEncoderDictionary = type { i32, %struct.CompoundDictionary, %struct.ContextualEncoderDictionary, i32 }
%struct.CompoundDictionary = type { i64, i64, [16 x ptr], [16 x ptr], [16 x i64], i64, [16 x ptr] }
%struct.ContextualEncoderDictionary = type { i32, i8, [64 x i8], [64 x ptr], i64, %struct.BrotliEncoderDictionary, ptr }
%struct.BrotliEncoderDictionary = type { ptr, i32, i32, i64, ptr, ptr, ptr, ptr, %struct.BrotliTrie, i32, ptr, ptr, ptr, i64, ptr, i64, ptr, ptr }
%struct.BrotliTrie = type { ptr, i64, i64, %struct.BrotliTrieNode }
%struct.BrotliTrieNode = type { i8, i8, i8, i32, i32 }

; Function Attrs: nounwind uwtable
define hidden void @BrotliCleanupSharedEncoderDictionary(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %21, %2
  %7 = load i64, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.SharedEncoderDictionary, ptr %8, i32 0, i32 1
  %10 = getelementptr inbounds %struct.CompoundDictionary, ptr %9, i32 0, i32 5
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = icmp ult i64 %7, %11
  br i1 %12, label %13, label %24

13:                                               ; preds = %6
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SharedEncoderDictionary, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.CompoundDictionary, ptr %16, i32 0, i32 6
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds [16 x ptr], ptr %17, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  call void @DestroyPreparedDictionary(ptr noundef %14, ptr noundef %20)
  br label %21

21:                                               ; preds = %13
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = add i64 %22, 1
  store i64 %23, ptr %5, align 8, !tbaa !9
  br label %6, !llvm.loop !19

24:                                               ; preds = %6
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.SharedEncoderDictionary, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds %struct.ContextualEncoderDictionary, ptr %26, i32 0, i32 4
  %28 = load i64, ptr %27, align 8, !tbaa !21
  %29 = icmp eq i64 %28, 1
  br i1 %29, label %30, label %35

30:                                               ; preds = %24
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SharedEncoderDictionary, ptr %32, i32 0, i32 2
  %34 = getelementptr inbounds %struct.ContextualEncoderDictionary, ptr %33, i32 0, i32 5
  call void @BrotliDestroyEncoderDictionary(ptr noundef %31, ptr noundef %34)
  br label %67

35:                                               ; preds = %24
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SharedEncoderDictionary, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds %struct.ContextualEncoderDictionary, ptr %37, i32 0, i32 4
  %39 = load i64, ptr %38, align 8, !tbaa !21
  %40 = icmp ugt i64 %39, 1
  br i1 %40, label %41, label %66

41:                                               ; preds = %35
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %57, %41
  %43 = load i64, ptr %5, align 8, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.SharedEncoderDictionary, ptr %44, i32 0, i32 2
  %46 = getelementptr inbounds %struct.ContextualEncoderDictionary, ptr %45, i32 0, i32 4
  %47 = load i64, ptr %46, align 8, !tbaa !21
  %48 = icmp ult i64 %43, %47
  br i1 %48, label %49, label %60

49:                                               ; preds = %42
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.SharedEncoderDictionary, ptr %51, i32 0, i32 2
  %53 = getelementptr inbounds %struct.ContextualEncoderDictionary, ptr %52, i32 0, i32 6
  %54 = load ptr, ptr %53, align 8, !tbaa !22
  %55 = load i64, ptr %5, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.BrotliEncoderDictionary, ptr %54, i64 %55
  call void @BrotliDestroyEncoderDictionary(ptr noundef %50, ptr noundef %56)
  br label %57

57:                                               ; preds = %49
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = add i64 %58, 1
  store i64 %59, ptr %5, align 8, !tbaa !9
  br label %42, !llvm.loop !23

60:                                               ; preds = %42
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.SharedEncoderDictionary, ptr %62, i32 0, i32 2
  %64 = getelementptr inbounds %struct.ContextualEncoderDictionary, ptr %63, i32 0, i32 6
  %65 = load ptr, ptr %64, align 8, !tbaa !22
  call void @BrotliFree(ptr noundef %61, ptr noundef %65)
  br label %66

66:                                               ; preds = %60, %35
  br label %67

67:                                               ; preds = %66, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

declare hidden void @DestroyPreparedDictionary(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @BrotliDestroyEncoderDictionary(ptr noundef, ptr noundef) #0

declare hidden void @BrotliFree(ptr noundef, ptr noundef) #2

; 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 = { "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, !10, i64 408}
!12 = !{!"SharedEncoderDictionary", !13, i64 0, !14, i64 8, !15, i64 544, !13, i64 1312}
!13 = !{!"int", !7, i64 0}
!14 = !{!"CompoundDictionary", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 144, !7, i64 272, !10, i64 400, !7, i64 408}
!15 = !{!"ContextualEncoderDictionary", !13, i64 0, !7, i64 4, !7, i64 5, !7, i64 72, !10, i64 584, !16, i64 592, !6, i64 760}
!16 = !{!"BrotliEncoderDictionary", !6, i64 0, !13, i64 8, !13, i64 12, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !17, i64 56, !13, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !10, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !6, i64 160}
!17 = !{!"BrotliTrie", !6, i64 0, !10, i64 8, !10, i64 16, !18, i64 24}
!18 = !{!"BrotliTrieNode", !7, i64 0, !7, i64 1, !7, i64 2, !13, i64 4, !13, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !10, i64 1128}
!22 = !{!12, !6, i64 1304}
!23 = distinct !{!23, !20}


; 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.BrotliEncoderDictionary = type { ptr, i32, i32, i64, ptr, ptr, ptr, ptr, %struct.BrotliTrie, i32, ptr, ptr, ptr, i64, ptr, i64, ptr, ptr }
%struct.BrotliTrie = type { ptr, i64, i64, %struct.BrotliTrieNode }
%struct.BrotliTrieNode = type { i8, i8, i8, i32, i32 }

; Function Attrs: nounwind uwtable
define hidden void @BrotliCleanupSharedEncoderDictionary(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 408
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

6:                                                ; preds = %.lr.ph, %6
  %.018 = phi i64 [ 0, %.lr.ph ], [ %9, %6 ]
  %7 = getelementptr inbounds [16 x ptr], ptr %5, i64 0, i64 %.018
  %8 = load ptr, ptr %7, align 8, !tbaa !17
  tail call void @DestroyPreparedDictionary(ptr noundef %0, ptr noundef %8) #2
  %9 = add nuw i64 %.018, 1
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = icmp ult i64 %9, %10
  br i1 %11, label %6, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %6, %2
  %12 = getelementptr inbounds i8, ptr %1, i64 1128
  %13 = load i64, ptr %12, align 8, !tbaa !20
  switch i64 %13, label %.lr.ph20 [
    i64 1, label %15
    i64 0, label %25
  ]

.lr.ph20:                                         ; preds = %._crit_edge
  %14 = getelementptr inbounds i8, ptr %1, i64 1304
  br label %17

15:                                               ; preds = %._crit_edge
  %16 = getelementptr inbounds i8, ptr %1, i64 1136
  tail call void @BrotliDestroyEncoderDictionary(ptr noundef %0, ptr noundef nonnull %16)
  br label %25

17:                                               ; preds = %.lr.ph20, %17
  %.119 = phi i64 [ 0, %.lr.ph20 ], [ %20, %17 ]
  %18 = load ptr, ptr %14, align 8, !tbaa !21
  %19 = getelementptr inbounds %struct.BrotliEncoderDictionary, ptr %18, i64 %.119
  tail call void @BrotliDestroyEncoderDictionary(ptr noundef %0, ptr noundef %19)
  %20 = add nuw i64 %.119, 1
  %21 = load i64, ptr %12, align 8, !tbaa !20
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %17, label %._crit_edge21, !llvm.loop !22

._crit_edge21:                                    ; preds = %17
  %23 = getelementptr inbounds i8, ptr %1, i64 1304
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  tail call void @BrotliFree(ptr noundef %0, ptr noundef %24) #2
  br label %25

25:                                               ; preds = %._crit_edge, %._crit_edge21, %15
  ret void
}

declare hidden void @DestroyPreparedDictionary(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @BrotliDestroyEncoderDictionary(ptr noundef, ptr noundef) local_unnamed_addr #0

declare hidden void @BrotliFree(ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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, !11, i64 408}
!6 = !{!"SharedEncoderDictionary", !7, i64 0, !10, i64 8, !12, i64 544, !7, i64 1312}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"CompoundDictionary", !11, i64 0, !11, i64 8, !8, i64 16, !8, i64 144, !8, i64 272, !11, i64 400, !8, i64 408}
!11 = !{!"long", !8, i64 0}
!12 = !{!"ContextualEncoderDictionary", !7, i64 0, !8, i64 4, !8, i64 5, !8, i64 72, !11, i64 584, !13, i64 592, !14, i64 760}
!13 = !{!"BrotliEncoderDictionary", !14, i64 0, !7, i64 8, !7, i64 12, !11, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !15, i64 56, !7, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !11, i64 128, !14, i64 136, !11, i64 144, !14, i64 152, !14, i64 160}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"BrotliTrie", !14, i64 0, !11, i64 8, !11, i64 16, !16, i64 24}
!16 = !{!"BrotliTrieNode", !8, i64 0, !8, i64 1, !8, i64 2, !7, i64 4, !7, i64 8}
!17 = !{!14, !14, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !11, i64 1128}
!21 = !{!6, !14, i64 1304}
!22 = distinct !{!22, !19}


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