; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数学算法/递推式求解.ll (Z5solvePiS_x)

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

@tmpa = external dso_local global [2100 x i32], align 16
@res = external dso_local global [2100 x i32], align 16
@k = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3mulPiS_S_(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5solvePiS_x(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %10 = load i64, ptr %7, align 8, !tbaa !9
  %11 = load i32, ptr @k, align 4, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %10, %12
  br i1 %13, label %14, label %19

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = getelementptr inbounds i32, ptr %15, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !11
  store i32 %18, ptr %4, align 4
  br label %63

19:                                               ; preds = %3
  call void @llvm.memset.p0.i64(ptr align 16 @tmpa, i8 0, i64 8400, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @res, i8 0, i64 8400, i1 false)
  store i32 1, ptr @res, align 16, !tbaa !11
  store i32 1, ptr getelementptr inbounds ([2100 x i32], ptr @tmpa, i64 0, i64 1), align 4, !tbaa !11
  br label %20

20:                                               ; preds = %29, %19
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %33

23:                                               ; preds = %20
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = and i64 %24, 1
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z3mulPiS_S_(ptr noundef @res, ptr noundef @tmpa, ptr noundef %28)
  br label %29

29:                                               ; preds = %27, %23
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z3mulPiS_S_(ptr noundef @tmpa, ptr noundef @tmpa, ptr noundef %30)
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = ashr i64 %31, 1
  store i64 %32, ptr %7, align 8, !tbaa !9
  br label %20, !llvm.loop !13

33:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %58, %33
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = load i32, ptr @k, align 4, !tbaa !11
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %61

39:                                               ; preds = %34
  %40 = load i32, ptr %8, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = mul nsw i64 1, %47
  %49 = load i32, ptr %9, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [2100 x i32], ptr @res, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = sext i32 %52 to i64
  %54 = mul nsw i64 %48, %53
  %55 = add nsw i64 %41, %54
  %56 = srem i64 %55, 1000000007
  %57 = trunc i64 %56 to i32
  store i32 %57, ptr %8, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %39
  %59 = load i32, ptr %9, align 4, !tbaa !11
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %9, align 4, !tbaa !11
  br label %34, !llvm.loop !15

61:                                               ; preds = %38
  %62 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %62, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %63

63:                                               ; preds = %61, %14
  %64 = load i32, ptr %4, align 4
  ret i32 %64
}

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@tmpa = external dso_local global [2100 x i32], align 16
@res = external dso_local global [2100 x i32], align 16
@k = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3mulPiS_S_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5solvePiS_x(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @k, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = icmp sgt i64 %5, %2
  br i1 %6, label %7, label %10

7:                                                ; preds = %3
  %8 = getelementptr inbounds i32, ptr %0, i64 %2
  %9 = load i32, ptr %8, align 4, !tbaa !5
  br label %.loopexit

10:                                               ; preds = %3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(8400) @tmpa, i8 0, i64 8400, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(8400) @res, i8 0, i64 8400, i1 false)
  store i32 1, ptr @res, align 16, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @tmpa, i64 4), align 4, !tbaa !5
  %.not20 = icmp eq i64 %2, 0
  br i1 %.not20, label %.preheader, label %.lr.ph

.preheader.loopexit:                              ; preds = %16
  %.pre = load i32, ptr @k, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %10
  %11 = phi i32 [ %.pre, %.preheader.loopexit ], [ %4, %10 ]
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph24.preheader, label %.loopexit

.lr.ph24.preheader:                               ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %11 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %13 = icmp eq i32 %11, 1
  br i1 %13, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph24.preheader.new

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

.lr.ph:                                           ; preds = %10, %16
  %.01621 = phi i64 [ %17, %16 ], [ %2, %10 ]
  %14 = and i64 %.01621, 1
  %.not19 = icmp eq i64 %14, 0
  br i1 %.not19, label %16, label %15

15:                                               ; preds = %.lr.ph
  tail call void @_Z3mulPiS_S_(ptr noundef nonnull @res, ptr noundef nonnull @tmpa, ptr noundef %1)
  br label %16

16:                                               ; preds = %15, %.lr.ph
  tail call void @_Z3mulPiS_S_(ptr noundef nonnull @tmpa, ptr noundef nonnull @tmpa, ptr noundef %1)
  %17 = ashr i64 %.01621, 1
  %.not = icmp ult i64 %.01621, 2
  br i1 %.not, label %.preheader.loopexit, label %.lr.ph, !llvm.loop !9

.lr.ph24:                                         ; preds = %.lr.ph24, %.lr.ph24.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph24.preheader.new ], [ %indvars.iv.next.1, %.lr.ph24 ]
  %.01522 = phi i64 [ 0, %.lr.ph24.preheader.new ], [ %35, %.lr.ph24 ]
  %niter = phi i64 [ 0, %.lr.ph24.preheader.new ], [ %niter.next.1, %.lr.ph24 ]
  %18 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [2100 x i32], ptr @res, i64 0, i64 %indvars.iv
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %23, %20
  %25 = add nsw i64 %24, %.01522
  %26 = srem i64 %25, 1000000007
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %27 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2100 x i32], ptr @res, i64 0, i64 %indvars.iv.next
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = mul nsw i64 %32, %29
  %34 = add nsw i64 %33, %26
  %35 = srem i64 %34, 1000000007
  %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 %.loopexit.loopexit.unr-lcssa, label %.lr.ph24, !llvm.loop !11

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

.lr.ph24.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa
  %36 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.unr
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2100 x i32], ptr @res, i64 0, i64 %indvars.iv.unr
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = mul nsw i64 %41, %38
  %43 = add nsw i64 %42, %.01522.unr
  %44 = srem i64 %43, 1000000007
  br label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph24.epil
  %.lcssa = phi i64 [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %44, %.lr.ph24.epil ]
  %45 = trunc nsw i64 %.lcssa to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.preheader, %7
  %.017 = phi i32 [ %9, %7 ], [ 0, %.preheader ], [ %45, %.loopexit.loopexit ]
  ret i32 %.017
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

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


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