; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/lzma/C/7zip/Common/OutBuffer.ll (ZN10COutBuffer9FlushPartEv)

; 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.COutBuffer = type <{ ptr, i32, i32, i32, i32, %class.CMyComPtr, i64, ptr, i8, [7 x i8] }>
%class.CMyComPtr = type { ptr }

; 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 @_ZN10COutBuffer9FlushPartEv(ptr noundef nonnull align 8 dereferenceable(49) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %7 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !15
  %11 = icmp uge i32 %8, %10
  br i1 %11, label %12, label %18

12:                                               ; preds = %1
  %13 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 4
  %14 = load i32, ptr %13, align 4, !tbaa !16
  %15 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = sub i32 %14, %16
  br label %24

18:                                               ; preds = %1
  %19 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = sub i32 %20, %22
  br label %24

24:                                               ; preds = %18, %12
  %25 = phi i32 [ %17, %12 ], [ %23, %18 ]
  store i32 %25, ptr %3, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !17
  %26 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 7
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %45

29:                                               ; preds = %24
  %30 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 7
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %35 = load i32, ptr %34, align 8, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  %38 = load i32, ptr %3, align 4, !tbaa !17
  %39 = zext i32 %38 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %31, ptr align 1 %37, i64 %39, i1 false)
  %40 = load i32, ptr %3, align 4, !tbaa !17
  %41 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 7
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = zext i32 %40 to i64
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  store ptr %44, ptr %41, align 8, !tbaa !18
  br label %45

45:                                               ; preds = %29, %24
  %46 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 5
  %47 = call noundef ptr @_ZNK9CMyComPtrI20ISequentialOutStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8) %46)
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %64

49:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !17
  %50 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 5
  %51 = call noundef ptr @_ZNK9CMyComPtrI20ISequentialOutStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %50)
  %52 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  %54 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %55 = load i32, ptr %54, align 8, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %53, i64 %56
  %58 = load i32, ptr %3, align 4, !tbaa !17
  %59 = load ptr, ptr %51, align 8, !tbaa !20
  %60 = getelementptr inbounds ptr, ptr %59, i64 3
  %61 = load ptr, ptr %60, align 8
  %62 = call noundef i32 %61(ptr noundef nonnull align 8 dereferenceable(8) %51, ptr noundef %57, i32 noundef %58, ptr noundef %5)
  store i32 %62, ptr %4, align 4, !tbaa !17
  %63 = load i32, ptr %5, align 4, !tbaa !17
  store i32 %63, ptr %3, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %64

64:                                               ; preds = %49, %45
  %65 = load i32, ptr %3, align 4, !tbaa !17
  %66 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %67 = load i32, ptr %66, align 8, !tbaa !9
  %68 = add i32 %67, %65
  store i32 %68, ptr %66, align 8, !tbaa !9
  %69 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %70 = load i32, ptr %69, align 8, !tbaa !9
  %71 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 4
  %72 = load i32, ptr %71, align 4, !tbaa !16
  %73 = icmp eq i32 %70, %72
  br i1 %73, label %74, label %76

74:                                               ; preds = %64
  %75 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  store i32 0, ptr %75, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %74, %64
  %77 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 1
  %78 = load i32, ptr %77, align 8, !tbaa !15
  %79 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 4
  %80 = load i32, ptr %79, align 4, !tbaa !16
  %81 = icmp eq i32 %78, %80
  br i1 %81, label %82, label %85

82:                                               ; preds = %76
  %83 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 8
  store i8 1, ptr %83, align 8, !tbaa !22
  %84 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 1
  store i32 0, ptr %84, align 8, !tbaa !15
  br label %85

85:                                               ; preds = %82, %76
  %86 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %87 = load i32, ptr %86, align 8, !tbaa !9
  %88 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 1
  %89 = load i32, ptr %88, align 8, !tbaa !15
  %90 = icmp ugt i32 %87, %89
  br i1 %90, label %91, label %94

91:                                               ; preds = %85
  %92 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 3
  %93 = load i32, ptr %92, align 8, !tbaa !9
  br label %97

94:                                               ; preds = %85
  %95 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 4
  %96 = load i32, ptr %95, align 4, !tbaa !16
  br label %97

97:                                               ; preds = %94, %91
  %98 = phi i32 [ %93, %91 ], [ %96, %94 ]
  %99 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 2
  store i32 %98, ptr %99, align 4, !tbaa !23
  %100 = load i32, ptr %3, align 4, !tbaa !17
  %101 = zext i32 %100 to i64
  %102 = getelementptr inbounds %class.COutBuffer, ptr %6, i32 0, i32 6
  %103 = load i64, ptr %102, align 8, !tbaa !24
  %104 = add i64 %103, %101
  store i64 %104, ptr %102, align 8, !tbaa !24
  %105 = load i32, ptr %4, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %105
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9CMyComPtrI20ISequentialOutStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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, !11, i64 16}
!10 = !{!"_ZTS10COutBuffer", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !12, i64 24, !13, i64 32, !6, i64 40, !14, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !6, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !11, i64 20}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !6, i64 40}
!19 = !{!10, !6, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !8, i64 0}
!22 = !{!10, !14, i64 48}
!23 = !{!10, !11, i64 12}
!24 = !{!10, !13, i64 32}


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

; Function Attrs: mustprogress 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 @_ZN10COutBuffer9FlushPartEv(ptr noundef nonnull align 8 dereferenceable(49) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !14
  %.not = icmp ult i32 %4, %6
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  %8 = load i32, ptr %7, align 4
  %.pn = select i1 %.not, i32 %6, i32 %8
  %9 = sub i32 %.pn, %4
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %.not11 = icmp eq ptr %11, null
  br i1 %.not11, label %19, label %12

12:                                               ; preds = %1
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = zext i32 %4 to i64
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  %16 = zext i32 %9 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %11, ptr align 1 %15, i64 %16, i1 false)
  %17 = load ptr, ptr %10, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %17, i64 %16
  store ptr %18, ptr %10, align 8, !tbaa !15
  br label %19

19:                                               ; preds = %12, %1
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = tail call noundef ptr @_ZNK9CMyComPtrI20ISequentialOutStreamEcvPS0_Ev(ptr noundef nonnull align 8 dereferenceable(8) %20)
  %.not12 = icmp eq ptr %21, null
  br i1 %.not12, label %33, label %22

22:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 0, ptr %2, align 4, !tbaa !17
  %23 = tail call noundef ptr @_ZNK9CMyComPtrI20ISequentialOutStreamEptEv(ptr noundef nonnull align 8 dereferenceable(8) %20)
  %24 = load ptr, ptr %0, align 8, !tbaa !16
  %25 = load i32, ptr %3, align 8, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = load ptr, ptr %23, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %28, i64 24
  %30 = load ptr, ptr %29, align 8
  %31 = call noundef i32 %30(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef %27, i32 noundef %9, ptr noundef nonnull %2)
  %32 = load i32, ptr %2, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %33

33:                                               ; preds = %22, %19
  %.06 = phi i32 [ %32, %22 ], [ %9, %19 ]
  %.0 = phi i32 [ %31, %22 ], [ 0, %19 ]
  %34 = load i32, ptr %3, align 8, !tbaa !5
  %35 = add i32 %34, %.06
  %36 = load i32, ptr %7, align 4
  %37 = icmp eq i32 %35, %36
  %spec.store.select = select i1 %37, i32 0, i32 %35
  store i32 %spec.store.select, ptr %3, align 8
  %38 = load i32, ptr %5, align 8, !tbaa !14
  %39 = icmp eq i32 %38, %36
  br i1 %39, label %40, label %42

40:                                               ; preds = %33
  %41 = getelementptr inbounds i8, ptr %0, i64 48
  store i8 1, ptr %41, align 8, !tbaa !20
  store i32 0, ptr %5, align 8, !tbaa !14
  br label %42

42:                                               ; preds = %40, %33
  %43 = phi i32 [ 0, %40 ], [ %38, %33 ]
  %44 = icmp ugt i32 %spec.store.select, %43
  %45 = select i1 %44, i32 %spec.store.select, i32 %36
  %46 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %45, ptr %46, align 4, !tbaa !21
  %47 = zext i32 %.06 to i64
  %48 = getelementptr inbounds i8, ptr %0, i64 32
  %49 = load i64, ptr %48, align 8, !tbaa !22
  %50 = add i64 %49, %47
  store i64 %50, ptr %48, align 8, !tbaa !22
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

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

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

attributes #0 = { mustprogress 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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, !10, i64 16}
!6 = !{!"_ZTS10COutBuffer", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !11, i64 24, !12, i64 32, !7, i64 40, !13, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS9CMyComPtrI20ISequentialOutStreamE", !7, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!6, !10, i64 8}
!15 = !{!6, !7, i64 40}
!16 = !{!6, !7, i64 0}
!17 = !{!10, !10, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !9, i64 0}
!20 = !{!6, !13, i64 48}
!21 = !{!6, !10, i64 12}
!22 = !{!6, !12, i64 32}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass