; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/lzma/C/7zip/Compress/LZMA_Alone (LzmaRam)

; 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.CInStreamRam = 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 @_ZN12CInStreamRam4ReadEPvjPj(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 i32, align 4
  %10 = 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
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %12 = getelementptr inbounds %class.CInStreamRam, ptr %11, i32 0, i32 3
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %class.CInStreamRam, ptr %11, i32 0, i32 4
  %15 = load i64, ptr %14, align 8, !tbaa !17
  %16 = sub i64 %13, %15
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp ugt i32 %18, %19
  br i1 %20, label %21, label %23

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

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

24:                                               ; preds = %43, %23
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp ult i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %46

29:                                               ; preds = %24
  %30 = getelementptr inbounds %class.CInStreamRam, ptr %11, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = getelementptr inbounds %class.CInStreamRam, ptr %11, i32 0, i32 4
  %33 = load i64, ptr %32, align 8, !tbaa !17
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = add i64 %33, %35
  %37 = getelementptr inbounds i8, ptr %31, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !19
  %39 = load ptr, ptr %6, 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
  store i8 %38, ptr %42, align 1, !tbaa !19
  br label %43

43:                                               ; preds = %29
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = add i32 %44, 1
  store i32 %45, ptr %10, align 4, !tbaa !9
  br label %24, !llvm.loop !20

46:                                               ; preds = %28
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds %class.CInStreamRam, ptr %11, i32 0, i32 4
  %50 = load i64, ptr %49, align 8, !tbaa !17
  %51 = add i64 %50, %48
  store i64 %51, ptr %49, align 8, !tbaa !17
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %57

54:                                               ; preds = %46
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %55, ptr %56, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %54, %46
  call void @llvm.lifetime.end.p0(i64 4, 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 24}
!12 = !{!"_ZTS12CInStreamRam", !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 32}
!18 = !{!12, !6, i64 16}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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 @_ZN12CInStreamRam4ReadEPvjPj(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 24
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load i64, ptr %7, align 8, !tbaa !15
  %9 = sub i64 %6, %8
  %10 = trunc i64 %9 to i32
  %spec.select = tail call i32 @llvm.umin.i32(i32 %10, i32 %2)
  %.not18 = icmp eq i32 %spec.select, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %wide.trip.count = zext i32 %spec.select to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %12 = icmp ult i32 %spec.select, 4
  br i1 %12, 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 %21

._crit_edge.loopexit.unr-lcssa:                   ; preds = %21, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %21 ]
  %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 ]
  %13 = load ptr, ptr %11, align 8, !tbaa !16
  %14 = load i64, ptr %7, align 8, !tbaa !15
  %15 = getelementptr i8, ptr %13, i64 %14
  %16 = getelementptr i8, ptr %15, i64 %indvars.iv.epil
  %17 = load i8, ptr %16, align 1, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.epil
  store i8 %17, ptr %18, 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 ]
  %19 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %8, %4 ]
  %20 = add i64 %19, %.pre-phi
  store i64 %20, ptr %7, align 8, !tbaa !15
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %47, label %46

21:                                               ; preds = %21, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %21 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %21 ]
  %22 = load ptr, ptr %11, align 8, !tbaa !16
  %23 = load i64, ptr %7, align 8, !tbaa !15
  %24 = getelementptr i8, ptr %22, i64 %23
  %25 = getelementptr i8, ptr %24, i64 %indvars.iv
  %26 = load i8, ptr %25, align 1, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  store i8 %26, ptr %27, align 1, !tbaa !17
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %28 = load ptr, ptr %11, align 8, !tbaa !16
  %29 = load i64, ptr %7, align 8, !tbaa !15
  %30 = getelementptr i8, ptr %28, i64 %29
  %31 = getelementptr i8, ptr %30, i64 %indvars.iv.next
  %32 = load i8, ptr %31, align 1, !tbaa !17
  %33 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  store i8 %32, ptr %33, align 1, !tbaa !17
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %34 = load ptr, ptr %11, align 8, !tbaa !16
  %35 = load i64, ptr %7, align 8, !tbaa !15
  %36 = getelementptr i8, ptr %34, i64 %35
  %37 = getelementptr i8, ptr %36, i64 %indvars.iv.next.1
  %38 = load i8, ptr %37, align 1, !tbaa !17
  %39 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.1
  store i8 %38, ptr %39, align 1, !tbaa !17
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %40 = load ptr, ptr %11, align 8, !tbaa !16
  %41 = load i64, ptr %7, align 8, !tbaa !15
  %42 = getelementptr i8, ptr %40, i64 %41
  %43 = getelementptr i8, ptr %42, i64 %indvars.iv.next.2
  %44 = load i8, ptr %43, align 1, !tbaa !17
  %45 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.2
  store i8 %44, ptr %45, 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 %21, !llvm.loop !20

46:                                               ; preds = %._crit_edge
  store i32 %spec.select, ptr %3, align 4, !tbaa !22
  br label %47

47:                                               ; preds = %46, %._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 24}
!6 = !{!"_ZTS12CInStreamRam", !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 32}
!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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass