; LLVM IR from JayXon/Leanify :: lib/zopfli (cache)

; 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.ZopfliLongestMatchCache = type { ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__.ZopfliSublenToCache = external hidden unnamed_addr constant [92 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [54 x i8], align 1

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

23:                                               ; preds = %4
  store i32 1, ptr %13, align 4
  br label %125

24:                                               ; preds = %4
  store i64 3, ptr %9, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %88, %24
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = icmp ule i64 %26, %27
  br i1 %28, label %29, label %91

29:                                               ; preds = %25
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = icmp eq i64 %30, %31
  br i1 %32, label %46, label %33

33:                                               ; preds = %29
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds i16, ptr %34, i64 %35
  %37 = load i16, ptr %36, align 2, !tbaa !15
  %38 = zext i16 %37 to i32
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = add i64 %40, 1
  %42 = getelementptr inbounds i16, ptr %39, i64 %41
  %43 = load i16, ptr %42, align 2, !tbaa !15
  %44 = zext i16 %43 to i32
  %45 = icmp ne i32 %38, %44
  br i1 %45, label %46, label %87

46:                                               ; preds = %33, %29
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = sub i64 %47, 3
  %49 = trunc i64 %48 to i8
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = mul i64 %51, 3
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  store i8 %49, ptr %53, align 1, !tbaa !17
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = getelementptr inbounds i16, ptr %54, i64 %55
  %57 = load i16, ptr %56, align 2, !tbaa !15
  %58 = zext i16 %57 to i32
  %59 = srem i32 %58, 256
  %60 = trunc i32 %59 to i8
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = load i64, ptr %10, align 8, !tbaa !9
  %63 = mul i64 %62, 3
  %64 = add i64 %63, 1
  %65 = getelementptr inbounds i8, ptr %61, i64 %64
  store i8 %60, ptr %65, align 1, !tbaa !17
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load i64, ptr %9, align 8, !tbaa !9
  %68 = getelementptr inbounds i16, ptr %66, i64 %67
  %69 = load i16, ptr %68, align 2, !tbaa !15
  %70 = zext i16 %69 to i32
  %71 = ashr i32 %70, 8
  %72 = srem i32 %71, 256
  %73 = trunc i32 %72 to i8
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = load i64, ptr %10, align 8, !tbaa !9
  %76 = mul i64 %75, 3
  %77 = add i64 %76, 2
  %78 = getelementptr inbounds i8, ptr %74, i64 %77
  store i8 %73, ptr %78, align 1, !tbaa !17
  %79 = load i64, ptr %9, align 8, !tbaa !9
  %80 = trunc i64 %79 to i32
  store i32 %80, ptr %11, align 4, !tbaa !11
  %81 = load i64, ptr %10, align 8, !tbaa !9
  %82 = add i64 %81, 1
  store i64 %82, ptr %10, align 8, !tbaa !9
  %83 = load i64, ptr %10, align 8, !tbaa !9
  %84 = icmp uge i64 %83, 8
  br i1 %84, label %85, label %86

85:                                               ; preds = %46
  br label %91

86:                                               ; preds = %46
  br label %87

87:                                               ; preds = %86, %33
  br label %88

88:                                               ; preds = %87
  %89 = load i64, ptr %9, align 8, !tbaa !9
  %90 = add i64 %89, 1
  store i64 %90, ptr %9, align 8, !tbaa !9
  br label %25, !llvm.loop !18

91:                                               ; preds = %85, %25
  %92 = load i64, ptr %10, align 8, !tbaa !9
  %93 = icmp ult i64 %92, 8
  br i1 %93, label %94, label %107

94:                                               ; preds = %91
  %95 = load i32, ptr %11, align 4, !tbaa !11
  %96 = zext i32 %95 to i64
  %97 = load i64, ptr %7, align 8, !tbaa !9
  %98 = icmp eq i64 %96, %97
  br i1 %98, label %99, label %100

99:                                               ; preds = %94
  br label %101

100:                                              ; preds = %94
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 79, ptr noundef @__PRETTY_FUNCTION__.ZopfliSublenToCache) #4
  unreachable

101:                                              ; preds = %99
  %102 = load i32, ptr %11, align 4, !tbaa !11
  %103 = sub i32 %102, 3
  %104 = trunc i32 %103 to i8
  %105 = load ptr, ptr %12, align 8, !tbaa !5
  %106 = getelementptr inbounds i8, ptr %105, i64 21
  store i8 %104, ptr %106, align 1, !tbaa !17
  br label %115

107:                                              ; preds = %91
  %108 = load i32, ptr %11, align 4, !tbaa !11
  %109 = zext i32 %108 to i64
  %110 = load i64, ptr %7, align 8, !tbaa !9
  %111 = icmp ule i64 %109, %110
  br i1 %111, label %112, label %113

112:                                              ; preds = %107
  br label %114

113:                                              ; preds = %107
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 82, ptr noundef @__PRETTY_FUNCTION__.ZopfliSublenToCache) #4
  unreachable

114:                                              ; preds = %112
  br label %115

115:                                              ; preds = %114, %101
  %116 = load i32, ptr %11, align 4, !tbaa !11
  %117 = load ptr, ptr %8, align 8, !tbaa !5
  %118 = load i64, ptr %6, align 8, !tbaa !9
  %119 = load i64, ptr %7, align 8, !tbaa !9
  %120 = call i32 @ZopfliMaxCachedSublen(ptr noundef %117, i64 noundef %118, i64 noundef %119)
  %121 = icmp eq i32 %116, %120
  br i1 %121, label %122, label %123

122:                                              ; preds = %115
  br label %124

123:                                              ; preds = %115
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.2, i32 noundef 84, ptr noundef @__PRETTY_FUNCTION__.ZopfliSublenToCache) #4
  unreachable

124:                                              ; preds = %122
  store i32 0, ptr %13, align 4
  br label %125

125:                                              ; preds = %124, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, 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
  %126 = load i32, ptr %13, align 4
  switch i32 %126, label %128 [
    i32 0, label %127
    i32 1, label %127
  ]

127:                                              ; preds = %125, %125
  ret void

128:                                              ; preds = %125
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @ZopfliMaxCachedSublen(ptr noundef, i64 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 = { noreturn nounwind "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 }
attributes #4 = { noreturn 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"ZopfliLongestMatchCache", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [67 x i8], align 1
@__PRETTY_FUNCTION__.ZopfliSublenToCache = external hidden unnamed_addr constant [92 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ZopfliSublenToCache(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = mul i64 %1, 24
  %8 = getelementptr inbounds i8, ptr %6, i64 %7
  %9 = icmp ult i64 %2, 3
  br i1 %9, label %50, label %.preheader

.preheader:                                       ; preds = %4, %32
  %.053 = phi i64 [ %33, %32 ], [ 3, %4 ]
  %.03652 = phi i32 [ %.1, %32 ], [ 0, %4 ]
  %.03751 = phi i64 [ %.138, %32 ], [ 0, %4 ]
  %10 = icmp eq i64 %.053, %2
  br i1 %10, label %16, label %11

11:                                               ; preds = %.preheader
  %12 = getelementptr inbounds i16, ptr %0, i64 %.053
  %13 = load i16, ptr %12, align 2, !tbaa !10
  %14 = getelementptr i8, ptr %12, i64 2
  %15 = load i16, ptr %14, align 2, !tbaa !10
  %.not43 = icmp eq i16 %13, %15
  br i1 %.not43, label %32, label %16

16:                                               ; preds = %11, %.preheader
  %17 = trunc i64 %.053 to i8
  %18 = add i8 %17, -3
  %19 = mul i64 %.03751, 3
  %20 = getelementptr inbounds i8, ptr %8, i64 %19
  store i8 %18, ptr %20, align 1, !tbaa !12
  %21 = getelementptr inbounds i16, ptr %0, i64 %.053
  %22 = load i16, ptr %21, align 2, !tbaa !10
  %23 = trunc i16 %22 to i8
  %24 = getelementptr i8, ptr %20, i64 1
  store i8 %23, ptr %24, align 1, !tbaa !12
  %25 = load i16, ptr %21, align 2, !tbaa !10
  %26 = lshr i16 %25, 8
  %27 = trunc nuw i16 %26 to i8
  %28 = getelementptr i8, ptr %20, i64 2
  store i8 %27, ptr %28, align 1, !tbaa !12
  %29 = trunc i64 %.053 to i32
  %30 = add i64 %.03751, 1
  %31 = icmp ugt i64 %30, 7
  br i1 %31, label %.thread, label %32

32:                                               ; preds = %11, %16
  %.138 = phi i64 [ %30, %16 ], [ %.03751, %11 ]
  %.1 = phi i32 [ %29, %16 ], [ %.03652, %11 ]
  %33 = add i64 %.053, 1
  %.not = icmp ugt i64 %33, %2
  br i1 %.not, label %34, label %.preheader, !llvm.loop !13

34:                                               ; preds = %32
  %35 = icmp ult i64 %.138, 8
  br i1 %35, label %36, label %.thread

36:                                               ; preds = %34
  %37 = zext i32 %.1 to i64
  %38 = icmp eq i64 %37, %2
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 79, ptr noundef nonnull @__PRETTY_FUNCTION__.ZopfliSublenToCache) #2
  unreachable

40:                                               ; preds = %36
  %41 = trunc i32 %.1 to i8
  %42 = add i8 %41, -3
  %43 = getelementptr inbounds i8, ptr %8, i64 21
  store i8 %42, ptr %43, align 1, !tbaa !12
  br label %46

.thread:                                          ; preds = %16, %34
  %.248 = phi i32 [ %.1, %34 ], [ %29, %16 ]
  %44 = zext i32 %.248 to i64
  %.not44 = icmp ugt i64 %44, %2
  br i1 %.not44, label %45, label %46

45:                                               ; preds = %.thread
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2, i32 noundef 82, ptr noundef nonnull @__PRETTY_FUNCTION__.ZopfliSublenToCache) #2
  unreachable

46:                                               ; preds = %.thread, %40
  %.247 = phi i32 [ %.248, %.thread ], [ %.1, %40 ]
  %47 = tail call i32 @ZopfliMaxCachedSublen(ptr noundef %3, i64 noundef %1, i64 noundef %2)
  %48 = icmp eq i32 %.247, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.2, i32 noundef 84, ptr noundef nonnull @__PRETTY_FUNCTION__.ZopfliSublenToCache) #2
  unreachable

50:                                               ; preds = %46, %4
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @ZopfliMaxCachedSublen(ptr noundef, i64 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 = { noreturn nounwind "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 = { noreturn 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 16}
!6 = !{!"ZopfliLongestMatchCache", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass