; LLVM IR from vczh/herodb :: Kernel/Source/Vlpp.ll (ZN2vl6stream10FileStream4ReadEPvl)

; 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.vl::stream::FileStream" = type { %"class.vl::Object", i32, ptr, %"class.vl::stream::IStream" }
%"class.vl::Object" = type { ptr }
%"class.vl::stream::IStream" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }

@_ZTIN2vl5ErrorE = external dso_local constant { ptr, ptr }, align 8
@.str.589 = external hidden unnamed_addr constant [73 x i32], align 4
@.str.590 = external hidden unnamed_addr constant [64 x i32], align 4

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_throw(ptr, ptr, ptr)

declare void @__cxa_free_exception(ptr)

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream10FileStream4ReadEPvl(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  br label %10

10:                                               ; preds = %3
  %11 = getelementptr inbounds %"class.vl::stream::FileStream", ptr %9, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = icmp ne ptr %12, null
  br i1 %13, label %21, label %14

14:                                               ; preds = %10
  %15 = call ptr @__cxa_allocate_exception(i64 8) #2
  invoke void @_ZN2vl5ErrorC1EPKw(ptr noundef nonnull align 8 dereferenceable(8) %15, ptr noundef @.str.589)
          to label %16 unwind label %17

16:                                               ; preds = %14
  call void @__cxa_throw(ptr %15, ptr @_ZTIN2vl5ErrorE, ptr null) #3
  unreachable

17:                                               ; preds = %14
  %18 = landingpad { ptr, i32 }
          cleanup
  %19 = extractvalue { ptr, i32 } %18, 0
  store ptr %19, ptr %7, align 8
  %20 = extractvalue { ptr, i32 } %18, 1
  store i32 %20, ptr %8, align 4
  call void @__cxa_free_exception(ptr %15) #2
  br label %40

21:                                               ; preds = %10
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp sge i64 %24, 0
  br i1 %25, label %33, label %26

26:                                               ; preds = %23
  %27 = call ptr @__cxa_allocate_exception(i64 8) #2
  invoke void @_ZN2vl5ErrorC1EPKw(ptr noundef nonnull align 8 dereferenceable(8) %27, ptr noundef @.str.590)
          to label %28 unwind label %29

28:                                               ; preds = %26
  call void @__cxa_throw(ptr %27, ptr @_ZTIN2vl5ErrorE, ptr null) #3
  unreachable

29:                                               ; preds = %26
  %30 = landingpad { ptr, i32 }
          cleanup
  %31 = extractvalue { ptr, i32 } %30, 0
  store ptr %31, ptr %7, align 8
  %32 = extractvalue { ptr, i32 } %30, 1
  store i32 %32, ptr %8, align 4
  call void @__cxa_free_exception(ptr %27) #2
  br label %40

33:                                               ; preds = %23
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = getelementptr inbounds %"class.vl::stream::FileStream", ptr %9, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = call i64 @fread(ptr noundef %35, i64 noundef 1, i64 noundef %36, ptr noundef %38)
  ret i64 %39

40:                                               ; preds = %29, %17
  %41 = load ptr, ptr %7, align 8
  %42 = load i32, ptr %8, align 4
  %43 = insertvalue { ptr, i32 } poison, ptr %41, 0
  %44 = insertvalue { ptr, i32 } %43, i32 %42, 1
  resume { ptr, i32 } %44
}

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

declare void @_ZN2vl5ErrorC1EPKw(ptr, ptr)

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 = { "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 }
attributes #3 = { noreturn }

!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, !6, i64 16}
!12 = !{!"_ZTSN2vl6stream10FileStreamE", !13, i64 0, !14, i64 8, !6, i64 16}
!13 = !{!"_ZTSN2vl6ObjectE"}
!14 = !{!"_ZTSN2vl6stream10FileStream11AccessRightE", !7, i64 0}


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

@_ZTIN2vl5ErrorE = external dso_local constant { ptr, ptr }, align 8
@.str.589 = external hidden unnamed_addr constant [73 x i32], align 4
@.str.590 = external hidden unnamed_addr constant [64 x i32], align 4

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream10FileStream4ReadEPvl(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, ptr nocapture noundef %1, i64 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %6, label %11

6:                                                ; preds = %3
  %7 = tail call ptr @__cxa_allocate_exception(i64 8) #2
  invoke void @_ZN2vl5ErrorC1EPKw(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull @.str.589)
          to label %8 unwind label %9

8:                                                ; preds = %6
  tail call void @__cxa_throw(ptr %7, ptr nonnull @_ZTIN2vl5ErrorE, ptr null) #3
  unreachable

9:                                                ; preds = %6
  %10 = landingpad { ptr, i32 }
          cleanup
  br label %20

11:                                               ; preds = %3
  %12 = icmp sgt i64 %2, -1
  br i1 %12, label %18, label %13

13:                                               ; preds = %11
  %14 = tail call ptr @__cxa_allocate_exception(i64 8) #2
  invoke void @_ZN2vl5ErrorC1EPKw(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef nonnull @.str.590)
          to label %15 unwind label %16

15:                                               ; preds = %13
  tail call void @__cxa_throw(ptr %14, ptr nonnull @_ZTIN2vl5ErrorE, ptr null) #3
  unreachable

16:                                               ; preds = %13
  %17 = landingpad { ptr, i32 }
          cleanup
  br label %20

18:                                               ; preds = %11
  %19 = tail call i64 @fread(ptr noundef %1, i64 noundef 1, i64 noundef %2, ptr noundef nonnull %5)
  ret i64 %19

20:                                               ; preds = %16, %9
  %.sink = phi ptr [ %14, %16 ], [ %7, %9 ]
  %.pn = phi { ptr, i32 } [ %17, %16 ], [ %10, %9 ]
  tail call void @__cxa_free_exception(ptr %.sink) #2
  resume { ptr, i32 } %.pn
}

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

declare void @_ZN2vl5ErrorC1EPKw(ptr, ptr) local_unnamed_addr

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 = { nofree nounwind "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 }
attributes #3 = { noreturn }

!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, !11, i64 16}
!6 = !{!"_ZTSN2vl6stream10FileStreamE", !7, i64 0, !8, i64 8, !11, i64 16}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"_ZTSN2vl6stream10FileStream11AccessRightE", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}


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