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

; 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::CharDecoder" = type { %"class.vl::Object", %"class.vl::stream::IDecoder", ptr, [4 x i8], i64 }
%"class.vl::Object" = type { ptr }
%"class.vl::stream::IDecoder" = 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 @_ZN2vl6stream11CharDecoder4ReadEPvl(ptr noundef nonnull align 8 dereferenceable(40) %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 ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = 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
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %24, %3
  %16 = getelementptr inbounds %"class.vl::stream::CharDecoder", ptr %13, i32 0, i32 4
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = icmp sgt i64 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = icmp sgt i64 %20, 0
  br label %22

22:                                               ; preds = %19, %15
  %23 = phi i1 [ false, %15 ], [ %21, %19 ]
  br i1 %23, label %24, label %39

24:                                               ; preds = %22
  %25 = getelementptr inbounds %"class.vl::stream::CharDecoder", ptr %13, i32 0, i32 3
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = getelementptr inbounds [4 x i8], ptr %25, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !16
  %29 = add i8 %28, 1
  store i8 %29, ptr %27, align 1, !tbaa !16
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i32 1
  store ptr %31, ptr %7, align 8, !tbaa !5
  store i8 %28, ptr %30, align 1, !tbaa !16
  %32 = getelementptr inbounds %"class.vl::stream::CharDecoder", ptr %13, i32 0, i32 4
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = add nsw i64 %33, -1
  store i64 %34, ptr %32, align 8, !tbaa !11
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = add nsw i64 %35, -1
  store i64 %36, ptr %6, align 8, !tbaa !9
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr %8, align 8, !tbaa !9
  br label %15, !llvm.loop !17

39:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = udiv i64 %40, 4
  store i64 %41, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = load ptr, ptr %13, align 8, !tbaa !19
  %45 = getelementptr inbounds ptr, ptr %44, i64 2
  %46 = load ptr, ptr %45, align 8
  %47 = call noundef i64 %46(ptr noundef nonnull align 8 dereferenceable(40) %13, ptr noundef %42, i64 noundef %43)
  %48 = mul i64 %47, 4
  store i64 %48, ptr %11, align 8, !tbaa !9
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = load i64, ptr %8, align 8, !tbaa !9
  %51 = add nsw i64 %50, %49
  store i64 %51, ptr %8, align 8, !tbaa !9
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = sub nsw i64 %53, %52
  store i64 %54, ptr %6, align 8, !tbaa !9
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 %55
  store ptr %57, ptr %7, align 8, !tbaa !5
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = icmp sgt i64 %58, 0
  br i1 %59, label %60, label %82

60:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %61 = load ptr, ptr %13, align 8, !tbaa !19
  %62 = getelementptr inbounds ptr, ptr %61, i64 2
  %63 = load ptr, ptr %62, align 8
  %64 = call noundef i64 %63(ptr noundef nonnull align 8 dereferenceable(40) %13, ptr noundef %12, i64 noundef 1)
  %65 = icmp eq i64 %64, 1
  br i1 %65, label %66, label %81

66:                                               ; preds = %60
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = sub i64 4, %67
  %69 = getelementptr inbounds %"class.vl::stream::CharDecoder", ptr %13, i32 0, i32 4
  store i64 %68, ptr %69, align 8, !tbaa !11
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %70, ptr align 4 %12, i64 %71, i1 false)
  %72 = getelementptr inbounds %"class.vl::stream::CharDecoder", ptr %13, i32 0, i32 3
  %73 = getelementptr inbounds [4 x i8], ptr %72, i64 0, i64 0
  %74 = load i64, ptr %6, align 8, !tbaa !9
  %75 = getelementptr inbounds i8, ptr %12, i64 %74
  %76 = getelementptr inbounds %"class.vl::stream::CharDecoder", ptr %13, i32 0, i32 4
  %77 = load i64, ptr %76, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %73, ptr align 1 %75, i64 %77, i1 false)
  %78 = load i64, ptr %6, align 8, !tbaa !9
  %79 = load i64, ptr %8, align 8, !tbaa !9
  %80 = add nsw i64 %79, %78
  store i64 %80, ptr %8, align 8, !tbaa !9
  br label %81

81:                                               ; preds = %66, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %82

82:                                               ; preds = %81, %39
  %83 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %83
}

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 32}
!12 = !{!"_ZTSN2vl6stream11CharDecoderE", !13, i64 0, !14, i64 8, !6, i64 16, !7, i64 24, !10, i64 32}
!13 = !{!"_ZTSN2vl6ObjectE"}
!14 = !{!"_ZTSN2vl6stream8IDecoderE", !15, i64 0}
!15 = !{!"_ZTSN2vl9InterfaceE"}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !20, i64 0}
!20 = !{!"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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; 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) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream11CharDecoder4ReadEPvl(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca i32, align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i64 %6, 0
  %8 = icmp sgt i64 %2, 0
  %9 = and i1 %7, %8
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  br label %11

11:                                               ; preds = %.lr.ph, %11
  %.028 = phi i64 [ %2, %.lr.ph ], [ %17, %11 ]
  %.02327 = phi ptr [ %1, %.lr.ph ], [ %14, %11 ]
  %.02426 = phi i64 [ 0, %.lr.ph ], [ %18, %11 ]
  %12 = load i8, ptr %10, align 8, !tbaa !14
  %13 = add i8 %12, 1
  store i8 %13, ptr %10, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %.02327, i64 1
  store i8 %12, ptr %.02327, align 1, !tbaa !14
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = add nsw i64 %15, -1
  store i64 %16, ptr %5, align 8, !tbaa !5
  %17 = add nsw i64 %.028, -1
  %18 = add nuw nsw i64 %.02426, 1
  %19 = icmp sgt i64 %15, 1
  %20 = icmp ugt i64 %.028, 1
  %21 = select i1 %19, i1 %20, i1 false
  br i1 %21, label %11, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %11, %3
  %.024.lcssa = phi i64 [ 0, %3 ], [ %18, %11 ]
  %.023.lcssa = phi ptr [ %1, %3 ], [ %14, %11 ]
  %.0.lcssa = phi i64 [ %2, %3 ], [ %17, %11 ]
  %22 = lshr i64 %.0.lcssa, 2
  %23 = load ptr, ptr %0, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load ptr, ptr %24, align 8
  %26 = tail call noundef i64 %25(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %.023.lcssa, i64 noundef %22)
  %27 = shl i64 %26, 2
  %28 = add nsw i64 %27, %.024.lcssa
  %29 = sub nsw i64 %.0.lcssa, %27
  %30 = getelementptr inbounds i8, ptr %.023.lcssa, i64 %27
  %31 = icmp sgt i64 %29, 0
  br i1 %31, label %32, label %45

32:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %33 = load ptr, ptr %0, align 8, !tbaa !17
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  %35 = load ptr, ptr %34, align 8
  %36 = call noundef i64 %35(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull %4, i64 noundef 1)
  %37 = icmp eq i64 %36, 1
  br i1 %37, label %38, label %44

38:                                               ; preds = %32
  %39 = sub nsw i64 4, %29
  store i64 %39, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %30, ptr nonnull align 4 %4, i64 %29, i1 false)
  %40 = getelementptr inbounds i8, ptr %0, i64 24
  %41 = getelementptr inbounds i8, ptr %4, i64 %29
  %42 = load i64, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %40, ptr nonnull align 1 %41, i64 %42, i1 false)
  %43 = add i64 %.0.lcssa, %.024.lcssa
  br label %44

44:                                               ; preds = %38, %32
  %.1 = phi i64 [ %43, %38 ], [ %28, %32 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %45

45:                                               ; preds = %44, %._crit_edge
  %.2 = phi i64 [ %.1, %44 ], [ %28, %._crit_edge ]
  ret i64 %.2
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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, !13, i64 32}
!6 = !{!"_ZTSN2vl6stream11CharDecoderE", !7, i64 0, !8, i64 8, !10, i64 16, !11, i64 24, !13, i64 32}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"_ZTSN2vl6stream8IDecoderE", !9, i64 0}
!9 = !{!"_ZTSN2vl9InterfaceE"}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"long", !11, i64 0}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !12, i64 0}


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