; 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_Skip2(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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._CMatchFinder, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  store ptr %9, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 2
  %12 = load i8, ptr %11, align 1, !tbaa !13
  %13 = zext i8 %12 to i32
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 0
  %16 = load i8, ptr %15, align 1, !tbaa !13
  %17 = zext i8 %16 to i32
  %18 = shl i32 %17, 8
  %19 = or i32 %13, %18
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 1
  %22 = load i8, ptr %21, align 1, !tbaa !13
  %23 = zext i8 %22 to i64
  %24 = getelementptr inbounds [256 x i32], ptr @crc, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = xor i32 %19, %25
  %27 = and i32 %26, 32767
  store i32 %27, ptr %6, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %32, %2
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = add i32 %29, -1
  store i32 %30, ptr %4, align 4, !tbaa !9
  %31 = icmp ne i32 %29, 0
  br i1 %31, label %32, label %64

32:                                               ; preds = %28
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._CMatchFinder, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 8, !tbaa !14
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._CMatchFinder, ptr %36, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %38, i64 %40
  store i32 %35, ptr %41, align 4, !tbaa !9
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._CMatchFinder, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._CMatchFinder, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 4, !tbaa !17
  call void @SkipMatches2(ptr noundef %44, i32 noundef %47)
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._CMatchFinder, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 4, !tbaa !17
  %51 = add i32 %50, 1
  store i32 %51, ptr %49, align 4, !tbaa !17
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._CMatchFinder, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 4, !tbaa !17
  %55 = and i32 %54, 32767
  store i32 %55, ptr %53, align 4, !tbaa !17
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._CMatchFinder, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = getelementptr inbounds i8, ptr %58, i32 1
  store ptr %59, ptr %57, align 8, !tbaa !11
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._CMatchFinder, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 8, !tbaa !14
  %63 = add i32 %62, 1
  store i32 %63, ptr %61, align 8, !tbaa !14
  br label %28, !llvm.loop !18

64:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @SkipMatches2(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, !10, i64 16}
!15 = !{!12, !6, i64 24}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !10, i64 20}
!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"

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

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

.lr.ph:                                           ; preds = %2
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = load i8, ptr %3, align 1, !tbaa !11
  %5 = zext i8 %4 to i32
  %6 = shl nuw nsw i32 %5, 8
  %7 = getelementptr inbounds i8, ptr %3, i64 2
  %8 = load i8, ptr %7, align 1, !tbaa !11
  %9 = zext i8 %8 to i32
  %10 = or disjoint i32 %6, %9
  %11 = getelementptr inbounds i8, ptr %3, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = zext i8 %12 to i64
  %14 = getelementptr inbounds [256 x i32], ptr @crc, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = xor i32 %10, %15
  %17 = and i32 %16, 32767
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = zext nneg i32 %17 to i64
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = getelementptr inbounds i8, ptr %0, i64 20
  %.pre = load i32, ptr %18, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %.lr.ph, %23
  %24 = phi i32 [ %.pre, %.lr.ph ], [ %36, %23 ]
  %.014 = phi i32 [ %1, %.lr.ph ], [ %25, %23 ]
  %25 = add i32 %.014, -1
  %26 = load ptr, ptr %19, align 8, !tbaa !14
  %27 = getelementptr inbounds i32, ptr %26, i64 %20
  store i32 %24, ptr %27, align 4, !tbaa !12
  %28 = load ptr, ptr %21, align 8, !tbaa !15
  %29 = load i32, ptr %22, align 4, !tbaa !16
  tail call void @SkipMatches2(ptr noundef %28, i32 noundef %29)
  %30 = load i32, ptr %22, align 4, !tbaa !16
  %31 = add i32 %30, 1
  %32 = and i32 %31, 32767
  store i32 %32, ptr %22, align 4, !tbaa !16
  %33 = load ptr, ptr %0, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  store ptr %34, ptr %0, align 8, !tbaa !5
  %35 = load i32, ptr %18, align 8, !tbaa !13
  %36 = add i32 %35, 1
  store i32 %36, ptr %18, align 8, !tbaa !13
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %._crit_edge, label %23, !llvm.loop !17

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

; Function Attrs: nounwind uwtable
declare hidden void @SkipMatches2(ptr noundef, i32 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" }

!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 = !{!8, !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !7, i64 24}
!15 = !{!6, !7, i64 32}
!16 = !{!6, !10, i64 20}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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