; 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 nounwind uwtable
define dso_local noundef i32 @_ZN9NCompress5NBcj28CDecoder25GetInStreamProcessedSize2EjPy(ptr noundef nonnull align 8 dereferenceable(880) %0, i32 noundef %1, ptr noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %8, i32 0, i32 17
  %10 = getelementptr inbounds %struct.CBcj2Dec, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [4 x ptr], ptr %10, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %8, i32 0, i32 17
  %16 = getelementptr inbounds %struct.CBcj2Dec, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds [4 x ptr], ptr %16, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = ptrtoint ptr %14 to i64
  %22 = ptrtoint ptr %20 to i64
  %23 = sub i64 %21, %22
  %24 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %8, i32 0, i32 9
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [4 x i32], ptr %24, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = add nsw i64 %23, %29
  store i64 %30, ptr %7, align 8, !tbaa !11
  %31 = getelementptr inbounds %"class.NCompress::NBcj2::CDecoder", ptr %8, i32 0, i32 10
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [4 x i64], ptr %31, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !13
  %36 = load i64, ptr %7, align 8, !tbaa !11
  %37 = sub i64 %35, %36
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %37, ptr %38, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef i32 @_ZN9NCompress5NBcj28CDecoder25GetInStreamProcessedSize2EjPy(ptr nocapture noundef nonnull readonly align 8 dereferenceable(880) %0, i32 noundef %1, ptr nocapture noundef writeonly %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 264
  %5 = getelementptr inbounds i8, ptr %0, i64 296
  %6 = zext i32 %1 to i64
  %7 = getelementptr inbounds [4 x ptr], ptr %5, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds [4 x ptr], ptr %4, i64 0, i64 %6
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = ptrtoint ptr %8 to i64
  %12 = ptrtoint ptr %10 to i64
  %13 = getelementptr inbounds i8, ptr %0, i64 144
  %14 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 %6
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 160
  %18 = getelementptr inbounds [4 x i64], ptr %17, i64 0, i64 %6
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = add i64 %11, %16
  %.neg9 = sub i64 %12, %20
  %21 = add i64 %.neg9, %19
  store i64 %21, ptr %2, align 8, !tbaa !11
  ret i32 0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass