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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl6stream11CacheStream5FlushEv(ptr noundef nonnull align 8 dereferenceable(80) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 7
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %7, label %45

7:                                                ; preds = %1
  %8 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = getelementptr inbounds ptr, ptr %10, i64 9
  %12 = load ptr, ptr %11, align 8
  %13 = call noundef i64 %12(ptr noundef nonnull align 8 dereferenceable(8) %9)
  %14 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !16
  %16 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 6
  %17 = load i64, ptr %16, align 8, !tbaa !17
  %18 = add nsw i64 %15, %17
  %19 = icmp ne i64 %13, %18
  br i1 %19, label %20, label %31

20:                                               ; preds = %7
  %21 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 3
  %24 = load i64, ptr %23, align 8, !tbaa !16
  %25 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 6
  %26 = load i64, ptr %25, align 8, !tbaa !17
  %27 = add nsw i64 %24, %26
  %28 = load ptr, ptr %22, align 8, !tbaa !14
  %29 = getelementptr inbounds ptr, ptr %28, i64 12
  %30 = load ptr, ptr %29, align 8
  call void %30(ptr noundef nonnull align 8 dereferenceable(8) %22, i64 noundef %27)
  br label %31

31:                                               ; preds = %20, %7
  %32 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 5
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 6
  %37 = load i64, ptr %36, align 8, !tbaa !17
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  %39 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 7
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = load ptr, ptr %33, align 8, !tbaa !14
  %42 = getelementptr inbounds ptr, ptr %41, i64 15
  %43 = load ptr, ptr %42, align 8
  %44 = call noundef i64 %43(ptr noundef nonnull align 8 dereferenceable(8) %33, ptr noundef %38, i64 noundef %40)
  br label %45

45:                                               ; preds = %31, %1
  %46 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 6
  store i64 0, ptr %46, align 8, !tbaa !17
  %47 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 7
  store i64 0, ptr %47, align 8, !tbaa !9
  %48 = getelementptr inbounds %"class.vl::stream::CacheStream", ptr %3, i32 0, i32 8
  store i64 0, ptr %48, align 8, !tbaa !19
  ret void
}

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

!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, !12, i64 56}
!10 = !{!"_ZTSN2vl6stream11CacheStreamE", !11, i64 0, !6, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !6, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72}
!11 = !{!"_ZTSN2vl6ObjectE"}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !8, i64 0}
!16 = !{!10, !12, i64 24}
!17 = !{!10, !12, i64 48}
!18 = !{!10, !6, i64 40}
!19 = !{!10, !12, i64 64}


; 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 void @_ZN2vl6stream11CacheStream5FlushEv(ptr nocapture noundef nonnull align 8 dereferenceable(80) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 56
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %5, label %33

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 72
  %10 = load ptr, ptr %9, align 8
  %11 = tail call noundef i64 %10(ptr noundef nonnull align 8 dereferenceable(8) %7)
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %15 = load i64, ptr %14, align 8, !tbaa !16
  %16 = add nsw i64 %15, %13
  %.not = icmp eq i64 %11, %16
  br i1 %.not, label %22, label %17

17:                                               ; preds = %5
  %18 = load ptr, ptr %6, align 8, !tbaa !12
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %19, i64 96
  %21 = load ptr, ptr %20, align 8
  tail call void %21(ptr noundef nonnull align 8 dereferenceable(8) %18, i64 noundef %16)
  %.pre = load i64, ptr %14, align 8, !tbaa !16
  br label %22

22:                                               ; preds = %17, %5
  %23 = phi i64 [ %.pre, %17 ], [ %15, %5 ]
  %24 = load ptr, ptr %6, align 8, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %26, i64 %23
  %28 = load i64, ptr %2, align 8, !tbaa !5
  %29 = load ptr, ptr %24, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %29, i64 120
  %31 = load ptr, ptr %30, align 8
  %32 = tail call noundef i64 %31(ptr noundef nonnull align 8 dereferenceable(8) %24, ptr noundef %27, i64 noundef %28)
  br label %33

33:                                               ; preds = %22, %1
  %34 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %34, i8 0, i64 24, i1 false)
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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 56}
!6 = !{!"_ZTSN2vl6stream11CacheStreamE", !7, i64 0, !8, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !8, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!6, !8, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !10, i64 0}
!15 = !{!6, !11, i64 24}
!16 = !{!6, !11, i64 48}
!17 = !{!6, !8, i64 40}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass