; LLVM IR from tangjz/acm-icpc :: loj (2563)

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

@ptot = external dso_local global i32, align 4
@p = external dso_local global [10000001 x i32], align 16
@d = external dso_local global [10000001 x i32], align 16
@t = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@etot = external dso_local global i32, align 4
@ex = external dso_local global [15 x i32], align 16
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@pr = external dso_local global [15 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9factorizexRiPxPi(i64 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsixx(i32 noundef, i64 noundef, i64 noundef) #1

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

6:                                                ; preds = %59, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 10000001
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %62

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %25, label %16

16:                                               ; preds = %10
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr @ptot, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @ptot, align 4, !tbaa !5
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds [10000001 x i32], ptr @p, i64 0, i64 %23
  store i32 %17, ptr %24, align 4, !tbaa !5
  br label %25

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

26:                                               ; preds = %54, %25
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10000001 x i32], ptr @p, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = mul nsw i32 %27, %31
  store i32 %32, ptr %5, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 10000001
  br i1 %33, label %35, label %34

34:                                               ; preds = %26
  store i32 5, ptr %3, align 4
  br label %57

35:                                               ; preds = %26
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10000001 x i32], ptr @p, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [10000001 x i32], ptr @p, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp eq i32 %46, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %35
  store i32 5, ptr %3, align 4
  br label %57

53:                                               ; preds = %35
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %4, align 4, !tbaa !5
  br label %26, !llvm.loop !9

57:                                               ; preds = %52, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

62:                                               ; preds = %9
  %63 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %64

64:                                               ; preds = %68, %62
  %65 = load i32, ptr @t, align 4, !tbaa !5
  %66 = add nsw i32 %65, -1
  store i32 %66, ptr @t, align 4, !tbaa !5
  %67 = icmp ne i32 %65, 0
  br i1 %67, label %68, label %77

68:                                               ; preds = %64
  %69 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m, ptr noundef @mod)
  %70 = load i32, ptr @mod, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = load i64, ptr @m, align 8, !tbaa !12
  %73 = srem i64 %72, %71
  store i64 %73, ptr @m, align 8, !tbaa !12
  %74 = load i64, ptr @n, align 8, !tbaa !12
  call void @_Z9factorizexRiPxPi(i64 noundef %74, ptr noundef nonnull align 4 dereferenceable(4) @etot, ptr noundef @pr, ptr noundef @ex)
  %75 = call noundef i32 @_Z3dfsixx(i32 noundef 0, i64 noundef 1, i64 noundef 1)
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %75)
  br label %64, !llvm.loop !14

77:                                               ; preds = %64
  ret i32 0
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 #3 = { "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 #4 = { 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 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !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"

@ptot = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@d = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@t = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@etot = external dso_local global i32, align 4
@ex = external dso_local global [15 x i32], align 16
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@pr = external dso_local global [15 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9factorizexRiPxPi(i64 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %ptot.promoted = load i32, ptr @ptot, align 4, !tbaa !5
  br label %5

1:                                                ; preds = %._crit_edge
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not18 = icmp eq i32 %3, 0
  br i1 %.not18, label %._crit_edge21, label %.lr.ph20

5:                                                ; preds = %0, %._crit_edge
  %indvars.iv23 = phi i64 [ 2, %0 ], [ %indvars.iv.next24, %._crit_edge ]
  %6 = phi i32 [ %ptot.promoted, %0 ], [ %14, %._crit_edge ]
  %7 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %indvars.iv23
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not14 = icmp eq i32 %8, 0
  %9 = trunc nuw nsw i64 %indvars.iv23 to i32
  br i1 %.not14, label %10, label %._crit_edge26

10:                                               ; preds = %5
  store i32 %9, ptr %7, align 4, !tbaa !5
  %11 = add nsw i32 %6, 1
  store i32 %11, ptr @ptot, align 4, !tbaa !5
  %12 = sext i32 %6 to i64
  %13 = getelementptr inbounds [10000001 x i32], ptr @p, i64 0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !5
  br label %._crit_edge26

._crit_edge26:                                    ; preds = %5, %10
  %14 = phi i32 [ %11, %10 ], [ %6, %5 ]
  %15 = load i32, ptr @p, align 16, !tbaa !5
  %16 = mul nsw i32 %15, %9
  %17 = icmp slt i32 %16, 10000001
  br i1 %17, label %.lr.ph, label %._crit_edge

18:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = getelementptr inbounds [10000001 x i32], ptr @p, i64 0, i64 %indvars.iv.next
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = mul nsw i32 %20, %9
  %22 = icmp slt i32 %21, 10000001
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph:                                           ; preds = %._crit_edge26, %18
  %indvars.iv = phi i64 [ %indvars.iv.next, %18 ], [ 0, %._crit_edge26 ]
  %23 = phi i32 [ %21, %18 ], [ %16, %._crit_edge26 ]
  %24 = phi i32 [ %20, %18 ], [ %15, %._crit_edge26 ]
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %25
  store i32 %24, ptr %26, align 4, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp eq i32 %27, %24
  br i1 %28, label %._crit_edge, label %18

._crit_edge:                                      ; preds = %18, %.lr.ph, %._crit_edge26
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next24, 10000001
  br i1 %exitcond.not, label %1, label %5, !llvm.loop !11

.lr.ph20:                                         ; preds = %1, %.lr.ph20
  %29 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @mod)
  %30 = load i32, ptr @mod, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = load i64, ptr @m, align 8, !tbaa !12
  %33 = srem i64 %32, %31
  store i64 %33, ptr @m, align 8, !tbaa !12
  %34 = load i64, ptr @n, align 8, !tbaa !12
  tail call void @_Z9factorizexRiPxPi(i64 noundef %34, ptr noundef nonnull align 4 dereferenceable(4) @etot, ptr noundef nonnull @pr, ptr noundef nonnull @ex)
  %35 = tail call noundef i32 @_Z3dfsixx(i32 noundef 0, i64 noundef 1, i64 noundef 1)
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %35)
  %37 = load i32, ptr @t, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %37, 0
  br i1 %.not, label %._crit_edge21, label %.lr.ph20, !llvm.loop !14

._crit_edge21:                                    ; preds = %.lr.ph20, %1
  ret i32 0
}

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

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

attributes #0 = { mustprogress 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 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 #2 = { 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 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass