; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/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, %class.CMyComPtr, i64, i32, i8, i64, ptr, i32, i32, %class.CMyComPtr.0, %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 { ptr, i32, i32 }
%class.CRecordVector.1 = type { ptr, i32, i32 }
%class.CRecordVector.2 = type { ptr, i32, i32 }

; 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(128) %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
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 14
  %14 = call noundef i32 @_ZNK13CRecordVectorIyE4SizeEv(ptr noundef nonnull align 8 dereferenceable(16) %13)
  %15 = zext i32 %14 to i64
  %16 = icmp ugt i64 %12, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %55

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %8, align 4, !tbaa !11
  %21 = load i32, ptr %8, align 4, !tbaa !11
  %22 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 14
  %23 = call noundef i32 @_ZNK13CRecordVectorIyE4SizeEv(ptr noundef nonnull align 8 dereferenceable(16) %22)
  %24 = icmp ult i32 %21, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %18
  %26 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 14
  %27 = load i32, ptr %8, align 4, !tbaa !11
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN13CRecordVectorIyEixEj(ptr noundef nonnull align 8 dereferenceable(16) %26, i32 noundef %27)
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %29, ptr %30, align 8, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %54

31:                                               ; preds = %18
  %32 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 6
  %33 = load i8, ptr %32, align 4, !tbaa !13, !range !25, !noundef !26
  %34 = trunc i8 %33 to i1
  br i1 %34, label %39, label %35

35:                                               ; preds = %31
  %36 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !27
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %37, ptr %38, align 8, !tbaa !9
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %54

39:                                               ; preds = %31
  %40 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 4
  %41 = load i64, ptr %40, align 8, !tbaa !27
  %42 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 7
  %43 = load i64, ptr %42, align 8, !tbaa !28
  %44 = icmp ugt i64 %41, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %39
  %46 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 4
  %47 = load i64, ptr %46, align 8, !tbaa !27
  br label %51

48:                                               ; preds = %39
  %49 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %10, i32 0, i32 7
  %50 = load i64, ptr %49, align 8, !tbaa !28
  br label %51

51:                                               ; preds = %48, %45
  %52 = phi i64 [ %47, %45 ], [ %50, %48 ]
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %52, ptr %53, align 8, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %54

54:                                               ; preds = %51, %35, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %55

55:                                               ; preds = %54, %17
  %56 = load i32, ptr %4, align 4
  ret i32 %56
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN13CRecordVectorIyEixEj(ptr noundef nonnull align 8 dereferenceable(16), 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, !20, i64 44}
!14 = !{!"_ZTSN8NArchive3N7z15CFolderInStreamE", !15, i64 0, !17, i64 8, !18, i64 16, !19, i64 24, !10, i64 32, !12, i64 40, !20, i64 44, !10, i64 48, !6, i64 56, !12, i64 64, !12, i64 68, !21, i64 72, !22, i64 80, !23, i64 96, !24, i64 112}
!15 = !{!"_ZTS19ISequentialInStream", !16, i64 0}
!16 = !{!"_ZTS8IUnknown"}
!17 = !{!"_ZTS25ICompressGetSubStreamSize", !16, i64 0}
!18 = !{!"_ZTS13CMyUnknownImp", !12, i64 0}
!19 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTS9CMyComPtrI22IArchiveUpdateCallbackE", !6, i64 0}
!22 = !{!"_ZTS13CRecordVectorIbE", !6, i64 0, !12, i64 8, !12, i64 12}
!23 = !{!"_ZTS13CRecordVectorIjE", !6, i64 0, !12, i64 8, !12, i64 12}
!24 = !{!"_ZTS13CRecordVectorIyE", !6, i64 0, !12, i64 8, !12, i64 12}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = !{!14, !10, i64 32}
!28 = !{!14, !10, i64 48}


; 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 0, 2) i32 @_ZN8NArchive3N7z15CFolderInStream16GetSubStreamSizeEyPy(ptr noundef nonnull align 8 dereferenceable(128) %0, i64 noundef %1, ptr nocapture noundef writeonly %2) unnamed_addr #0 align 2 {
  store i64 0, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 112
  %5 = tail call noundef i32 @_ZNK13CRecordVectorIyE4SizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  %6 = zext i32 %5 to i64
  %7 = icmp ult i64 %6, %1
  br i1 %7, label %24, label %8

8:                                                ; preds = %3
  %9 = trunc nuw i64 %1 to i32
  %10 = tail call noundef i32 @_ZNK13CRecordVectorIyE4SizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  %11 = icmp ugt i32 %10, %9
  br i1 %11, label %12, label %15

12:                                               ; preds = %8
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN13CRecordVectorIyEixEj(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef %9)
  %14 = load i64, ptr %13, align 8, !tbaa !5
  br label %.sink.split

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %0, i64 44
  %17 = load i8, ptr %16, align 4, !tbaa !9, !range !23, !noundef !24
  %18 = trunc nuw i8 %17 to i1
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load i64, ptr %19, align 8, !tbaa !25
  br i1 %18, label %21, label %.sink.split

21:                                               ; preds = %15
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  %23 = load i64, ptr %22, align 8, !tbaa !26
  %. = tail call i64 @llvm.umax.i64(i64 %20, i64 %23)
  br label %.sink.split

.sink.split:                                      ; preds = %15, %21, %12
  %.sink = phi i64 [ %14, %12 ], [ %., %21 ], [ %20, %15 ]
  %.1.ph = phi i32 [ 0, %12 ], [ 0, %21 ], [ 1, %15 ]
  store i64 %.sink, ptr %2, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %.sink.split, %3
  %.1 = phi i32 [ 1, %3 ], [ %.1.ph, %.sink.split ]
  ret i32 %.1
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #1

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !18, i64 44}
!10 = !{!"_ZTSN8NArchive3N7z15CFolderInStreamE", !11, i64 0, !13, i64 8, !14, i64 16, !16, i64 24, !6, i64 32, !15, i64 40, !18, i64 44, !6, i64 48, !17, i64 56, !15, i64 64, !15, i64 68, !19, i64 72, !20, i64 80, !21, i64 96, !22, i64 112}
!11 = !{!"_ZTS19ISequentialInStream", !12, i64 0}
!12 = !{!"_ZTS8IUnknown"}
!13 = !{!"_ZTS25ICompressGetSubStreamSize", !12, i64 0}
!14 = !{!"_ZTS13CMyUnknownImp", !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !17, i64 0}
!17 = !{!"any pointer", !7, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTS9CMyComPtrI22IArchiveUpdateCallbackE", !17, i64 0}
!20 = !{!"_ZTS13CRecordVectorIbE", !17, i64 0, !15, i64 8, !15, i64 12}
!21 = !{!"_ZTS13CRecordVectorIjE", !17, i64 0, !15, i64 8, !15, i64 12}
!22 = !{!"_ZTS13CRecordVectorIyE", !17, i64 0, !15, i64 8, !15, i64 12}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!10, !6, i64 32}
!26 = !{!10, !6, i64 48}


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