; LLVM IR from upupming/algorithm :: kick-start/2021/RoundC/A.  Smaller Strings.ll (Z7preworkv)

; 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 i64, align 8
@k = external dso_local global i64, align 8
@f = external dso_local global [100010 x i64], align 16

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

2:                                                ; preds = %20, %0
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = icmp sle i64 %3, %4
  br i1 %5, label %7, label %6

6:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  br label %23

7:                                                ; preds = %2
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = sub nsw i64 %8, 1
  %10 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = load i64, ptr @k, align 8, !tbaa !5
  %13 = mul nsw i64 %11, %12
  %14 = srem i64 %13, 1000000007
  %15 = load i64, ptr %1, align 8, !tbaa !5
  %16 = add nsw i64 %15, 1
  %17 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %16
  store i64 %14, ptr %17, align 8, !tbaa !5
  %18 = load i64, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %18
  store i64 %14, ptr %19, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %7
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = add nsw i64 %21, 2
  store i64 %22, ptr %1, align 8, !tbaa !5
  br label %2, !llvm.loop !9

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


; 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 i64, align 8
@k = external dso_local local_unnamed_addr global i64, align 8
@f = external dso_local local_unnamed_addr global [100010 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7preworkv() local_unnamed_addr #0 {
  store i64 1, ptr @f, align 16, !tbaa !5
  %1 = load i64, ptr @n, align 8, !tbaa !5
  %.not5 = icmp slt i64 %1, 1
  br i1 %.not5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %2 = load i64, ptr @k, align 8, !tbaa !5
  %3 = add nsw i64 %1, -1
  %4 = icmp ult i64 %1, 3
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %5 = lshr i64 %3, 1
  %6 = add nuw i64 %5, 1
  %unroll_iter = and i64 %6, -2
  br label %13

._crit_edge.loopexit.unr-lcssa:                   ; preds = %13, %.lr.ph
  %.unr = phi i64 [ 1, %.lr.ph ], [ %22, %13 ]
  %.06.unr = phi i64 [ 1, %.lr.ph ], [ %26, %13 ]
  %7 = and i64 %3, 2
  %lcmp.mod.not.not = icmp eq i64 %7, 0
  br i1 %lcmp.mod.not.not, label %._crit_edge.loopexit.epilog-lcssa, label %._crit_edge

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %8 = mul nsw i64 %2, %.unr
  %9 = srem i64 %8, 1000000007
  %10 = add nuw nsw i64 %.06.unr, 1
  %11 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %10
  store i64 %9, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %.06.unr
  store i64 %9, ptr %12, align 8, !tbaa !5
  br label %._crit_edge

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

13:                                               ; preds = %13, %.lr.ph.new
  %14 = phi i64 [ 1, %.lr.ph.new ], [ %22, %13 ]
  %.06 = phi i64 [ 1, %.lr.ph.new ], [ %26, %13 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %13 ]
  %15 = mul nsw i64 %2, %14
  %16 = srem i64 %15, 1000000007
  %17 = add nuw nsw i64 %.06, 1
  %18 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %17
  store i64 %16, ptr %18, align 8, !tbaa !5
  %19 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %.06
  store i64 %16, ptr %19, align 8, !tbaa !5
  %20 = add nuw nsw i64 %.06, 2
  %21 = mul nsw i64 %2, %16
  %22 = srem i64 %21, 1000000007
  %23 = add nuw nsw i64 %.06, 3
  %24 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %23
  store i64 %22, ptr %24, align 8, !tbaa !5
  %25 = getelementptr inbounds [100010 x i64], ptr @f, i64 0, i64 %20
  store i64 %22, ptr %25, align 8, !tbaa !5
  %26 = add nuw nsw i64 %.06, 4
  %niter.next.1 = add nuw nsw 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 %13, !llvm.loop !9
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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