; LLVM IR from lzyrapx/Competitive-Programming :: 51Nod (1057（大数阶乘）)

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

@a = external dso_local global <{ i32, [9998 x i32] }>, align 16
@n = external dso_local global i32, align 4
@i = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@len = external dso_local global i32, align 4
@j = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 1, ptr @len, align 4, !tbaa !5
  store i32 2, ptr @j, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %40, %0
  %4 = load i32, ptr @j, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sle i32 %4, %5
  br i1 %6, label %7, label %43

7:                                                ; preds = %3
  store i32 0, ptr @c, align 4, !tbaa !5
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %27, %7
  %9 = load i32, ptr @i, align 4, !tbaa !5
  %10 = load i32, ptr @len, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %30

12:                                               ; preds = %8
  %13 = load i32, ptr @i, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = load i32, ptr @j, align 4, !tbaa !5
  %18 = mul nsw i32 %16, %17
  %19 = load i32, ptr @c, align 4, !tbaa !5
  %20 = add nsw i32 %19, %18
  store i32 %20, ptr @c, align 4, !tbaa !5
  %21 = srem i32 %20, 100000
  %22 = load i32, ptr @i, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %23
  store i32 %21, ptr %24, align 4, !tbaa !5
  %25 = load i32, ptr @c, align 4, !tbaa !5
  %26 = sdiv i32 %25, 100000
  store i32 %26, ptr @c, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %12
  %28 = load i32, ptr @i, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @i, align 4, !tbaa !5
  br label %8, !llvm.loop !9

30:                                               ; preds = %8
  %31 = load i32, ptr @c, align 4, !tbaa !5
  %32 = load i32, ptr @i, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %33
  store i32 %31, ptr %34, align 4, !tbaa !5
  %35 = icmp sgt i32 %31, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %30
  %37 = load i32, ptr @len, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @len, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %36, %30
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr @j, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr @j, align 4, !tbaa !5
  br label %3, !llvm.loop !11

43:                                               ; preds = %3
  %44 = load i32, ptr @len, align 4, !tbaa !5
  %45 = add nsw i32 %44, -1
  store i32 %45, ptr @len, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %48)
  br label %50

50:                                               ; preds = %53, %43
  %51 = load i32, ptr @len, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %60

53:                                               ; preds = %50
  %54 = load i32, ptr @len, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr @len, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %58)
  br label %50, !llvm.loop !12

60:                                               ; preds = %50
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { mustprogress norecurse 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 = { "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}


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

@a = external dso_local local_unnamed_addr global <{ i32, [9998 x i32] }>, align 16
@n = external dso_local global i32, align 4
@i = external dso_local local_unnamed_addr global i32, align 4
@c = external dso_local local_unnamed_addr global i32, align 4
@len = external dso_local local_unnamed_addr global i32, align 4
@j = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not11 = icmp slt i32 %2, 2
  br i1 %.not11, label %21, label %.lr.ph14.preheader

.lr.ph14.preheader:                               ; preds = %0
  %3 = add nuw i32 %2, 1
  br label %.lr.ph14

.lr.ph14:                                         ; preds = %.lr.ph14.preheader, %17
  %storemerge12 = phi i32 [ %19, %17 ], [ 2, %.lr.ph14.preheader ]
  %4 = phi i32 [ %18, %17 ], [ 1, %.lr.ph14.preheader ]
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.lr.ph14
  store i32 0, ptr @a, align 16, !tbaa !5
  br label %17

.lr.ph.preheader:                                 ; preds = %.lr.ph14
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %6 = phi i32 [ 0, %.lr.ph.preheader ], [ %12, %.lr.ph ]
  %7 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %indvars.iv
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = mul nsw i32 %8, %storemerge12
  %10 = add nsw i32 %6, %9
  %11 = srem i32 %10, 100000
  store i32 %11, ptr %7, align 4, !tbaa !5
  %12 = sdiv i32 %10, 100000
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %13 = zext nneg i32 %4 to i64
  %14 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %13
  store i32 %12, ptr %14, align 4, !tbaa !5
  %15 = icmp sgt i32 %10, 99999
  %16 = zext i1 %15 to i32
  %spec.select = add nuw nsw i32 %4, %16
  br label %17

17:                                               ; preds = %._crit_edge, %._crit_edge.thread
  %storemerge3.lcssa428 = phi i32 [ 0, %._crit_edge.thread ], [ %4, %._crit_edge ]
  %.lcssa81027 = phi i32 [ 0, %._crit_edge.thread ], [ %12, %._crit_edge ]
  %18 = phi i32 [ %4, %._crit_edge.thread ], [ %spec.select, %._crit_edge ]
  %19 = add nuw i32 %storemerge12, 1
  %exitcond24.not = icmp eq i32 %storemerge12, %2
  br i1 %exitcond24.not, label %._crit_edge15, label %.lr.ph14, !llvm.loop !11

._crit_edge15:                                    ; preds = %17
  store i32 %.lcssa81027, ptr @c, align 4, !tbaa !5
  store i32 %storemerge3.lcssa428, ptr @i, align 4, !tbaa !5
  %20 = add nsw i32 %18, -1
  br label %21

21:                                               ; preds = %._crit_edge15, %0
  %22 = phi i32 [ %20, %._crit_edge15 ], [ 0, %0 ]
  %storemerge.lcssa = phi i32 [ %3, %._crit_edge15 ], [ 2, %0 ]
  store i32 %storemerge.lcssa, ptr @j, align 4, !tbaa !5
  store i32 %22, ptr @len, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %25)
  %27 = load i32, ptr @len, align 4, !tbaa !5
  %.not217 = icmp eq i32 %27, 0
  br i1 %.not217, label %._crit_edge20, label %.lr.ph19

.lr.ph19:                                         ; preds = %21, %.lr.ph19
  %28 = phi i32 [ %34, %.lr.ph19 ], [ %27, %21 ]
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr @len, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [9999 x i32], ptr @a, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %32)
  %34 = load i32, ptr @len, align 4, !tbaa !5
  %.not2 = icmp eq i32 %34, 0
  br i1 %.not2, label %._crit_edge20, label %.lr.ph19, !llvm.loop !12

._crit_edge20:                                    ; preds = %.lr.ph19, %21
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nofree norecurse 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 = { nofree nounwind "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: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass