; LLVM IR from pmwkaa/monotone :: monotone/runtime/runtime (vfs)

; 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: 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: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

; Function Attrs: nounwind uwtable
define dso_local i64 @vfs_pread(i32 noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !11
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %48, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  br label %14

14:                                               ; preds = %34, %13
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !11
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %16, i64 %17
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = load i64, ptr %10, align 8, !tbaa !9
  %21 = sub i64 %19, %20
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = add i64 %22, %23
  %25 = call i64 @pread(i32 noundef %15, ptr noundef %18, i64 noundef %21, i64 noundef %24)
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %11, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %14
  %28 = load i32, ptr %11, align 4, !tbaa !5
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %30, label %34

30:                                               ; preds = %27
  %31 = call ptr @__errno_location() #5
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 4
  br label %34

34:                                               ; preds = %30, %27
  %35 = phi i1 [ false, %27 ], [ %33, %30 ]
  br i1 %35, label %14, label %36, !llvm.loop !13

36:                                               ; preds = %34
  %37 = load i32, ptr %11, align 4, !tbaa !5
  %38 = icmp sle i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i64 -1, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %45

40:                                               ; preds = %36
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = add i64 %43, %42
  store i64 %44, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %12, align 4
  br label %45

45:                                               ; preds = %40, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %46 = load i32, ptr %12, align 4
  switch i32 %46, label %54 [
    i32 0, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = icmp ne i64 %49, %50
  br i1 %51, label %13, label %52, !llvm.loop !15

52:                                               ; preds = %48
  %53 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %53, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %54

54:                                               ; preds = %52, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %55 = load i64, ptr %5, align 8
  ret i64 %55
}

declare i64 @pread(i32 noundef, ptr noundef, i64 noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(none) "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 = { 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 #3 = { "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 }
attributes #5 = { nounwind 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i64 @vfs_pread(i32 noundef %0, i64 noundef %1, ptr nocapture noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  br label %5

5:                                                ; preds = %18, %4
  %.016 = phi i64 [ 0, %4 ], [ %20, %18 ]
  %6 = getelementptr inbounds i8, ptr %2, i64 %.016
  %7 = sub i64 %3, %.016
  %8 = add i64 %.016, %1
  br label %9

9:                                                ; preds = %13, %5
  %10 = tail call i64 @pread(i32 noundef %0, ptr noundef %6, i64 noundef %7, i64 noundef %8) #3
  %11 = trunc i64 %10 to i32
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %9
  %14 = tail call ptr @__errno_location() #4
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 4
  br i1 %16, label %9, label %.critedge.thread, !llvm.loop !9

.critedge:                                        ; preds = %9
  %17 = icmp sgt i32 %11, 0
  br i1 %17, label %18, label %.critedge.thread

18:                                               ; preds = %.critedge
  %19 = and i64 %10, 2147483647
  %20 = add i64 %19, %.016
  %.not = icmp eq i64 %20, %3
  br i1 %.not, label %.critedge.thread, label %5, !llvm.loop !11

.critedge.thread:                                 ; preds = %18, %.critedge, %13
  %.2 = phi i64 [ -1, %13 ], [ %3, %18 ], [ -1, %.critedge ]
  ret i64 %.2
}

; Function Attrs: nofree
declare noundef i64 @pread(i32 noundef, ptr nocapture noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nofree 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 #2 = { nofree "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 #3 = { nounwind }
attributes #4 = { nounwind 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass