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

; 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 }
%"class.NCompress::NPpmd::CDecoder" = type { %struct.ICompressCoder, %struct.ICompressSetDecoderProperties2, %struct.ICompressGetInStreamProcessedSize, %struct.ICompressSetInStream, %struct.ICompressSetOutStreamSize, %struct.ISequentialInStream, %class.CMyUnknownImp, ptr, %struct.CPpmd7z_RangeDec, %struct.CByteInBufWrap, %struct.CPpmd7, i8, i8, i32, i64, i64, %class.CMyComPtr }
%struct.ICompressCoder = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetDecoderProperties2 = type { %struct.IUnknown }
%struct.ICompressGetInStreamProcessedSize = type { %struct.IUnknown }
%struct.ICompressSetInStream = type { %struct.IUnknown }
%struct.ICompressSetOutStreamSize = type { %struct.IUnknown }
%struct.ISequentialInStream = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%struct.CPpmd7z_RangeDec = type { %struct.IPpmd7_RangeDec, i32, i32, ptr }
%struct.IPpmd7_RangeDec = type { ptr, ptr, ptr }
%struct.CByteInBufWrap = type { %struct.IByteIn, ptr, ptr, ptr, i32, ptr, i64, i8, i32 }
%struct.IByteIn = type { ptr }
%struct.CPpmd7 = type { ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i32, [38 x i8], [128 x i8], [38 x i32], [256 x i8], [256 x i8], [256 x i8], %struct.CPpmd_See, [25 x [16 x %struct.CPpmd_See]], [128 x [64 x i16]] }
%struct.CPpmd_See = type { i16, i8, i8 }
%class.CMyComPtr = type { ptr }

@g_BigAlloc = external global %struct.ISzAlloc, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NPpmd8CDecoder21SetDecoderProperties2EPKhj(ptr noundef nonnull align 8 dereferenceable(19384) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp ult i32 %11, 5
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i32 -2147024809, ptr %4, align 4
  br label %50

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 0
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = getelementptr inbounds %"class.NCompress::NPpmd::CDecoder", ptr %10, i32 0, i32 11
  store i8 %17, ptr %18, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 1
  %21 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %21, ptr %8, align 4, !tbaa !9
  %22 = getelementptr inbounds %"class.NCompress::NPpmd::CDecoder", ptr %10, i32 0, i32 11
  %23 = load i8, ptr %22, align 8, !tbaa !12
  %24 = zext i8 %23 to i32
  %25 = icmp slt i32 %24, 2
  br i1 %25, label %37, label %26

26:                                               ; preds = %14
  %27 = getelementptr inbounds %"class.NCompress::NPpmd::CDecoder", ptr %10, i32 0, i32 11
  %28 = load i8, ptr %27, align 8, !tbaa !12
  %29 = zext i8 %28 to i32
  %30 = icmp sgt i32 %29, 64
  br i1 %30, label %37, label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp ult i32 %32, 2048
  br i1 %33, label %37, label %34

34:                                               ; preds = %31
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = icmp ugt i32 %35, -37
  br i1 %36, label %37, label %38

37:                                               ; preds = %34, %31, %26, %14
  store i32 -2147467263, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %49

38:                                               ; preds = %34
  %39 = getelementptr inbounds %"class.NCompress::NPpmd::CDecoder", ptr %10, i32 0, i32 9
  %40 = call noundef zeroext i1 @_ZN14CByteInBufWrap5AllocEj(ptr noundef nonnull align 8 dereferenceable(64) %39, i32 noundef 1048576) #4
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  store i32 -2147024882, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %49

42:                                               ; preds = %38
  %43 = getelementptr inbounds %"class.NCompress::NPpmd::CDecoder", ptr %10, i32 0, i32 10
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = call i32 @Ppmd7_Alloc(ptr noundef %43, i32 noundef %44, ptr noundef @g_BigAlloc)
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %48, label %47

47:                                               ; preds = %42
  store i32 -2147024882, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %49

48:                                               ; preds = %42
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %49

49:                                               ; preds = %48, %47, %41, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %50

50:                                               ; preds = %49, %13
  %51 = load i32, ptr %4, align 4
  ret i32 %51
}

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

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN14CByteInBufWrap5AllocEj(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 19352}
!13 = !{!"_ZTSN9NCompress5NPpmd8CDecoderE", !14, i64 0, !16, i64 8, !17, i64 16, !18, i64 24, !19, i64 32, !20, i64 40, !21, i64 48, !6, i64 56, !22, i64 64, !24, i64 104, !28, i64 168, !7, i64 19352, !27, i64 19353, !10, i64 19356, !26, i64 19360, !26, i64 19368, !31, i64 19376}
!14 = !{!"_ZTS14ICompressCoder", !15, i64 0}
!15 = !{!"_ZTS8IUnknown"}
!16 = !{!"_ZTS30ICompressSetDecoderProperties2", !15, i64 0}
!17 = !{!"_ZTS33ICompressGetInStreamProcessedSize", !15, i64 0}
!18 = !{!"_ZTS20ICompressSetInStream", !15, i64 0}
!19 = !{!"_ZTS25ICompressSetOutStreamSize", !15, i64 0}
!20 = !{!"_ZTS19ISequentialInStream", !15, i64 0}
!21 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!22 = !{!"_ZTS16CPpmd7z_RangeDec", !23, i64 0, !10, i64 24, !10, i64 28, !6, i64 32}
!23 = !{!"_ZTS15IPpmd7_RangeDec", !6, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!"_ZTS14CByteInBufWrap", !25, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !26, i64 48, !27, i64 56, !10, i64 60}
!25 = !{!"_ZTS7IByteIn", !6, i64 0}
!26 = !{!"long long", !7, i64 0}
!27 = !{!"bool", !7, i64 0}
!28 = !{!"_ZTS6CPpmd7", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !10, i64 104, !7, i64 108, !7, i64 146, !7, i64 276, !7, i64 428, !7, i64 684, !7, i64 940, !29, i64 1196, !7, i64 1200, !7, i64 2800}
!29 = !{!"_ZTS9CPpmd_See", !30, i64 0, !7, i64 2, !7, i64 3}
!30 = !{!"short", !7, i64 0}
!31 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, 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 }

@g_BigAlloc = external global %struct.ISzAlloc, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147467263, 1) i32 @_ZN9NCompress5NPpmd8CDecoder21SetDecoderProperties2EPKhj(ptr noundef nonnull align 8 dereferenceable(19384) %0, ptr nocapture noundef readonly %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = icmp ult i32 %2, 5
  br i1 %4, label %21, label %5

5:                                                ; preds = %3
  %6 = load i8, ptr %1, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 19352
  store i8 %6, ptr %7, align 8, !tbaa !8
  %8 = getelementptr inbounds i8, ptr %1, i64 1
  %9 = load i32, ptr %8, align 4, !tbaa !30
  %10 = icmp ult i8 %6, 2
  br i1 %10, label %21, label %11

11:                                               ; preds = %5
  %12 = icmp ugt i8 %6, 64
  %13 = add i32 %9, 36
  %14 = icmp ult i32 %13, 2084
  %or.cond3 = select i1 %12, i1 true, i1 %14
  br i1 %or.cond3, label %21, label %15

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 104
  %17 = tail call noundef zeroext i1 @_ZN14CByteInBufWrap5AllocEj(ptr noundef nonnull align 8 dereferenceable(64) %16, i32 noundef 1048576) #3
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 168
  %20 = tail call i32 @Ppmd7_Alloc(ptr noundef nonnull %19, i32 noundef %9, ptr noundef nonnull @g_BigAlloc)
  %.not = icmp eq i32 %20, 0
  %. = select i1 %.not, i32 -2147024882, i32 0
  br label %21

21:                                               ; preds = %11, %5, %15, %18, %3
  %.1 = phi i32 [ -2147024809, %3 ], [ -2147467263, %11 ], [ -2147467263, %5 ], [ -2147024882, %15 ], [ %., %18 ]
  ret i32 %.1
}

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN14CByteInBufWrap5AllocEj(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef) local_unnamed_addr #1

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

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 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !6, i64 19352}
!9 = !{!"_ZTSN9NCompress5NPpmd8CDecoderE", !10, i64 0, !12, i64 8, !13, i64 16, !14, i64 24, !15, i64 32, !16, i64 40, !17, i64 48, !19, i64 56, !20, i64 64, !22, i64 104, !26, i64 168, !6, i64 19352, !25, i64 19353, !18, i64 19356, !24, i64 19360, !24, i64 19368, !29, i64 19376}
!10 = !{!"_ZTS14ICompressCoder", !11, i64 0}
!11 = !{!"_ZTS8IUnknown"}
!12 = !{!"_ZTS30ICompressSetDecoderProperties2", !11, i64 0}
!13 = !{!"_ZTS33ICompressGetInStreamProcessedSize", !11, i64 0}
!14 = !{!"_ZTS20ICompressSetInStream", !11, i64 0}
!15 = !{!"_ZTS25ICompressSetOutStreamSize", !11, i64 0}
!16 = !{!"_ZTS19ISequentialInStream", !11, i64 0}
!17 = !{!"_ZTS13CMyUnknownImp", !18, i64 0}
!18 = !{!"int", !6, i64 0}
!19 = !{!"any pointer", !6, i64 0}
!20 = !{!"_ZTS16CPpmd7z_RangeDec", !21, i64 0, !18, i64 24, !18, i64 28, !19, i64 32}
!21 = !{!"_ZTS15IPpmd7_RangeDec", !19, i64 0, !19, i64 8, !19, i64 16}
!22 = !{!"_ZTS14CByteInBufWrap", !23, i64 0, !19, i64 8, !19, i64 16, !19, i64 24, !18, i64 32, !19, i64 40, !24, i64 48, !25, i64 56, !18, i64 60}
!23 = !{!"_ZTS7IByteIn", !19, i64 0}
!24 = !{!"long long", !6, i64 0}
!25 = !{!"bool", !6, i64 0}
!26 = !{!"_ZTS6CPpmd7", !19, i64 0, !19, i64 8, !19, i64 16, !18, i64 24, !18, i64 28, !18, i64 32, !18, i64 36, !18, i64 40, !18, i64 44, !18, i64 48, !18, i64 52, !18, i64 56, !19, i64 64, !19, i64 72, !19, i64 80, !19, i64 88, !19, i64 96, !18, i64 104, !6, i64 108, !6, i64 146, !6, i64 276, !6, i64 428, !6, i64 684, !6, i64 940, !27, i64 1196, !6, i64 1200, !6, i64 2800}
!27 = !{!"_ZTS9CPpmd_See", !28, i64 0, !6, i64 2, !6, i64 3}
!28 = !{!"short", !6, i64 0}
!29 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !19, i64 0}
!30 = !{!18, !18, i64 0}


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