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

; 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::BomDecoder::BomStream" = type { %"class.vl::Object", %"class.vl::stream::IStream", ptr, [3 x i8], i64, i64 }
%"class.vl::Object" = type { ptr }
%"class.vl::stream::IStream" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream10BomDecoder9BomStream4ReadEPvl(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = 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
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %11, ptr %8, align 8, !tbaa !5
  %12 = getelementptr inbounds %"class.vl::stream::BomDecoder::BomStream", ptr %10, i32 0, i32 5
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %"class.vl::stream::BomDecoder::BomStream", ptr %10, i32 0, i32 4
  %15 = load i64, ptr %14, align 8, !tbaa !15
  %16 = icmp slt i64 %13, %15
  br i1 %16, label %17, label %49

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %18 = getelementptr inbounds %"class.vl::stream::BomDecoder::BomStream", ptr %10, i32 0, i32 4
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds %"class.vl::stream::BomDecoder::BomStream", ptr %10, i32 0, i32 5
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = sub nsw i64 %19, %21
  store i64 %22, ptr %9, align 8, !tbaa !9
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp slt i64 %23, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %17
  %27 = load i64, ptr %9, align 8, !tbaa !9
  br label %30

28:                                               ; preds = %17
  %29 = load i64, ptr %6, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %28, %26
  %31 = phi i64 [ %27, %26 ], [ %29, %28 ]
  store i64 %31, ptr %7, align 8, !tbaa !9
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.vl::stream::BomDecoder::BomStream", ptr %10, i32 0, i32 3
  %34 = getelementptr inbounds [3 x i8], ptr %33, i64 0, i64 0
  %35 = getelementptr inbounds %"class.vl::stream::BomDecoder::BomStream", ptr %10, i32 0, i32 5
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  %38 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 1 %37, i64 %38, i1 false)
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 %39
  store ptr %41, ptr %8, align 8, !tbaa !5
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = getelementptr inbounds %"class.vl::stream::BomDecoder::BomStream", ptr %10, i32 0, i32 5
  %44 = load i64, ptr %43, align 8, !tbaa !11
  %45 = add nsw i64 %44, %42
  store i64 %45, ptr %43, align 8, !tbaa !11
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = sub nsw i64 %47, %46
  store i64 %48, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %49

49:                                               ; preds = %30, %3
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %52, label %63

52:                                               ; preds = %49
  %53 = getelementptr inbounds %"class.vl::stream::BomDecoder::BomStream", ptr %10, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = load ptr, ptr %54, align 8, !tbaa !17
  %58 = getelementptr inbounds ptr, ptr %57, i64 14
  %59 = load ptr, ptr %58, align 8
  %60 = call noundef i64 %59(ptr noundef nonnull align 8 dereferenceable(8) %54, ptr noundef %55, i64 noundef %56)
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = add nsw i64 %61, %60
  store i64 %62, ptr %7, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %52, %49
  %64 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %64
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream10BomDecoder9BomStream4ReadEPvl(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i64, ptr %6, align 8, !tbaa !13
  %8 = icmp slt i64 %5, %7
  br i1 %8, label %9, label %18

9:                                                ; preds = %3
  %10 = sub nsw i64 %7, %5
  %11 = tail call i64 @llvm.smin.i64(i64 %10, i64 %2)
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = getelementptr inbounds i8, ptr %12, i64 %5
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr nonnull align 1 %13, i64 %11, i1 false)
  %14 = getelementptr inbounds i8, ptr %1, i64 %11
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = add nsw i64 %15, %11
  store i64 %16, ptr %4, align 8, !tbaa !5
  %17 = sub nsw i64 %2, %11
  br label %18

18:                                               ; preds = %9, %3
  %.018 = phi i64 [ %11, %9 ], [ 0, %3 ]
  %.017 = phi ptr [ %14, %9 ], [ %1, %3 ]
  %.0 = phi i64 [ %17, %9 ], [ %2, %3 ]
  %.not = icmp eq i64 %.0, 0
  br i1 %.not, label %27, label %19

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %22, i64 112
  %24 = load ptr, ptr %23, align 8
  %25 = tail call noundef i64 %24(ptr noundef nonnull align 8 dereferenceable(8) %21, ptr noundef %.017, i64 noundef %.0)
  %26 = add nsw i64 %25, %.018
  br label %27

27:                                               ; preds = %19, %18
  %.1 = phi i64 [ %26, %19 ], [ %.018, %18 ]
  ret i64 %.1
}

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

attributes #0 = { mustprogress nocallback nofree 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 = { nocallback nofree nosync nounwind speculatable 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, !12, i64 40}
!6 = !{!"_ZTSN2vl6stream10BomDecoder9BomStreamE", !7, i64 0, !8, i64 8, !9, i64 16, !10, i64 24, !12, i64 32, !12, i64 40}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"_ZTSN2vl6stream7IStreamE"}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!6, !12, i64 32}
!14 = !{!6, !9, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !11, i64 0}


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