; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/CPP/7zip/Archive/7z (7zFolderInStream)

; 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.NArchive::N7z::CFolderInStream" = type { %struct.ISequentialInStream, %struct.ICompressGetSubStreamSize, %class.CMyUnknownImp, ptr, %class.CMyComPtr, %class.CMyComPtr.0, i8, i64, i8, i64, ptr, i32, i32, %class.CRecordVector, %class.CRecordVector.1, %class.CRecordVector.2 }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICompressGetSubStreamSize = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr = type { ptr }
%class.CMyComPtr.0 = type { ptr }
%class.CRecordVector = type { %class.CBaseRecordVector }
%class.CBaseRecordVector = type { ptr, i32, i32, ptr, i64 }
%class.CRecordVector.1 = type { %class.CBaseRecordVector }
%class.CRecordVector.2 = type { %class.CBaseRecordVector }

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

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

; 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
declare dso_local noundef i32 @_ZN13CRecordVectorIyE3AddEy(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN13CRecordVectorIbE3AddEb(ptr noundef nonnull align 8 dereferenceable(32), i1 noundef zeroext) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8NArchive3N7z15CFolderInStream9AddDigestEv(ptr noundef nonnull align 8 dereferenceable(192)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8NArchive3N7z15CFolderInStream11CloseStreamEv(ptr noundef nonnull align 8 dereferenceable(192) %0) #2 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %7 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %6, i32 0, i32 5
  %8 = call noundef ptr @_ZNK9CMyComPtrI22IArchiveUpdateCallbackEptEv(ptr noundef nonnull align 8 dereferenceable(8) %7)
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds ptr, ptr %9, i64 10
  %11 = load ptr, ptr %10, align 8
  %12 = call noundef i32 %11(ptr noundef nonnull align 8 dereferenceable(8) %8, i32 noundef 0)
  store i32 %12, ptr %4, align 4, !tbaa !11
  %13 = load i32, ptr %4, align 4, !tbaa !11
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %1
  %16 = load i32, ptr %4, align 4, !tbaa !11
  store i32 %16, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %18

17:                                               ; preds = %1
  store i32 0, ptr %5, align 4
  br label %18

18:                                               ; preds = %17, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %19 = load i32, ptr %5, align 4
  switch i32 %19, label %32 [
    i32 0, label %20
    i32 1, label %30
  ]

20:                                               ; preds = %18
  %21 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %6, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  call void @_ZN26CSequentialInStreamWithCRC13ReleaseStreamEv(ptr noundef nonnull align 8 dereferenceable(37) %22)
  %23 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %6, i32 0, i32 8
  store i8 0, ptr %23, align 8, !tbaa !28
  %24 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %6, i32 0, i32 13
  %25 = call noundef i32 @_ZN13CRecordVectorIbE3AddEb(ptr noundef nonnull align 8 dereferenceable(32) %24, i1 noundef zeroext true)
  %26 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %6, i32 0, i32 15
  %27 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %6, i32 0, i32 9
  %28 = load i64, ptr %27, align 8, !tbaa !29
  %29 = call noundef i32 @_ZN13CRecordVectorIyE3AddEy(ptr noundef nonnull align 8 dereferenceable(32) %26, i64 noundef %28)
  call void @_ZN8NArchive3N7z15CFolderInStream9AddDigestEv(ptr noundef nonnull align 8 dereferenceable(192) %6)
  store i32 0, ptr %2, align 4
  br label %30

30:                                               ; preds = %20, %18
  %31 = load i32, ptr %2, align 4
  ret i32 %31

32:                                               ; preds = %18
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN26CSequentialInStreamWithCRC13ReleaseStreamEv(ptr noundef nonnull align 8 dereferenceable(37)) #2 align 2

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 = { 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 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"_ZTSN8NArchive3N7z15CFolderInStreamE", !15, i64 0, !17, i64 8, !18, i64 16, !6, i64 24, !19, i64 32, !20, i64 40, !21, i64 48, !22, i64 56, !21, i64 64, !22, i64 72, !6, i64 80, !12, i64 88, !12, i64 92, !23, i64 96, !26, i64 128, !27, i64 160}
!15 = !{!"_ZTS19ISequentialInStream", !16, i64 0}
!16 = !{!"_ZTS8IUnknown"}
!17 = !{!"_ZTS25ICompressGetSubStreamSize", !16, i64 0}
!18 = !{!"_ZTS13CMyUnknownImp", !12, i64 0}
!19 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!20 = !{!"_ZTS9CMyComPtrI22IArchiveUpdateCallbackE", !6, i64 0}
!21 = !{!"bool", !7, i64 0}
!22 = !{!"long long", !7, i64 0}
!23 = !{!"_ZTS13CRecordVectorIbE", !24, i64 0}
!24 = !{!"_ZTS17CBaseRecordVector", !12, i64 8, !12, i64 12, !6, i64 16, !25, i64 24}
!25 = !{!"long", !7, i64 0}
!26 = !{!"_ZTS13CRecordVectorIjE", !24, i64 0}
!27 = !{!"_ZTS13CRecordVectorIyE", !24, i64 0}
!28 = !{!14, !21, i64 64}
!29 = !{!14, !22, i64 72}


; 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 nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI22IArchiveUpdateCallbackEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN13CRecordVectorIyE3AddEy(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN13CRecordVectorIbE3AddEb(ptr noundef nonnull align 8 dereferenceable(32), i1 noundef zeroext) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8NArchive3N7z15CFolderInStream9AddDigestEv(ptr noundef nonnull align 8 dereferenceable(192)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8NArchive3N7z15CFolderInStream11CloseStreamEv(ptr noundef nonnull align 8 dereferenceable(192) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = tail call noundef ptr @_ZNK9CMyComPtrI22IArchiveUpdateCallbackEptEv(ptr noundef nonnull align 8 dereferenceable(8) %2)
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 80
  %6 = load ptr, ptr %5, align 8
  %7 = tail call noundef i32 %6(ptr noundef nonnull align 8 dereferenceable(8) %3, i32 noundef 0)
  %.not.not = icmp eq i32 %7, 0
  br i1 %.not.not, label %8, label %18

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !8
  tail call void @_ZN26CSequentialInStreamWithCRC13ReleaseStreamEv(ptr noundef nonnull align 8 dereferenceable(37) %10)
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  store i8 0, ptr %11, align 8, !tbaa !26
  %12 = getelementptr inbounds i8, ptr %0, i64 96
  %13 = tail call noundef i32 @_ZN13CRecordVectorIbE3AddEb(ptr noundef nonnull align 8 dereferenceable(32) %12, i1 noundef zeroext true)
  %14 = getelementptr inbounds i8, ptr %0, i64 160
  %15 = getelementptr inbounds i8, ptr %0, i64 72
  %16 = load i64, ptr %15, align 8, !tbaa !27
  %17 = tail call noundef i32 @_ZN13CRecordVectorIyE3AddEy(ptr noundef nonnull align 8 dereferenceable(32) %14, i64 noundef %16)
  tail call void @_ZN8NArchive3N7z15CFolderInStream9AddDigestEv(ptr noundef nonnull align 8 dereferenceable(192) %0)
  br label %18

18:                                               ; preds = %1, %8
  ret i32 %7
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN26CSequentialInStreamWithCRC13ReleaseStreamEv(ptr noundef nonnull align 8 dereferenceable(37)) local_unnamed_addr #1 align 2

attributes #0 = { 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 #1 = { 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" }

!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, !16, i64 24}
!9 = !{!"_ZTSN8NArchive3N7z15CFolderInStreamE", !10, i64 0, !12, i64 8, !13, i64 16, !16, i64 24, !17, i64 32, !18, i64 40, !19, i64 48, !20, i64 56, !19, i64 64, !20, i64 72, !16, i64 80, !14, i64 88, !14, i64 92, !21, i64 96, !24, i64 128, !25, i64 160}
!10 = !{!"_ZTS19ISequentialInStream", !11, i64 0}
!11 = !{!"_ZTS8IUnknown"}
!12 = !{!"_ZTS25ICompressGetSubStreamSize", !11, i64 0}
!13 = !{!"_ZTS13CMyUnknownImp", !14, i64 0}
!14 = !{!"int", !15, i64 0}
!15 = !{!"omnipotent char", !7, i64 0}
!16 = !{!"any pointer", !15, i64 0}
!17 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !16, i64 0}
!18 = !{!"_ZTS9CMyComPtrI22IArchiveUpdateCallbackE", !16, i64 0}
!19 = !{!"bool", !15, i64 0}
!20 = !{!"long long", !15, i64 0}
!21 = !{!"_ZTS13CRecordVectorIbE", !22, i64 0}
!22 = !{!"_ZTS17CBaseRecordVector", !14, i64 8, !14, i64 12, !16, i64 16, !23, i64 24}
!23 = !{!"long", !15, i64 0}
!24 = !{!"_ZTS13CRecordVectorIjE", !22, i64 0}
!25 = !{!"_ZTS13CRecordVectorIyE", !22, i64 0}
!26 = !{!9, !19, i64 64}
!27 = !{!9, !20, i64 72}


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