; 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.NCompress::NLZMA::CEncoder" = type <{ %struct.ICompressCoder, %struct.ICompressSetOutStream, %struct.ICompressSetCoderProperties, %struct.ICompressWriteCoderProperties, %"class.NCompress::NLZMA::CBaseState", %class.CMyUnknownImp, [4096 x %"struct.NCompress::NLZMA::COptimal"], %class.CMyComPtr.5, %"class.NCompress::NRangeCoder::CEncoder", [12 x [16 x %"class.NCompress::NRangeCoder::CBitEncoder"]], [12 x %"class.NCompress::NRangeCoder::CBitEncoder"], [12 x %"class.NCompress::NRangeCoder::CBitEncoder"], [12 x %"class.NCompress::NRangeCoder::CBitEncoder"], [12 x %"class.NCompress::NRangeCoder::CBitEncoder"], [12 x [16 x %"class.NCompress::NRangeCoder::CBitEncoder"]], [4 x %"class.NCompress::NRangeCoder::CBitTreeEncoder.7"], [114 x %"class.NCompress::NRangeCoder::CBitEncoder"], %"class.NCompress::NRangeCoder::CBitTreeEncoder.8", %"class.NCompress::NLZMA::NLength::CPriceTableEncoder", %"class.NCompress::NLZMA::NLength::CPriceTableEncoder", %"class.NCompress::NLZMA::CLiteralEncoder", [274 x i32], i8, i8, [2 x i8], i32, i32, i32, i32, i32, i8, [3 x i8], [4 x [64 x i32]], [4 x [128 x i32]], [16 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, i8, [7 x i8], ptr, i32, i8, i8, [2 x i8] }>
%struct.ICompressCoder = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetOutStream = type { %struct.IUnknown }
%struct.ICompressSetCoderProperties = type { %struct.IUnknown }
%struct.ICompressWriteCoderProperties = type { %struct.IUnknown }
%"class.NCompress::NLZMA::CBaseState" = type { %"class.NCompress::NLZMA::CState", i8, [4 x i32] }
%"class.NCompress::NLZMA::CState" = type { i8 }
%class.CMyUnknownImp = type { i32 }
%"struct.NCompress::NLZMA::COptimal" = type { %"class.NCompress::NLZMA::CState", i8, i8, i32, i32, i32, i32, i32, [4 x i32] }
%class.CMyComPtr.5 = type { ptr }
%"class.NCompress::NRangeCoder::CEncoder" = type { i32, i8, i64, i32, [4 x i8], %class.COutBuffer }
%class.COutBuffer = type <{ ptr, i32, i32, i32, i32, %class.CMyComPtr.6, i64, ptr, i8, [7 x i8] }>
%class.CMyComPtr.6 = type { ptr }
%"class.NCompress::NRangeCoder::CBitEncoder" = type { %"class.NCompress::NRangeCoder::CBitModel" }
%"class.NCompress::NRangeCoder::CBitModel" = type { i32 }
%"class.NCompress::NRangeCoder::CBitTreeEncoder.7" = type { [64 x %"class.NCompress::NRangeCoder::CBitEncoder"] }
%"class.NCompress::NRangeCoder::CBitTreeEncoder.8" = type { [16 x %"class.NCompress::NRangeCoder::CBitEncoder"] }
%"class.NCompress::NLZMA::NLength::CPriceTableEncoder" = type { %"class.NCompress::NLZMA::NLength::CEncoder", [272 x [16 x i32]], i32, [16 x i32] }
%"class.NCompress::NLZMA::NLength::CEncoder" = type { %"class.NCompress::NRangeCoder::CBitEncoder", %"class.NCompress::NRangeCoder::CBitEncoder", [16 x %"class.NCompress::NRangeCoder::CBitTreeEncoder"], [16 x %"class.NCompress::NRangeCoder::CBitTreeEncoder"], %"class.NCompress::NRangeCoder::CBitTreeEncoder.4" }
%"class.NCompress::NRangeCoder::CBitTreeEncoder" = type { [8 x %"class.NCompress::NRangeCoder::CBitEncoder"] }
%"class.NCompress::NRangeCoder::CBitTreeEncoder.4" = type { [256 x %"class.NCompress::NRangeCoder::CBitEncoder"] }
%"class.NCompress::NLZMA::CLiteralEncoder" = type <{ ptr, i32, i32, i32, [4 x i8] }>

; 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 nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI12IMatchFinderEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NLZMA8CEncoder7MovePosEj(ptr noundef nonnull align 8 dereferenceable(210678) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  br label %9

9:                                                ; preds = %35, %2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %38

12:                                               ; preds = %9
  %13 = getelementptr inbounds %"class.NCompress::NLZMA::CEncoder", ptr %8, i32 0, i32 7
  %14 = call noundef ptr @_ZNK9CMyComPtrI12IMatchFinderEptEv(ptr noundef nonnull align 8 dereferenceable(8) %13)
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds ptr, ptr %15, i64 12
  %17 = load ptr, ptr %16, align 8
  call void %17(ptr noundef nonnull align 8 dereferenceable(8) %14)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %18 = getelementptr inbounds %"class.NCompress::NLZMA::CEncoder", ptr %8, i32 0, i32 7
  %19 = call noundef ptr @_ZNK9CMyComPtrI12IMatchFinderEptEv(ptr noundef nonnull align 8 dereferenceable(8) %18)
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds ptr, ptr %20, i64 5
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(8) %19)
  store i32 %23, ptr %6, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %12
  %27 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %27, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %29

28:                                               ; preds = %12
  store i32 0, ptr %7, align 4
  br label %29

29:                                               ; preds = %28, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %30 = load i32, ptr %7, align 4
  switch i32 %30, label %41 [
    i32 0, label %31
    i32 1, label %39
  ]

31:                                               ; preds = %29
  %32 = getelementptr inbounds %"class.NCompress::NLZMA::CEncoder", ptr %8, i32 0, i32 27
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = add i32 %33, 1
  store i32 %34, ptr %32, align 4, !tbaa !13
  br label %35

35:                                               ; preds = %31
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = add i32 %36, -1
  store i32 %37, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !36

38:                                               ; preds = %9
  store i32 0, ptr %3, align 4
  br label %39

39:                                               ; preds = %38, %29
  %40 = load i32, ptr %3, align 4
  ret i32 %40

41:                                               ; preds = %29
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !10, i64 207452}
!14 = !{!"_ZTSN9NCompress5NLZMA8CEncoderE", !15, i64 0, !17, i64 8, !18, i64 16, !19, i64 24, !20, i64 32, !22, i64 52, !7, i64 56, !23, i64 163896, !24, i64 163904, !7, i64 163984, !7, i64 164752, !7, i64 164800, !7, i64 164848, !7, i64 164896, !7, i64 164944, !7, i64 165712, !7, i64 166736, !29, i64 167192, !30, i64 167256, !30, i64 186788, !35, i64 206320, !7, i64 206344, !28, i64 207440, !28, i64 207441, !10, i64 207444, !10, i64 207448, !10, i64 207452, !10, i64 207456, !10, i64 207460, !28, i64 207464, !7, i64 207468, !7, i64 208492, !7, i64 210540, !10, i64 210604, !10, i64 210608, !10, i64 210612, !10, i64 210616, !10, i64 210620, !10, i64 210624, !10, i64 210628, !10, i64 210632, !10, i64 210636, !25, i64 210640, !25, i64 210648, !28, i64 210656, !6, i64 210664, !10, i64 210672, !28, i64 210676, !28, i64 210677}
!15 = !{!"_ZTS14ICompressCoder", !16, i64 0}
!16 = !{!"_ZTS8IUnknown"}
!17 = !{!"_ZTS21ICompressSetOutStream", !16, i64 0}
!18 = !{!"_ZTS27ICompressSetCoderProperties", !16, i64 0}
!19 = !{!"_ZTS29ICompressWriteCoderProperties", !16, i64 0}
!20 = !{!"_ZTSN9NCompress5NLZMA10CBaseStateE", !21, i64 0, !7, i64 1, !7, i64 4}
!21 = !{!"_ZTSN9NCompress5NLZMA6CStateE", !7, i64 0}
!22 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!23 = !{!"_ZTS9CMyComPtrI12IMatchFinderE", !6, i64 0}
!24 = !{!"_ZTSN9NCompress11NRangeCoder8CEncoderE", !10, i64 0, !7, i64 4, !25, i64 8, !10, i64 16, !26, i64 24}
!25 = !{!"long long", !7, i64 0}
!26 = !{!"_ZTS10COutBuffer", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !27, i64 24, !25, i64 32, !6, i64 40, !28, i64 48}
!27 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !6, i64 0}
!28 = !{!"bool", !7, i64 0}
!29 = !{!"_ZTSN9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi4EEE", !7, i64 0}
!30 = !{!"_ZTSN9NCompress5NLZMA7NLength18CPriceTableEncoderE", !31, i64 0, !7, i64 2056, !10, i64 19464, !7, i64 19468}
!31 = !{!"_ZTSN9NCompress5NLZMA7NLength8CEncoderE", !32, i64 0, !32, i64 4, !7, i64 8, !7, i64 520, !34, i64 1032}
!32 = !{!"_ZTSN9NCompress11NRangeCoder11CBitEncoderILi5EEE", !33, i64 0}
!33 = !{!"_ZTSN9NCompress11NRangeCoder9CBitModelILi5EEE", !10, i64 0}
!34 = !{!"_ZTSN9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi8EEE", !7, i64 0}
!35 = !{!"_ZTSN9NCompress5NLZMA15CLiteralEncoderE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!36 = distinct !{!36, !37}
!37 = !{!"llvm.loop.mustprogress"}


; 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 nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI12IMatchFinderEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NLZMA8CEncoder7MovePosEj(ptr noundef nonnull align 8 dereferenceable(210678) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 163896
  %.not10 = icmp eq i32 %1, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 207452
  br label %5

5:                                                ; preds = %.lr.ph, %15
  %.0711 = phi i32 [ %1, %.lr.ph ], [ %18, %15 ]
  %6 = tail call noundef ptr @_ZNK9CMyComPtrI12IMatchFinderEptEv(ptr noundef nonnull align 8 dereferenceable(8) %3)
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 96
  %9 = load ptr, ptr %8, align 8
  tail call void %9(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %10 = tail call noundef ptr @_ZNK9CMyComPtrI12IMatchFinderEptEv(ptr noundef nonnull align 8 dereferenceable(8) %3)
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 40
  %13 = load ptr, ptr %12, align 8
  %14 = tail call noundef i32 %13(ptr noundef nonnull align 8 dereferenceable(8) %10)
  %.not9.not = icmp eq i32 %14, 0
  br i1 %.not9.not, label %15, label %._crit_edge

15:                                               ; preds = %5
  %16 = load i32, ptr %4, align 4, !tbaa !8
  %17 = add i32 %16, 1
  store i32 %17, ptr %4, align 4, !tbaa !8
  %18 = add i32 %.0711, -1
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %._crit_edge, label %5, !llvm.loop !34

._crit_edge:                                      ; preds = %15, %5, %2
  %.2 = phi i32 [ 0, %2 ], [ %14, %5 ], [ 0, %15 ]
  ret i32 %.2
}

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

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !19, i64 207452}
!9 = !{!"_ZTSN9NCompress5NLZMA8CEncoderE", !10, i64 0, !12, i64 8, !13, i64 16, !14, i64 24, !15, i64 32, !18, i64 52, !17, i64 56, !20, i64 163896, !22, i64 163904, !17, i64 163984, !17, i64 164752, !17, i64 164800, !17, i64 164848, !17, i64 164896, !17, i64 164944, !17, i64 165712, !17, i64 166736, !27, i64 167192, !28, i64 167256, !28, i64 186788, !33, i64 206320, !17, i64 206344, !26, i64 207440, !26, i64 207441, !19, i64 207444, !19, i64 207448, !19, i64 207452, !19, i64 207456, !19, i64 207460, !26, i64 207464, !17, i64 207468, !17, i64 208492, !17, i64 210540, !19, i64 210604, !19, i64 210608, !19, i64 210612, !19, i64 210616, !19, i64 210620, !19, i64 210624, !19, i64 210628, !19, i64 210632, !19, i64 210636, !23, i64 210640, !23, i64 210648, !26, i64 210656, !21, i64 210664, !19, i64 210672, !26, i64 210676, !26, i64 210677}
!10 = !{!"_ZTS14ICompressCoder", !11, i64 0}
!11 = !{!"_ZTS8IUnknown"}
!12 = !{!"_ZTS21ICompressSetOutStream", !11, i64 0}
!13 = !{!"_ZTS27ICompressSetCoderProperties", !11, i64 0}
!14 = !{!"_ZTS29ICompressWriteCoderProperties", !11, i64 0}
!15 = !{!"_ZTSN9NCompress5NLZMA10CBaseStateE", !16, i64 0, !17, i64 1, !17, i64 4}
!16 = !{!"_ZTSN9NCompress5NLZMA6CStateE", !17, i64 0}
!17 = !{!"omnipotent char", !7, i64 0}
!18 = !{!"_ZTS13CMyUnknownImp", !19, i64 0}
!19 = !{!"int", !17, i64 0}
!20 = !{!"_ZTS9CMyComPtrI12IMatchFinderE", !21, i64 0}
!21 = !{!"any pointer", !17, i64 0}
!22 = !{!"_ZTSN9NCompress11NRangeCoder8CEncoderE", !19, i64 0, !17, i64 4, !23, i64 8, !19, i64 16, !24, i64 24}
!23 = !{!"long long", !17, i64 0}
!24 = !{!"_ZTS10COutBuffer", !21, i64 0, !19, i64 8, !19, i64 12, !19, i64 16, !19, i64 20, !25, i64 24, !23, i64 32, !21, i64 40, !26, i64 48}
!25 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !21, i64 0}
!26 = !{!"bool", !17, i64 0}
!27 = !{!"_ZTSN9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi4EEE", !17, i64 0}
!28 = !{!"_ZTSN9NCompress5NLZMA7NLength18CPriceTableEncoderE", !29, i64 0, !17, i64 2056, !19, i64 19464, !17, i64 19468}
!29 = !{!"_ZTSN9NCompress5NLZMA7NLength8CEncoderE", !30, i64 0, !30, i64 4, !17, i64 8, !17, i64 520, !32, i64 1032}
!30 = !{!"_ZTSN9NCompress11NRangeCoder11CBitEncoderILi5EEE", !31, i64 0}
!31 = !{!"_ZTSN9NCompress11NRangeCoder9CBitModelILi5EEE", !19, i64 0}
!32 = !{!"_ZTSN9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi8EEE", !17, i64 0}
!33 = !{!"_ZTSN9NCompress5NLZMA15CLiteralEncoderE", !21, i64 0, !19, i64 8, !19, i64 12, !19, i64 16}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass