; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/CPP/7zip/Compress (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"

%struct.ISzAlloc = type { ptr, ptr }
%"struct.NCompress::NLzma::_CCompressProgressImp" = type { %struct.ICompressProgress, ptr, i32 }
%struct.ICompressProgress = type { ptr }
%"class.NCompress::NLzma::CEncoder" = type { %struct.ICompressCoder, %struct.ICompressSetOutStream, %struct.ICompressSetCoderProperties, %struct.ICompressWriteCoderProperties, %class.CMyUnknownImp, ptr, %"struct.NCompress::NLzma::CSeqInStream", %"struct.NCompress::NLzma::CSeqOutStream" }
%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.CMyUnknownImp = type { i32 }
%"struct.NCompress::NLzma::CSeqInStream" = type { %struct.ISeqInStream, ptr }
%struct.ISeqInStream = type { ptr }
%"struct.NCompress::NLzma::CSeqOutStream" = type <{ %struct.ISeqOutStream, %class.CMyComPtr, i32, [4 x i8] }>
%struct.ISeqOutStream = type { ptr }
%class.CMyComPtr = type { ptr }

@_ZN9NCompress5NLzmaL7g_AllocE = external hidden global %struct.ISzAlloc, align 8
@_ZN9NCompress5NLzmaL10g_BigAllocE = external hidden global %struct.ISzAlloc, align 8

; 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 hidden noundef i32 @_ZL13SResToHRESULTi(i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN9NCompress5NLzma16CompressProgressEPvyy(ptr noundef, i64 noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NLzma8CEncoder4CodeEP19ISequentialInStreamP20ISequentialOutStreamPKyS7_P21ICompressProgressInfo(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) unnamed_addr #2 align 2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %"struct.NCompress::NLzma::_CCompressProgressImp", align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #4
  %18 = getelementptr inbounds %"struct.NCompress::NLzma::_CCompressProgressImp", ptr %14, i32 0, i32 0
  %19 = getelementptr inbounds %struct.ICompressProgress, ptr %18, i32 0, i32 0
  store ptr @_ZN9NCompress5NLzma16CompressProgressEPvyy, ptr %19, align 8, !tbaa !9
  %20 = load ptr, ptr %13, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.NCompress::NLzma::_CCompressProgressImp", ptr %14, i32 0, i32 1
  store ptr %20, ptr %21, align 8, !tbaa !13
  %22 = getelementptr inbounds %"struct.NCompress::NLzma::_CCompressProgressImp", ptr %14, i32 0, i32 2
  store i32 0, ptr %22, align 8, !tbaa !14
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.NCompress::NLzma::CEncoder", ptr %17, i32 0, i32 6
  %25 = getelementptr inbounds %"struct.NCompress::NLzma::CSeqInStream", ptr %24, i32 0, i32 1
  store ptr %23, ptr %25, align 8, !tbaa !15
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = load ptr, ptr %17, align 8, !tbaa !28
  %28 = getelementptr inbounds ptr, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(88) %17, ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %31 = getelementptr inbounds %"class.NCompress::NLzma::CEncoder", ptr %17, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !30
  %33 = getelementptr inbounds %"class.NCompress::NLzma::CEncoder", ptr %17, i32 0, i32 7
  %34 = getelementptr inbounds %"struct.NCompress::NLzma::CSeqOutStream", ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %"class.NCompress::NLzma::CEncoder", ptr %17, i32 0, i32 6
  %36 = getelementptr inbounds %"struct.NCompress::NLzma::CSeqInStream", ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %41

39:                                               ; preds = %6
  %40 = getelementptr inbounds %"struct.NCompress::NLzma::_CCompressProgressImp", ptr %14, i32 0, i32 0
  br label %42

41:                                               ; preds = %6
  br label %42

42:                                               ; preds = %41, %39
  %43 = phi ptr [ %40, %39 ], [ null, %41 ]
  %44 = call i32 @LzmaEnc_Encode(ptr noundef %32, ptr noundef %34, ptr noundef %36, ptr noundef %43, ptr noundef @_ZN9NCompress5NLzmaL7g_AllocE, ptr noundef @_ZN9NCompress5NLzmaL10g_BigAllocE)
  store i32 %44, ptr %15, align 4, !tbaa !31
  %45 = load ptr, ptr %17, align 8, !tbaa !28
  %46 = getelementptr inbounds ptr, ptr %45, i64 9
  %47 = load ptr, ptr %46, align 8
  %48 = call noundef i32 %47(ptr noundef nonnull align 8 dereferenceable(88) %17)
  %49 = load i32, ptr %15, align 4, !tbaa !31
  %50 = icmp eq i32 %49, 9
  br i1 %50, label %51, label %60

51:                                               ; preds = %42
  %52 = getelementptr inbounds %"class.NCompress::NLzma::CEncoder", ptr %17, i32 0, i32 7
  %53 = getelementptr inbounds %"struct.NCompress::NLzma::CSeqOutStream", ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 8, !tbaa !32
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %51
  %57 = getelementptr inbounds %"class.NCompress::NLzma::CEncoder", ptr %17, i32 0, i32 7
  %58 = getelementptr inbounds %"struct.NCompress::NLzma::CSeqOutStream", ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 8, !tbaa !32
  store i32 %59, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %73

60:                                               ; preds = %51, %42
  %61 = load i32, ptr %15, align 4, !tbaa !31
  %62 = icmp eq i32 %61, 10
  br i1 %62, label %63, label %70

63:                                               ; preds = %60
  %64 = getelementptr inbounds %"struct.NCompress::NLzma::_CCompressProgressImp", ptr %14, i32 0, i32 2
  %65 = load i32, ptr %64, align 8, !tbaa !14
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %63
  %68 = getelementptr inbounds %"struct.NCompress::NLzma::_CCompressProgressImp", ptr %14, i32 0, i32 2
  %69 = load i32, ptr %68, align 8, !tbaa !14
  store i32 %69, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %73

70:                                               ; preds = %63, %60
  %71 = load i32, ptr %15, align 4, !tbaa !31
  %72 = call noundef i32 @_ZL13SResToHRESULTi(i32 noundef %71)
  store i32 %72, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %73

73:                                               ; preds = %70, %67, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #4
  %74 = load i32, ptr %7, align 4
  ret i32 %74
}

declare i32 @LzmaEnc_Encode(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

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 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN9NCompress5NLzma21_CCompressProgressImpE", !11, i64 0, !6, i64 8, !12, i64 16}
!11 = !{!"_ZTS17ICompressProgress", !6, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !12, i64 16}
!15 = !{!16, !6, i64 56}
!16 = !{!"_ZTSN9NCompress5NLzma8CEncoderE", !17, i64 0, !19, i64 8, !20, i64 16, !21, i64 24, !22, i64 32, !6, i64 40, !23, i64 48, !25, i64 64}
!17 = !{!"_ZTS14ICompressCoder", !18, i64 0}
!18 = !{!"_ZTS8IUnknown"}
!19 = !{!"_ZTS21ICompressSetOutStream", !18, i64 0}
!20 = !{!"_ZTS27ICompressSetCoderProperties", !18, i64 0}
!21 = !{!"_ZTS29ICompressWriteCoderProperties", !18, i64 0}
!22 = !{!"_ZTS13CMyUnknownImp", !12, i64 0}
!23 = !{!"_ZTSN9NCompress5NLzma12CSeqInStreamE", !24, i64 0, !6, i64 8}
!24 = !{!"_ZTS12ISeqInStream", !6, i64 0}
!25 = !{!"_ZTSN9NCompress5NLzma13CSeqOutStreamE", !26, i64 0, !27, i64 8, !12, i64 16}
!26 = !{!"_ZTS13ISeqOutStream", !6, i64 0}
!27 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !6, i64 0}
!28 = !{!29, !29, i64 0}
!29 = !{!"vtable pointer", !8, i64 0}
!30 = !{!16, !6, i64 40}
!31 = !{!12, !12, i64 0}
!32 = !{!16, !12, i64 80}


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

%struct.ISzAlloc = type { ptr, ptr }
%"struct.NCompress::NLzma::_CCompressProgressImp" = type { %struct.ICompressProgress, ptr, i32 }
%struct.ICompressProgress = type { ptr }

@_ZN9NCompress5NLzmaL7g_AllocE = external hidden global %struct.ISzAlloc, align 8
@_ZN9NCompress5NLzmaL10g_BigAllocE = external hidden global %struct.ISzAlloc, align 8

; 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 nounwind uwtable
declare hidden noundef i32 @_ZL13SResToHRESULTi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN9NCompress5NLzma16CompressProgressEPvyy(ptr noundef, i64 noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NLzma8CEncoder4CodeEP19ISequentialInStreamP20ISequentialOutStreamPKyS7_P21ICompressProgressInfo(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef %1, ptr noundef %2, ptr nocapture noundef readnone %3, ptr nocapture noundef readnone %4, ptr noundef %5) unnamed_addr #2 align 2 {
  %7 = alloca %"struct.NCompress::NLzma::_CCompressProgressImp", align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #4
  store ptr @_ZN9NCompress5NLzma16CompressProgressEPvyy, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  store ptr %5, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %7, i64 16
  store i32 0, ptr %9, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %1, ptr %11, align 8, !tbaa !14
  %12 = load ptr, ptr %0, align 8, !tbaa !27
  %13 = getelementptr inbounds i8, ptr %12, i64 64
  %14 = load ptr, ptr %13, align 8
  %15 = tail call noundef i32 %14(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef %2)
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = load ptr, ptr %16, align 8, !tbaa !29
  %18 = getelementptr inbounds i8, ptr %0, i64 64
  %.not = icmp eq ptr %5, null
  %19 = select i1 %.not, ptr null, ptr %7
  %20 = call i32 @LzmaEnc_Encode(ptr noundef %17, ptr noundef nonnull %18, ptr noundef nonnull %10, ptr noundef %19, ptr noundef nonnull @_ZN9NCompress5NLzmaL7g_AllocE, ptr noundef nonnull @_ZN9NCompress5NLzmaL10g_BigAllocE)
  %21 = load ptr, ptr %0, align 8, !tbaa !27
  %22 = getelementptr inbounds i8, ptr %21, i64 72
  %23 = load ptr, ptr %22, align 8
  %24 = call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(88) %0)
  %25 = icmp ne i32 %20, 9
  %26 = getelementptr inbounds i8, ptr %0, i64 80
  %27 = load i32, ptr %26, align 8
  %.not12 = icmp eq i32 %27, 0
  %or.cond14 = select i1 %25, i1 true, i1 %.not12
  br i1 %or.cond14, label %28, label %34

28:                                               ; preds = %6
  %29 = icmp eq i32 %20, 10
  %30 = load i32, ptr %9, align 8
  %31 = icmp ne i32 %30, 0
  %or.cond = select i1 %29, i1 %31, i1 false
  br i1 %or.cond, label %34, label %32

32:                                               ; preds = %28
  %33 = call noundef i32 @_ZL13SResToHRESULTi(i32 noundef %20)
  br label %34

34:                                               ; preds = %6, %28, %32
  %.0 = phi i32 [ %33, %32 ], [ %30, %28 ], [ %27, %6 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #4
  ret i32 %.0
}

declare i32 @LzmaEnc_Encode(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { "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, !8, i64 0}
!6 = !{!"_ZTSN9NCompress5NLzma21_CCompressProgressImpE", !7, i64 0, !8, i64 8, !11, i64 16}
!7 = !{!"_ZTS17ICompressProgress", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !8, i64 8}
!13 = !{!6, !11, i64 16}
!14 = !{!15, !8, i64 56}
!15 = !{!"_ZTSN9NCompress5NLzma8CEncoderE", !16, i64 0, !18, i64 8, !19, i64 16, !20, i64 24, !21, i64 32, !8, i64 40, !22, i64 48, !24, i64 64}
!16 = !{!"_ZTS14ICompressCoder", !17, i64 0}
!17 = !{!"_ZTS8IUnknown"}
!18 = !{!"_ZTS21ICompressSetOutStream", !17, i64 0}
!19 = !{!"_ZTS27ICompressSetCoderProperties", !17, i64 0}
!20 = !{!"_ZTS29ICompressWriteCoderProperties", !17, i64 0}
!21 = !{!"_ZTS13CMyUnknownImp", !11, i64 0}
!22 = !{!"_ZTSN9NCompress5NLzma12CSeqInStreamE", !23, i64 0, !8, i64 8}
!23 = !{!"_ZTS12ISeqInStream", !8, i64 0}
!24 = !{!"_ZTSN9NCompress5NLzma13CSeqOutStreamE", !25, i64 0, !26, i64 8, !11, i64 16}
!25 = !{!"_ZTS13ISeqOutStream", !8, i64 0}
!26 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !8, i64 0}
!27 = !{!28, !28, i64 0}
!28 = !{!"vtable pointer", !10, i64 0}
!29 = !{!15, !8, i64 40}


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