; LLVM IR from Dev-XYS/Algorithms :: Stirling-Number(Cycle,Unsigned,Recursion).ll (Z7init_suv)

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

@n = external dso_local global i32, align 4
@su = external dso_local global [100 x [100 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7init_suv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %18, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %21

10:                                               ; preds = %5
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %12
  %14 = getelementptr inbounds [100 x i32], ptr %13, i64 0, i64 0
  store i32 0, ptr %14, align 16, !tbaa !5
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100 x i32], ptr @su, i64 0, i64 %16
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %10
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !9

21:                                               ; preds = %9
  store i32 1, ptr @su, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %65, %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %68

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %61, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %64

33:                                               ; preds = %28
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100 x i32], ptr %37, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %45
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x i32], ptr %46, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = mul nsw i32 %50, %52
  %54 = add nsw i32 %42, %53
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %56
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100 x i32], ptr %57, i64 0, i64 %59
  store i32 %54, ptr %60, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %33
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %4, align 4, !tbaa !5
  br label %28, !llvm.loop !11

64:                                               ; preds = %32
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !12

68:                                               ; preds = %26
  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 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@su = external dso_local local_unnamed_addr global [100 x [100 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7init_suv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not19 = icmp slt i32 %1, 1
  br i1 %.not19, label %._crit_edge.thread, label %.lr.ph.preheader

._crit_edge.thread:                               ; preds = %0
  store i32 1, ptr @su, align 16, !tbaa !5
  br label %._crit_edge27

.lr.ph.preheader:                                 ; preds = %0
  %2 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %2, 3
  %3 = icmp ult i32 %1, 4
  br i1 %3, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

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

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 1, %.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.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %4 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %indvars.iv.epil
  store i32 0, ptr %4, align 16, !tbaa !5
  %5 = getelementptr inbounds [100 x i32], ptr @su, i64 0, i64 %indvars.iv.epil
  store i32 0, ptr %5, align 4, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %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 !9

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  store i32 1, ptr @su, align 16, !tbaa !5
  br i1 %.not19, label %._crit_edge27, label %.preheader.preheader

.preheader.preheader:                             ; preds = %._crit_edge
  %6 = add nuw i32 %1, 1
  %wide.trip.count37 = zext i32 %6 to i64
  %7 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 4
  %n.vec = and i64 %7, 2147483644
  %ind.end = or disjoint i64 %n.vec, 1
  %cmp.n = icmp eq i64 %n.vec, %7
  br label %.preheader

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %8 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %indvars.iv
  store i32 0, ptr %8, align 16, !tbaa !5
  %9 = getelementptr inbounds [100 x i32], ptr @su, i64 0, i64 %indvars.iv
  store i32 0, ptr %9, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %indvars.iv.next
  store i32 0, ptr %10, align 16, !tbaa !5
  %11 = getelementptr inbounds [100 x i32], ptr @su, i64 0, i64 %indvars.iv.next
  store i32 0, ptr %11, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %12 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %indvars.iv.next.1
  store i32 0, ptr %12, align 16, !tbaa !5
  %13 = getelementptr inbounds [100 x i32], ptr @su, i64 0, i64 %indvars.iv.next.1
  store i32 0, ptr %13, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %14 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %indvars.iv.next.2
  store i32 0, ptr %14, align 16, !tbaa !5
  %15 = getelementptr inbounds [100 x i32], ptr @su, i64 0, i64 %indvars.iv.next.2
  store i32 0, ptr %15, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add nuw i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge24
  %indvars.iv34 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next35, %._crit_edge24 ]
  %16 = add nsw i64 %indvars.iv34, -1
  %.phi.trans.insert = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %16, i64 0
  %.pre = load i32, ptr %.phi.trans.insert, align 16, !tbaa !5
  %17 = trunc nuw nsw i64 %16 to i32
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader
  %.ph = phi i32 [ %.pre, %.preheader ], [ %vector.recur.extract, %middle.block ]
  %indvars.iv29.ph = phi i64 [ 1, %.preheader ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.preheader
  %vector.recur.init = insertelement <4 x i32> poison, i32 %.pre, i64 3
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %17, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ %wide.load, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %18 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %16, i64 %offset.idx
  %wide.load = load <4 x i32>, ptr %18, align 4, !tbaa !5
  %19 = shufflevector <4 x i32> %vector.recur, <4 x i32> %wide.load, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %20 = mul nsw <4 x i32> %wide.load, %broadcast.splat
  %21 = add nsw <4 x i32> %20, %19
  %22 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %indvars.iv34, i64 %offset.idx
  store <4 x i32> %21, ptr %22, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %vector.recur.extract = extractelement <4 x i32> %wide.load, i64 3
  br i1 %cmp.n, label %._crit_edge24, label %scalar.ph.preheader

._crit_edge27:                                    ; preds = %._crit_edge24, %._crit_edge.thread, %._crit_edge
  ret void

._crit_edge24:                                    ; preds = %scalar.ph, %middle.block
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge27, label %.preheader, !llvm.loop !16

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %24 = phi i32 [ %26, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %scalar.ph ], [ %indvars.iv29.ph, %scalar.ph.preheader ]
  %25 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %16, i64 %indvars.iv29
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = mul nsw i32 %26, %17
  %28 = add nsw i32 %27, %24
  %29 = getelementptr inbounds [100 x [100 x i32]], ptr @su, i64 0, i64 %indvars.iv34, i64 %indvars.iv29
  store i32 %28, ptr %29, align 4, !tbaa !5
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next30, %wide.trip.count37
  br i1 %exitcond33.not, label %._crit_edge24, label %scalar.ph, !llvm.loop !17
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, 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" }

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass