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

; 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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z10ReadStreamP19ISequentialInStreamPvjPj(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %18

16:                                               ; preds = %4
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %16, %4
  br label %19

19:                                               ; preds = %60, %18
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %61

22:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load ptr, ptr %23, align 8, !tbaa !11
  %27 = getelementptr inbounds ptr, ptr %26, i64 3
  %28 = load ptr, ptr %27, align 8
  %29 = call noundef i32 %28(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef %24, i32 noundef %25, ptr noundef %10)
  store i32 %29, ptr %11, align 4, !tbaa !9
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %37

32:                                               ; preds = %22
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = add i32 %35, %33
  store i32 %36, ptr %34, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %32, %22
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  store ptr %41, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sub i32 %43, %42
  store i32 %44, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %45 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %45, ptr %12, align 4, !tbaa !9
  %46 = load i32, ptr %12, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %37
  %49 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %49, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %51

50:                                               ; preds = %37
  store i32 0, ptr %13, align 4
  br label %51

51:                                               ; preds = %50, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %52 = load i32, ptr %13, align 4
  switch i32 %52, label %58 [
    i32 0, label %53
  ]

53:                                               ; preds = %51
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %53
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %58

57:                                               ; preds = %53
  store i32 0, ptr %13, align 4
  br label %58

58:                                               ; preds = %57, %56, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %59 = load i32, ptr %13, align 4
  switch i32 %59, label %64 [
    i32 0, label %60
    i32 1, label %62
  ]

60:                                               ; preds = %58
  br label %19, !llvm.loop !13

61:                                               ; preds = %19
  store i32 0, ptr %5, align 4
  br label %62

62:                                               ; preds = %61, %58
  %63 = load i32, ptr %5, align 4
  ret i32 %63

64:                                               ; preds = %58
  unreachable
}

; 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 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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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
define dso_local noundef i32 @_Z10ReadStreamP19ISequentialInStreamPvjPj(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.split.us, label %6

6:                                                ; preds = %4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %.split

.split.us:                                        ; preds = %4, %7
  %.018.us = phi i32 [ %15, %7 ], [ %2, %4 ]
  %.017.us = phi ptr [ %14, %7 ], [ %1, %4 ]
  %.015.us = phi i32 [ %.2.us, %7 ], [ undef, %4 ]
  %.not22.us = icmp eq i32 %.018.us, 0
  br i1 %.not22.us, label %.split26.us, label %7

7:                                                ; preds = %.split.us
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %8 = load ptr, ptr %0, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %8, i64 24
  %10 = load ptr, ptr %9, align 8
  %11 = call noundef i32 %10(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %.017.us, i32 noundef %.018.us, ptr noundef nonnull %5)
  %12 = load i32, ptr %5, align 4
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %.017.us, i64 %13
  %15 = sub i32 %.018.us, %12
  %.not23.us = icmp eq i32 %11, 0
  %16 = icmp ne i32 %12, 0
  %17 = and i1 %.not23.us, %16
  %..015..us = select i1 %17, i32 %.015.us, i32 0
  %.2.us = select i1 %.not23.us, i32 %..015..us, i32 %11
  %.1.not.us = select i1 %.not23.us, i1 %16, i1 false
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  br i1 %.1.not.us, label %.split.us, label %.split26.us

.split:                                           ; preds = %6, %18
  %.018 = phi i32 [ %28, %18 ], [ %2, %6 ]
  %.017 = phi ptr [ %27, %18 ], [ %1, %6 ]
  %.015 = phi i32 [ %.2, %18 ], [ undef, %6 ]
  %.not22 = icmp eq i32 %.018, 0
  br i1 %.not22, label %.split26.us, label %18

18:                                               ; preds = %.split
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %19 = load ptr, ptr %0, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %19, i64 24
  %21 = load ptr, ptr %20, align 8
  %22 = call noundef i32 %21(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %.017, i32 noundef %.018, ptr noundef nonnull %5)
  %23 = load i32, ptr %5, align 4
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = add i32 %24, %23
  store i32 %25, ptr %3, align 4, !tbaa !5
  %26 = zext i32 %23 to i64
  %27 = getelementptr inbounds i8, ptr %.017, i64 %26
  %28 = sub i32 %.018, %23
  %.not23 = icmp eq i32 %22, 0
  %29 = icmp ne i32 %23, 0
  %30 = and i1 %.not23, %29
  %..015. = select i1 %30, i32 %.015, i32 0
  %.2 = select i1 %.not23, i32 %..015., i32 %22
  %.1.not = select i1 %.not23, i1 %29, i1 false
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  br i1 %.1.not, label %.split, label %.split26.us

.split26.us:                                      ; preds = %.split, %18, %.split.us, %7
  %.us-phi = phi i32 [ %.2.us, %7 ], [ 0, %.split.us ], [ %.2, %18 ], [ 0, %.split ]
  ret i32 %.us-phi
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass