; 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 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ZopfliInitCache(i64 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = mul i64 2, %6
  %8 = call noalias ptr @malloc(i64 noundef %7) #6
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.ZopfliLongestMatchCache, ptr %9, i32 0, i32 0
  store ptr %8, ptr %10, align 8, !tbaa !11
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = mul i64 2, %11
  %13 = call noalias ptr @malloc(i64 noundef %12) #6
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.ZopfliLongestMatchCache, ptr %14, i32 0, i32 1
  store ptr %13, ptr %15, align 8, !tbaa !13
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = mul i64 24, %16
  %18 = call noalias ptr @malloc(i64 noundef %17) #6
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.ZopfliLongestMatchCache, ptr %19, i32 0, i32 2
  store ptr %18, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.ZopfliLongestMatchCache, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %30

25:                                               ; preds = %2
  %26 = load ptr, ptr @stderr, align 8, !tbaa !9
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = mul i64 24, %27
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str, i64 noundef %28) #5
  call void @exit(i32 noundef 1) #7
  unreachable

30:                                               ; preds = %2
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %41, %30
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %35, label %44

35:                                               ; preds = %31
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.ZopfliLongestMatchCache, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds i16, ptr %38, i64 %39
  store i16 1, ptr %40, align 2, !tbaa !15
  br label %41

41:                                               ; preds = %35
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = add i64 %42, 1
  store i64 %43, ptr %5, align 8, !tbaa !5
  br label %31, !llvm.loop !17

44:                                               ; preds = %31
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %55, %44
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = icmp ult i64 %46, %47
  br i1 %48, label %49, label %58

49:                                               ; preds = %45
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.ZopfliLongestMatchCache, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !13
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds i16, ptr %52, i64 %53
  store i16 0, ptr %54, align 2, !tbaa !15
  br label %55

55:                                               ; preds = %49
  %56 = load i64, ptr %5, align 8, !tbaa !5
  %57 = add i64 %56, 1
  store i64 %57, ptr %5, align 8, !tbaa !5
  br label %45, !llvm.loop !19

58:                                               ; preds = %45
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %71, %58
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = load i64, ptr %3, align 8, !tbaa !5
  %62 = mul i64 8, %61
  %63 = mul i64 %62, 3
  %64 = icmp ult i64 %60, %63
  br i1 %64, label %65, label %74

65:                                               ; preds = %59
  %66 = load ptr, ptr %4, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.ZopfliLongestMatchCache, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = load i64, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %68, i64 %69
  store i8 0, ptr %70, align 1, !tbaa !20
  br label %71

71:                                               ; preds = %65
  %72 = load i64, ptr %5, align 8, !tbaa !5
  %73 = add i64 %72, 1
  store i64 %73, ptr %5, align 8, !tbaa !5
  br label %59, !llvm.loop !21

74:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

; 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 allocsize(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 "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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"ZopfliLongestMatchCache", !10, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !18}


; 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ZopfliInitCache(i64 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = shl i64 %0, 1
  %4 = tail call noalias ptr @malloc(i64 noundef %3) #5
  store ptr %4, ptr %1, align 8, !tbaa !5
  %5 = tail call noalias ptr @malloc(i64 noundef %3) #5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %5, ptr %6, align 8, !tbaa !10
  %7 = mul i64 %0, 24
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #5
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %8, ptr %9, align 8, !tbaa !11
  %10 = icmp eq ptr %8, null
  br i1 %10, label %14, label %.preheader24

.preheader24:                                     ; preds = %2
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader24
  %min.iters.check = icmp ult i64 %0, 16
  br i1 %min.iters.check, label %.lr.ph.preheader34, label %vector.ph

.lr.ph.preheader34:                               ; preds = %middle.block, %.lr.ph.preheader
  %.025.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %0, -16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %11 = getelementptr inbounds i16, ptr %4, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store <8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>, ptr %11, align 2, !tbaa !12
  store <8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>, ptr %12, align 2, !tbaa !12
  %index.next = add nuw i64 %index, 16
  %13 = icmp eq i64 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %0
  br i1 %cmp.n, label %.preheader, label %.lr.ph.preheader34

14:                                               ; preds = %2
  %15 = load ptr, ptr @stderr, align 8, !tbaa !18
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, i64 noundef %7) #6
  tail call void @exit(i32 noundef 1) #7
  unreachable

.lr.ph:                                           ; preds = %.lr.ph.preheader34, %.lr.ph
  %.025 = phi i64 [ %18, %.lr.ph ], [ %.025.ph, %.lr.ph.preheader34 ]
  %17 = getelementptr inbounds i16, ptr %4, i64 %.025
  store i16 1, ptr %17, align 2, !tbaa !12
  %18 = add nuw i64 %.025, 1
  %exitcond.not = icmp eq i64 %18, %0
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !19

.preheader:                                       ; preds = %.lr.ph, %middle.block
  tail call void @llvm.memset.p0.i64(ptr align 2 %5, i8 0, i64 %3, i1 false), !tbaa !12
  %.not31 = icmp eq i64 %7, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph29

.lr.ph29:                                         ; preds = %.preheader, %.lr.ph29
  %.228 = phi i64 [ %30, %.lr.ph29 ], [ 0, %.preheader ]
  %19 = load ptr, ptr %9, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %19, i64 %.228
  store i8 0, ptr %20, align 1, !tbaa !20
  %21 = or disjoint i64 %.228, 1
  %22 = load ptr, ptr %9, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %22, i64 %21
  store i8 0, ptr %23, align 1, !tbaa !20
  %24 = or disjoint i64 %.228, 2
  %25 = load ptr, ptr %9, align 8, !tbaa !11
  %26 = getelementptr inbounds i8, ptr %25, i64 %24
  store i8 0, ptr %26, align 1, !tbaa !20
  %27 = or disjoint i64 %.228, 3
  %28 = load ptr, ptr %9, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %28, i64 %27
  store i8 0, ptr %29, align 1, !tbaa !20
  %30 = add nuw i64 %.228, 4
  %exitcond32.not.3 = icmp eq i64 %30, %7
  br i1 %exitcond32.not.3, label %._crit_edge, label %.lr.ph29, !llvm.loop !21

._crit_edge:                                      ; preds = %.lr.ph29, %.preheader24, %.preheader
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree 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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { cold nounwind }
attributes #7 = { 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 0}
!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 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !15, !17, !16}
!20 = !{!8, !8, i64 0}
!21 = distinct !{!21, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass