; LLVM IR from ShahjalalShohag/code-library :: Math/Matrix Exponentiation With Polynomial Coefficients.ll (Z10precomputei)

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

@lim = external dso_local global i32, align 4
@rev = external dso_local global [65536 x i32], align 16
@wn = external dso_local global [65536 x i32], align 16
@inv_lim = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3POWiii(i32 noundef, i32 noundef, i32 noundef) #0

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

7:                                                ; preds = %11, %1
  %8 = load i32, ptr @lim, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %11, label %16

11:                                               ; preds = %7
  %12 = load i32, ptr @lim, align 4, !tbaa !5
  %13 = shl i32 %12, 1
  store i32 %13, ptr @lim, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %3, align 4, !tbaa !5
  br label %7, !llvm.loop !9

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

17:                                               ; preds = %37, %16
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr @lim, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %17
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = ashr i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [65536 x i32], ptr @rev, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = ashr i32 %27, 1
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = and i32 %29, 1
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = shl i32 %30, %31
  %33 = or i32 %28, %32
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [65536 x i32], ptr @rev, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %22
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %4, align 4, !tbaa !5
  br label %17, !llvm.loop !11

40:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %41 = load i32, ptr @lim, align 4, !tbaa !5
  %42 = sdiv i32 998244352, %41
  %43 = call noundef i32 @_Z3POWiii(i32 noundef 3, i32 noundef %42, i32 noundef 1)
  store i32 %43, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr @lim, align 4, !tbaa !5
  %45 = call noundef i32 @_Z3POWiii(i32 noundef %44, i32 noundef 998244351, i32 noundef 1)
  store i32 %45, ptr @inv_lim, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %66, %40
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr @lim, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %69

51:                                               ; preds = %46
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sub nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [65536 x i32], ptr @wn, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %57, %59
  %61 = srem i64 %60, 998244353
  %62 = trunc i64 %61 to i32
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [65536 x i32], ptr @wn, i64 0, i64 %64
  store i32 %62, ptr %65, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %51
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %6, align 4, !tbaa !5
  br label %46, !llvm.loop !12

69:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #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 = { 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"

@lim = external dso_local local_unnamed_addr global i32, align 4
@rev = external dso_local local_unnamed_addr global [65536 x i32], align 16
@wn = external dso_local local_unnamed_addr global [65536 x i32], align 16
@inv_lim = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3POWiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10precomputei(i32 noundef %0) local_unnamed_addr #0 {
  store i32 1, ptr @wn, align 16, !tbaa !5
  store i32 1, ptr @lim, align 4, !tbaa !5
  %2 = icmp sgt i32 %0, 1
  br i1 %2, label %.lr.ph, label %.lr.ph21.preheader

.preheader:                                       ; preds = %.lr.ph
  store i32 %7, ptr @lim, align 4, !tbaa !5
  %3 = icmp sgt i32 %7, 0
  br i1 %3, label %.lr.ph21.preheader, label %._crit_edge

.lr.ph21.preheader:                               ; preds = %1, %.preheader
  %.lcssa38 = phi i32 [ %7, %.preheader ], [ 1, %1 ]
  %.013.lcssa36 = phi i32 [ %8, %.preheader ], [ -1, %1 ]
  %wide.trip.count = zext nneg i32 %.lcssa38 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %4 = icmp eq i32 %.lcssa38, 1
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph21.preheader.new

.lr.ph21.preheader.new:                           ; preds = %.lr.ph21.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %5 = shl nuw i32 1, %.013.lcssa36
  br label %.lr.ph21

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.01317 = phi i32 [ %8, %.lr.ph ], [ -1, %1 ]
  %6 = phi i32 [ %7, %.lr.ph ], [ 1, %1 ]
  %7 = shl i32 %6, 1
  %8 = add nsw i32 %.01317, 1
  %9 = icmp slt i32 %7, %0
  br i1 %9, label %.lr.ph, label %.preheader, !llvm.loop !9

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

.lr.ph21.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %10 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %11 = lshr i64 %indvars.iv.unr, 1
  %12 = and i64 %11, 2147483647
  %13 = getelementptr inbounds [65536 x i32], ptr @rev, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = ashr i32 %14, 1
  %16 = and i32 %10, 1
  %17 = shl nuw i32 %16, %.013.lcssa36
  %18 = or i32 %15, %17
  %19 = getelementptr inbounds [65536 x i32], ptr @rev, i64 0, i64 %indvars.iv.unr
  store i32 %18, ptr %19, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph21.epil, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %.lcssa37 = phi i32 [ %7, %.preheader ], [ %.lcssa38, %._crit_edge.loopexit.unr-lcssa ], [ %.lcssa38, %.lr.ph21.epil ]
  %20 = sdiv i32 998244352, %.lcssa37
  %21 = tail call noundef i32 @_Z3POWiii(i32 noundef 3, i32 noundef %20, i32 noundef 1)
  %22 = load i32, ptr @lim, align 4, !tbaa !5
  %23 = tail call noundef i32 @_Z3POWiii(i32 noundef %22, i32 noundef 998244351, i32 noundef 1)
  store i32 %23, ptr @inv_lim, align 4, !tbaa !5
  %24 = load i32, ptr @lim, align 4, !tbaa !5
  %25 = icmp sgt i32 %24, 1
  br i1 %25, label %.lr.ph24, label %._crit_edge25

.lr.ph24:                                         ; preds = %._crit_edge
  %26 = sext i32 %21 to i64
  %wide.trip.count32 = zext nneg i32 %24 to i64
  %.pre = load i32, ptr @wn, align 16, !tbaa !5
  %27 = add nsw i64 %wide.trip.count32, -1
  %xtraiter42 = and i64 %27, 1
  %28 = icmp eq i32 %24, 2
  br i1 %28, label %._crit_edge25.loopexit.unr-lcssa, label %.lr.ph24.new

.lr.ph24.new:                                     ; preds = %.lr.ph24
  %unroll_iter44 = and i64 %27, -2
  br label %47

.lr.ph21:                                         ; preds = %.lr.ph21, %.lr.ph21.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph21.preheader.new ], [ %indvars.iv.next.1, %.lr.ph21 ]
  %niter = phi i64 [ 0, %.lr.ph21.preheader.new ], [ %niter.next.1, %.lr.ph21 ]
  %29 = lshr exact i64 %indvars.iv, 1
  %30 = and i64 %29, 2147483647
  %31 = getelementptr inbounds [65536 x i32], ptr @rev, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = ashr i32 %32, 1
  %34 = getelementptr inbounds [65536 x i32], ptr @rev, i64 0, i64 %indvars.iv
  store i32 %33, ptr %34, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %35 = lshr exact i64 %indvars.iv, 1
  %36 = and i64 %35, 2147483647
  %37 = getelementptr inbounds [65536 x i32], ptr @rev, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = ashr i32 %38, 1
  %40 = or i32 %39, %5
  %41 = getelementptr inbounds [65536 x i32], ptr @rev, i64 0, i64 %indvars.iv.next
  store i32 %40, ptr %41, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph21, !llvm.loop !11

._crit_edge25.loopexit.unr-lcssa:                 ; preds = %47, %.lr.ph24
  %.unr = phi i32 [ %.pre, %.lr.ph24 ], [ %56, %47 ]
  %indvars.iv29.unr = phi i64 [ 1, %.lr.ph24 ], [ %indvars.iv.next30.1, %47 ]
  %lcmp.mod43.not = icmp eq i64 %xtraiter42, 0
  br i1 %lcmp.mod43.not, label %._crit_edge25, label %._crit_edge25.loopexit.epilog-lcssa

._crit_edge25.loopexit.epilog-lcssa:              ; preds = %._crit_edge25.loopexit.unr-lcssa
  %42 = sext i32 %.unr to i64
  %43 = mul nsw i64 %42, %26
  %44 = srem i64 %43, 998244353
  %45 = trunc nsw i64 %44 to i32
  %46 = getelementptr inbounds [65536 x i32], ptr @wn, i64 0, i64 %indvars.iv29.unr
  store i32 %45, ptr %46, align 4, !tbaa !5
  br label %._crit_edge25

._crit_edge25:                                    ; preds = %._crit_edge25.loopexit.epilog-lcssa, %._crit_edge25.loopexit.unr-lcssa, %._crit_edge
  ret void

47:                                               ; preds = %47, %.lr.ph24.new
  %48 = phi i32 [ %.pre, %.lr.ph24.new ], [ %56, %47 ]
  %indvars.iv29 = phi i64 [ 1, %.lr.ph24.new ], [ %indvars.iv.next30.1, %47 ]
  %niter45 = phi i64 [ 0, %.lr.ph24.new ], [ %niter45.next.1, %47 ]
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %49, %26
  %51 = srem i64 %50, 998244353
  %52 = trunc nsw i64 %51 to i32
  %53 = getelementptr inbounds [65536 x i32], ptr @wn, i64 0, i64 %indvars.iv29
  store i32 %52, ptr %53, align 4, !tbaa !5
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %54 = mul nsw i64 %51, %26
  %55 = srem i64 %54, 998244353
  %56 = trunc nsw i64 %55 to i32
  %57 = getelementptr inbounds [65536 x i32], ptr @wn, i64 0, i64 %indvars.iv.next30
  store i32 %56, ptr %57, align 4, !tbaa !5
  %indvars.iv.next30.1 = add nuw nsw i64 %indvars.iv29, 2
  %niter45.next.1 = add i64 %niter45, 2
  %niter45.ncmp.1 = icmp eq i64 %niter45.next.1, %unroll_iter44
  br i1 %niter45.ncmp.1, label %._crit_edge25.loopexit.unr-lcssa, label %47, !llvm.loop !12
}

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

!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}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass