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

; 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.CMultiStream = type { %struct.IInStream, %class.CMyUnknownImp, i32, i64, i64, i64, %class.CObjectVector }
%struct.IInStream = type { %struct.ISequentialInStream }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%class.CMyUnknownImp = type { i32 }
%class.CObjectVector = type { %class.CRecordVector }
%class.CRecordVector = type { %class.CBaseRecordVector }
%class.CBaseRecordVector = type { ptr, i32, i32, ptr, i64 }
%"struct.CMultiStream::CSubStreamInfo" = type { %class.CMyComPtr, i64, i64 }
%class.CMyComPtr = type { ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #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: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN13CObjectVectorIN12CMultiStream14CSubStreamInfoEEixEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #2 align 2

; 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
define dso_local noundef i32 @_ZN12CMultiStream4SeekExjPy(ptr noundef nonnull align 8 dereferenceable(72) %0, i64 noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #2 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %14 = load i32, ptr %8, align 4, !tbaa !11
  switch i32 %14, label %27 [
    i32 0, label %15
    i32 1, label %17
    i32 2, label %22
  ]

15:                                               ; preds = %4
  %16 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %16, ptr %10, align 8, !tbaa !9
  br label %28

17:                                               ; preds = %4
  %18 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 4
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = add i64 %19, %20
  store i64 %21, ptr %10, align 8, !tbaa !9
  br label %28

22:                                               ; preds = %4
  %23 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 5
  %24 = load i64, ptr %23, align 8, !tbaa !23
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = add i64 %24, %25
  store i64 %26, ptr %10, align 8, !tbaa !9
  br label %28

27:                                               ; preds = %4
  store i32 -2147287039, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %92

28:                                               ; preds = %22, %17, %15
  %29 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 4
  store i64 0, ptr %29, align 8, !tbaa !13
  %30 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 2
  store i32 0, ptr %30, align 4, !tbaa !24
  br label %31

31:                                               ; preds = %75, %28
  %32 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !24
  %34 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 6
  %35 = call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %34)
  %36 = icmp slt i32 %33, %35
  br i1 %36, label %37, label %79

37:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %38 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 6
  %39 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !24
  %41 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN13CObjectVectorIN12CMultiStream14CSubStreamInfoEEixEi(ptr noundef nonnull align 8 dereferenceable(32) %38, i32 noundef %40)
  %42 = getelementptr inbounds %"struct.CMultiStream::CSubStreamInfo", ptr %41, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !25
  store i64 %43, ptr %12, align 8, !tbaa !9
  %44 = load i64, ptr %10, align 8, !tbaa !9
  %45 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 4
  %46 = load i64, ptr %45, align 8, !tbaa !13
  %47 = load i64, ptr %12, align 8, !tbaa !9
  %48 = add i64 %46, %47
  %49 = icmp ult i64 %44, %48
  br i1 %49, label %50, label %67

50:                                               ; preds = %37
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 4
  %53 = load i64, ptr %52, align 8, !tbaa !13
  %54 = sub i64 %51, %53
  %55 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 3
  store i64 %54, ptr %55, align 8, !tbaa !28
  %56 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 3
  %57 = load i64, ptr %56, align 8, !tbaa !28
  %58 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 4
  %59 = load i64, ptr %58, align 8, !tbaa !13
  %60 = add i64 %59, %57
  store i64 %60, ptr %58, align 8, !tbaa !13
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %66

63:                                               ; preds = %50
  %64 = load i64, ptr %10, align 8, !tbaa !9
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %64, ptr %65, align 8, !tbaa !9
  br label %66

66:                                               ; preds = %63, %50
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %72

67:                                               ; preds = %37
  %68 = load i64, ptr %12, align 8, !tbaa !9
  %69 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 4
  %70 = load i64, ptr %69, align 8, !tbaa !13
  %71 = add i64 %70, %68
  store i64 %71, ptr %69, align 8, !tbaa !13
  store i32 0, ptr %11, align 4
  br label %72

72:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %73 = load i32, ptr %11, align 4
  switch i32 %73, label %92 [
    i32 0, label %74
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74
  %76 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 2
  %77 = load i32, ptr %76, align 4, !tbaa !24
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %76, align 4, !tbaa !24
  br label %31, !llvm.loop !29

79:                                               ; preds = %31
  %80 = load i64, ptr %10, align 8, !tbaa !9
  %81 = getelementptr inbounds %class.CMultiStream, ptr %13, i32 0, i32 4
  %82 = load i64, ptr %81, align 8, !tbaa !13
  %83 = icmp eq i64 %80, %82
  br i1 %83, label %84, label %91

84:                                               ; preds = %79
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %90

87:                                               ; preds = %84
  %88 = load i64, ptr %10, align 8, !tbaa !9
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %88, ptr %89, align 8, !tbaa !9
  br label %90

90:                                               ; preds = %87, %84
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %92

91:                                               ; preds = %79
  store i32 -2147467259, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %92

92:                                               ; preds = %91, %90, %72, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %93 = load i32, ptr %5, align 4
  ret i32 %93
}

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 willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 24}
!14 = !{!"_ZTS12CMultiStream", !15, i64 0, !18, i64 8, !12, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !19, i64 40}
!15 = !{!"_ZTS9IInStream", !16, i64 0}
!16 = !{!"_ZTS19ISequentialInStream", !17, i64 0}
!17 = !{!"_ZTS8IUnknown"}
!18 = !{!"_ZTS13CMyUnknownImp", !12, i64 0}
!19 = !{!"_ZTS13CObjectVectorIN12CMultiStream14CSubStreamInfoEE", !20, i64 0}
!20 = !{!"_ZTS13CRecordVectorIPvE", !21, i64 0}
!21 = !{!"_ZTS17CBaseRecordVector", !12, i64 8, !12, i64 12, !6, i64 16, !22, i64 24}
!22 = !{!"long", !7, i64 0}
!23 = !{!14, !10, i64 32}
!24 = !{!14, !12, i64 12}
!25 = !{!26, !10, i64 16}
!26 = !{!"_ZTSN12CMultiStream14CSubStreamInfoE", !27, i64 0, !10, i64 8, !10, i64 16}
!27 = !{!"_ZTS9CMyComPtrI9IInStreamE", !6, i64 0}
!28 = !{!14, !10, i64 16}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


; 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 i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12CMultiStream4SeekExjPy(ptr noundef nonnull align 8 dereferenceable(72) %0, i64 noundef %1, i32 noundef %2, ptr noundef writeonly %3) unnamed_addr #1 align 2 {
  switch i32 %2, label %.thread [
    i32 0, label %13
    i32 1, label %5
    i32 2, label %9
  ]

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = add i64 %7, %1
  br label %13

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i64, ptr %10, align 8, !tbaa !20
  %12 = add i64 %11, %1
  br label %13

13:                                               ; preds = %4, %9, %5
  %.018 = phi i64 [ %12, %9 ], [ %8, %5 ], [ %1, %4 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 0, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 0, ptr %15, align 4, !tbaa !21
  %17 = tail call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %16)
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13, %28
  %19 = load i32, ptr %15, align 4, !tbaa !21
  %20 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZN13CObjectVectorIN12CMultiStream14CSubStreamInfoEEixEi(ptr noundef nonnull align 8 dereferenceable(32) %16, i32 noundef %19)
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = load i64, ptr %21, align 8, !tbaa !22
  %23 = load i64, ptr %14, align 8, !tbaa !5
  %24 = add i64 %23, %22
  %.not23 = icmp ult i64 %.018, %24
  br i1 %.not23, label %25, label %28

25:                                               ; preds = %.lr.ph
  %26 = sub i64 %.018, %23
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %26, ptr %27, align 8, !tbaa !25
  store i64 %.018, ptr %14, align 8, !tbaa !5
  %.not22 = icmp eq ptr %3, null
  br i1 %.not22, label %.thread, label %.thread.sink.split

28:                                               ; preds = %.lr.ph
  store i64 %24, ptr %14, align 8, !tbaa !5
  %29 = load i32, ptr %15, align 4, !tbaa !21
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %15, align 4, !tbaa !21
  %31 = tail call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %16)
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !26

._crit_edge:                                      ; preds = %28, %13
  %33 = load i64, ptr %14, align 8, !tbaa !5
  %34 = icmp eq i64 %.018, %33
  br i1 %34, label %35, label %.thread

35:                                               ; preds = %._crit_edge
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.thread, label %.thread.sink.split

.thread.sink.split:                               ; preds = %35, %25
  store i64 %.018, ptr %3, align 8, !tbaa !28
  br label %.thread

.thread:                                          ; preds = %.thread.sink.split, %25, %._crit_edge, %35, %4
  %.2 = phi i32 [ -2147287039, %4 ], [ 0, %35 ], [ -2147467259, %._crit_edge ], [ 0, %25 ], [ 0, %.thread.sink.split ]
  ret i32 %.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, !14, i64 24}
!6 = !{!"_ZTS12CMultiStream", !7, i64 0, !10, i64 8, !11, i64 12, !14, i64 16, !14, i64 24, !14, i64 32, !15, i64 40}
!7 = !{!"_ZTS9IInStream", !8, i64 0}
!8 = !{!"_ZTS19ISequentialInStream", !9, i64 0}
!9 = !{!"_ZTS8IUnknown"}
!10 = !{!"_ZTS13CMyUnknownImp", !11, i64 0}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"long long", !12, i64 0}
!15 = !{!"_ZTS13CObjectVectorIN12CMultiStream14CSubStreamInfoEE", !16, i64 0}
!16 = !{!"_ZTS13CRecordVectorIPvE", !17, i64 0}
!17 = !{!"_ZTS17CBaseRecordVector", !11, i64 8, !11, i64 12, !18, i64 16, !19, i64 24}
!18 = !{!"any pointer", !12, i64 0}
!19 = !{!"long", !12, i64 0}
!20 = !{!6, !14, i64 32}
!21 = !{!6, !11, i64 12}
!22 = !{!23, !14, i64 16}
!23 = !{!"_ZTSN12CMultiStream14CSubStreamInfoE", !24, i64 0, !14, i64 8, !14, i64 16}
!24 = !{!"_ZTS9CMyComPtrI9IInStreamE", !18, i64 0}
!25 = !{!6, !14, i64 16}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!14, !14, i64 0}


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