; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library (InternalPrintLibFillBuffer)

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

; 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: nounwind uwtable
define dso_local ptr @InternalPrintLibFillBuffer(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) #1 {
  %6 = alloca ptr, 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
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i64 %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %38, %5
  %13 = load i64, ptr %11, align 8, !tbaa !9
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %12
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ult ptr %17, %18
  br label %20

20:                                               ; preds = %16, %12
  %21 = phi i1 [ false, %12 ], [ %19, %16 ]
  br i1 %21, label %22, label %41

22:                                               ; preds = %20
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = trunc i64 %23 to i8
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 %24, ptr %25, align 1, !tbaa !11
  %26 = load i64, ptr %10, align 8, !tbaa !9
  %27 = icmp ne i64 %26, 1
  br i1 %27, label %28, label %34

28:                                               ; preds = %22
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = lshr i64 %29, 8
  %31 = trunc i64 %30 to i8
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 1
  store i8 %31, ptr %33, align 1, !tbaa !11
  br label %34

34:                                               ; preds = %28, %22
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 %35
  store ptr %37, ptr %6, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %34
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %11, align 8, !tbaa !9
  br label %12, !llvm.loop !12

41:                                               ; preds = %20
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret ptr %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind 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 }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(write, inaccessiblemem: none) uwtable
define dso_local ptr @InternalPrintLibFillBuffer(ptr noundef writeonly %0, ptr noundef readnone %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = ptrtoint ptr %0 to i64
  %7 = ptrtoint ptr %1 to i64
  %8 = icmp sgt i64 %2, 0
  %9 = icmp ult ptr %0, %1
  %10 = and i1 %8, %9
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %11 = trunc i64 %3 to i8
  %.not = icmp eq i64 %4, 1
  %12 = lshr i64 %3, 8
  %13 = trunc i64 %12 to i8
  br i1 %.not, label %.lr.ph.split.us.preheader, label %.lr.ph.split

.lr.ph.split.us.preheader:                        ; preds = %.lr.ph
  %14 = xor i64 %6, -1
  %15 = add i64 %14, %7
  %16 = add nsw i64 %2, -1
  %umin = tail call i64 @llvm.umin.i64(i64 %15, i64 %16)
  %17 = add i64 %umin, 1
  %min.iters.check = icmp ult i64 %17, 32
  br i1 %min.iters.check, label %.lr.ph.split.us.preheader23, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.split.us.preheader
  %n.vec = and i64 %17, -32
  %ind.end = getelementptr i8, ptr %0, i64 %n.vec
  %broadcast.splatinsert = insertelement <16 x i8> poison, i8 %11, i64 0
  %broadcast.splat = shufflevector <16 x i8> %broadcast.splatinsert, <16 x i8> poison, <16 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %0, i64 %index
  %18 = getelementptr i8, ptr %next.gep, i64 16
  store <16 x i8> %broadcast.splat, ptr %next.gep, align 1, !tbaa !5
  store <16 x i8> %broadcast.splat, ptr %18, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %17, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.split.us.preheader23

.lr.ph.split.us.preheader23:                      ; preds = %middle.block, %.lr.ph.split.us.preheader
  %.014.us.ph = phi i64 [ 0, %.lr.ph.split.us.preheader ], [ %n.vec, %middle.block ]
  %.01213.us.ph = phi ptr [ %0, %.lr.ph.split.us.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.preheader23, %.lr.ph.split.us
  %.014.us = phi i64 [ %21, %.lr.ph.split.us ], [ %.014.us.ph, %.lr.ph.split.us.preheader23 ]
  %.01213.us = phi ptr [ %20, %.lr.ph.split.us ], [ %.01213.us.ph, %.lr.ph.split.us.preheader23 ]
  store i8 %11, ptr %.01213.us, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.01213.us, i64 1
  %21 = add nuw nsw i64 %.014.us, 1
  %22 = icmp slt i64 %21, %2
  %23 = icmp ult ptr %20, %1
  %24 = select i1 %22, i1 %23, i1 false
  br i1 %24, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !12

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %.014 = phi i64 [ %27, %.lr.ph.split ], [ 0, %.lr.ph ]
  %.01213 = phi ptr [ %26, %.lr.ph.split ], [ %0, %.lr.ph ]
  store i8 %11, ptr %.01213, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.01213, i64 1
  store i8 %13, ptr %25, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.01213, i64 %4
  %27 = add nuw nsw i64 %.014, 1
  %28 = icmp slt i64 %27, %2
  %29 = icmp ult ptr %26, %1
  %30 = select i1 %28, i1 %29, i1 false
  br i1 %30, label %.lr.ph.split, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph.split, %.lr.ph.split.us, %middle.block, %5
  %.012.lcssa = phi ptr [ %0, %5 ], [ %ind.end, %middle.block ], [ %20, %.lr.ph.split.us ], [ %26, %.lr.ph.split ]
  ret ptr %.012.lcssa
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(write, inaccessiblemem: none) 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) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10, !11}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !9, !11, !10}
!13 = distinct !{!13, !9}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass