; 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 uwtable
define dso_local noundef i32 @_ZN9NCompress5NLZMA8CEncoder20WriteCoderPropertiesEP20ISequentialOutStream(ptr noundef nonnull align 8 dereferenceable(210678) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [5 x i8], align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 5, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 5, ptr %6) #3
  %9 = getelementptr inbounds %"class.NCompress::NLZMA::CEncoder", ptr %8, i32 0, i32 37
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = mul i32 %10, 5
  %12 = getelementptr inbounds %"class.NCompress::NLZMA::CEncoder", ptr %8, i32 0, i32 39
  %13 = load i32, ptr %12, align 4, !tbaa !34
  %14 = add i32 %11, %13
  %15 = mul i32 %14, 9
  %16 = getelementptr inbounds %"class.NCompress::NLZMA::CEncoder", ptr %8, i32 0, i32 40
  %17 = load i32, ptr %16, align 8, !tbaa !35
  %18 = add i32 %15, %17
  %19 = trunc i32 %18 to i8
  %20 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 0
  store i8 %19, ptr %20, align 1, !tbaa !36
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %36, %2
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp slt i32 %22, 4
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %39

25:                                               ; preds = %21
  %26 = getelementptr inbounds %"class.NCompress::NLZMA::CEncoder", ptr %8, i32 0, i32 41
  %27 = load i32, ptr %26, align 4, !tbaa !37
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = mul nsw i32 8, %28
  %30 = lshr i32 %27, %29
  %31 = trunc i32 %30 to i8
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = add nsw i32 1, %32
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 %34
  store i8 %31, ptr %35, align 1, !tbaa !36
  br label %36

36:                                               ; preds = %25
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !9
  br label %21, !llvm.loop !38

39:                                               ; preds = %24
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 0
  %42 = call noundef i32 @_Z11WriteStreamP20ISequentialOutStreamPKvjPj(ptr noundef %40, ptr noundef %41, i32 noundef 5, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 5, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %42
}

declare noundef i32 @_Z11WriteStreamP20ISequentialOutStreamPKvjPj(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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 = { "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, !10, i64 210612}
!12 = !{!"_ZTSN9NCompress5NLZMA8CEncoderE", !13, i64 0, !15, i64 8, !16, i64 16, !17, i64 24, !18, i64 32, !20, i64 52, !7, i64 56, !21, i64 163896, !22, 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, !27, i64 167192, !28, i64 167256, !28, i64 186788, !33, i64 206320, !7, i64 206344, !26, i64 207440, !26, i64 207441, !10, i64 207444, !10, i64 207448, !10, i64 207452, !10, i64 207456, !10, i64 207460, !26, 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, !23, i64 210640, !23, i64 210648, !26, i64 210656, !6, i64 210664, !10, i64 210672, !26, i64 210676, !26, i64 210677}
!13 = !{!"_ZTS14ICompressCoder", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS21ICompressSetOutStream", !14, i64 0}
!16 = !{!"_ZTS27ICompressSetCoderProperties", !14, i64 0}
!17 = !{!"_ZTS29ICompressWriteCoderProperties", !14, i64 0}
!18 = !{!"_ZTSN9NCompress5NLZMA10CBaseStateE", !19, i64 0, !7, i64 1, !7, i64 4}
!19 = !{!"_ZTSN9NCompress5NLZMA6CStateE", !7, i64 0}
!20 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!21 = !{!"_ZTS9CMyComPtrI12IMatchFinderE", !6, i64 0}
!22 = !{!"_ZTSN9NCompress11NRangeCoder8CEncoderE", !10, i64 0, !7, i64 4, !23, i64 8, !10, i64 16, !24, i64 24}
!23 = !{!"long long", !7, i64 0}
!24 = !{!"_ZTS10COutBuffer", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !25, i64 24, !23, i64 32, !6, i64 40, !26, i64 48}
!25 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !6, i64 0}
!26 = !{!"bool", !7, i64 0}
!27 = !{!"_ZTSN9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi4EEE", !7, i64 0}
!28 = !{!"_ZTSN9NCompress5NLZMA7NLength18CPriceTableEncoderE", !29, i64 0, !7, i64 2056, !10, i64 19464, !7, i64 19468}
!29 = !{!"_ZTSN9NCompress5NLZMA7NLength8CEncoderE", !30, i64 0, !30, i64 4, !7, i64 8, !7, i64 520, !32, i64 1032}
!30 = !{!"_ZTSN9NCompress11NRangeCoder11CBitEncoderILi5EEE", !31, i64 0}
!31 = !{!"_ZTSN9NCompress11NRangeCoder9CBitModelILi5EEE", !10, i64 0}
!32 = !{!"_ZTSN9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi8EEE", !7, i64 0}
!33 = !{!"_ZTSN9NCompress5NLZMA15CLiteralEncoderE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!34 = !{!12, !10, i64 210620}
!35 = !{!12, !10, i64 210624}
!36 = !{!7, !7, i64 0}
!37 = !{!12, !10, i64 210628}
!38 = distinct !{!38, !39}
!39 = !{!"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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NLZMA8CEncoder20WriteCoderPropertiesEP20ISequentialOutStream(ptr nocapture noundef nonnull readonly align 8 dereferenceable(210678) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca [5 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 210612
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = mul i32 %5, 5
  %7 = getelementptr inbounds i8, ptr %0, i64 210620
  %8 = load i32, ptr %7, align 4, !tbaa !32
  %9 = add i32 %6, %8
  %10 = mul i32 %9, 9
  %11 = getelementptr inbounds i8, ptr %0, i64 210624
  %12 = load i32, ptr %11, align 8, !tbaa !33
  %13 = add i32 %10, %12
  %14 = trunc i32 %13 to i8
  store i8 %14, ptr %3, align 1, !tbaa !34
  %15 = getelementptr inbounds i8, ptr %0, i64 210628
  %16 = load i32, ptr %15, align 4, !tbaa !35
  %17 = trunc i32 %16 to i8
  %18 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 %17, ptr %18, align 1, !tbaa !34
  %19 = lshr i32 %16, 8
  %20 = trunc i32 %19 to i8
  %21 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 %20, ptr %21, align 1, !tbaa !34
  %22 = lshr i32 %16, 16
  %23 = trunc i32 %22 to i8
  %24 = getelementptr inbounds i8, ptr %3, i64 3
  store i8 %23, ptr %24, align 1, !tbaa !34
  %25 = lshr i32 %16, 24
  %26 = trunc nuw i32 %25 to i8
  %27 = getelementptr inbounds i8, ptr %3, i64 4
  store i8 %26, ptr %27, align 1, !tbaa !34
  %28 = call noundef i32 @_Z11WriteStreamP20ISequentialOutStreamPKvjPj(ptr noundef %1, ptr noundef nonnull %3, i32 noundef 5, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #3
  ret i32 %28
}

declare noundef i32 @_Z11WriteStreamP20ISequentialOutStreamPKvjPj(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass