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

; 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::NBcj2::CDecoder" = type { %struct.ICompressCoder2, %struct.ICompressSetFinishMode, %struct.ICompressGetInStreamProcessedSize2, %struct.ICompressSetInStream2, %struct.ISequentialInStream, %struct.ICompressSetOutStreamSize, %struct.ICompressSetBufSize, %class.CMyUnknownImp, %"class.NCompress::NBcj2::CBaseCoder", [4 x i32], [4 x i64], [4 x i32], [4 x %class.CMyComPtr.0], i8, i8, i64, i64, %struct.CBcj2Dec }
%struct.ICompressCoder2 = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetFinishMode = type { %struct.IUnknown }
%struct.ICompressGetInStreamProcessedSize2 = type { %struct.IUnknown }
%struct.ICompressSetInStream2 = type { %struct.IUnknown }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.ICompressSetOutStreamSize = type { %struct.IUnknown }
%struct.ICompressSetBufSize = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%"class.NCompress::NBcj2::CBaseCoder" = type { [5 x ptr], [5 x i32], [5 x i32] }
%class.CMyComPtr.0 = type { ptr }
%struct.CBcj2Dec = type { [4 x ptr], [4 x ptr], ptr, ptr, i32, i32, [4 x i8], i32, i32, [258 x i16] }

; 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 @_ZN9NCompress5NBcj210CBaseCoder5AllocEb(ptr noundef nonnull align 8 dereferenceable(80), i1 noundef zeroext) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NBcj28CDecoder16SetOutStreamSizeEPKy(ptr noundef nonnull align 8 dereferenceable(880) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  %9 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %6, i32 0, i32 14
  %10 = zext i1 %8 to i8
  store i8 %10, ptr %9, align 1, !tbaa !9
  %11 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %6, i32 0, i32 15
  store i64 0, ptr %11, align 8, !tbaa !25
  %12 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %6, i32 0, i32 14
  %13 = load i8, ptr %12, align 1, !tbaa !9, !range !26, !noundef !27
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %19

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i64, ptr %16, align 8, !tbaa !28
  %18 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %6, i32 0, i32 15
  store i64 %17, ptr %18, align 8, !tbaa !25
  br label %19

19:                                               ; preds = %15, %2
  %20 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %6, i32 0, i32 16
  store i64 0, ptr %20, align 8, !tbaa !29
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %21 = getelementptr inbounds i8, ptr %6, i64 64
  %22 = call noundef i32 @_ZN9NCompress5NBcj210CBaseCoder5AllocEb(ptr noundef nonnull align 8 dereferenceable(80) %21, i1 noundef zeroext false)
  store i32 %22, ptr %5, align 4, !tbaa !30
  call void @_ZN9NCompress5NBcj28CDecoder10InitCommonEv(ptr noundef nonnull align 8 dereferenceable(880) %6)
  %23 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %6, i32 0, i32 17
  %24 = getelementptr inbounds %struct.CBcj2Dec, ptr %23, i32 0, i32 2
  store ptr null, ptr %24, align 8, !tbaa !31
  %25 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %6, i32 0, i32 17
  %26 = getelementptr inbounds %struct.CBcj2Dec, ptr %25, i32 0, i32 3
  store ptr null, ptr %26, align 8, !tbaa !32
  %27 = load i32, ptr %5, align 4, !tbaa !30
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %27
}

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, !22, i64 241}
!10 = !{!"_ZTSN9NCompress5NBcj28CDecoderE", !11, i64 0, !13, i64 8, !14, i64 16, !15, i64 24, !16, i64 32, !17, i64 40, !18, i64 48, !19, i64 56, !21, i64 64, !7, i64 144, !7, i64 160, !7, i64 192, !7, i64 208, !22, i64 240, !22, i64 241, !23, i64 248, !23, i64 256, !24, i64 264}
!11 = !{!"_ZTS15ICompressCoder2", !12, i64 0}
!12 = !{!"_ZTS8IUnknown"}
!13 = !{!"_ZTS22ICompressSetFinishMode", !12, i64 0}
!14 = !{!"_ZTS34ICompressGetInStreamProcessedSize2", !12, i64 0}
!15 = !{!"_ZTS21ICompressSetInStream2", !12, i64 0}
!16 = !{!"_ZTS19ISequentialInStream", !12, i64 0}
!17 = !{!"_ZTS25ICompressSetOutStreamSize", !12, i64 0}
!18 = !{!"_ZTS19ICompressSetBufSize", !12, i64 0}
!19 = !{!"_ZTS13CMyUnknownImp", !20, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = !{!"_ZTSN9NCompress5NBcj210CBaseCoderE", !7, i64 0, !7, i64 40, !7, i64 60}
!22 = !{!"bool", !7, i64 0}
!23 = !{!"long long", !7, i64 0}
!24 = !{!"_ZTS8CBcj2Dec", !7, i64 0, !7, i64 32, !6, i64 64, !6, i64 72, !20, i64 80, !20, i64 84, !7, i64 88, !20, i64 92, !20, i64 96, !7, i64 100}
!25 = !{!10, !23, i64 248}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!23, !23, i64 0}
!29 = !{!10, !23, i64 256}
!30 = !{!20, !20, i64 0}
!31 = !{!10, !6, i64 328}
!32 = !{!10, !6, i64 336}


; 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 @_ZN9NCompress5NBcj210CBaseCoder5AllocEb(ptr noundef nonnull align 8 dereferenceable(80), i1 noundef zeroext) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NBcj28CDecoder16SetOutStreamSizeEPKy(ptr noundef nonnull align 8 dereferenceable(880) %0, ptr noundef readonly %1) unnamed_addr #0 align 2 {
  %3 = icmp ne ptr %1, null
  %4 = getelementptr inbounds i8, ptr %0, i64 241
  %5 = zext i1 %3 to i8
  store i8 %5, ptr %4, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 248
  store i64 0, ptr %6, align 8, !tbaa !24
  br i1 %3, label %7, label %9

7:                                                ; preds = %2
  %8 = load i64, ptr %1, align 8, !tbaa !25
  store i64 %8, ptr %6, align 8, !tbaa !24
  br label %9

9:                                                ; preds = %7, %2
  %10 = getelementptr inbounds i8, ptr %0, i64 256
  store i64 0, ptr %10, align 8, !tbaa !26
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = tail call noundef i32 @_ZN9NCompress5NBcj210CBaseCoder5AllocEb(ptr noundef nonnull align 8 dereferenceable(80) %11, i1 noundef zeroext false)
  tail call void @_ZN9NCompress5NBcj28CDecoder10InitCommonEv(ptr noundef nonnull align 8 dereferenceable(880) %0)
  %13 = getelementptr inbounds i8, ptr %0, i64 328
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %13, i8 0, i64 16, i1 false)
  ret i32 %12
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !20, i64 241}
!6 = !{!"_ZTSN9NCompress5NBcj28CDecoderE", !7, i64 0, !9, i64 8, !10, i64 16, !11, i64 24, !12, i64 32, !13, i64 40, !14, i64 48, !15, i64 56, !19, i64 64, !17, i64 144, !17, i64 160, !17, i64 192, !17, i64 208, !20, i64 240, !20, i64 241, !21, i64 248, !21, i64 256, !22, i64 264}
!7 = !{!"_ZTS15ICompressCoder2", !8, i64 0}
!8 = !{!"_ZTS8IUnknown"}
!9 = !{!"_ZTS22ICompressSetFinishMode", !8, i64 0}
!10 = !{!"_ZTS34ICompressGetInStreamProcessedSize2", !8, i64 0}
!11 = !{!"_ZTS21ICompressSetInStream2", !8, i64 0}
!12 = !{!"_ZTS19ISequentialInStream", !8, i64 0}
!13 = !{!"_ZTS25ICompressSetOutStreamSize", !8, i64 0}
!14 = !{!"_ZTS19ICompressSetBufSize", !8, i64 0}
!15 = !{!"_ZTS13CMyUnknownImp", !16, i64 0}
!16 = !{!"int", !17, i64 0}
!17 = !{!"omnipotent char", !18, i64 0}
!18 = !{!"Simple C++ TBAA"}
!19 = !{!"_ZTSN9NCompress5NBcj210CBaseCoderE", !17, i64 0, !17, i64 40, !17, i64 60}
!20 = !{!"bool", !17, i64 0}
!21 = !{!"long long", !17, i64 0}
!22 = !{!"_ZTS8CBcj2Dec", !17, i64 0, !17, i64 32, !23, i64 64, !23, i64 72, !16, i64 80, !16, i64 84, !17, i64 88, !16, i64 92, !16, i64 96, !17, i64 100}
!23 = !{!"any pointer", !17, i64 0}
!24 = !{!6, !21, i64 248}
!25 = !{!21, !21, i64 0}
!26 = !{!6, !21, i64 256}


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