; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/lzma/C/7zip/Compress/LZMA (LZMAEncoder)

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

%"class.NHC3::CMatchFinderHC" = type { %struct.IMatchFinder, %struct.IMatchFinderSetCallback, %class.CLZInWindow, %class.CMyUnknownImp, i32, i32, i32, ptr, i32, %class.CMyComPtr }
%struct.IMatchFinder = type { %struct.IInWindowStream }
%struct.IInWindowStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.IMatchFinderSetCallback = type { %struct.IUnknown }
%class.CLZInWindow = type { ptr, ptr, ptr, i32, i8, ptr, ptr, i32, i32, i32, i32, i32, i32 }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr = type { ptr }

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

declare noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind
declare noundef ptr @_Z7MyAllocm(i64 noundef) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NHC314CMatchFinderHC19FreeThisClassMemoryEv(ptr noundef nonnull align 8 dereferenceable(128)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4NHC314CMatchFinderHC10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(128)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4NHC314CMatchFinderHC6CreateEjjjj(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #4 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  %15 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = add i32 %16, %17
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = add i32 %18, %19
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = add i32 %20, %21
  %23 = udiv i32 %22, 2
  %24 = add i32 %23, 256
  store i32 %24, ptr %12, align 4, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %15, i64 16
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = add i32 %26, %27
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = add i32 %29, %30
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = call noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72) %25, i32 noundef %28, i32 noundef %31, i32 noundef %32)
  br i1 %33, label %34, label %71

34:                                               ; preds = %5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = add i32 %35, 256
  %37 = icmp ugt i32 %36, 2147483647
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  call void @_ZN4NHC314CMatchFinderHC10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(128) %15)
  store i32 -2147024809, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %72

39:                                               ; preds = %34
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = getelementptr inbounds %"class.NHC3::CMatchFinderHC", ptr %15, i32 0, i32 6
  store i32 %40, ptr %41, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %14, align 4, !tbaa !9
  %44 = getelementptr inbounds %"class.NHC3::CMatchFinderHC", ptr %15, i32 0, i32 7
  %45 = load ptr, ptr %44, align 8, !tbaa !21
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %53

47:                                               ; preds = %39
  %48 = load i32, ptr %14, align 4, !tbaa !9
  %49 = getelementptr inbounds %"class.NHC3::CMatchFinderHC", ptr %15, i32 0, i32 5
  %50 = load i32, ptr %49, align 8, !tbaa !22
  %51 = icmp eq i32 %48, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %68

53:                                               ; preds = %47, %39
  call void @_ZN4NHC314CMatchFinderHC19FreeThisClassMemoryEv(ptr noundef nonnull align 8 dereferenceable(128) %15)
  %54 = load i32, ptr %14, align 4, !tbaa !9
  %55 = getelementptr inbounds %"class.NHC3::CMatchFinderHC", ptr %15, i32 0, i32 5
  store i32 %54, ptr %55, align 8, !tbaa !22
  %56 = getelementptr inbounds %"class.NHC3::CMatchFinderHC", ptr %15, i32 0, i32 5
  %57 = load i32, ptr %56, align 8, !tbaa !22
  %58 = add i32 66560, %57
  %59 = zext i32 %58 to i64
  %60 = mul i64 %59, 4
  %61 = call noundef ptr @_Z7MyAllocm(i64 noundef %60) #5
  %62 = getelementptr inbounds %"class.NHC3::CMatchFinderHC", ptr %15, i32 0, i32 7
  store ptr %61, ptr %62, align 8, !tbaa !21
  %63 = getelementptr inbounds %"class.NHC3::CMatchFinderHC", ptr %15, i32 0, i32 7
  %64 = load ptr, ptr %63, align 8, !tbaa !21
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %67

66:                                               ; preds = %53
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %68

67:                                               ; preds = %53
  store i32 0, ptr %13, align 4
  br label %68

68:                                               ; preds = %67, %66, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %69 = load i32, ptr %13, align 4
  switch i32 %69, label %72 [
    i32 0, label %70
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70, %5
  call void @_ZN4NHC314CMatchFinderHC10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(128) %15)
  store i32 -2147024882, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %72

72:                                               ; preds = %71, %68, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %73 = load i32, ptr %6, align 4
  ret i32 %73
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 #3 = { mustprogress 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 #4 = { mustprogress 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 #5 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 100}
!12 = !{!"_ZTSN4NHC314CMatchFinderHCE", !13, i64 0, !16, i64 8, !17, i64 16, !19, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !6, i64 104, !10, i64 112, !20, i64 120}
!13 = !{!"_ZTS12IMatchFinder", !14, i64 0}
!14 = !{!"_ZTS15IInWindowStream", !15, i64 0}
!15 = !{!"_ZTS8IUnknown"}
!16 = !{!"_ZTS23IMatchFinderSetCallback", !15, i64 0}
!17 = !{!"_ZTS11CLZInWindow", !6, i64 8, !6, i64 16, !10, i64 24, !18, i64 28, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!20 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !6, i64 0}
!21 = !{!12, !6, i64 104}
!22 = !{!12, !10, i64 96}


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

declare noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare noundef ptr @_Z7MyAllocm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NHC314CMatchFinderHC19FreeThisClassMemoryEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4NHC314CMatchFinderHC10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147024882, 1) i32 @_ZN4NHC314CMatchFinderHC6CreateEjjjj(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #3 align 2 {
  %6 = add i32 %2, %1
  %7 = add i32 %4, %3
  %8 = add i32 %7, %6
  %9 = lshr i32 %8, 1
  %10 = add nuw i32 %9, 256
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = tail call noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72) %11, i32 noundef %6, i32 noundef %7, i32 noundef %10)
  br i1 %12, label %13, label %.critedge.sink.split

13:                                               ; preds = %5
  %14 = add i32 %1, 256
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %.critedge.sink.split, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %0, i64 100
  store i32 %3, ptr %17, align 4, !tbaa !5
  %18 = add nsw i32 %1, 1
  %19 = getelementptr inbounds i8, ptr %0, i64 104
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  %.not = icmp ne ptr %20, null
  %21 = getelementptr inbounds i8, ptr %0, i64 96
  %22 = load i32, ptr %21, align 8
  %23 = icmp eq i32 %18, %22
  %or.cond = select i1 %.not, i1 %23, i1 false
  br i1 %or.cond, label %.critedge, label %24

24:                                               ; preds = %16
  tail call void @_ZN4NHC314CMatchFinderHC19FreeThisClassMemoryEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  store i32 %18, ptr %21, align 8, !tbaa !20
  %25 = add i32 %1, 66561
  %26 = zext i32 %25 to i64
  %27 = shl nuw nsw i64 %26, 2
  %28 = tail call noundef ptr @_Z7MyAllocm(i64 noundef %27) #4
  store ptr %28, ptr %19, align 8, !tbaa !19
  %.not17 = icmp eq ptr %28, null
  br i1 %.not17, label %.critedge.sink.split, label %.critedge

.critedge.sink.split:                             ; preds = %5, %24, %13
  %.1.ph = phi i32 [ -2147024809, %13 ], [ -2147024882, %24 ], [ -2147024882, %5 ]
  tail call void @_ZN4NHC314CMatchFinderHC10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  br label %.critedge

.critedge:                                        ; preds = %.critedge.sink.split, %16, %24
  %.1 = phi i32 [ 0, %24 ], [ 0, %16 ], [ %.1.ph, %.critedge.sink.split ]
  ret i32 %.1
}

attributes #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 = { nounwind "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 = { mustprogress 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 #3 = { mustprogress 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 #4 = { 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, !15, i64 100}
!6 = !{!"_ZTSN4NHC314CMatchFinderHCE", !7, i64 0, !10, i64 8, !11, i64 16, !17, i64 88, !15, i64 92, !15, i64 96, !15, i64 100, !12, i64 104, !15, i64 112, !18, i64 120}
!7 = !{!"_ZTS12IMatchFinder", !8, i64 0}
!8 = !{!"_ZTS15IInWindowStream", !9, i64 0}
!9 = !{!"_ZTS8IUnknown"}
!10 = !{!"_ZTS23IMatchFinderSetCallback", !9, i64 0}
!11 = !{!"_ZTS11CLZInWindow", !12, i64 8, !12, i64 16, !15, i64 24, !16, i64 28, !12, i64 32, !12, i64 40, !15, i64 48, !15, i64 52, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68}
!12 = !{!"any pointer", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"int", !13, i64 0}
!16 = !{!"bool", !13, i64 0}
!17 = !{!"_ZTS13CMyUnknownImp", !15, i64 0}
!18 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !12, i64 0}
!19 = !{!6, !12, i64 104}
!20 = !{!6, !15, i64 96}


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