; LLVM IR from philanc/luazen :: src/lzma (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, i32, i32, i32, i32, i32, i32, i8, i8, i8, i8, i32, ptr, ptr, i32, i32, ptr, ptr, i32, i32, i32, i32, i64, i32, i32, i32, i32, [256 x i32], i64, i64 }

; Function Attrs: nounwind uwtable
define dso_local void @MatchFinder_ReadIfRequired(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct._CMatchFinder, ptr %3, i32 0, i32 7
  %5 = load i8, ptr %4, align 8, !tbaa !9
  %6 = icmp ne i8 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  br label %22

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._CMatchFinder, ptr %9, i32 0, i32 20
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._CMatchFinder, ptr %12, i32 0, i32 3
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._CMatchFinder, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !16
  %18 = sub i32 %14, %17
  %19 = icmp uge i32 %11, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %8
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  call void @MatchFinder_ReadBlock(ptr noundef %21)
  br label %22

22:                                               ; preds = %20, %8, %7
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @MatchFinder_ReadBlock(ptr noundef) #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 32}
!10 = !{!"_CMatchFinder", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !7, i64 32, !7, i64 33, !7, i64 34, !7, i64 35, !11, i64 36, !6, i64 40, !6, i64 48, !11, i64 56, !11, i64 60, !6, i64 64, !6, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !12, i64 96, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !7, i64 120, !12, i64 1144, !13, i64 1152}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!10, !11, i64 88}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !11, i64 8}


; 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"

; Function Attrs: nounwind uwtable
define dso_local void @MatchFinder_ReadIfRequired(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load i8, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %4, label %13

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  %6 = load i32, ptr %5, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !15
  %11 = sub i32 %8, %10
  %.not5 = icmp ult i32 %6, %11
  br i1 %.not5, label %13, label %12

12:                                               ; preds = %4
  tail call void @MatchFinder_ReadBlock(ptr noundef nonnull %0)
  br label %13

13:                                               ; preds = %1, %12, %4
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @MatchFinder_ReadBlock(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, !8, i64 32}
!6 = !{!"_CMatchFinder", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !8, i64 32, !8, i64 33, !8, i64 34, !8, i64 35, !10, i64 36, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !7, i64 64, !7, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !11, i64 96, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !8, i64 120, !11, i64 1144, !12, i64 1152}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!6, !10, i64 88}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !10, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass