; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/CPP/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 @_Z10ReadStreamP19ISequentialInStreamPvPm(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %15, ptr %8, align 8, !tbaa !9
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %64, %3
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %65

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = icmp ult i64 %21, 2147483648
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = trunc i64 %24 to i32
  br label %27

26:                                               ; preds = %20
  br label %27

27:                                               ; preds = %26, %23
  %28 = phi i32 [ %25, %23 ], [ -2147483648, %26 ]
  store i32 %28, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !11
  %32 = load ptr, ptr %29, align 8, !tbaa !13
  %33 = getelementptr inbounds ptr, ptr %32, i64 5
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef i32 %34(ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef %30, i32 noundef %31, ptr noundef %10)
  store i32 %35, ptr %11, align 4, !tbaa !11
  %36 = load i32, ptr %10, align 4, !tbaa !11
  %37 = zext i32 %36 to i64
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = add i64 %39, %37
  store i64 %40, ptr %38, align 8, !tbaa !9
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !11
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  store ptr %44, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %10, align 4, !tbaa !11
  %46 = zext i32 %45 to i64
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = sub i64 %47, %46
  store i64 %48, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %49 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %49, ptr %12, align 4, !tbaa !11
  %50 = load i32, ptr %12, align 4, !tbaa !11
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %27
  %53 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %53, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %55

54:                                               ; preds = %27
  store i32 0, ptr %13, align 4
  br label %55

55:                                               ; preds = %54, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %56 = load i32, ptr %13, align 4
  switch i32 %56, label %62 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  %58 = load i32, ptr %10, align 4, !tbaa !11
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %57
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %62

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

62:                                               ; preds = %61, %60, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %63 = load i32, ptr %13, align 4
  switch i32 %63, label %66 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %17, !llvm.loop !15

65:                                               ; preds = %17
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %66

66:                                               ; preds = %65, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %67 = load i32, ptr %4, align 4
  ret i32 %67
}

; 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 @_Z10ReadStreamP19ISequentialInStreamPvPm(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = alloca i32, align 4
  %5 = load i64, ptr %2, align 8, !tbaa !5
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %7, %3
  %.020 = phi i64 [ %5, %3 ], [ %19, %7 ]
  %.019 = phi ptr [ %1, %3 ], [ %18, %7 ]
  %.017 = phi i32 [ undef, %3 ], [ %.2, %7 ]
  %.not = icmp eq i64 %.020, 0
  br i1 %.not, label %22, label %7

7:                                                ; preds = %6
  %8 = call i64 @llvm.umin.i64(i64 %.020, i64 2147483648)
  %9 = trunc nuw i64 %8 to i32
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %10 = load ptr, ptr %0, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 40
  %12 = load ptr, ptr %11, align 8
  %13 = call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %.019, i32 noundef %9, ptr noundef nonnull %4)
  %14 = load i32, ptr %4, align 4
  %15 = zext i32 %14 to i64
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = add i64 %16, %15
  store i64 %17, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.019, i64 %15
  %19 = sub i64 %.020, %15
  %.not22 = icmp eq i32 %13, 0
  %20 = icmp ne i32 %14, 0
  %21 = and i1 %20, %.not22
  %..017. = select i1 %21, i32 %.017, i32 0
  %.2 = select i1 %.not22, i32 %..017., i32 %13
  %cond1 = select i1 %.not22, i1 %20, i1 false
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br i1 %cond1, label %6, label %22, !llvm.loop !11

22:                                               ; preds = %6, %7
  %.3 = phi i32 [ %.2, %7 ], [ 0, %6 ]
  ret i32 %.3
}

; 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

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass