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

; 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::CFolderOutStream" = type { %struct.ISequentialOutStream, %class.CMyUnknownImp, ptr, %class.CMyComPtr, ptr, ptr, i32, i32, i32, %class.CMyComPtr.0, i8, i8, i8, i64 }
%struct.ISequentialOutStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr = type { ptr }
%class.CMyComPtr.0 = type { ptr }

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8NArchive3N7z16CFolderOutStream14FlushCorruptedEi(ptr noundef nonnull align 8 dereferenceable(88) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  br label %10

10:                                               ; preds = %54, %2
  %11 = getelementptr inbounds %"class.NArchive::N7z::CFolderOutStream", ptr %9, i32 0, i32 8
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %"class.NArchive::N7z::CFolderOutStream", ptr %9, i32 0, i32 5
  %14 = load ptr, ptr %13, align 8, !tbaa !20
  %15 = call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %14)
  %16 = icmp slt i32 %12, %15
  br i1 %16, label %17, label %55

17:                                               ; preds = %10
  %18 = getelementptr inbounds %"class.NArchive::N7z::CFolderOutStream", ptr %9, i32 0, i32 11
  %19 = load i8, ptr %18, align 1, !tbaa !21, !range !22, !noundef !23
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %43

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %22 = getelementptr inbounds %"class.NArchive::N7z::CFolderOutStream", ptr %9, i32 0, i32 9
  %23 = call noundef ptr @_ZNK9CMyComPtrI23IArchiveExtractCallbackEptEv(ptr noundef nonnull align 8 dereferenceable(8) %22)
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = load ptr, ptr %23, align 8, !tbaa !24
  %26 = getelementptr inbounds ptr, ptr %25, i64 9
  %27 = load ptr, ptr %26, align 8
  %28 = call noundef i32 %27(ptr noundef nonnull align 8 dereferenceable(8) %23, i32 noundef %24)
  store i32 %28, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %33

31:                                               ; preds = %21
  %32 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %32, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %34

33:                                               ; preds = %21
  store i32 0, ptr %7, align 4
  br label %34

34:                                               ; preds = %33, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %35 = load i32, ptr %7, align 4
  switch i32 %35, label %58 [
    i32 0, label %36
    i32 1, label %56
  ]

36:                                               ; preds = %34
  %37 = getelementptr inbounds %"class.NArchive::N7z::CFolderOutStream", ptr %9, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !26
  call void @_ZN17COutStreamWithCRC13ReleaseStreamEv(ptr noundef nonnull align 8 dereferenceable(37) %38)
  %39 = getelementptr inbounds %"class.NArchive::N7z::CFolderOutStream", ptr %9, i32 0, i32 11
  store i8 0, ptr %39, align 1, !tbaa !21
  %40 = getelementptr inbounds %"class.NArchive::N7z::CFolderOutStream", ptr %9, i32 0, i32 8
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %40, align 8, !tbaa !11
  br label %54

43:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %44 = call noundef i32 @_ZN8NArchive3N7z16CFolderOutStream8OpenFileEv(ptr noundef nonnull align 8 dereferenceable(88) %9)
  store i32 %44, ptr %8, align 4, !tbaa !9
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %48, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

49:                                               ; preds = %43
  store i32 0, ptr %7, align 4
  br label %50

50:                                               ; preds = %49, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %51 = load i32, ptr %7, align 4
  switch i32 %51, label %58 [
    i32 0, label %52
    i32 1, label %56
  ]

52:                                               ; preds = %50
  %53 = getelementptr inbounds %"class.NArchive::N7z::CFolderOutStream", ptr %9, i32 0, i32 11
  store i8 1, ptr %53, align 1, !tbaa !21
  br label %54

54:                                               ; preds = %52, %36
  br label %10, !llvm.loop !27

55:                                               ; preds = %10
  store i32 0, ptr %3, align 4
  br label %56

56:                                               ; preds = %55, %50, %34
  %57 = load i32, ptr %3, align 4
  ret i32 %57

58:                                               ; preds = %50, %34
  unreachable
}

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 56}
!12 = !{!"_ZTSN8NArchive3N7z16CFolderOutStreamE", !13, i64 0, !15, i64 8, !6, i64 16, !16, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !17, i64 64, !18, i64 72, !18, i64 73, !18, i64 74, !19, i64 80}
!13 = !{!"_ZTS20ISequentialOutStream", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!16 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !6, i64 0}
!17 = !{!"_ZTS9CMyComPtrI23IArchiveExtractCallbackE", !6, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"long long", !7, i64 0}
!20 = !{!12, !6, i64 40}
!21 = !{!12, !18, i64 73}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !8, i64 0}
!26 = !{!12, !6, i64 16}
!27 = distinct !{!27, !28}
!28 = !{!"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 uwtable
declare dso_local noundef i32 @_ZN8NArchive3N7z16CFolderOutStream8OpenFileEv(ptr noundef nonnull align 8 dereferenceable(88)) local_unnamed_addr #0 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8NArchive3N7z16CFolderOutStream14FlushCorruptedEi(ptr noundef nonnull align 8 dereferenceable(88) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load i32, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !18
  %8 = tail call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  %9 = icmp slt i32 %6, %8
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 73
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  br label %12

12:                                               ; preds = %.lr.ph, %28
  %13 = load i8, ptr %10, align 1, !tbaa !19, !range !20, !noundef !21
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %15, label %25

15:                                               ; preds = %12
  %16 = tail call noundef ptr @_ZNK9CMyComPtrI23IArchiveExtractCallbackEptEv(ptr noundef nonnull align 8 dereferenceable(8) %3)
  %17 = load ptr, ptr %16, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %17, i64 72
  %19 = load ptr, ptr %18, align 8
  %20 = tail call noundef i32 %19(ptr noundef nonnull align 8 dereferenceable(8) %16, i32 noundef %1)
  %.not12.not = icmp eq i32 %20, 0
  br i1 %.not12.not, label %21, label %._crit_edge

21:                                               ; preds = %15
  %22 = load ptr, ptr %11, align 8, !tbaa !24
  tail call void @_ZN17COutStreamWithCRC13ReleaseStreamEv(ptr noundef nonnull align 8 dereferenceable(37) %22)
  store i8 0, ptr %10, align 1, !tbaa !19
  %23 = load i32, ptr %4, align 8, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %4, align 8, !tbaa !5
  br label %28

25:                                               ; preds = %12
  %26 = tail call noundef i32 @_ZN8NArchive3N7z16CFolderOutStream8OpenFileEv(ptr noundef nonnull align 8 dereferenceable(88) %0)
  %.not.not = icmp eq i32 %26, 0
  br i1 %.not.not, label %27, label %._crit_edge

27:                                               ; preds = %25
  store i8 1, ptr %10, align 1, !tbaa !19
  %.pre = load i32, ptr %4, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %27, %21
  %29 = phi i32 [ %.pre, %27 ], [ %24, %21 ]
  %30 = load ptr, ptr %5, align 8, !tbaa !18
  %31 = tail call noundef i32 @_ZNK17CBaseRecordVector4SizeEv(ptr noundef nonnull align 8 dereferenceable(32) %30)
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %12, label %._crit_edge, !llvm.loop !25

._crit_edge:                                      ; preds = %28, %15, %25, %2
  %.4 = phi i32 [ 0, %2 ], [ %26, %25 ], [ %20, %15 ], [ 0, %28 ]
  ret i32 %.4
}

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 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, !10, i64 56}
!6 = !{!"_ZTSN8NArchive3N7z16CFolderOutStreamE", !7, i64 0, !9, i64 8, !13, i64 16, !14, i64 24, !13, i64 32, !13, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !15, i64 64, !16, i64 72, !16, i64 73, !16, i64 74, !17, i64 80}
!7 = !{!"_ZTS20ISequentialOutStream", !8, i64 0}
!8 = !{!"_ZTS8IUnknown"}
!9 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"any pointer", !11, i64 0}
!14 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !13, i64 0}
!15 = !{!"_ZTS9CMyComPtrI23IArchiveExtractCallbackE", !13, i64 0}
!16 = !{!"bool", !11, i64 0}
!17 = !{!"long long", !11, i64 0}
!18 = !{!6, !13, i64 40}
!19 = !{!6, !16, i64 73}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !12, i64 0}
!24 = !{!6, !13, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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