; 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: 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 @_ZN8NArchive3N7z15CFolderInStream16GetSubStreamSizeEyPy(ptr noundef nonnull align 8 dereferenceable(192) %0, i64 noundef %1, ptr noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr %8, align 4, !tbaa !11
  %14 = load i32, ptr %8, align 4, !tbaa !11
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %22, label %16

16:                                               ; preds = %3
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 15
  %19 = call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %18)
  %20 = sext i32 %19 to i64
  %21 = icmp ugt i64 %17, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %16, %3
  store i32 -2147467259, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %43

23:                                               ; preds = %16
  %24 = load i32, ptr %8, align 4, !tbaa !11
  %25 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 15
  %26 = call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %25)
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %28, label %34

28:                                               ; preds = %23
  %29 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 15
  %30 = load i32, ptr %8, align 4, !tbaa !11
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN13CRecordVectorIyEixEi(ptr noundef nonnull align 8 dereferenceable(32) %29, i32 noundef %30)
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %32, ptr %33, align 8, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %43

34:                                               ; preds = %23
  %35 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 6
  %36 = load i8, ptr %35, align 8, !tbaa !13, !range !27, !noundef !28
  %37 = trunc i8 %36 to i1
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %43

39:                                               ; preds = %34
  %40 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 7
  %41 = load i64, ptr %40, align 8, !tbaa !29
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %41, ptr %42, align 8, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %43

43:                                               ; preds = %39, %38, %28, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %44 = load i32, ptr %4, align 4
  ret i32 %44
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !21, i64 48}
!14 = !{!"_ZTSN8NArchive3N7z15CFolderInStreamE", !15, i64 0, !17, i64 8, !18, i64 16, !6, i64 24, !19, i64 32, !20, i64 40, !21, i64 48, !10, i64 56, !21, i64 64, !10, i64 72, !6, i64 80, !12, i64 88, !12, i64 92, !22, i64 96, !25, i64 128, !26, 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 = !{!"_ZTS13CRecordVectorIbE", !23, i64 0}
!23 = !{!"_ZTS17CBaseRecordVector", !12, i64 8, !12, i64 12, !6, i64 16, !24, i64 24}
!24 = !{!"long", !7, i64 0}
!25 = !{!"_ZTS13CRecordVectorIjE", !23, i64 0}
!26 = !{!"_ZTS13CRecordVectorIyE", !23, i64 0}
!27 = !{i8 0, i8 2}
!28 = !{}
!29 = !{!14, !10, i64 56}


; 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
define dso_local noundef range(i32 -2147467259, 2) i32 @_ZN8NArchive3N7z15CFolderInStream16GetSubStreamSizeEyPy(ptr noundef nonnull align 8 dereferenceable(192) %0, i64 noundef %1, ptr nocapture noundef writeonly %2) unnamed_addr #0 align 2 {
  store i64 0, ptr %2, align 8, !tbaa !5
  %4 = trunc i64 %1 to i32
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %23, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 160
  %8 = tail call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  %9 = sext i32 %8 to i64
  %10 = icmp ult i64 %9, %1
  br i1 %10, label %23, label %11

11:                                               ; preds = %6
  %12 = tail call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  %13 = icmp sgt i32 %12, %4
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN13CRecordVectorIyEixEi(ptr noundef nonnull align 8 dereferenceable(32) %7, i32 noundef %4)
  br label %.sink.split

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 48
  %18 = load i8, ptr %17, align 8, !tbaa !9, !range !25, !noundef !26
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %20, label %23

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %0, i64 56
  br label %.sink.split

.sink.split:                                      ; preds = %14, %20
  %.sink10 = phi ptr [ %21, %20 ], [ %15, %14 ]
  %22 = load i64, ptr %.sink10, align 8, !tbaa !5
  store i64 %22, ptr %2, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %.sink.split, %16, %3, %6
  %.0 = phi i32 [ -2147467259, %6 ], [ -2147467259, %3 ], [ 1, %16 ], [ 0, %.sink.split ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN13CRecordVectorIyEixEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #0 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" }

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


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