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

; 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::CharEncoder" = type { %"class.vl::Object", %"class.vl::stream::IEncoder", ptr, [4 x i8], i64 }
%"class.vl::Object" = type { ptr }
%"class.vl::stream::IEncoder" = 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream11CharEncoder5WriteEPvl(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #5 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = 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
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %14 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = add nsw i64 %15, %16
  store i64 %17, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = udiv i64 %18, 4
  store i64 %19, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = mul i64 %20, 4
  store i64 %21, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #6
  store i8 0, ptr %11, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  store i64 0, ptr %12, align 8, !tbaa !9
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %63

24:                                               ; preds = %3
  %25 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = icmp sgt i64 %26, 0
  br i1 %27, label %28, label %49

28:                                               ; preds = %24
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %29, i64 4)
  %31 = extractvalue { i64, i1 } %30, 1
  %32 = extractvalue { i64, i1 } %30, 0
  %33 = select i1 %31, i64 -1, i64 %32
  %34 = call noalias noundef nonnull ptr @_Znam(i64 noundef %33) #7
  store ptr %34, ptr %10, align 8, !tbaa !5
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 3
  %37 = getelementptr inbounds [4 x i8], ptr %36, i64 0, i64 0
  %38 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %39 = load i64, ptr %38, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %35, ptr align 8 %37, i64 %39, i1 false)
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %47 = load i64, ptr %46, align 8, !tbaa !11
  %48 = sub nsw i64 %45, %47
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %43, ptr align 1 %44, i64 %48, i1 false)
  store i8 1, ptr %11, align 1, !tbaa !16
  br label %51

49:                                               ; preds = %24
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %50, ptr %10, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %49, %28
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = load ptr, ptr %13, align 8, !tbaa !18
  %55 = getelementptr inbounds ptr, ptr %54, i64 2
  %56 = load ptr, ptr %55, align 8
  %57 = call noundef i64 %56(ptr noundef nonnull align 8 dereferenceable(40) %13, ptr noundef %52, i64 noundef %53)
  %58 = mul i64 %57, 4
  %59 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = sub i64 %58, %60
  store i64 %61, ptr %12, align 8, !tbaa !9
  %62 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  store i64 0, ptr %62, align 8, !tbaa !11
  br label %63

63:                                               ; preds = %51, %3
  %64 = load i8, ptr %11, align 1, !tbaa !16, !range !20, !noundef !21
  %65 = trunc i8 %64 to i1
  br i1 %65, label %66, label %71

66:                                               ; preds = %63
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = icmp eq ptr %67, null
  br i1 %68, label %70, label %69

69:                                               ; preds = %66
  call void @_ZdaPv(ptr noundef %67) #8
  br label %70

70:                                               ; preds = %69, %66
  br label %71

71:                                               ; preds = %70, %63
  %72 = load i64, ptr %7, align 8, !tbaa !9
  %73 = load i64, ptr %9, align 8, !tbaa !9
  %74 = sub nsw i64 %72, %73
  %75 = icmp sgt i64 %74, 0
  br i1 %75, label %76, label %96

76:                                               ; preds = %71
  %77 = load i64, ptr %7, align 8, !tbaa !9
  %78 = load i64, ptr %9, align 8, !tbaa !9
  %79 = sub nsw i64 %77, %78
  %80 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  store i64 %79, ptr %80, align 8, !tbaa !11
  %81 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 3
  %82 = getelementptr inbounds [4 x i8], ptr %81, i64 0, i64 0
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load i64, ptr %6, align 8, !tbaa !9
  %85 = getelementptr inbounds i8, ptr %83, i64 %84
  %86 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %87 = load i64, ptr %86, align 8, !tbaa !11
  %88 = sub i64 0, %87
  %89 = getelementptr inbounds i8, ptr %85, i64 %88
  %90 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %91 = load i64, ptr %90, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %82, ptr align 1 %89, i64 %91, i1 false)
  %92 = getelementptr inbounds %"class.vl::stream::CharEncoder", ptr %13, i32 0, i32 4
  %93 = load i64, ptr %92, align 8, !tbaa !11
  %94 = load i64, ptr %12, align 8, !tbaa !9
  %95 = add nsw i64 %94, %93
  store i64 %95, ptr %12, align 8, !tbaa !9
  br label %96

96:                                               ; preds = %76, %71
  %97 = load i64, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  ret i64 %97
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nobuiltin allocsize(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 #4 = { nobuiltin 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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 = !{!"_ZTSN2vl6stream11CharEncoderE", !13, i64 0, !14, i64 8, !6, i64 16, !7, i64 24, !10, i64 32}
!13 = !{!"_ZTSN2vl6ObjectE"}
!14 = !{!"_ZTSN2vl6stream8IEncoderE", !15, i64 0}
!15 = !{!"_ZTSN2vl9InterfaceE"}
!16 = !{!17, !17, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN2vl6stream11CharEncoder5WriteEPvl(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #3 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = add nsw i64 %5, %2
  %7 = lshr i64 %6, 2
  %8 = and i64 %6, -4
  %.not = icmp ult i64 %6, 4
  br i1 %.not, label %.thread, label %9

9:                                                ; preds = %3
  %10 = icmp slt i64 %5, 1
  br i1 %10, label %16, label %11

11:                                               ; preds = %9
  %12 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %8) #4
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %12, ptr nonnull align 8 %13, i64 %5, i1 false)
  %14 = getelementptr inbounds i8, ptr %12, i64 %5
  %15 = sub nsw i64 %8, %5
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %14, ptr align 1 %1, i64 %15, i1 false)
  br label %16

16:                                               ; preds = %11, %9
  %.024 = phi ptr [ %12, %11 ], [ %1, %9 ]
  %17 = load ptr, ptr %0, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load ptr, ptr %18, align 8
  %20 = tail call noundef i64 %19(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %.024, i64 noundef %7)
  %21 = shl i64 %20, 2
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = sub i64 %21, %22
  store i64 0, ptr %4, align 8, !tbaa !5
  %24 = icmp eq ptr %.024, null
  %or.cond = or i1 %10, %24
  br i1 %or.cond, label %.thread, label %25

25:                                               ; preds = %16
  tail call void @_ZdaPv(ptr noundef nonnull %.024) #5
  br label %.thread

.thread:                                          ; preds = %3, %25, %16
  %.034 = phi i64 [ %23, %25 ], [ %23, %16 ], [ 0, %3 ]
  %26 = and i64 %6, 3
  %.not28 = icmp eq i64 %26, 0
  br i1 %.not28, label %34, label %27

27:                                               ; preds = %.thread
  store i64 %26, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = getelementptr inbounds i8, ptr %1, i64 %2
  %30 = sub nsw i64 0, %26
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %28, ptr nonnull align 1 %31, i64 %26, i1 false)
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = add nsw i64 %32, %.034
  br label %34

34:                                               ; preds = %27, %.thread
  %.1 = phi i64 [ %33, %27 ], [ %.034, %.thread ]
  ret i64 %.1
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { nobuiltin 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 #3 = { 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 #4 = { builtin allocsize(0) }
attributes #5 = { builtin 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 = !{!"_ZTSN2vl6stream11CharEncoderE", !7, i64 0, !8, i64 8, !10, i64 16, !11, i64 24, !13, i64 32}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"_ZTSN2vl6stream8IEncoderE", !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 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !12, i64 0}


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