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

; 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::CacheStream" = type { %"class.vl::Object", ptr, i64, i64, i64, ptr, i64, i64, i64, i64, %"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.573 = external hidden unnamed_addr constant [65 x i32], align 4
@.str.574 = external hidden unnamed_addr constant [77 x i32], align 4

; 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

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
declare dso_local noundef i64 @_ZN2vl6stream11CacheStream13InternalWriteEPvl(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream11CacheStream5WriteEPvl(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #1 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
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  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
  %11 = load ptr, ptr %4, align 8
  br label %12

12:                                               ; preds = %3
  %13 = load ptr, ptr %11, align 8, !tbaa !11
  %14 = getelementptr inbounds ptr, ptr %13, i64 3
  %15 = load ptr, ptr %14, align 8
  %16 = call noundef zeroext i1 %15(ptr noundef nonnull align 8 dereferenceable(80) %11)
  br i1 %16, label %24, label %17

17:                                               ; preds = %12
  %18 = call ptr @__cxa_allocate_exception(i64 8) #2
  invoke void @_ZN2vl5ErrorC1EPKw(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef @.str.574)
          to label %19 unwind label %20

19:                                               ; preds = %17
  call void @__cxa_throw(ptr %18, ptr @_ZTIN2vl5ErrorE, ptr null) #3
  unreachable

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

24:                                               ; preds = %12
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = icmp sge i64 %27, 0
  br i1 %28, label %36, label %29

29:                                               ; preds = %26
  %30 = call ptr @__cxa_allocate_exception(i64 8) #2
  invoke void @_ZN2vl5ErrorC1EPKw(ptr noundef nonnull align 8 dereferenceable(8) %30, ptr noundef @.str.573)
          to label %31 unwind label %32

31:                                               ; preds = %29
  call void @__cxa_throw(ptr %30, ptr @_ZTIN2vl5ErrorE, ptr null) #3
  unreachable

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

36:                                               ; preds = %26
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr %11, align 8, !tbaa !11
  %39 = getelementptr inbounds ptr, ptr %38, i64 6
  %40 = load ptr, ptr %39, align 8
  %41 = call noundef zeroext i1 %40(ptr noundef nonnull align 8 dereferenceable(80) %11)
  br i1 %41, label %42, label %64

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %43 = load ptr, ptr %11, align 8, !tbaa !11
  %44 = getelementptr inbounds ptr, ptr %43, i64 10
  %45 = load ptr, ptr %44, align 8
  %46 = call noundef i64 %45(ptr noundef nonnull align 8 dereferenceable(80) %11)
  store i64 %46, ptr %9, align 8, !tbaa !9
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = icmp ne i64 %47, -1
  br i1 %48, label %49, label %63

49:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %11, i32 0, i32 4
  %52 = load i64, ptr %51, align 8, !tbaa !13
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = add nsw i64 %52, %53
  %55 = sub nsw i64 %50, %54
  store i64 %55, ptr %10, align 8, !tbaa !9
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = icmp slt i64 %56, 0
  br i1 %57, label %58, label %62

58:                                               ; preds = %49
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = load i64, ptr %6, align 8, !tbaa !9
  %61 = sub nsw i64 %60, %59
  store i64 %61, ptr %6, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %58, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %63

63:                                               ; preds = %62, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %64

64:                                               ; preds = %63, %37
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load i64, ptr %6, align 8, !tbaa !9
  %67 = call noundef i64 @_ZN2vl6stream11CacheStream13InternalWriteEPvl(ptr noundef nonnull align 8 dereferenceable(80) %11, ptr noundef %65, i64 noundef %66)
  store i64 %67, ptr %6, align 8, !tbaa !9
  %68 = load i64, ptr %6, align 8, !tbaa !9
  %69 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %11, i32 0, i32 4
  %70 = load i64, ptr %69, align 8, !tbaa !13
  %71 = add nsw i64 %70, %68
  store i64 %71, ptr %69, align 8, !tbaa !13
  %72 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %11, i32 0, i32 9
  %73 = load i64, ptr %72, align 8, !tbaa !16
  %74 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %11, i32 0, i32 4
  %75 = load i64, ptr %74, align 8, !tbaa !13
  %76 = icmp slt i64 %73, %75
  br i1 %76, label %77, label %81

77:                                               ; preds = %64
  %78 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %11, i32 0, i32 4
  %79 = load i64, ptr %78, align 8, !tbaa !13
  %80 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %11, i32 0, i32 9
  store i64 %79, ptr %80, align 8, !tbaa !16
  br label %81

81:                                               ; preds = %77, %64
  %82 = load i64, ptr %6, align 8, !tbaa !9
  ret i64 %82

83:                                               ; preds = %32, %20
  %84 = load ptr, ptr %7, align 8
  %85 = load i32, ptr %8, align 4
  %86 = insertvalue { ptr, i32 } poison, ptr %84, 0
  %87 = insertvalue { ptr, i32 } %86, i32 %85, 1
  resume { ptr, i32 } %87
}

declare void @_ZN2vl5ErrorC1EPKw(ptr, ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !10, i64 32}
!14 = !{!"_ZTSN2vl6stream11CacheStreamE", !15, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!15 = !{!"_ZTSN2vl6ObjectE"}
!16 = !{!14, !10, i64 72}


; 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.573 = external hidden unnamed_addr constant [65 x i32], align 4
@.str.574 = external hidden unnamed_addr constant [77 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
declare dso_local noundef i64 @_ZN2vl6stream11CacheStream13InternalWriteEPvl(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream11CacheStream5WriteEPvl(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 24
  %6 = load ptr, ptr %5, align 8
  %7 = tail call noundef zeroext i1 %6(ptr noundef nonnull align 8 dereferenceable(80) %0)
  br i1 %7, label %13, label %8

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

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

11:                                               ; preds = %8
  %12 = landingpad { ptr, i32 }
          cleanup
  br label %46

13:                                               ; preds = %3
  %14 = icmp sgt i64 %2, -1
  br i1 %14, label %20, label %15

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

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

18:                                               ; preds = %15
  %19 = landingpad { ptr, i32 }
          cleanup
  br label %46

20:                                               ; preds = %13
  %21 = load ptr, ptr %0, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 48
  %23 = load ptr, ptr %22, align 8
  %24 = tail call noundef zeroext i1 %23(ptr noundef nonnull align 8 dereferenceable(80) %0)
  br i1 %24, label %25, label %36

25:                                               ; preds = %20
  %26 = load ptr, ptr %0, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 80
  %28 = load ptr, ptr %27, align 8
  %29 = tail call noundef i64 %28(ptr noundef nonnull align 8 dereferenceable(80) %0)
  %.not = icmp eq i64 %29, -1
  br i1 %.not, label %36, label %30

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  %32 = load i64, ptr %31, align 8, !tbaa !8
  %33 = add i64 %32, %2
  %34 = sub i64 %29, %33
  %35 = tail call i64 @llvm.smin.i64(i64 %34, i64 0)
  %spec.select = sub nsw i64 %2, %35
  br label %36

36:                                               ; preds = %25, %30, %20
  %.2 = phi i64 [ %2, %20 ], [ %spec.select, %30 ], [ %2, %25 ]
  %37 = tail call noundef i64 @_ZN2vl6stream11CacheStream13InternalWriteEPvl(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef %1, i64 noundef %.2)
  %38 = getelementptr inbounds i8, ptr %0, i64 32
  %39 = load i64, ptr %38, align 8, !tbaa !8
  %40 = add nsw i64 %39, %37
  store i64 %40, ptr %38, align 8, !tbaa !8
  %41 = getelementptr inbounds i8, ptr %0, i64 72
  %42 = load i64, ptr %41, align 8, !tbaa !14
  %43 = icmp slt i64 %42, %40
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  store i64 %40, ptr %41, align 8, !tbaa !14
  br label %45

45:                                               ; preds = %44, %36
  ret i64 %37

46:                                               ; preds = %18, %11
  %.sink = phi ptr [ %16, %18 ], [ %9, %11 ]
  %.pn = phi { ptr, i32 } [ %19, %18 ], [ %12, %11 ]
  tail call void @__cxa_free_exception(ptr %.sink) #2
  resume { ptr, i32 } %.pn
}

declare void @_ZN2vl5ErrorC1EPKw(ptr, ptr) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #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 speculatable willreturn memory(none) }
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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !13, i64 32}
!9 = !{!"_ZTSN2vl6stream11CacheStreamE", !10, i64 0, !11, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !11, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72}
!10 = !{!"_ZTSN2vl6ObjectE"}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"long", !12, i64 0}
!14 = !{!9, !13, i64 72}


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