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

; 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::CDecoder" = type { %struct.ICompressCoder, %struct.ICompressSetDecoderProperties2, %struct.ICompressSetFinishMode, %struct.ICompressGetInStreamProcessedSize, %struct.ICompressSetBufSize, %struct.ICompressSetInStream, %struct.ICompressSetOutStreamSize, %struct.ISequentialInStream, %class.CMyUnknownImp, ptr, i32, i32, i32, i8, i8, i8, i64, i64, i64, i32, i32, i32, %struct.CLzmaDec, %class.CMyComPtr }
%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 }
%class.CMyUnknownImp = type { i32 }
%struct.CLzmaDec = type { %struct._CLzmaProps, ptr, ptr, ptr, i64, i64, ptr, i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, [20 x i8] }
%struct._CLzmaProps = type { i8, i8, i8, i8, i32 }
%class.CMyComPtr = type { ptr }

declare void @MyFree(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NLzma8CDecoder17CreateInputBufferEv(ptr noundef nonnull align 8 dereferenceable(272) %0) #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  %5 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 9
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %14

8:                                                ; preds = %1
  %9 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 21
  %10 = load i32, ptr %9, align 8, !tbaa !29
  %11 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 20
  %12 = load i32, ptr %11, align 4, !tbaa !30
  %13 = icmp ne i32 %10, %12
  br i1 %13, label %14, label %31

14:                                               ; preds = %8, %1
  %15 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 9
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  call void @MyFree(ptr noundef %16)
  %17 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 20
  store i32 0, ptr %17, align 4, !tbaa !30
  %18 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 21
  %19 = load i32, ptr %18, align 8, !tbaa !29
  %20 = zext i32 %19 to i64
  %21 = call ptr @MyAlloc(i64 noundef %20)
  %22 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 9
  store ptr %21, ptr %22, align 8, !tbaa !9
  %23 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 9
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %14
  store i32 -2147024882, ptr %2, align 4
  br label %32

27:                                               ; preds = %14
  %28 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 21
  %29 = load i32, ptr %28, align 8, !tbaa !29
  %30 = getelementptr inbounds %"class.NCompress::NLzma::CDecoder", ptr %4, i32 0, i32 20
  store i32 %29, ptr %30, align 4, !tbaa !30
  br label %31

31:                                               ; preds = %27, %8
  store i32 0, ptr %2, align 4
  br label %32

32:                                               ; preds = %31, %26
  %33 = load i32, ptr %2, align 4
  ret i32 %33
}

declare ptr @MyAlloc(i64 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 72}
!10 = !{!"_ZTSN9NCompress5NLzma8CDecoderE", !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, !6, i64 72, !21, i64 80, !21, i64 84, !22, i64 88, !23, i64 92, !23, i64 93, !23, i64 94, !24, i64 96, !24, i64 104, !24, i64 112, !21, i64 120, !21, i64 124, !21, i64 128, !25, i64 136, !28, i64 264}
!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 = !{!"_ZTS13CMyUnknownImp", !21, i64 0}
!21 = !{!"int", !7, i64 0}
!22 = !{!"_ZTS11ELzmaStatus", !7, i64 0}
!23 = !{!"bool", !7, i64 0}
!24 = !{!"long long", !7, i64 0}
!25 = !{!"_ZTS8CLzmaDec", !26, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !27, i64 32, !27, i64 40, !6, i64 48, !21, i64 56, !21, i64 60, !21, i64 64, !21, i64 68, !7, i64 72, !21, i64 88, !21, i64 92, !21, i64 96, !21, i64 100, !7, i64 104}
!26 = !{!"_ZTS11_CLzmaProps", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !21, i64 4}
!27 = !{!"long", !7, i64 0}
!28 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!29 = !{!10, !21, i64 128}
!30 = !{!10, !21, i64 124}


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

declare void @MyFree(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147024882, 1) i32 @_ZN9NCompress5NLzma8CDecoder17CreateInputBufferEv(ptr nocapture noundef nonnull align 8 dereferenceable(272) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 72
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %9, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 128
  %6 = load i32, ptr %5, align 8, !tbaa !28
  %7 = getelementptr inbounds i8, ptr %0, i64 124
  %8 = load i32, ptr %7, align 4, !tbaa !29
  %.not1 = icmp eq i32 %6, %8
  br i1 %.not1, label %17, label %9

9:                                                ; preds = %4, %1
  tail call void @MyFree(ptr noundef %3)
  %10 = getelementptr inbounds i8, ptr %0, i64 124
  store i32 0, ptr %10, align 4, !tbaa !29
  %11 = getelementptr inbounds i8, ptr %0, i64 128
  %12 = load i32, ptr %11, align 8, !tbaa !28
  %13 = zext i32 %12 to i64
  %14 = tail call ptr @MyAlloc(i64 noundef %13)
  store ptr %14, ptr %2, align 8, !tbaa !5
  %.not2 = icmp eq ptr %14, null
  br i1 %.not2, label %17, label %15

15:                                               ; preds = %9
  %16 = load i32, ptr %11, align 8, !tbaa !28
  store i32 %16, ptr %10, align 4, !tbaa !29
  br label %17

17:                                               ; preds = %4, %15, %9
  %.0 = phi i32 [ -2147024882, %9 ], [ 0, %15 ], [ 0, %4 ]
  ret i32 %.0
}

declare ptr @MyAlloc(i64 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 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, !20, i64 72}
!6 = !{!"_ZTSN9NCompress5NLzma8CDecoderE", !7, i64 0, !9, i64 8, !10, i64 16, !11, i64 24, !12, i64 32, !13, i64 40, !14, i64 48, !15, i64 56, !16, i64 64, !20, i64 72, !17, i64 80, !17, i64 84, !21, i64 88, !22, i64 92, !22, i64 93, !22, i64 94, !23, i64 96, !23, i64 104, !23, i64 112, !17, i64 120, !17, i64 124, !17, i64 128, !24, i64 136, !27, i64 264}
!7 = !{!"_ZTS14ICompressCoder", !8, i64 0}
!8 = !{!"_ZTS8IUnknown"}
!9 = !{!"_ZTS30ICompressSetDecoderProperties2", !8, i64 0}
!10 = !{!"_ZTS22ICompressSetFinishMode", !8, i64 0}
!11 = !{!"_ZTS33ICompressGetInStreamProcessedSize", !8, i64 0}
!12 = !{!"_ZTS19ICompressSetBufSize", !8, i64 0}
!13 = !{!"_ZTS20ICompressSetInStream", !8, i64 0}
!14 = !{!"_ZTS25ICompressSetOutStreamSize", !8, i64 0}
!15 = !{!"_ZTS19ISequentialInStream", !8, i64 0}
!16 = !{!"_ZTS13CMyUnknownImp", !17, i64 0}
!17 = !{!"int", !18, i64 0}
!18 = !{!"omnipotent char", !19, i64 0}
!19 = !{!"Simple C++ TBAA"}
!20 = !{!"any pointer", !18, i64 0}
!21 = !{!"_ZTS11ELzmaStatus", !18, i64 0}
!22 = !{!"bool", !18, i64 0}
!23 = !{!"long long", !18, i64 0}
!24 = !{!"_ZTS8CLzmaDec", !25, i64 0, !20, i64 8, !20, i64 16, !20, i64 24, !26, i64 32, !26, i64 40, !20, i64 48, !17, i64 56, !17, i64 60, !17, i64 64, !17, i64 68, !18, i64 72, !17, i64 88, !17, i64 92, !17, i64 96, !17, i64 100, !18, i64 104}
!25 = !{!"_ZTS11_CLzmaProps", !18, i64 0, !18, i64 1, !18, i64 2, !18, i64 3, !17, i64 4}
!26 = !{!"long", !18, i64 0}
!27 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !20, i64 0}
!28 = !{!6, !17, i64 128}
!29 = !{!6, !17, i64 124}


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