; 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: mustprogress uwtable
declare dso_local noundef i32 @_ZN8NArchive3N7z15CFolderInStream10OpenStreamEv(ptr noundef nonnull align 8 dereferenceable(192)) #0 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8NArchive3N7z15CFolderInStream4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %92, %80, %4
  %18 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %16, i32 0, i32 12
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %16, i32 0, i32 11
  %21 = load i32, ptr %20, align 8, !tbaa !26
  %22 = icmp ult i32 %19, %21
  br i1 %22, label %27, label %23

23:                                               ; preds = %17
  %24 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %16, i32 0, i32 8
  %25 = load i8, ptr %24, align 8, !tbaa !27, !range !28, !noundef !29
  %26 = trunc i8 %25 to i1
  br i1 %26, label %27, label %30

27:                                               ; preds = %23, %17
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp ugt i32 %28, 0
  br label %30

30:                                               ; preds = %27, %23
  %31 = phi i1 [ false, %23 ], [ %29, %27 ]
  br i1 %31, label %32, label %93

32:                                               ; preds = %30
  %33 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %16, i32 0, i32 8
  %34 = load i8, ptr %33, align 8, !tbaa !27, !range !28, !noundef !29
  %35 = trunc i8 %34 to i1
  br i1 %35, label %36, label %82

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %37 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %16, i32 0, i32 4
  %38 = call noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %37)
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load ptr, ptr %38, align 8, !tbaa !30
  %45 = getelementptr inbounds ptr, ptr %44, i64 5
  %46 = load ptr, ptr %45, align 8
  %47 = call noundef i32 %46(ptr noundef nonnull align 8 dereferenceable(8) %38, ptr noundef %42, i32 noundef %43, ptr noundef %11)
  store i32 %47, ptr %12, align 4, !tbaa !9
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %52

50:                                               ; preds = %36
  %51 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %51, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %53

52:                                               ; preds = %36
  store i32 0, ptr %13, align 4
  br label %53

53:                                               ; preds = %52, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %54 = load i32, ptr %13, align 4
  switch i32 %54, label %80 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %68

58:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %59 = call noundef i32 @_ZN8NArchive3N7z15CFolderInStream11CloseStreamEv(ptr noundef nonnull align 8 dereferenceable(192) %16)
  store i32 %59, ptr %14, align 4, !tbaa !9
  %60 = load i32, ptr %14, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %58
  %63 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %63, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %65

64:                                               ; preds = %58
  store i32 0, ptr %13, align 4
  br label %65

65:                                               ; preds = %64, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %66 = load i32, ptr %13, align 4
  switch i32 %66, label %80 [
    i32 0, label %67
  ]

67:                                               ; preds = %65
  store i32 2, ptr %13, align 4
  br label %80, !llvm.loop !32

68:                                               ; preds = %55
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = add i32 %70, %69
  store i32 %71, ptr %10, align 4, !tbaa !9
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds %"class.NArchive::N7z::CFolderInStream", ptr %16, i32 0, i32 9
  %75 = load i64, ptr %74, align 8, !tbaa !34
  %76 = add i64 %75, %73
  store i64 %76, ptr %74, align 8, !tbaa !34
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = sub i32 %78, %77
  store i32 %79, ptr %8, align 4, !tbaa !9
  store i32 3, ptr %13, align 4
  br label %80

80:                                               ; preds = %68, %67, %65, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %81 = load i32, ptr %13, align 4
  switch i32 %81, label %100 [
    i32 2, label %17
    i32 3, label %93
  ]

82:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %83 = call noundef i32 @_ZN8NArchive3N7z15CFolderInStream10OpenStreamEv(ptr noundef nonnull align 8 dereferenceable(192) %16)
  store i32 %83, ptr %15, align 4, !tbaa !9
  %84 = load i32, ptr %15, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %88

86:                                               ; preds = %82
  %87 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %87, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %89

88:                                               ; preds = %82
  store i32 0, ptr %13, align 4
  br label %89

89:                                               ; preds = %88, %86
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  %90 = load i32, ptr %13, align 4
  switch i32 %90, label %100 [
    i32 0, label %91
  ]

91:                                               ; preds = %89
  br label %92

92:                                               ; preds = %91
  br label %17, !llvm.loop !32

93:                                               ; preds = %80, %30
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = icmp ne ptr %94, null
  br i1 %95, label %96, label %99

96:                                               ; preds = %93
  %97 = load i32, ptr %10, align 4, !tbaa !9
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %97, ptr %98, align 4, !tbaa !9
  br label %99

99:                                               ; preds = %96, %93
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %100

100:                                              ; preds = %99, %89, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %101 = load i32, ptr %5, align 4
  ret i32 %101
}

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

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 = { 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, !10, i64 92}
!12 = !{!"_ZTSN8NArchive3N7z15CFolderInStreamE", !13, i64 0, !15, i64 8, !16, i64 16, !6, i64 24, !17, i64 32, !18, i64 40, !19, i64 48, !20, i64 56, !19, i64 64, !20, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !21, i64 96, !24, i64 128, !25, i64 160}
!13 = !{!"_ZTS19ISequentialInStream", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS25ICompressGetSubStreamSize", !14, i64 0}
!16 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!17 = !{!"_ZTS9CMyComPtrI19ISequentialInStreamE", !6, i64 0}
!18 = !{!"_ZTS9CMyComPtrI22IArchiveUpdateCallbackE", !6, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"long long", !7, i64 0}
!21 = !{!"_ZTS13CRecordVectorIbE", !22, i64 0}
!22 = !{!"_ZTS17CBaseRecordVector", !10, i64 8, !10, i64 12, !6, i64 16, !23, i64 24}
!23 = !{!"long", !7, i64 0}
!24 = !{!"_ZTS13CRecordVectorIjE", !22, i64 0}
!25 = !{!"_ZTS13CRecordVectorIyE", !22, i64 0}
!26 = !{!12, !10, i64 88}
!27 = !{!12, !19, i64 64}
!28 = !{i8 0, i8 2}
!29 = !{}
!30 = !{!31, !31, i64 0}
!31 = !{!"vtable pointer", !8, i64 0}
!32 = distinct !{!32, !33}
!33 = !{!"llvm.loop.mustprogress"}
!34 = !{!12, !20, 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 uwtable
declare dso_local noundef i32 @_ZN8NArchive3N7z15CFolderInStream10OpenStreamEv(ptr noundef nonnull align 8 dereferenceable(192)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8NArchive3N7z15CFolderInStream4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1, i32 noundef %2, ptr noundef writeonly %3) unnamed_addr #0 align 2 {
  %5 = alloca i32, align 4
  %6 = getelementptr inbounds i8, ptr %0, i64 92
  %7 = getelementptr inbounds i8, ptr %0, i64 88
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  %.not67 = icmp eq i32 %2, 0
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %.not67, label %.critedge, label %.split.split

.split.split:                                     ; preds = %4, %.split.split.backedge
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr %7, align 8, !tbaa !24
  %12 = icmp ult i32 %10, %11
  %.pre = load i8, ptr %8, align 8, !tbaa !25, !range !26
  %.pre69 = trunc nuw i8 %.pre to i1
  br i1 %12, label %14, label %13

13:                                               ; preds = %.split.split
  br i1 %.pre69, label %.thread70, label %.critedge

14:                                               ; preds = %.split.split
  br i1 %.pre69, label %.thread70, label %30

.thread70:                                        ; preds = %13, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %15 = call noundef ptr @_ZNK9CMyComPtrI19ISequentialInStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %9)
  %16 = load ptr, ptr %15, align 8, !tbaa !27
  %17 = getelementptr inbounds i8, ptr %16, i64 40
  %18 = load ptr, ptr %17, align 8
  %19 = call noundef i32 %18(ptr noundef nonnull align 8 dereferenceable(8) %15, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %5)
  %.not38 = icmp eq i32 %19, 0
  br i1 %.not38, label %20, label %.thread

20:                                               ; preds = %.thread70
  %21 = load i32, ptr %5, align 4, !tbaa !29
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %.thread46

23:                                               ; preds = %20
  %24 = call noundef i32 @_ZN8NArchive3N7z15CFolderInStream11CloseStreamEv(ptr noundef nonnull align 8 dereferenceable(192) %0)
  %.not39 = icmp eq i32 %24, 0
  br i1 %.not39, label %29, label %.thread

.thread46:                                        ; preds = %20
  %25 = zext i32 %21 to i64
  %26 = getelementptr inbounds i8, ptr %0, i64 72
  %27 = load i64, ptr %26, align 8, !tbaa !30
  %28 = add i64 %27, %25
  store i64 %28, ptr %26, align 8, !tbaa !30
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %.critedge

.thread:                                          ; preds = %23, %.thread70
  %.us-phi52 = phi i32 [ %19, %.thread70 ], [ %24, %23 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %.loopexit

29:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %.split.split.backedge

30:                                               ; preds = %14
  %31 = call noundef i32 @_ZN8NArchive3N7z15CFolderInStream10OpenStreamEv(ptr noundef nonnull align 8 dereferenceable(192) %0)
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %.split.split.backedge, label %.loopexit

.split.split.backedge:                            ; preds = %30, %29
  br label %.split.split, !llvm.loop !31

.critedge:                                        ; preds = %13, %4, %.thread46
  %.232 = phi i32 [ %21, %.thread46 ], [ 0, %4 ], [ 0, %13 ]
  %.not40 = icmp eq ptr %3, null
  br i1 %.not40, label %.loopexit, label %32

32:                                               ; preds = %.critedge
  store i32 %.232, ptr %3, align 4, !tbaa !29
  br label %.loopexit

.loopexit:                                        ; preds = %30, %.thread, %.critedge, %32
  %.5 = phi i32 [ 0, %32 ], [ 0, %.critedge ], [ %.us-phi52, %.thread ], [ %31, %30 ]
  ret i32 %.5
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass