; LLVM IR from ejoy/ejoy2d :: lib/render (carray)

; 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.array_node = type { ptr }
%struct.array = type { i32, i32, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @array_init(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = add nsw i32 %15, 7
  %17 = and i32 %16, -8
  store i32 %17, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %18, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %41, %4
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sub nsw i32 %21, 1
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %24, label %44

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = mul nsw i32 %26, %27
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %25, i64 %29
  store ptr %30, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = mul nsw i32 %33, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %31, i64 %36
  store ptr %37, ptr %13, align 8, !tbaa !5
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.array_node, ptr %39, i32 0, i32 0
  store ptr %38, ptr %40, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %41

41:                                               ; preds = %24
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !13

44:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sub nsw i32 %46, 1
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = mul nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %45, i64 %50
  store ptr %51, ptr %14, align 8, !tbaa !5
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.array_node, ptr %52, i32 0, i32 0
  store ptr null, ptr %53, align 8, !tbaa !11
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.array, ptr %55, i32 0, i32 0
  store i32 %54, ptr %56, align 8, !tbaa !15
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.array, ptr %58, i32 0, i32 1
  store i32 %57, ptr %59, align 4, !tbaa !17
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.array, ptr %61, i32 0, i32 2
  store ptr %60, ptr %62, align 8, !tbaa !18
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.array, ptr %64, i32 0, i32 3
  store ptr %63, ptr %65, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"array_node", !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 0}
!16 = !{!"array", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!17 = !{!16, !10, i64 4}
!18 = !{!16, !6, i64 8}
!19 = !{!16, !6, i64 16}


; 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 @array_init(ptr nocapture noundef writeonly %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add nsw i32 %3, 7
  %6 = and i32 %5, -8
  %7 = add i32 %2, -1
  %8 = icmp sgt i32 %2, 1
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %9 = sext i32 %6 to i64
  %wide.trip.count = zext nneg i32 %7 to i64
  %10 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %wide.trip.count, 3
  %11 = icmp ult i64 %10, 3
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %12 = mul nsw i64 %indvars.iv, %9
  %13 = getelementptr inbounds i8, ptr %1, i64 %12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %14 = mul nsw i64 %indvars.iv.next, %9
  %15 = getelementptr inbounds i8, ptr %1, i64 %14
  store ptr %15, ptr %13, align 8, !tbaa !5
  %16 = mul nsw i64 %indvars.iv.next, %9
  %17 = getelementptr inbounds i8, ptr %1, i64 %16
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %18 = mul nsw i64 %indvars.iv.next.1, %9
  %19 = getelementptr inbounds i8, ptr %1, i64 %18
  store ptr %19, ptr %17, align 8, !tbaa !5
  %20 = mul nsw i64 %indvars.iv.next.1, %9
  %21 = getelementptr inbounds i8, ptr %1, i64 %20
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %22 = mul nsw i64 %indvars.iv.next.2, %9
  %23 = getelementptr inbounds i8, ptr %1, i64 %22
  store ptr %23, ptr %21, align 8, !tbaa !5
  %24 = mul nsw i64 %indvars.iv.next.2, %9
  %25 = getelementptr inbounds i8, ptr %1, i64 %24
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %26 = mul nsw i64 %indvars.iv.next.3, %9
  %27 = getelementptr inbounds i8, ptr %1, i64 %26
  store ptr %27, ptr %25, align 8, !tbaa !5
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !10

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %28 = mul nsw i64 %indvars.iv.epil, %9
  %29 = getelementptr inbounds i8, ptr %1, i64 %28
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %30 = mul nsw i64 %indvars.iv.next.epil, %9
  %31 = getelementptr inbounds i8, ptr %1, i64 %30
  store ptr %31, ptr %29, align 8, !tbaa !5
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !12

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %4
  %32 = mul nsw i32 %6, %7
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %1, i64 %33
  store ptr null, ptr %34, align 8, !tbaa !5
  store i32 %2, ptr %0, align 8, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %6, ptr %35, align 4, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %36, align 8, !tbaa !18
  %37 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %1, ptr %37, align 8, !tbaa !19
  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, !7, i64 0}
!6 = !{!"array_node", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = !{!15, !16, i64 0}
!15 = !{!"array", !16, i64 0, !16, i64 4, !7, i64 8, !7, i64 16}
!16 = !{!"int", !8, i64 0}
!17 = !{!15, !16, i64 4}
!18 = !{!15, !7, i64 8}
!19 = !{!15, !7, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass