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

; 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.CompoundDictionary = type { i64, i64, [16 x ptr], [16 x ptr], [16 x i64], i64, [16 x ptr] }
%struct.PreparedDictionary = type { i32, i32, i32, i32, i32, i32 }

; 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 i32 @AttachPreparedDictionary(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.CompoundDictionary, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp eq i64 %15, 15
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %92

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %92

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.PreparedDictionary, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = zext i32 %25 to i64
  store i64 %26, ptr %6, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.CompoundDictionary, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !11
  store i64 %29, ptr %7, align 8, !tbaa !9
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.CompoundDictionary, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = add i64 %33, %30
  store i64 %34, ptr %32, align 8, !tbaa !16
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.CompoundDictionary, ptr %36, i32 0, i32 2
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds [16 x ptr], ptr %37, i64 0, i64 %38
  store ptr %35, ptr %39, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CompoundDictionary, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !16
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.CompoundDictionary, ptr %43, i32 0, i32 4
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = add i64 %45, 1
  %47 = getelementptr inbounds [16 x i64], ptr %44, i64 0, i64 %46
  store i64 %42, ptr %47, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PreparedDictionary, ptr %48, i64 1
  store ptr %49, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.PreparedDictionary, ptr %51, i32 0, i32 5
  %53 = load i32, ptr %52, align 4, !tbaa !17
  %54 = shl i32 1, %53
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %50, i64 %55
  store ptr %56, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.PreparedDictionary, ptr %58, i32 0, i32 4
  %60 = load i32, ptr %59, align 4, !tbaa !18
  %61 = shl i32 1, %60
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i16, ptr %57, i64 %62
  store ptr %63, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.PreparedDictionary, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !19
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %64, i64 %68
  store ptr %69, ptr %12, align 8, !tbaa !5
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.PreparedDictionary, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 4, !tbaa !20
  %73 = icmp eq i32 %72, -558043680
  br i1 %73, label %74, label %80

74:                                               ; preds = %22
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.CompoundDictionary, ptr %76, i32 0, i32 3
  %78 = load i64, ptr %7, align 8, !tbaa !9
  %79 = getelementptr inbounds [16 x ptr], ptr %77, i64 0, i64 %78
  store ptr %75, ptr %79, align 8, !tbaa !5
  br label %87

80:                                               ; preds = %22
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = call ptr @BROTLI_UNALIGNED_LOAD_PTR(ptr noundef %81)
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.CompoundDictionary, ptr %83, i32 0, i32 3
  %85 = load i64, ptr %7, align 8, !tbaa !9
  %86 = getelementptr inbounds [16 x ptr], ptr %84, i64 0, i64 %85
  store ptr %82, ptr %86, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %80, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.CompoundDictionary, ptr %88, i32 0, i32 0
  %90 = load i64, ptr %89, align 8, !tbaa !11
  %91 = add i64 %90, 1
  store i64 %91, ptr %89, align 8, !tbaa !11
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %92

92:                                               ; preds = %87, %21, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %93 = load i32, ptr %3, align 4
  ret i32 %93
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @BROTLI_UNALIGNED_LOAD_PTR(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 = { alwaysinline 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 #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 0}
!12 = !{!"CompoundDictionary", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 144, !7, i64 272, !10, i64 400, !7, i64 408}
!13 = !{!14, !15, i64 8}
!14 = !{!"PreparedDictionary", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20}
!15 = !{!"int", !7, i64 0}
!16 = !{!12, !10, i64 8}
!17 = !{!14, !15, i64 20}
!18 = !{!14, !15, i64 16}
!19 = !{!14, !15, i64 4}
!20 = !{!14, !15, i64 0}


; 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 @AttachPreparedDictionary(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = icmp eq i64 %3, 15
  %.not = icmp eq ptr %1, null
  %or.cond = or i1 %.not, %4
  br i1 %or.cond, label %41, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = add i64 %10, %8
  store i64 %11, ptr %9, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = getelementptr inbounds [16 x ptr], ptr %12, i64 0, i64 %3
  store ptr %1, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 272
  %15 = add i64 %3, 1
  %16 = getelementptr inbounds [16 x i64], ptr %14, i64 0, i64 %15
  store i64 %11, ptr %16, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %1, i64 24
  %18 = getelementptr inbounds i8, ptr %1, i64 20
  %19 = load i32, ptr %18, align 4, !tbaa !17
  %20 = shl nuw i32 1, %19
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %17, i64 %21
  %23 = getelementptr inbounds i8, ptr %1, i64 16
  %24 = load i32, ptr %23, align 4, !tbaa !18
  %25 = shl nuw i32 1, %24
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i16, ptr %22, i64 %26
  %28 = getelementptr inbounds i8, ptr %1, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !19
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %27, i64 %30
  %32 = load i32, ptr %1, align 4, !tbaa !20
  %33 = icmp eq i32 %32, -558043680
  br i1 %33, label %36, label %34

34:                                               ; preds = %5
  %35 = tail call ptr @BROTLI_UNALIGNED_LOAD_PTR(ptr noundef nonnull %31)
  br label %36

36:                                               ; preds = %5, %34
  %.sink = phi ptr [ %35, %34 ], [ %31, %5 ]
  %37 = getelementptr inbounds i8, ptr %0, i64 144
  %38 = getelementptr inbounds [16 x ptr], ptr %37, i64 0, i64 %3
  store ptr %.sink, ptr %38, align 8, !tbaa !14
  %39 = load i64, ptr %0, align 8, !tbaa !5
  %40 = add i64 %39, 1
  store i64 %40, ptr %0, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %2, %36
  %.0 = phi i32 [ 1, %36 ], [ 0, %2 ]
  ret i32 %.0
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @BROTLI_UNALIGNED_LOAD_PTR(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 = { alwaysinline 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" }

!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 = !{!"CompoundDictionary", !7, i64 0, !7, i64 8, !8, i64 16, !8, i64 144, !8, i64 272, !7, i64 400, !8, i64 408}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 8}
!11 = !{!"PreparedDictionary", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!11, !12, i64 20}
!18 = !{!11, !12, i64 16}
!19 = !{!11, !12, i64 4}
!20 = !{!11, !12, i64 0}


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