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

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

@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@__PRETTY_FUNCTION__.ZopfliVerifyLenDist = external hidden unnamed_addr constant [96 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [38 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ZopfliVerifyLenDist(ptr noundef %0, i64 noundef %1, i64 noundef %2, i16 noundef zeroext %3, i16 noundef zeroext %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i16 %3, ptr %9, align 2, !tbaa !11
  store i16 %4, ptr %10, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %12 = load i64, ptr %8, align 8, !tbaa !9
  %13 = load i16, ptr %10, align 2, !tbaa !11
  %14 = zext i16 %13 to i64
  %15 = add i64 %12, %14
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = icmp ule i64 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  br label %20

19:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 276, ptr noundef @__PRETTY_FUNCTION__.ZopfliVerifyLenDist) #4
  unreachable

20:                                               ; preds = %18
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %68, %20
  %22 = load i64, ptr %11, align 8, !tbaa !9
  %23 = load i16, ptr %10, align 2, !tbaa !11
  %24 = zext i16 %23 to i64
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %26, label %71

26:                                               ; preds = %21
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i64, ptr %8, align 8, !tbaa !9
  %29 = load i16, ptr %9, align 2, !tbaa !11
  %30 = zext i16 %29 to i64
  %31 = sub i64 %28, %30
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = add i64 %31, %32
  %34 = getelementptr inbounds i8, ptr %27, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !13
  %36 = zext i8 %35 to i32
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = add i64 %38, %39
  %41 = getelementptr inbounds i8, ptr %37, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = icmp ne i32 %36, %43
  br i1 %44, label %45, label %67

45:                                               ; preds = %26
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = load i16, ptr %9, align 2, !tbaa !11
  %49 = zext i16 %48 to i64
  %50 = sub i64 %47, %49
  %51 = load i64, ptr %11, align 8, !tbaa !9
  %52 = add i64 %50, %51
  %53 = getelementptr inbounds i8, ptr %46, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = zext i8 %54 to i32
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = add i64 %57, %58
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !13
  %62 = zext i8 %61 to i32
  %63 = icmp eq i32 %55, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %45
  br label %66

65:                                               ; preds = %45
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 279, ptr noundef @__PRETTY_FUNCTION__.ZopfliVerifyLenDist) #4
  unreachable

66:                                               ; preds = %64
  br label %71

67:                                               ; preds = %26
  br label %68

68:                                               ; preds = %67
  %69 = load i64, ptr %11, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %11, align 8, !tbaa !9
  br label %21, !llvm.loop !14

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 }
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 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 [66 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@__PRETTY_FUNCTION__.ZopfliVerifyLenDist = external hidden unnamed_addr constant [96 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @ZopfliVerifyLenDist(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i16 noundef zeroext %3, i16 noundef zeroext %4) local_unnamed_addr #1 {
  %6 = zext i16 %4 to i64
  %7 = add i64 %6, %2
  %.not = icmp ugt i64 %7, %1
  br i1 %.not, label %11, label %.preheader

.preheader:                                       ; preds = %5
  %invariant.gep = getelementptr i8, ptr %0, i64 %2
  %.not21 = icmp eq i16 %4, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %8 = zext i16 %3 to i64
  %9 = sub i64 %2, %8
  %10 = getelementptr i8, ptr %0, i64 %9
  br label %14

11:                                               ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 276, ptr noundef nonnull @__PRETTY_FUNCTION__.ZopfliVerifyLenDist) #2
  unreachable

12:                                               ; preds = %14
  %13 = add nuw nsw i64 %.020, 1
  %exitcond.not = icmp eq i64 %13, %6
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !5

14:                                               ; preds = %.lr.ph, %12
  %.020 = phi i64 [ 0, %.lr.ph ], [ %13, %12 ]
  %15 = getelementptr i8, ptr %10, i64 %.020
  %16 = load i8, ptr %15, align 1, !tbaa !7
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.020
  %17 = load i8, ptr %gep, align 1, !tbaa !7
  %.not19 = icmp eq i8 %16, %17
  br i1 %.not19, label %12, label %18

18:                                               ; preds = %14
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 279, ptr noundef nonnull @__PRETTY_FUNCTION__.ZopfliVerifyLenDist) #2
  unreachable

._crit_edge:                                      ; preds = %12, %.preheader
  ret void
}

attributes #0 = { 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 #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 }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


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