; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Common/FilterCoder.ll (ZN12CFilterCoder5AllocEv)

; 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.CFilterCoder = type { %struct.ICompressCoder, %struct.ICompressSetOutStreamSize, %struct.ICompressInitEncoder, %struct.ICompressSetInStream, %struct.ISequentialInStream, %struct.ICompressSetOutStream, %struct.ISequentialOutStream, %struct.IOutStreamFinish, %struct.ICompressSetBufSize, %struct.ICryptoSetPassword, %struct.ICryptoProperties, %struct.ICompressSetCoderProperties, %struct.ICompressWriteCoderProperties, %struct.ICryptoResetInitVector, %struct.ICompressSetDecoderProperties2, %class.CMyUnknownImp, %struct.CAlignedMidBuffer, i32, i32, i32, i8, i8, i64, i64, %class.CMyComPtr, %class.CMyComPtr.0, i32, i32, i32, %class.CMyComPtr.1, %class.CMyComPtr.2, %class.CMyComPtr.3, %class.CMyComPtr.4, %class.CMyComPtr.5, %class.CMyComPtr.6, %class.CMyComPtr.7 }
%struct.ICompressCoder = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressSetOutStreamSize = type { %struct.IUnknown }
%struct.ICompressInitEncoder = type { %struct.IUnknown }
%struct.ICompressSetInStream = type { %struct.IUnknown }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.ICompressSetOutStream = type { %struct.IUnknown }
%struct.ISequentialOutStream = type { %struct.IUnknown }
%struct.IOutStreamFinish = type { %struct.IUnknown }
%struct.ICompressSetBufSize = type { %struct.IUnknown }
%struct.ICryptoSetPassword = type { %struct.IUnknown }
%struct.ICryptoProperties = type { %struct.IUnknown }
%struct.ICompressSetCoderProperties = type { %struct.IUnknown }
%struct.ICompressWriteCoderProperties = type { %struct.IUnknown }
%struct.ICryptoResetInitVector = type { %struct.IUnknown }
%struct.ICompressSetDecoderProperties2 = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%struct.CAlignedMidBuffer = type { ptr }
%class.CMyComPtr = type { ptr }
%class.CMyComPtr.0 = type { ptr }
%class.CMyComPtr.1 = type { ptr }
%class.CMyComPtr.2 = type { ptr }
%class.CMyComPtr.3 = type { ptr }
%class.CMyComPtr.4 = type { ptr }
%class.CMyComPtr.5 = type { ptr }
%class.CMyComPtr.6 = type { ptr }
%class.CMyComPtr.7 = type { ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17CAlignedMidBuffer12AllocAlignedEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12CFilterCoder5AllocEv(ptr noundef nonnull align 8 dereferenceable(256) %0) #0 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = getelementptr inbounds %class.CFilterCoder, ptr %7, i32 0, i32 18
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds %class.CFilterCoder, ptr %7, i32 0, i32 19
  %11 = load i32, ptr %10, align 8, !tbaa !41
  %12 = call noundef i32 @_Z5MyMinIjET_S0_S0_(i32 noundef %9, i32 noundef %11)
  store i32 %12, ptr %4, align 4, !tbaa !42
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 4096, ptr %5, align 4, !tbaa !42
  %13 = load i32, ptr %4, align 4, !tbaa !42
  %14 = and i32 %13, -4096
  store i32 %14, ptr %4, align 4, !tbaa !42
  %15 = load i32, ptr %4, align 4, !tbaa !42
  %16 = icmp ult i32 %15, 4096
  br i1 %16, label %17, label %18

17:                                               ; preds = %1
  store i32 4096, ptr %4, align 4, !tbaa !42
  br label %18

18:                                               ; preds = %17, %1
  %19 = getelementptr inbounds i8, ptr %7, i64 128
  %20 = getelementptr inbounds %struct.CAlignedMidBuffer, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !43
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  %24 = getelementptr inbounds %class.CFilterCoder, ptr %7, i32 0, i32 17
  %25 = load i32, ptr %24, align 8, !tbaa !44
  %26 = load i32, ptr %4, align 4, !tbaa !42
  %27 = icmp ne i32 %25, %26
  br i1 %27, label %28, label %40

28:                                               ; preds = %23, %18
  %29 = getelementptr inbounds i8, ptr %7, i64 128
  %30 = load i32, ptr %4, align 4, !tbaa !42
  %31 = zext i32 %30 to i64
  call void @_ZN17CAlignedMidBuffer12AllocAlignedEm(ptr noundef nonnull align 8 dereferenceable(8) %29, i64 noundef %31)
  %32 = getelementptr inbounds i8, ptr %7, i64 128
  %33 = getelementptr inbounds %struct.CAlignedMidBuffer, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !43
  %35 = icmp ne ptr %34, null
  br i1 %35, label %37, label %36

36:                                               ; preds = %28
  store i32 -2147024882, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %41

37:                                               ; preds = %28
  %38 = load i32, ptr %4, align 4, !tbaa !42
  %39 = getelementptr inbounds %class.CFilterCoder, ptr %7, i32 0, i32 17
  store i32 %38, ptr %39, align 8, !tbaa !44
  br label %40

40:                                               ; preds = %37, %23
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %41

41:                                               ; preds = %40, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %42 = load i32, ptr %2, align 4
  ret i32 %42
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5MyMinIjET_S0_S0_(i32 noundef, i32 noundef) #2

; 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 = { inlinehint 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !28, i64 140}
!10 = !{!"_ZTS12CFilterCoder", !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, !23, i64 88, !24, i64 96, !25, i64 104, !26, i64 112, !27, i64 120, !29, i64 128, !28, i64 136, !28, i64 140, !28, i64 144, !30, i64 148, !30, i64 149, !31, i64 152, !31, i64 160, !32, i64 168, !33, i64 176, !28, i64 184, !28, i64 188, !28, i64 192, !34, i64 200, !35, i64 208, !36, i64 216, !37, i64 224, !38, i64 232, !39, i64 240, !40, i64 248}
!11 = !{!"_ZTS14ICompressCoder", !12, i64 0}
!12 = !{!"_ZTS8IUnknown"}
!13 = !{!"_ZTS25ICompressSetOutStreamSize", !12, i64 0}
!14 = !{!"_ZTS20ICompressInitEncoder", !12, i64 0}
!15 = !{!"_ZTS20ICompressSetInStream", !12, i64 0}
!16 = !{!"_ZTS19ISequentialInStream", !12, i64 0}
!17 = !{!"_ZTS21ICompressSetOutStream", !12, i64 0}
!18 = !{!"_ZTS20ISequentialOutStream", !12, i64 0}
!19 = !{!"_ZTS16IOutStreamFinish", !12, i64 0}
!20 = !{!"_ZTS19ICompressSetBufSize", !12, i64 0}
!21 = !{!"_ZTS18ICryptoSetPassword", !12, i64 0}
!22 = !{!"_ZTS17ICryptoProperties", !12, i64 0}
!23 = !{!"_ZTS27ICompressSetCoderProperties", !12, i64 0}
!24 = !{!"_ZTS29ICompressWriteCoderProperties", !12, i64 0}
!25 = !{!"_ZTS22ICryptoResetInitVector", !12, i64 0}
!26 = !{!"_ZTS30ICompressSetDecoderProperties2", !12, i64 0}
!27 = !{!"_ZTS13CMyUnknownImp", !28, i64 0}
!28 = !{!"int", !7, i64 0}
!29 = !{!"_ZTS17CAlignedMidBuffer", !6, i64 0}
!30 = !{!"bool", !7, i64 0}
!31 = !{!"long long", !7, i64 0}
!32 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!33 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !6, i64 0}
!34 = !{!"_ZTS9CMyComPtrI18ICryptoSetPasswordE", !6, i64 0}
!35 = !{!"_ZTS9CMyComPtrI17ICryptoPropertiesE", !6, i64 0}
!36 = !{!"_ZTS9CMyComPtrI27ICompressSetCoderPropertiesE", !6, i64 0}
!37 = !{!"_ZTS9CMyComPtrI29ICompressWriteCoderPropertiesE", !6, i64 0}
!38 = !{!"_ZTS9CMyComPtrI22ICryptoResetInitVectorE", !6, i64 0}
!39 = !{!"_ZTS9CMyComPtrI30ICompressSetDecoderProperties2E", !6, i64 0}
!40 = !{!"_ZTS9CMyComPtrI15ICompressFilterE", !6, i64 0}
!41 = !{!10, !28, i64 144}
!42 = !{!28, !28, i64 0}
!43 = !{!29, !6, i64 0}
!44 = !{!10, !28, i64 136}


; 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 void @_ZN17CAlignedMidBuffer12AllocAlignedEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147024882, 1) i32 @_ZN12CFilterCoder5AllocEv(ptr noundef nonnull align 8 dereferenceable(256) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 140
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 144
  %5 = load i32, ptr %4, align 8, !tbaa !40
  %6 = tail call noundef i32 @_Z5MyMinIjET_S0_S0_(i32 noundef %3, i32 noundef %5)
  %7 = and i32 %6, -4096
  %8 = icmp ult i32 %6, 4096
  %spec.store.select = select i1 %8, i32 4096, i32 %7
  %9 = getelementptr inbounds i8, ptr %0, i64 128
  %10 = load ptr, ptr %9, align 8, !tbaa !41
  %.not = icmp ne ptr %10, null
  %11 = getelementptr inbounds i8, ptr %0, i64 136
  %12 = load i32, ptr %11, align 8
  %.not6 = icmp eq i32 %12, %spec.store.select
  %or.cond = select i1 %.not, i1 %.not6, i1 false
  br i1 %or.cond, label %17, label %13

13:                                               ; preds = %1
  %14 = zext i32 %spec.store.select to i64
  tail call void @_ZN17CAlignedMidBuffer12AllocAlignedEm(ptr noundef nonnull align 8 dereferenceable(8) %9, i64 noundef %14)
  %15 = load ptr, ptr %9, align 8, !tbaa !41
  %.not7 = icmp eq ptr %15, null
  br i1 %.not7, label %17, label %16

16:                                               ; preds = %13
  store i32 %spec.store.select, ptr %11, align 8, !tbaa !42
  br label %17

17:                                               ; preds = %16, %1, %13
  %.0 = phi i32 [ -2147024882, %13 ], [ 0, %1 ], [ 0, %16 ]
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5MyMinIjET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #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 = { inlinehint 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" }

!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, !24, i64 140}
!6 = !{!"_ZTS12CFilterCoder", !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, !17, i64 72, !18, i64 80, !19, i64 88, !20, i64 96, !21, i64 104, !22, i64 112, !23, i64 120, !27, i64 128, !24, i64 136, !24, i64 140, !24, i64 144, !29, i64 148, !29, i64 149, !30, i64 152, !30, i64 160, !31, i64 168, !32, i64 176, !24, i64 184, !24, i64 188, !24, i64 192, !33, i64 200, !34, i64 208, !35, i64 216, !36, i64 224, !37, i64 232, !38, i64 240, !39, i64 248}
!7 = !{!"_ZTS14ICompressCoder", !8, i64 0}
!8 = !{!"_ZTS8IUnknown"}
!9 = !{!"_ZTS25ICompressSetOutStreamSize", !8, i64 0}
!10 = !{!"_ZTS20ICompressInitEncoder", !8, i64 0}
!11 = !{!"_ZTS20ICompressSetInStream", !8, i64 0}
!12 = !{!"_ZTS19ISequentialInStream", !8, i64 0}
!13 = !{!"_ZTS21ICompressSetOutStream", !8, i64 0}
!14 = !{!"_ZTS20ISequentialOutStream", !8, i64 0}
!15 = !{!"_ZTS16IOutStreamFinish", !8, i64 0}
!16 = !{!"_ZTS19ICompressSetBufSize", !8, i64 0}
!17 = !{!"_ZTS18ICryptoSetPassword", !8, i64 0}
!18 = !{!"_ZTS17ICryptoProperties", !8, i64 0}
!19 = !{!"_ZTS27ICompressSetCoderProperties", !8, i64 0}
!20 = !{!"_ZTS29ICompressWriteCoderProperties", !8, i64 0}
!21 = !{!"_ZTS22ICryptoResetInitVector", !8, i64 0}
!22 = !{!"_ZTS30ICompressSetDecoderProperties2", !8, i64 0}
!23 = !{!"_ZTS13CMyUnknownImp", !24, i64 0}
!24 = !{!"int", !25, i64 0}
!25 = !{!"omnipotent char", !26, i64 0}
!26 = !{!"Simple C++ TBAA"}
!27 = !{!"_ZTS17CAlignedMidBuffer", !28, i64 0}
!28 = !{!"any pointer", !25, i64 0}
!29 = !{!"bool", !25, i64 0}
!30 = !{!"long long", !25, i64 0}
!31 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !28, i64 0}
!32 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !28, i64 0}
!33 = !{!"_ZTS9CMyComPtrI18ICryptoSetPasswordE", !28, i64 0}
!34 = !{!"_ZTS9CMyComPtrI17ICryptoPropertiesE", !28, i64 0}
!35 = !{!"_ZTS9CMyComPtrI27ICompressSetCoderPropertiesE", !28, i64 0}
!36 = !{!"_ZTS9CMyComPtrI29ICompressWriteCoderPropertiesE", !28, i64 0}
!37 = !{!"_ZTS9CMyComPtrI22ICryptoResetInitVectorE", !28, i64 0}
!38 = !{!"_ZTS9CMyComPtrI30ICompressSetDecoderProperties2E", !28, i64 0}
!39 = !{!"_ZTS9CMyComPtrI15ICompressFilterE", !28, i64 0}
!40 = !{!6, !24, i64 144}
!41 = !{!27, !28, i64 0}
!42 = !{!6, !24, i64 136}


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