; 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 zeroext i16 @Bt3Zip_MatchFinder_GetMatches2(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %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 ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._CMatchFinder, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 2
  %14 = load i8, ptr %13, align 1, !tbaa !12
  %15 = zext i8 %14 to i32
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 0
  %18 = load i8, ptr %17, align 1, !tbaa !12
  %19 = zext i8 %18 to i32
  %20 = shl i32 %19, 8
  %21 = or i32 %15, %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !12
  %25 = zext i8 %24 to i64
  %26 = getelementptr inbounds [256 x i32], ptr @crc, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = xor i32 %21, %27
  %29 = and i32 %28, 32767
  store i32 %29, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._CMatchFinder, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load i32, ptr %6, align 4, !tbaa !13
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %32, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !13
  store i32 %36, ptr %7, align 4, !tbaa !13
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._CMatchFinder, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !15
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._CMatchFinder, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load i32, ptr %6, align 4, !tbaa !13
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  store i32 %39, ptr %45, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %46 = load i32, ptr %7, align 4, !tbaa !13
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._CMatchFinder, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 8, !tbaa !15
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._CMatchFinder, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._CMatchFinder, ptr %53, i32 0, i32 5
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._CMatchFinder, ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 4, !tbaa !17
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = call ptr @GetMatches2(i32 noundef 258, i32 noundef %46, i32 noundef %49, ptr noundef %52, ptr noundef %55, i32 noundef %58, ptr noundef %59)
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = ptrtoint ptr %60 to i64
  %63 = ptrtoint ptr %61 to i64
  %64 = sub i64 %62, %63
  %65 = sdiv exact i64 %64, 2
  %66 = trunc i64 %65 to i32
  store i32 %66, ptr %8, align 4, !tbaa !13
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._CMatchFinder, ptr %67, i32 0, i32 3
  %69 = load i32, ptr %68, align 4, !tbaa !17
  %70 = add i32 %69, 1
  store i32 %70, ptr %68, align 4, !tbaa !17
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._CMatchFinder, ptr %71, i32 0, i32 3
  %73 = load i32, ptr %72, align 4, !tbaa !17
  %74 = and i32 %73, 32767
  store i32 %74, ptr %72, align 4, !tbaa !17
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._CMatchFinder, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !9
  %78 = getelementptr inbounds i8, ptr %77, i32 1
  store ptr %78, ptr %76, align 8, !tbaa !9
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._CMatchFinder, ptr %79, i32 0, i32 2
  %81 = load i32, ptr %80, align 8, !tbaa !15
  %82 = add i32 %81, 1
  store i32 %82, ptr %80, align 8, !tbaa !15
  %83 = load i32, ptr %8, align 4, !tbaa !13
  %84 = trunc i32 %83 to i16
  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
  ret i16 %84
}

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


; 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 zeroext i16 @Bt3Zip_MatchFinder_GetMatches2(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 2
  %5 = load i8, ptr %4, align 1, !tbaa !11
  %6 = zext i8 %5 to i32
  %7 = load i8, ptr %3, align 1, !tbaa !11
  %8 = zext i8 %7 to i32
  %9 = shl nuw nsw i32 %8, 8
  %10 = or disjoint i32 %9, %6
  %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 24
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = zext nneg i32 %17 to i64
  %21 = getelementptr inbounds i32, ptr %19, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load i32, ptr %23, align 8, !tbaa !14
  store i32 %24, ptr %21, align 4, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %0, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %0, i64 20
  %28 = load i32, ptr %27, align 4, !tbaa !16
  %29 = tail call ptr @GetMatches2(i32 noundef 258, i32 noundef %22, i32 noundef %24, ptr noundef nonnull %3, ptr noundef %26, i32 noundef %28, ptr noundef %1)
  %30 = ptrtoint ptr %29 to i64
  %31 = ptrtoint ptr %1 to i64
  %32 = sub i64 %30, %31
  %33 = lshr exact i64 %32, 1
  %34 = load i32, ptr %27, align 4, !tbaa !16
  %35 = add i32 %34, 1
  %36 = and i32 %35, 32767
  store i32 %36, ptr %27, align 4, !tbaa !16
  %37 = load ptr, ptr %0, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 1
  store ptr %38, ptr %0, align 8, !tbaa !5
  %39 = load i32, ptr %23, align 8, !tbaa !14
  %40 = add i32 %39, 1
  store i32 %40, ptr %23, align 8, !tbaa !14
  %41 = trunc i64 %33 to i16
  ret i16 %41
}

; Function Attrs: nounwind uwtable
declare hidden ptr @GetMatches2(i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr 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, !7, i64 24}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !7, i64 32}
!16 = !{!6, !10, i64 20}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass