; 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.CLZInWindow = type { ptr, ptr, ptr, i32, i8, ptr, ptr, i32, i32, i32, i32, i32, i32 }
%"class.NPat2R::CPatricia" = type { %struct.IMatchFinder, %struct.IMatchFinderSetCallback, %class.CMyUnknownImp, %class.CLZInWindow, i32, i32, ptr, ptr, i32, i32, i8, i8, i32, ptr, %class.CMyComPtr }
%struct.IMatchFinder = type { %struct.IInWindowStream }
%struct.IInWindowStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.IMatchFinderSetCallback = type { %struct.IUnknown }
%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 noundef i32 @_ZN11CLZInWindow7MovePosEv(ptr noundef nonnull align 8 dereferenceable(72)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6NPat2R9CPatricia7MovePosEv(ptr noundef nonnull align 8 dereferenceable(152) %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 i8, ptr %6, i64 24
  %8 = getelementptr inbounds %class.CLZInWindow, ptr %7, i32 0, i32 8
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds %"class.NPat2R::CPatricia", ptr %6, i32 0, i32 4
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp uge i32 %9, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  call void @_ZN6NPat2R9CPatricia11RemoveMatchEv(ptr noundef nonnull align 8 dereferenceable(152) %6)
  br label %14

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

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

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

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

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %6, i64 24
  %26 = getelementptr inbounds %class.CLZInWindow, ptr %25, i32 0, i32 8
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = icmp uge i32 %27, 2147483645
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  call void @_ZN6NPat2R9CPatricia9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(152) %6)
  br label %30

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

31:                                               ; preds = %30, %22
  %32 = load i32, ptr %2, align 4
  ret i32 %32

33:                                               ; preds = %22
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6NPat2R9CPatricia9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(152)) #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, !11, i64 52}
!10 = !{!"_ZTS11CLZInWindow", !6, i64 8, !6, i64 16, !11, i64 24, !12, i64 28, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !11, i64 96}
!14 = !{!"_ZTSN6NPat2R9CPatriciaE", !15, i64 0, !18, i64 8, !19, i64 16, !10, i64 24, !11, i64 96, !11, i64 100, !6, i64 104, !6, i64 112, !11, i64 120, !11, i64 124, !12, i64 128, !12, i64 129, !11, i64 132, !6, i64 136, !20, i64 144}
!15 = !{!"_ZTS12IMatchFinder", !16, i64 0}
!16 = !{!"_ZTS15IInWindowStream", !17, i64 0}
!17 = !{!"_ZTS8IUnknown"}
!18 = !{!"_ZTS23IMatchFinderSetCallback", !17, i64 0}
!19 = !{!"_ZTS13CMyUnknownImp", !11, i64 0}
!20 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !6, i64 0}
!21 = !{!11, !11, i64 0}


; 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 noundef i32 @_ZN11CLZInWindow7MovePosEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6NPat2R9CPatricia11RemoveMatchEv(ptr noundef nonnull align 8 dereferenceable(152)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6NPat2R9CPatricia7MovePosEv(ptr noundef nonnull align 8 dereferenceable(152) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = getelementptr inbounds i8, ptr %0, i64 76
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %.not = icmp ult i32 %4, %6
  br i1 %.not, label %8, label %7

7:                                                ; preds = %1
  tail call void @_ZN6NPat2R9CPatricia11RemoveMatchEv(ptr noundef nonnull align 8 dereferenceable(152) %0)
  br label %8

8:                                                ; preds = %7, %1
  %9 = tail call noundef i32 @_ZN11CLZInWindow7MovePosEv(ptr noundef nonnull align 8 dereferenceable(72) %2)
  %.not5.not = icmp eq i32 %9, 0
  %10 = load i32, ptr %3, align 4
  %11 = icmp ugt i32 %10, 2147483644
  %or.cond = select i1 %.not5.not, i1 %11, i1 false
  br i1 %or.cond, label %12, label %13

12:                                               ; preds = %8
  tail call void @_ZN6NPat2R9CPatricia9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(152) %0)
  br label %13

13:                                               ; preds = %8, %12
  ret i32 %9
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6NPat2R9CPatricia9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(152)) 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, !10, i64 52}
!6 = !{!"_ZTS11CLZInWindow", !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 28, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!13, !10, i64 96}
!13 = !{!"_ZTSN6NPat2R9CPatriciaE", !14, i64 0, !17, i64 8, !18, i64 16, !6, i64 24, !10, i64 96, !10, i64 100, !7, i64 104, !7, i64 112, !10, i64 120, !10, i64 124, !11, i64 128, !11, i64 129, !10, i64 132, !7, i64 136, !19, i64 144}
!14 = !{!"_ZTS12IMatchFinder", !15, i64 0}
!15 = !{!"_ZTS15IInWindowStream", !16, i64 0}
!16 = !{!"_ZTS8IUnknown"}
!17 = !{!"_ZTS23IMatchFinderSetCallback", !16, i64 0}
!18 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!19 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !7, i64 0}


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