; 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: nounwind uwtable
define dso_local zeroext i16 @Bt3Zip_MatchFinder_GetMatches(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i16, align 2
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._CMatchFinder, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._CMatchFinder, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = ptrtoint ptr %14 to i64
  %19 = ptrtoint ptr %17 to i64
  %20 = sub i64 %18, %19
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr %6, align 4, !tbaa !13
  %22 = load i32, ptr %6, align 4, !tbaa !13
  %23 = icmp ult i32 %22, 3
  br i1 %23, label %24, label %25

24:                                               ; preds = %2
  store i16 0, ptr %3, align 2
  store i32 1, ptr %7, align 4
  br label %109

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

65:                                               ; preds = %25
  br label %68

66:                                               ; preds = %25
  %67 = load i32, ptr %6, align 4, !tbaa !13
  br label %68

68:                                               ; preds = %66, %65
  %69 = phi i32 [ 258, %65 ], [ %67, %66 ]
  %70 = load i32, ptr %10, align 4, !tbaa !13
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._CMatchFinder, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 8, !tbaa !16
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._CMatchFinder, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !12
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._CMatchFinder, ptr %77, i32 0, i32 5
  %79 = load ptr, ptr %78, align 8, !tbaa !17
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._CMatchFinder, ptr %80, i32 0, i32 3
  %82 = load i32, ptr %81, align 4, !tbaa !18
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = call ptr @GetMatches(i32 noundef %69, i32 noundef %70, i32 noundef %73, ptr noundef %76, ptr noundef %79, i32 noundef %82, ptr noundef %83)
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = ptrtoint ptr %84 to i64
  %87 = ptrtoint ptr %85 to i64
  %88 = sub i64 %86, %87
  %89 = sdiv exact i64 %88, 2
  %90 = trunc i64 %89 to i32
  store i32 %90, ptr %11, align 4, !tbaa !13
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._CMatchFinder, ptr %91, i32 0, i32 3
  %93 = load i32, ptr %92, align 4, !tbaa !18
  %94 = add i32 %93, 1
  store i32 %94, ptr %92, align 4, !tbaa !18
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct._CMatchFinder, ptr %95, i32 0, i32 3
  %97 = load i32, ptr %96, align 4, !tbaa !18
  %98 = and i32 %97, 32767
  store i32 %98, ptr %96, align 4, !tbaa !18
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._CMatchFinder, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !12
  %102 = getelementptr inbounds i8, ptr %101, i32 1
  store ptr %102, ptr %100, align 8, !tbaa !12
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct._CMatchFinder, ptr %103, i32 0, i32 2
  %105 = load i32, ptr %104, align 8, !tbaa !16
  %106 = add i32 %105, 1
  store i32 %106, ptr %104, align 8, !tbaa !16
  %107 = load i32, ptr %11, align 4, !tbaa !13
  %108 = trunc i32 %107 to i16
  store i16 %108, ptr %3, align 2
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %109

109:                                              ; preds = %68, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %110 = load i16, ptr %3, align 2
  ret i16 %110
}

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
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 8}
!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 = !{!10, !6, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !11, i64 16}
!17 = !{!10, !6, i64 32}
!18 = !{!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_GetMatches(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  %6 = ptrtoint ptr %4 to i64
  %7 = ptrtoint ptr %5 to i64
  %8 = sub i64 %6, %7
  %9 = trunc i64 %8 to i32
  %10 = icmp ult i32 %9, 3
  br i1 %10, label %51, label %11

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %5, i64 2
  %13 = load i8, ptr %12, align 1, !tbaa !12
  %14 = zext i8 %13 to i32
  %15 = load i8, ptr %5, 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 %5, 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 = getelementptr inbounds i8, ptr %0, i64 24
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = zext nneg i32 %25 to i64
  %29 = getelementptr inbounds i32, ptr %27, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load i32, ptr %31, align 8, !tbaa !15
  store i32 %32, ptr %29, align 4, !tbaa !13
  %33 = tail call i32 @llvm.umin.i32(i32 %9, i32 258)
  %34 = getelementptr inbounds i8, ptr %0, i64 32
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = getelementptr inbounds i8, ptr %0, i64 20
  %37 = load i32, ptr %36, align 4, !tbaa !17
  %38 = tail call ptr @GetMatches(i32 noundef %33, i32 noundef %30, i32 noundef %32, ptr noundef nonnull %5, ptr noundef %35, i32 noundef %37, ptr noundef %1)
  %39 = ptrtoint ptr %38 to i64
  %40 = ptrtoint ptr %1 to i64
  %41 = sub i64 %39, %40
  %42 = lshr exact i64 %41, 1
  %43 = load i32, ptr %36, align 4, !tbaa !17
  %44 = add i32 %43, 1
  %45 = and i32 %44, 32767
  store i32 %45, ptr %36, align 4, !tbaa !17
  %46 = load ptr, ptr %0, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %46, i64 1
  store ptr %47, ptr %0, align 8, !tbaa !11
  %48 = load i32, ptr %31, align 8, !tbaa !15
  %49 = add i32 %48, 1
  store i32 %49, ptr %31, align 8, !tbaa !15
  %50 = trunc i64 %42 to i16
  br label %51

51:                                               ; preds = %2, %11
  %.0 = phi i16 [ %50, %11 ], [ 0, %2 ]
  ret i16 %.0
}

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


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