; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/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.CSequentialInStreamWithCRC = type <{ %struct.ISequentialInStream, %class.CMyUnknownImp, [4 x i8], %class.CMyComPtr, i64, i32, i8, [3 x i8] }>
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN26CSequentialInStreamWithCRC4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(37) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #0 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %12 = getelementptr inbounds %class.CSequentialInStreamWithCRC, ptr %11, i32 0, i32 3
  %13 = call noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %12)
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = load ptr, ptr %13, align 8, !tbaa !11
  %17 = getelementptr inbounds ptr, ptr %16, i64 5
  %18 = load ptr, ptr %17, align 8
  %19 = call noundef i32 %18(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef %14, i32 noundef %15, ptr noundef %9)
  store i32 %19, ptr %10, align 4, !tbaa !9
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds %class.CSequentialInStreamWithCRC, ptr %11, i32 0, i32 4
  %23 = load i64, ptr %22, align 8, !tbaa !13
  %24 = add i64 %23, %21
  store i64 %24, ptr %22, align 8, !tbaa !13
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp ugt i32 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %4
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %27
  %31 = getelementptr inbounds %class.CSequentialInStreamWithCRC, ptr %11, i32 0, i32 6
  store i8 1, ptr %31, align 4, !tbaa !21
  br label %32

32:                                               ; preds = %30, %27, %4
  %33 = getelementptr inbounds %class.CSequentialInStreamWithCRC, ptr %11, i32 0, i32 5
  %34 = load i32, ptr %33, align 8, !tbaa !22
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = call i32 @CrcUpdate(i32 noundef %34, ptr noundef %35, i64 noundef %37)
  %39 = getelementptr inbounds %class.CSequentialInStreamWithCRC, ptr %11, i32 0, i32 5
  store i32 %38, ptr %39, align 8, !tbaa !22
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %45

42:                                               ; preds = %32
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %43, ptr %44, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %42, %32
  %46 = 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 %46
}

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

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

declare i32 @CrcUpdate(i32 noundef, ptr noundef, i64 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 = { 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 = { "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, !19, i64 24}
!14 = !{!"_ZTS26CSequentialInStreamWithCRC", !15, i64 0, !17, i64 8, !18, i64 16, !19, i64 24, !10, i64 32, !20, i64 36}
!15 = !{!"_ZTS19ISequentialInStream", !16, i64 0}
!16 = !{!"_ZTS8IUnknown"}
!17 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!18 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!19 = !{!"long long", !7, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{!14, !20, i64 36}
!22 = !{!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 uwtable
define dso_local noundef i32 @_ZN26CSequentialInStreamWithCRC4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(37) %0, ptr noundef %1, i32 noundef %2, ptr noundef writeonly %3) unnamed_addr #0 align 2 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = tail call noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 40
  %10 = load ptr, ptr %9, align 8
  %11 = call noundef i32 %10(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %5)
  %12 = load i32, ptr %5, align 4
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load i64, ptr %14, align 8, !tbaa !8
  %16 = add i64 %15, %13
  store i64 %16, ptr %14, align 8, !tbaa !8
  %17 = icmp ne i32 %2, 0
  %18 = icmp eq i32 %12, 0
  %or.cond = select i1 %17, i1 %18, i1 false
  br i1 %or.cond, label %19, label %21

19:                                               ; preds = %4
  %20 = getelementptr inbounds i8, ptr %0, i64 36
  store i8 1, ptr %20, align 4, !tbaa !19
  br label %21

21:                                               ; preds = %19, %4
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  %23 = load i32, ptr %22, align 8, !tbaa !20
  %24 = call i32 @CrcUpdate(i32 noundef %23, ptr noundef %1, i64 noundef %13)
  store i32 %24, ptr %22, align 8, !tbaa !20
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %27, label %25

25:                                               ; preds = %21
  %26 = load i32, ptr %5, align 4, !tbaa !21
  store i32 %26, ptr %3, align 4, !tbaa !21
  br label %27

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

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

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

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { "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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !17, i64 24}
!9 = !{!"_ZTS26CSequentialInStreamWithCRC", !10, i64 0, !12, i64 8, !15, i64 16, !17, i64 24, !13, i64 32, !18, i64 36}
!10 = !{!"_ZTS19ISequentialInStream", !11, i64 0}
!11 = !{!"_ZTS8IUnknown"}
!12 = !{!"_ZTS13CMyUnknownImp", !13, i64 0}
!13 = !{!"int", !14, i64 0}
!14 = !{!"omnipotent char", !7, i64 0}
!15 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !16, i64 0}
!16 = !{!"any pointer", !14, i64 0}
!17 = !{!"long long", !14, i64 0}
!18 = !{!"bool", !14, i64 0}
!19 = !{!9, !18, i64 36}
!20 = !{!9, !13, i64 32}
!21 = !{!13, !13, i64 0}


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