; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/CPP/7zip/Compress/LZMA_Alone (LzmaBench)

; 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.CBenchmarkInStream = type { %struct.ISequentialInStream, %class.CMyUnknownImp, ptr, i64, i64 }
%struct.ISequentialInStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%class.CMyUnknownImp = type { i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN18CBenchmarkInStream4ReadEPvjPj(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %13 = getelementptr inbounds %class.CBenchmarkInStream, ptr %12, i32 0, i32 4
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %class.CBenchmarkInStream, ptr %12, i32 0, i32 3
  %16 = load i64, ptr %15, align 8, !tbaa !17
  %17 = sub i64 %14, %16
  store i64 %17, ptr %9, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 1048576, ptr %10, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = icmp ugt i32 %18, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %4
  %22 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %22, ptr %7, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %21, %4
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = load i64, ptr %9, align 8, !tbaa !18
  %27 = icmp ugt i64 %25, %26
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = load i64, ptr %9, align 8, !tbaa !18
  %30 = trunc i64 %29 to i32
  store i32 %30, ptr %7, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %28, %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %51, %31
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = icmp ult i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %54

37:                                               ; preds = %32
  %38 = getelementptr inbounds %class.CBenchmarkInStream, ptr %12, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !19
  %40 = getelementptr inbounds %class.CBenchmarkInStream, ptr %12, i32 0, i32 3
  %41 = load i64, ptr %40, align 8, !tbaa !17
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = add i64 %41, %43
  %45 = getelementptr inbounds i8, ptr %39, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !20
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %47, i64 %49
  store i8 %46, ptr %50, align 1, !tbaa !20
  br label %51

51:                                               ; preds = %37
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = add i32 %52, 1
  store i32 %53, ptr %11, align 4, !tbaa !9
  br label %32, !llvm.loop !21

54:                                               ; preds = %36
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds %class.CBenchmarkInStream, ptr %12, i32 0, i32 3
  %58 = load i64, ptr %57, align 8, !tbaa !17
  %59 = add i64 %58, %56
  store i64 %59, ptr %57, align 8, !tbaa !17
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %65

62:                                               ; preds = %54
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %63, ptr %64, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %62, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i32 0
}

; 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

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 = { 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, !16, i64 32}
!12 = !{!"_ZTS18CBenchmarkInStream", !13, i64 0, !15, i64 8, !6, i64 16, !16, i64 24, !16, i64 32}
!13 = !{!"_ZTS19ISequentialInStream", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !16, i64 24}
!18 = !{!16, !16, i64 0}
!19 = !{!12, !6, i64 16}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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 nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN18CBenchmarkInStream4ReadEPvjPj(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0, ptr nocapture noundef writeonly %1, i32 noundef %2, ptr noundef writeonly %3) unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i64, ptr %7, align 8, !tbaa !15
  %9 = sub i64 %6, %8
  %spec.select = tail call i32 @llvm.umin.i32(i32 %2, i32 1048576)
  %10 = zext nneg i32 %spec.select to i64
  %11 = icmp ult i64 %9, %10
  %12 = trunc nuw nsw i64 %9 to i32
  %.1 = select i1 %11, i32 %12, i32 %spec.select
  %.not21 = icmp eq i32 %.1, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %wide.trip.count = zext i32 %.1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %14 = icmp ult i32 %.1, 4
  br i1 %14, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %23

._crit_edge.loopexit.unr-lcssa:                   ; preds = %23, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %15 = load ptr, ptr %13, align 8, !tbaa !16
  %16 = load i64, ptr %7, align 8, !tbaa !15
  %17 = getelementptr i8, ptr %15, i64 %16
  %18 = getelementptr i8, ptr %17, i64 %indvars.iv.epil
  %19 = load i8, ptr %18, align 1, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.epil
  store i8 %19, ptr %20, align 1, !tbaa !17
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.loopexit, label %.epil.preheader, !llvm.loop !18

._crit_edge.loopexit:                             ; preds = %.epil.preheader, %._crit_edge.loopexit.unr-lcssa
  %.pre = load i64, ptr %7, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %4, %._crit_edge.loopexit
  %.pre-phi = phi i64 [ %wide.trip.count, %._crit_edge.loopexit ], [ 0, %4 ]
  %21 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %8, %4 ]
  %22 = add i64 %21, %.pre-phi
  store i64 %22, ptr %7, align 8, !tbaa !15
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %49, label %48

23:                                               ; preds = %23, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %23 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %23 ]
  %24 = load ptr, ptr %13, align 8, !tbaa !16
  %25 = load i64, ptr %7, align 8, !tbaa !15
  %26 = getelementptr i8, ptr %24, i64 %25
  %27 = getelementptr i8, ptr %26, i64 %indvars.iv
  %28 = load i8, ptr %27, align 1, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  store i8 %28, ptr %29, align 1, !tbaa !17
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %30 = load ptr, ptr %13, align 8, !tbaa !16
  %31 = load i64, ptr %7, align 8, !tbaa !15
  %32 = getelementptr i8, ptr %30, i64 %31
  %33 = getelementptr i8, ptr %32, i64 %indvars.iv.next
  %34 = load i8, ptr %33, align 1, !tbaa !17
  %35 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  store i8 %34, ptr %35, align 1, !tbaa !17
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %36 = load ptr, ptr %13, align 8, !tbaa !16
  %37 = load i64, ptr %7, align 8, !tbaa !15
  %38 = getelementptr i8, ptr %36, i64 %37
  %39 = getelementptr i8, ptr %38, i64 %indvars.iv.next.1
  %40 = load i8, ptr %39, align 1, !tbaa !17
  %41 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.1
  store i8 %40, ptr %41, align 1, !tbaa !17
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %42 = load ptr, ptr %13, align 8, !tbaa !16
  %43 = load i64, ptr %7, align 8, !tbaa !15
  %44 = getelementptr i8, ptr %42, i64 %43
  %45 = getelementptr i8, ptr %44, i64 %indvars.iv.next.2
  %46 = load i8, ptr %45, align 1, !tbaa !17
  %47 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.2
  store i8 %46, ptr %47, align 1, !tbaa !17
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %23, !llvm.loop !20

48:                                               ; preds = %._crit_edge
  store i32 %.1, ptr %3, align 4, !tbaa !22
  br label %49

49:                                               ; preds = %48, %._crit_edge
  ret i32 0
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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, !14, i64 32}
!6 = !{!"_ZTS18CBenchmarkInStream", !7, i64 0, !9, i64 8, !13, i64 16, !14, i64 24, !14, i64 32}
!7 = !{!"_ZTS19ISequentialInStream", !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 = !{!"long", !11, i64 0}
!15 = !{!6, !14, i64 24}
!16 = !{!6, !13, i64 16}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !10, i64 0}


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