; LLVM IR from Dev-XYS/Algorithms :: Stirling-Number(Subset,Recursion).ll (Z6init_Sv)

; 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
@S = external dso_local global [100 x [100 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6init_Sv() #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 @S, 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 @S, 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 @S, 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 = %64, %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 %67

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 = %60, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %2, 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 %63

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 @S, 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 @S, 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 %4, align 4, !tbaa !5
  %52 = mul nsw i32 %50, %51
  %53 = add nsw i32 %42, %52
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %55
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100 x i32], ptr %56, i64 0, i64 %58
  store i32 %53, ptr %59, align 4, !tbaa !5
  br label %60

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

63:                                               ; preds = %32
  br label %64

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

67:                                               ; 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
@S = 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 @_Z6init_Sv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not20 = icmp slt i32 %1, 1
  br i1 %.not20, label %._crit_edge.thread, label %.lr.ph.preheader

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

.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 @S, i64 0, i64 %indvars.iv.epil
  store i32 0, ptr %4, align 16, !tbaa !5
  %5 = getelementptr inbounds [100 x i32], ptr @S, 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 @S, align 16, !tbaa !5
  br i1 %.not20, label %._crit_edge25, label %.preheader.preheader

.preheader.preheader:                             ; preds = %._crit_edge
  %6 = add nuw i32 %1, 1
  %wide.trip.count41 = zext i32 %6 to i64
  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 ]
  %7 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %indvars.iv
  store i32 0, ptr %7, align 16, !tbaa !5
  %8 = getelementptr inbounds [100 x i32], ptr @S, i64 0, i64 %indvars.iv
  store i32 0, ptr %8, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %indvars.iv.next
  store i32 0, ptr %9, align 16, !tbaa !5
  %10 = getelementptr inbounds [100 x i32], ptr @S, i64 0, i64 %indvars.iv.next
  store i32 0, ptr %10, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %11 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %indvars.iv.next.1
  store i32 0, ptr %11, align 16, !tbaa !5
  %12 = getelementptr inbounds [100 x i32], ptr @S, i64 0, i64 %indvars.iv.next.1
  store i32 0, ptr %12, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %13 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %indvars.iv.next.2
  store i32 0, ptr %13, align 16, !tbaa !5
  %14 = getelementptr inbounds [100 x i32], ptr @S, i64 0, i64 %indvars.iv.next.2
  store i32 0, ptr %14, 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, %.loopexit
  %indvars.iv36 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next37, %.loopexit ]
  %indvars.iv34 = phi i64 [ 2, %.preheader.preheader ], [ %indvars.iv.next35, %.loopexit ]
  %15 = add nsw i64 %indvars.iv36, -1
  %.phi.trans.insert = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %15, i64 0
  %.pre = load i32, ptr %.phi.trans.insert, align 16, !tbaa !5
  %min.iters.check = icmp ult i64 %indvars.iv36, 4
  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.iv27.ph = phi i64 [ 1, %.preheader ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.preheader
  %n.vec = and i64 %indvars.iv36, 9223372036854775804
  %ind.end = or disjoint i64 %n.vec, 1
  %vector.recur.init = insertelement <4 x i32> poison, i32 %.pre, i64 3
  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 ]
  %vec.ind = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %16 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %15, i64 %offset.idx
  %wide.load = load <4 x i32>, ptr %16, align 4, !tbaa !5
  %17 = shufflevector <4 x i32> %vector.recur, <4 x i32> %wide.load, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %18 = mul nsw <4 x i32> %wide.load, %vec.ind
  %19 = add nsw <4 x i32> %18, %17
  %20 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %indvars.iv36, i64 %offset.idx
  store <4 x i32> %19, ptr %20, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, 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
  %cmp.n = icmp eq i64 %indvars.iv36, %n.vec
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

._crit_edge25:                                    ; preds = %.loopexit, %._crit_edge.thread, %._crit_edge
  ret void

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count41
  br i1 %exitcond42.not, label %._crit_edge25, label %.preheader, !llvm.loop !16

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %22 = phi i32 [ %24, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %scalar.ph ], [ %indvars.iv27.ph, %scalar.ph.preheader ]
  %23 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %15, i64 %indvars.iv27
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = trunc nuw nsw i64 %indvars.iv27 to i32
  %26 = mul nsw i32 %24, %25
  %27 = add nsw i32 %26, %22
  %28 = getelementptr inbounds [100 x [100 x i32]], ptr @S, i64 0, i64 %indvars.iv36, i64 %indvars.iv27
  store i32 %27, ptr %28, align 4, !tbaa !5
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next28, %indvars.iv34
  br i1 %exitcond33.not, label %.loopexit, 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,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass