; LLVM IR from NaitikSanas/MicroCanvas :: components/MicroCanvas2D (uCanvas_Frame_buffer)

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

%struct.Framebuffer_t = type { [240 x [240 x i16]] }

; Function Attrs: nounwind uwtable
define dso_local void @framebuffer_clear(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %8

8:                                                ; preds = %31, %2
  %9 = load i32, ptr %5, align 4, !tbaa !11
  %10 = icmp slt i32 %9, 240
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %34

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %27, %12
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = icmp slt i32 %14, 240
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %30

17:                                               ; preds = %13
  %18 = load i16, ptr %4, align 2, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Framebuffer_t, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %5, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [240 x [240 x i16]], ptr %20, i64 0, i64 %22
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [240 x i16], ptr %23, i64 0, i64 %25
  store i16 %18, ptr %26, align 2, !tbaa !9
  br label %27

27:                                               ; preds = %17
  %28 = load i32, ptr %7, align 4, !tbaa !11
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %7, align 4, !tbaa !11
  br label %13, !llvm.loop !13

30:                                               ; preds = %16
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %5, align 4, !tbaa !11
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %5, align 4, !tbaa !11
  br label %8, !llvm.loop !15

34:                                               ; preds = %11
  ret void
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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(argmem: write) uwtable
define dso_local void @framebuffer_clear(ptr nocapture noundef writeonly %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %broadcast.splatinsert = insertelement <8 x i16> poison, i16 %1, i64 0
  %broadcast.splat = shufflevector <8 x i16> %broadcast.splatinsert, <8 x i16> poison, <8 x i32> zeroinitializer
  br label %vector.ph

vector.ph:                                        ; preds = %vector.ph, %2
  %indvars.iv11 = phi i64 [ 0, %2 ], [ %indvars.iv.next12, %vector.ph ]
  %3 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 0
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  store <8 x i16> %broadcast.splat, ptr %3, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %4, align 2, !tbaa !5
  %5 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 16
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  store <8 x i16> %broadcast.splat, ptr %5, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %6, align 2, !tbaa !5
  %7 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 32
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store <8 x i16> %broadcast.splat, ptr %7, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %8, align 2, !tbaa !5
  %9 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 48
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  store <8 x i16> %broadcast.splat, ptr %9, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %10, align 2, !tbaa !5
  %11 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 64
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store <8 x i16> %broadcast.splat, ptr %11, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %12, align 2, !tbaa !5
  %13 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 80
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store <8 x i16> %broadcast.splat, ptr %13, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %14, align 2, !tbaa !5
  %15 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 96
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <8 x i16> %broadcast.splat, ptr %15, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %16, align 2, !tbaa !5
  %17 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 112
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  store <8 x i16> %broadcast.splat, ptr %17, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %18, align 2, !tbaa !5
  %19 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 128
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  store <8 x i16> %broadcast.splat, ptr %19, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %20, align 2, !tbaa !5
  %21 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 144
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  store <8 x i16> %broadcast.splat, ptr %21, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %22, align 2, !tbaa !5
  %23 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 160
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  store <8 x i16> %broadcast.splat, ptr %23, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %24, align 2, !tbaa !5
  %25 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 176
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  store <8 x i16> %broadcast.splat, ptr %25, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %26, align 2, !tbaa !5
  %27 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 192
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  store <8 x i16> %broadcast.splat, ptr %27, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %28, align 2, !tbaa !5
  %29 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 208
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  store <8 x i16> %broadcast.splat, ptr %29, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %30, align 2, !tbaa !5
  %31 = getelementptr inbounds [240 x [240 x i16]], ptr %0, i64 0, i64 %indvars.iv11, i64 224
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  store <8 x i16> %broadcast.splat, ptr %31, align 2, !tbaa !5
  store <8 x i16> %broadcast.splat, ptr %32, align 2, !tbaa !5
  %indvars.iv.next12 = add nuw nsw i64 %indvars.iv11, 1
  %exitcond14.not = icmp eq i64 %indvars.iv.next12, 240
  br i1 %exitcond14.not, label %33, label %vector.ph, !llvm.loop !9

33:                                               ; preds = %vector.ph
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass