; LLVM IR from fhanau/Efficient-Compression-Tool :: src/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 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__PRETTY_FUNCTION__.ZopfliVerifyLenDist = external hidden unnamed_addr constant [96 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 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) #0 {
  %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
  %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, ptr noundef @.str.1, i32 noundef 70, ptr noundef @__PRETTY_FUNCTION__.ZopfliVerifyLenDist) #3
  unreachable

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %49, %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 %27, label %26

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %52

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

46:                                               ; preds = %27
  br label %48

47:                                               ; preds = %27
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 72, ptr noundef @__PRETTY_FUNCTION__.ZopfliVerifyLenDist) #3
  unreachable

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = add i64 %50, 1
  store i64 %51, ptr %11, align 8, !tbaa !9
  br label %21, !llvm.loop !14

52:                                               ; preds = %26
  ret void
}

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noreturn nounwind }
attributes #4 = { 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 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__PRETTY_FUNCTION__.ZopfliVerifyLenDist = external hidden unnamed_addr constant [96 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [38 x i8], align 1

; 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 #0 {
  %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
  %.not13 = icmp eq i16 %4, 0
  br i1 %.not13, 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, ptr noundef nonnull @.str.1, i32 noundef 70, ptr noundef nonnull @__PRETTY_FUNCTION__.ZopfliVerifyLenDist) #2
  unreachable

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

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

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

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 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 = { 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 = 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