; LLVM IR from fhanau/Efficient-Compression-Tool :: src (LzFind)

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

@crc = external hidden constant [256 x i32], align 16

; 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 @Bt3Zip_MatchFinder_Skip(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %66, %2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = add i32 %10, -1
  store i32 %11, ptr %4, align 4, !tbaa !9
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %97

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._CMatchFinder, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  store ptr %16, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 2
  %19 = load i8, ptr %18, align 1, !tbaa !13
  %20 = zext i8 %19 to i32
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 0
  %23 = load i8, ptr %22, align 1, !tbaa !13
  %24 = zext i8 %23 to i32
  %25 = shl i32 %24, 8
  %26 = or i32 %20, %25
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !13
  %30 = zext i8 %29 to i64
  %31 = getelementptr inbounds [256 x i32], ptr @crc, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = xor i32 %26, %32
  %34 = and i32 %33, 32767
  store i32 %34, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._CMatchFinder, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %37, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  store i32 %41, ptr %7, align 4, !tbaa !9
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._CMatchFinder, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._CMatchFinder, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  store i32 %44, ptr %50, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._CMatchFinder, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._CMatchFinder, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = ptrtoint ptr %53 to i64
  %58 = ptrtoint ptr %56 to i64
  %59 = sub i64 %57, %58
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr %8, align 4, !tbaa !9
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = icmp ugt i32 %61, 258
  br i1 %62, label %63, label %64

63:                                               ; preds = %13
  br label %66

64:                                               ; preds = %13
  %65 = load i32, ptr %8, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %64, %63
  %67 = phi i32 [ 258, %63 ], [ %65, %64 ]
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._CMatchFinder, ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 8, !tbaa !15
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._CMatchFinder, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._CMatchFinder, ptr %75, i32 0, i32 5
  %77 = load ptr, ptr %76, align 8, !tbaa !17
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._CMatchFinder, ptr %78, i32 0, i32 3
  %80 = load i32, ptr %79, align 4, !tbaa !18
  call void @SkipMatches(i32 noundef %67, i32 noundef %68, i32 noundef %71, ptr noundef %74, ptr noundef %77, i32 noundef %80)
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._CMatchFinder, ptr %81, i32 0, i32 3
  %83 = load i32, ptr %82, align 4, !tbaa !18
  %84 = add i32 %83, 1
  store i32 %84, ptr %82, align 4, !tbaa !18
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._CMatchFinder, ptr %85, i32 0, i32 3
  %87 = load i32, ptr %86, align 4, !tbaa !18
  %88 = and i32 %87, 32767
  store i32 %88, ptr %86, align 4, !tbaa !18
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._CMatchFinder, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !11
  %92 = getelementptr inbounds i8, ptr %91, i32 1
  store ptr %92, ptr %90, align 8, !tbaa !11
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct._CMatchFinder, ptr %93, i32 0, i32 2
  %95 = load i32, ptr %94, align 8, !tbaa !15
  %96 = add i32 %95, 1
  store i32 %96, ptr %94, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %9, !llvm.loop !19

97:                                               ; preds = %9
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @SkipMatches(i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_CMatchFinder", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !6, i64 32}
!18 = !{!12, !10, i64 20}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@crc = external hidden local_unnamed_addr constant [256 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @Bt3Zip_MatchFinder_Skip(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not22 = icmp eq i32 %1, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  %.pre24 = load i32, ptr %4, align 8, !tbaa !11
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %9 = phi i32 [ %.pre24, %.lr.ph ], [ %45, %8 ]
  %10 = phi ptr [ %.pre, %.lr.ph ], [ %43, %8 ]
  %.023 = phi i32 [ %1, %.lr.ph ], [ %11, %8 ]
  %11 = add i32 %.023, -1
  %12 = getelementptr inbounds i8, ptr %10, i64 2
  %13 = load i8, ptr %12, align 1, !tbaa !12
  %14 = zext i8 %13 to i32
  %15 = load i8, ptr %10, align 1, !tbaa !12
  %16 = zext i8 %15 to i32
  %17 = shl nuw nsw i32 %16, 8
  %18 = or disjoint i32 %17, %14
  %19 = getelementptr inbounds i8, ptr %10, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !12
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds [256 x i32], ptr @crc, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = xor i32 %18, %23
  %25 = and i32 %24, 32767
  %26 = load ptr, ptr %3, align 8, !tbaa !14
  %27 = zext nneg i32 %25 to i64
  %28 = getelementptr inbounds i32, ptr %26, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !13
  store i32 %9, ptr %28, align 4, !tbaa !13
  %30 = load ptr, ptr %5, align 8, !tbaa !15
  %31 = ptrtoint ptr %30 to i64
  %32 = ptrtoint ptr %10 to i64
  %33 = sub i64 %31, %32
  %34 = trunc i64 %33 to i32
  %35 = tail call i32 @llvm.umin.i32(i32 %34, i32 258)
  %36 = load i32, ptr %4, align 8, !tbaa !11
  %37 = load ptr, ptr %6, align 8, !tbaa !16
  %38 = load i32, ptr %7, align 4, !tbaa !17
  tail call void @SkipMatches(i32 noundef %35, i32 noundef %29, i32 noundef %36, ptr noundef nonnull %10, ptr noundef %37, i32 noundef %38)
  %39 = load i32, ptr %7, align 4, !tbaa !17
  %40 = add i32 %39, 1
  %41 = and i32 %40, 32767
  store i32 %41, ptr %7, align 4, !tbaa !17
  %42 = load ptr, ptr %0, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 1
  store ptr %43, ptr %0, align 8, !tbaa !5
  %44 = load i32, ptr %4, align 8, !tbaa !11
  %45 = add i32 %44, 1
  store i32 %45, ptr %4, align 8, !tbaa !11
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %._crit_edge, label %8, !llvm.loop !18

._crit_edge:                                      ; preds = %8, %2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @SkipMatches(i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 speculatable willreturn memory(none) }

!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 = !{!"_CMatchFinder", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!8, !8, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !7, i64 24}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 32}
!17 = !{!6, !10, i64 20}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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