; LLVM IR from tangjz/acm-icpc :: lydsy (3667)

; 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
@pr = external dso_local global [65537 x i32], align 16
@d = external dso_local global [65537 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 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 noundef i64 @_Z9factorizex(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
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  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 %9

9:                                                ; preds = %62, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 65537
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [65537 x i32], ptr @d, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %28, label %19

19:                                               ; preds = %13
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [65537 x i32], ptr @d, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr @ptot, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @ptot, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [65537 x i32], ptr @pr, i64 0, i64 %26
  store i32 %20, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %19, %13
  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 %29

29:                                               ; preds = %57, %28
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [65537 x i32], ptr @pr, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %30, %34
  store i32 %35, ptr %5, align 4, !tbaa !5
  %36 = icmp slt i32 %35, 65537
  br i1 %36, label %38, label %37

37:                                               ; preds = %29
  store i32 5, ptr %3, align 4
  br label %60

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

55:                                               ; preds = %38
  store i32 5, ptr %3, align 4
  br label %60

56:                                               ; preds = %38
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %29, !llvm.loop !9

60:                                               ; preds = %55, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !11

65:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %66 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  br label %67

67:                                               ; preds = %86, %65
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = add nsw i32 %68, -1
  store i32 %69, ptr %6, align 4, !tbaa !5
  %70 = icmp ne i32 %68, 0
  br i1 %70, label %71, label %87

71:                                               ; preds = %67
  %72 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %73 = load i64, ptr %7, align 8, !tbaa !12
  %74 = call noundef i64 @_Z9factorizex(i64 noundef %73)
  store i64 %74, ptr %8, align 8, !tbaa !12
  %75 = load i64, ptr %8, align 8, !tbaa !12
  %76 = icmp eq i64 %75, 1
  br i1 %76, label %81, label %77

77:                                               ; preds = %71
  %78 = load i64, ptr %8, align 8, !tbaa !12
  %79 = load i64, ptr %7, align 8, !tbaa !12
  %80 = icmp slt i64 %78, %79
  br i1 %80, label %81, label %84

81:                                               ; preds = %77, %71
  %82 = load i64, ptr %8, align 8, !tbaa !12
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %82)
  br label %86

84:                                               ; preds = %77
  %85 = call i32 @puts(ptr noundef @.str.3)
  br label %86

86:                                               ; preds = %84, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %67, !llvm.loop !14

87:                                               ; preds = %67
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %88 = load i32, ptr %1, align 4
  ret i32 %88
}

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

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

declare i32 @puts(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
@pr = external dso_local local_unnamed_addr global [65537 x i32], align 16
@d = external dso_local local_unnamed_addr global [65537 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

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

; Function Attrs: mustprogress 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 noundef i64 @_Z9factorizex(i64 noundef) local_unnamed_addr #1

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

3:                                                ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr %1, align 4, !tbaa !5
  %.not24 = icmp eq i32 %5, 0
  br i1 %.not24, label %._crit_edge27, label %.lr.ph26

7:                                                ; preds = %0, %._crit_edge
  %indvars.iv29 = phi i64 [ 2, %0 ], [ %indvars.iv.next30, %._crit_edge ]
  %8 = phi i32 [ %ptot.promoted, %0 ], [ %16, %._crit_edge ]
  %9 = getelementptr inbounds [65537 x i32], ptr @d, i64 0, i64 %indvars.iv29
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not19 = icmp eq i32 %10, 0
  %11 = trunc nuw nsw i64 %indvars.iv29 to i32
  br i1 %.not19, label %12, label %._crit_edge32

12:                                               ; preds = %7
  store i32 %11, ptr %9, align 4, !tbaa !5
  %13 = add nsw i32 %8, 1
  store i32 %13, ptr @ptot, align 4, !tbaa !5
  %14 = sext i32 %8 to i64
  %15 = getelementptr inbounds [65537 x i32], ptr @pr, i64 0, i64 %14
  store i32 %11, ptr %15, align 4, !tbaa !5
  br label %._crit_edge32

._crit_edge32:                                    ; preds = %7, %12
  %16 = phi i32 [ %13, %12 ], [ %8, %7 ]
  %17 = load i32, ptr @pr, align 16, !tbaa !5
  %18 = mul nsw i32 %17, %11
  %19 = icmp slt i32 %18, 65537
  br i1 %19, label %.lr.ph, label %._crit_edge

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

.lr.ph:                                           ; preds = %._crit_edge32, %20
  %indvars.iv = phi i64 [ %indvars.iv.next, %20 ], [ 0, %._crit_edge32 ]
  %25 = phi i32 [ %23, %20 ], [ %18, %._crit_edge32 ]
  %26 = phi i32 [ %22, %20 ], [ %17, %._crit_edge32 ]
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [65537 x i32], ptr @d, i64 0, i64 %27
  store i32 %26, ptr %28, align 4, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = icmp eq i32 %29, %26
  br i1 %30, label %._crit_edge, label %20

._crit_edge:                                      ; preds = %20, %.lr.ph, %._crit_edge32
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next30, 65537
  br i1 %exitcond.not, label %3, label %7, !llvm.loop !11

.lr.ph26:                                         ; preds = %3, %41
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %32 = load i64, ptr %2, align 8, !tbaa !12
  %33 = call noundef i64 @_Z9factorizex(i64 noundef %32)
  %34 = icmp eq i64 %33, 1
  %35 = load i64, ptr %2, align 8
  %36 = icmp slt i64 %33, %35
  %or.cond = select i1 %34, i1 true, i1 %36
  br i1 %or.cond, label %37, label %39

37:                                               ; preds = %.lr.ph26
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %33)
  br label %41

39:                                               ; preds = %.lr.ph26
  %40 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %41

41:                                               ; preds = %39, %37
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %42, 0
  br i1 %.not, label %._crit_edge27, label %.lr.ph26, !llvm.loop !14

._crit_edge27:                                    ; preds = %41, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #3

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


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