; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Archive/Common (InStreamWithCRC)

; 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.CInStreamWithCRC = type <{ %struct.IInStream, %class.CMyUnknownImp, [4 x i8], %class.CMyComPtr.0, i64, i32, [4 x i8] }>
%struct.IInStream = type { %struct.ISequentialInStream }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr.0 = type { ptr }

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

declare i32 @CrcUpdate(i32 noundef, ptr noundef, i64 noundef) #1

; 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
define dso_local noundef i32 @_ZN16CInStreamWithCRC4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(36) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = 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
  store ptr %3, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  %12 = getelementptr inbounds %class.CInStreamWithCRC, ptr %11, i32 0, i32 3
  %13 = call noundef ptr @_ZNK9CMyComPtrI9IInStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8) %12)
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %24

15:                                               ; preds = %4
  %16 = getelementptr inbounds %class.CInStreamWithCRC, ptr %11, i32 0, i32 3
  %17 = call noundef ptr @_ZNK9CMyComPtrI9IInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %16)
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load ptr, ptr %17, align 8, !tbaa !11
  %21 = getelementptr inbounds ptr, ptr %20, i64 5
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(8) %17, ptr noundef %18, i32 noundef %19, ptr noundef %9)
  store i32 %23, ptr %10, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %15, %4
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds %class.CInStreamWithCRC, ptr %11, i32 0, i32 4
  %28 = load i64, ptr %27, align 8, !tbaa !13
  %29 = add i64 %28, %26
  store i64 %29, ptr %27, align 8, !tbaa !13
  %30 = getelementptr inbounds %class.CInStreamWithCRC, ptr %11, i32 0, i32 5
  %31 = load i32, ptr %30, align 8, !tbaa !21
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = zext i32 %33 to i64
  %35 = call i32 @CrcUpdate(i32 noundef %31, ptr noundef %32, i64 noundef %34)
  %36 = getelementptr inbounds %class.CInStreamWithCRC, ptr %11, i32 0, i32 5
  store i32 %35, ptr %36, align 8, !tbaa !21
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %42

39:                                               ; preds = %24
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %40, ptr %41, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %39, %24
  %43 = load i32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %43
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI9IInStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI9IInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #3 = { 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 #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 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !20, i64 24}
!14 = !{!"_ZTS16CInStreamWithCRC", !15, i64 0, !18, i64 8, !19, i64 16, !20, i64 24, !10, i64 32}
!15 = !{!"_ZTS9IInStream", !16, i64 0}
!16 = !{!"_ZTS19ISequentialInStream", !17, i64 0}
!17 = !{!"_ZTS8IUnknown"}
!18 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!19 = !{!"_ZTS9CMyComPtrI9IInStreamE", !6, i64 0}
!20 = !{!"long long", !7, i64 0}
!21 = !{!14, !10, i64 32}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @CrcUpdate(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN16CInStreamWithCRC4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(36) %0, ptr noundef %1, i32 noundef %2, ptr noundef writeonly %3) unnamed_addr #2 align 2 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = tail call noundef ptr @_ZNK9CMyComPtrI9IInStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %15, label %8

8:                                                ; preds = %4
  %9 = tail call noundef ptr @_ZNK9CMyComPtrI9IInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 40
  %12 = load ptr, ptr %11, align 8
  %13 = call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %5)
  %.pre = load i32, ptr %5, align 4, !tbaa !5
  %14 = zext i32 %.pre to i64
  br label %15

15:                                               ; preds = %8, %4
  %16 = phi i64 [ %14, %8 ], [ 0, %4 ]
  %.0 = phi i32 [ %13, %8 ], [ 0, %4 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = add i64 %18, %16
  store i64 %19, ptr %17, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %21 = load i32, ptr %20, align 8, !tbaa !20
  %22 = call i32 @CrcUpdate(i32 noundef %21, ptr noundef %1, i64 noundef %16)
  store i32 %22, ptr %20, align 8, !tbaa !20
  %.not7 = icmp eq ptr %3, null
  br i1 %.not7, label %25, label %23

23:                                               ; preds = %15
  %24 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %24, ptr %3, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %23, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  ret i32 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI9IInStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI9IInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #3 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !19, i64 24}
!12 = !{!"_ZTS16CInStreamWithCRC", !13, i64 0, !16, i64 8, !17, i64 16, !19, i64 24, !6, i64 32}
!13 = !{!"_ZTS9IInStream", !14, i64 0}
!14 = !{!"_ZTS19ISequentialInStream", !15, i64 0}
!15 = !{!"_ZTS8IUnknown"}
!16 = !{!"_ZTS13CMyUnknownImp", !6, i64 0}
!17 = !{!"_ZTS9CMyComPtrI9IInStreamE", !18, i64 0}
!18 = !{!"any pointer", !7, i64 0}
!19 = !{!"long long", !7, i64 0}
!20 = !{!12, !6, i64 32}


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