; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Compress (Lzma2Decoder)

; 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.CLzma2DecMtProps = type { i64, i64, i32, i64, i64, i64 }
%"class.NCompress::NLzma2::CDecoder" = type { %struct.ICompressCoder, %struct.ICompressSetDecoderProperties2, %struct.ICompressSetFinishMode, %struct.ICompressGetInStreamProcessedSize, %struct.ICompressSetBufSize, %struct.ICompressSetInStream, %struct.ICompressSetOutStreamSize, %struct.ISequentialInStream, %struct.ICompressSetCoderMt, %struct.ICompressSetMemLimit, %class.CMyUnknownImp, ptr, i64, i8, i32, i32, i32, i32, i32, i64, %class.CMyComPtr, %struct.CSeqInStreamWrap }
%struct.ICompressCoder = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetDecoderProperties2 = type { %struct.IUnknown }
%struct.ICompressSetFinishMode = type { %struct.IUnknown }
%struct.ICompressGetInStreamProcessedSize = type { %struct.IUnknown }
%struct.ICompressSetBufSize = type { %struct.IUnknown }
%struct.ICompressSetInStream = type { %struct.IUnknown }
%struct.ICompressSetOutStreamSize = type { %struct.IUnknown }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.ICompressSetCoderMt = type { %struct.IUnknown }
%struct.ICompressSetMemLimit = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr = type { ptr }
%struct.CSeqInStreamWrap = type { %struct.ISeqInStream, ptr, i32, i64 }
%struct.ISeqInStream = type { ptr }

@g_MidAlloc = external global %struct.ISzAlloc, align 8
@g_AlignedAlloc = external global %struct.ISzAlloc, align 8

declare ptr @Lzma2DecMt_Create(ptr noundef, ptr noundef) #0

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

declare void @Lzma2DecMtProps_Init(ptr noundef) #0

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

; Function Attrs: nounwind
declare void @_ZN16CSeqInStreamWrap4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) #2

; Function Attrs: nounwind
declare noundef i32 @_Z13SResToHRESULTi(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress6NLzma28CDecoder16SetOutStreamSizeEPKy(ptr noundef nonnull align 8 dereferenceable(176) %0, ptr noundef %1) unnamed_addr #3 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.CLzma2DecMtProps, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 48, ptr %6) #5
  call void @Lzma2DecMtProps_Init(ptr noundef %6)
  %10 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 15
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds %struct.CLzma2DecMtProps, ptr %6, i32 0, i32 0
  store i64 %12, ptr %13, align 8, !tbaa !28
  %14 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 16
  %15 = load i32, ptr %14, align 4, !tbaa !31
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds %struct.CLzma2DecMtProps, ptr %6, i32 0, i32 1
  store i64 %16, ptr %17, align 8, !tbaa !32
  %18 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 12
  store i64 0, ptr %18, align 8, !tbaa !33
  %19 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 11
  %20 = load ptr, ptr %19, align 8, !tbaa !34
  %21 = icmp ne ptr %20, null
  br i1 %21, label %30, label %22

22:                                               ; preds = %2
  %23 = call ptr @Lzma2DecMt_Create(ptr noundef @g_AlignedAlloc, ptr noundef @g_MidAlloc)
  %24 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 11
  store ptr %23, ptr %24, align 8, !tbaa !34
  %25 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 11
  %26 = load ptr, ptr %25, align 8, !tbaa !34
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  store i32 -2147024882, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %51

29:                                               ; preds = %22
  br label %30

30:                                               ; preds = %29, %2
  %31 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 21
  %32 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 20
  %33 = call noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8) %32)
  call void @_ZN16CSeqInStreamWrap4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(32) %31, ptr noundef %33) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %34 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 11
  %35 = load ptr, ptr %34, align 8, !tbaa !34
  %36 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 13
  %37 = load i8, ptr %36, align 8, !tbaa !35
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 14
  %40 = load i32, ptr %39, align 4, !tbaa !36
  %41 = getelementptr inbounds %"class.NCompress::NLzma2::CDecoder", ptr %9, i32 0, i32 21
  %42 = getelementptr inbounds %struct.CSeqInStreamWrap, ptr %41, i32 0, i32 0
  %43 = call i32 @Lzma2DecMt_Init(ptr noundef %35, i8 noundef zeroext %37, ptr noundef %6, ptr noundef %38, i32 noundef %40, ptr noundef %42)
  store i32 %43, ptr %8, align 4, !tbaa !37
  %44 = load i32, ptr %8, align 4, !tbaa !37
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %30
  %47 = load i32, ptr %8, align 4, !tbaa !37
  %48 = call noundef i32 @_Z13SResToHRESULTi(i32 noundef %47) #5
  store i32 %48, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

49:                                               ; preds = %30
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

50:                                               ; preds = %49, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %51

51:                                               ; preds = %50, %28
  call void @llvm.lifetime.end.p0(i64 48, ptr %6) #5
  %52 = load i32, ptr %3, align 4
  ret i32 %52
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8)) #4 align 2

declare i32 @Lzma2DecMt_Init(ptr noundef, i8 noundef zeroext, ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = { 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 #4 = { 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 #5 = { 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, !23, i64 112}
!10 = !{!"_ZTSN9NCompress6NLzma28CDecoderE", !11, i64 0, !13, i64 8, !14, i64 16, !15, i64 24, !16, i64 32, !17, i64 40, !18, i64 48, !19, i64 56, !20, i64 64, !21, i64 72, !22, i64 80, !6, i64 88, !24, i64 96, !7, i64 104, !23, i64 108, !23, i64 112, !23, i64 116, !23, i64 120, !23, i64 124, !24, i64 128, !25, i64 136, !26, i64 144}
!11 = !{!"_ZTS14ICompressCoder", !12, i64 0}
!12 = !{!"_ZTS8IUnknown"}
!13 = !{!"_ZTS30ICompressSetDecoderProperties2", !12, i64 0}
!14 = !{!"_ZTS22ICompressSetFinishMode", !12, i64 0}
!15 = !{!"_ZTS33ICompressGetInStreamProcessedSize", !12, i64 0}
!16 = !{!"_ZTS19ICompressSetBufSize", !12, i64 0}
!17 = !{!"_ZTS20ICompressSetInStream", !12, i64 0}
!18 = !{!"_ZTS25ICompressSetOutStreamSize", !12, i64 0}
!19 = !{!"_ZTS19ISequentialInStream", !12, i64 0}
!20 = !{!"_ZTS19ICompressSetCoderMt", !12, i64 0}
!21 = !{!"_ZTS20ICompressSetMemLimit", !12, i64 0}
!22 = !{!"_ZTS13CMyUnknownImp", !23, i64 0}
!23 = !{!"int", !7, i64 0}
!24 = !{!"long long", !7, i64 0}
!25 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!26 = !{!"_ZTS16CSeqInStreamWrap", !27, i64 0, !6, i64 8, !23, i64 16, !24, i64 24}
!27 = !{!"_ZTS12ISeqInStream", !6, i64 0}
!28 = !{!29, !30, i64 0}
!29 = !{!"_ZTS16CLzma2DecMtProps", !30, i64 0, !30, i64 8, !23, i64 16, !30, i64 24, !30, i64 32, !30, i64 40}
!30 = !{!"long", !7, i64 0}
!31 = !{!10, !23, i64 116}
!32 = !{!29, !30, i64 8}
!33 = !{!10, !24, i64 96}
!34 = !{!10, !6, i64 88}
!35 = !{!10, !7, i64 104}
!36 = !{!10, !23, i64 108}
!37 = !{!23, !23, 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"

%struct.ISzAlloc = type { ptr, ptr }
%struct.CLzma2DecMtProps = type { i64, i64, i32, i64, i64, i64 }

@g_MidAlloc = external global %struct.ISzAlloc, align 8
@g_AlignedAlloc = external global %struct.ISzAlloc, align 8

declare ptr @Lzma2DecMt_Create(ptr noundef, ptr noundef) local_unnamed_addr #0

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

declare void @Lzma2DecMtProps_Init(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind
declare void @_ZN16CSeqInStreamWrap4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare noundef i32 @_Z13SResToHRESULTi(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress6NLzma28CDecoder16SetOutStreamSizeEPKy(ptr noundef nonnull align 8 dereferenceable(176) %0, ptr noundef %1) unnamed_addr #3 align 2 {
  %3 = alloca %struct.CLzma2DecMtProps, align 16
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #5
  call void @Lzma2DecMtProps_Init(ptr noundef nonnull %3)
  %4 = getelementptr inbounds i8, ptr %0, i64 112
  %5 = load <2 x i32>, ptr %4, align 8, !tbaa !5
  %6 = zext <2 x i32> %5 to <2 x i64>
  store <2 x i64> %6, ptr %3, align 16, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %0, i64 96
  store i64 0, ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = load ptr, ptr %8, align 8, !tbaa !30
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %10, label %12

10:                                               ; preds = %2
  %11 = call ptr @Lzma2DecMt_Create(ptr noundef nonnull @g_AlignedAlloc, ptr noundef nonnull @g_MidAlloc)
  store ptr %11, ptr %8, align 8, !tbaa !30
  %.not5 = icmp eq ptr %11, null
  br i1 %.not5, label %24, label %12

12:                                               ; preds = %10, %2
  %13 = getelementptr inbounds i8, ptr %0, i64 144
  %14 = getelementptr inbounds i8, ptr %0, i64 136
  %15 = call noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8) %14)
  call void @_ZN16CSeqInStreamWrap4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(32) %13, ptr noundef %15) #5
  %16 = load ptr, ptr %8, align 8, !tbaa !30
  %17 = getelementptr inbounds i8, ptr %0, i64 104
  %18 = load i8, ptr %17, align 8, !tbaa !31
  %19 = getelementptr inbounds i8, ptr %0, i64 108
  %20 = load i32, ptr %19, align 4, !tbaa !32
  %21 = call i32 @Lzma2DecMt_Init(ptr noundef %16, i8 noundef zeroext %18, ptr noundef nonnull %3, ptr noundef %1, i32 noundef %20, ptr noundef nonnull %13)
  %.not6 = icmp eq i32 %21, 0
  br i1 %.not6, label %24, label %22

22:                                               ; preds = %12
  %23 = call noundef i32 @_Z13SResToHRESULTi(i32 noundef %21) #5
  br label %24

24:                                               ; preds = %22, %12, %10
  %.1 = phi i32 [ -2147024882, %10 ], [ %23, %22 ], [ 0, %12 ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #5
  ret i32 %.1
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4 align 2

declare i32 @Lzma2DecMt_Init(ptr noundef, i8 noundef zeroext, ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

attributes #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = { 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 #4 = { 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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !26, i64 96}
!12 = !{!"_ZTSN9NCompress6NLzma28CDecoderE", !13, i64 0, !15, i64 8, !16, i64 16, !17, i64 24, !18, i64 32, !19, i64 40, !20, i64 48, !21, i64 56, !22, i64 64, !23, i64 72, !24, i64 80, !25, i64 88, !26, i64 96, !7, i64 104, !6, i64 108, !6, i64 112, !6, i64 116, !6, i64 120, !6, i64 124, !26, i64 128, !27, i64 136, !28, i64 144}
!13 = !{!"_ZTS14ICompressCoder", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS30ICompressSetDecoderProperties2", !14, i64 0}
!16 = !{!"_ZTS22ICompressSetFinishMode", !14, i64 0}
!17 = !{!"_ZTS33ICompressGetInStreamProcessedSize", !14, i64 0}
!18 = !{!"_ZTS19ICompressSetBufSize", !14, i64 0}
!19 = !{!"_ZTS20ICompressSetInStream", !14, i64 0}
!20 = !{!"_ZTS25ICompressSetOutStreamSize", !14, i64 0}
!21 = !{!"_ZTS19ISequentialInStream", !14, i64 0}
!22 = !{!"_ZTS19ICompressSetCoderMt", !14, i64 0}
!23 = !{!"_ZTS20ICompressSetMemLimit", !14, i64 0}
!24 = !{!"_ZTS13CMyUnknownImp", !6, i64 0}
!25 = !{!"any pointer", !7, i64 0}
!26 = !{!"long long", !7, i64 0}
!27 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !25, i64 0}
!28 = !{!"_ZTS16CSeqInStreamWrap", !29, i64 0, !25, i64 8, !6, i64 16, !26, i64 24}
!29 = !{!"_ZTS12ISeqInStream", !25, i64 0}
!30 = !{!12, !25, i64 88}
!31 = !{!12, !7, i64 104}
!32 = !{!12, !6, i64 108}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass