; 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.NBT2::CMatchFinderBinTree" = 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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4NBT219CMatchFinderBinTree7MovePosEv(ptr noundef nonnull align 8 dereferenceable(128) %0) unnamed_addr #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.NBT2::CMatchFinderBinTree", ptr %6, i32 0, i32 4
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = add i32 %8, 1
  store i32 %9, ptr %7, align 4, !tbaa !9
  %10 = getelementptr inbounds %"class.NBT2::CMatchFinderBinTree", ptr %6, i32 0, i32 5
  %11 = load i32, ptr %10, align 8, !tbaa !20
  %12 = icmp eq i32 %9, %11
  br i1 %12, label %13, label %15

13:                                               ; preds = %1
  %14 = getelementptr inbounds %"class.NBT2::CMatchFinderBinTree", ptr %6, i32 0, i32 4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %13, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %16 = getelementptr inbounds i8, ptr %6, i64 16
  %17 = call noundef i32 @_ZN11CLZInWindow7MovePosEv(ptr noundef nonnull align 8 dereferenceable(72) %16)
  store i32 %17, ptr %4, align 4, !tbaa !21
  %18 = load i32, ptr %4, align 4, !tbaa !21
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %15
  %21 = load i32, ptr %4, align 4, !tbaa !21
  store i32 %21, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %23

22:                                               ; preds = %15
  store i32 0, ptr %5, align 4
  br label %23

23:                                               ; preds = %22, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %24 = load i32, ptr %5, align 4
  switch i32 %24, label %34 [
    i32 0, label %25
    i32 1, label %32
  ]

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %6, i64 16
  %27 = getelementptr inbounds %class.CLZInWindow, ptr %26, i32 0, i32 8
  %28 = load i32, ptr %27, align 4, !tbaa !22
  %29 = icmp eq i32 %28, 2147483647
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  call void @_ZN4NBT219CMatchFinderBinTree9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(128) %6)
  br label %31

31:                                               ; preds = %30, %25
  store i32 0, ptr %2, align 4
  br label %32

32:                                               ; preds = %31, %23
  %33 = load i32, ptr %2, align 4
  ret i32 %33

34:                                               ; preds = %23
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11CLZInWindow7MovePosEv(ptr noundef nonnull align 8 dereferenceable(72)) #1 align 2

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


; 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: mustprogress uwtable
declare dso_local void @_ZN4NBT219CMatchFinderBinTree9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4NBT219CMatchFinderBinTree7MovePosEv(ptr noundef nonnull align 8 dereferenceable(128) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 92
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = add i32 %3, 1
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = load i32, ptr %5, align 8, !tbaa !19
  %7 = icmp eq i32 %4, %6
  %spec.store.select = select i1 %7, i32 0, i32 %4
  store i32 %spec.store.select, ptr %2, align 4
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = tail call noundef i32 @_ZN11CLZInWindow7MovePosEv(ptr noundef nonnull align 8 dereferenceable(72) %8)
  %.not.not = icmp eq i32 %9, 0
  %10 = getelementptr inbounds i8, ptr %0, i64 68
  %11 = load i32, ptr %10, align 4
  %12 = icmp eq i32 %11, 2147483647
  %or.cond = select i1 %.not.not, i1 %12, i1 false
  br i1 %or.cond, label %13, label %14

13:                                               ; preds = %1
  tail call void @_ZN4NBT219CMatchFinderBinTree9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(128) %0)
  br label %14

14:                                               ; preds = %1, %13
  ret i32 %9
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11CLZInWindow7MovePosEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #0 align 2

attributes #0 = { 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" }

!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 92}
!6 = !{!"_ZTSN4NBT219CMatchFinderBinTreeE", !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, !15, i64 96}


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