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

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

@sum = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@f = external dso_local global [40 x i64], align 16
@s = external dso_local global [40 x i64], align 16
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = 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 void @_Z3dfsix(i32 noundef, i64 noundef) #1

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

6:                                                ; preds = %46, %0
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = mul nsw i64 %7, %8
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = icmp sle i64 %9, %10
  br i1 %11, label %12, label %15

12:                                               ; preds = %6
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = icmp sgt i64 %13, 1
  br label %15

15:                                               ; preds = %12, %6
  %16 = phi i1 [ false, %6 ], [ %14, %12 ]
  br i1 %16, label %18, label %17

17:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %49

18:                                               ; preds = %15
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = srem i64 %19, %20
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %45

23:                                               ; preds = %18
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = load i32, ptr @sum, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @sum, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [40 x i64], ptr @f, i64 0, i64 %27
  store i64 %24, ptr %28, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %38, %23
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = srem i64 %30, %31
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %44

34:                                               ; preds = %29
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr %2, align 8, !tbaa !5
  %37 = sdiv i64 %36, %35
  store i64 %37, ptr %2, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %34
  %39 = load i32, ptr @sum, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [40 x i64], ptr @s, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = add nsw i64 %42, 1
  store i64 %43, ptr %41, align 8, !tbaa !5
  br label %29, !llvm.loop !11

44:                                               ; preds = %29
  br label %45

45:                                               ; preds = %44, %18
  br label %46

46:                                               ; preds = %45
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %3, align 8, !tbaa !5
  br label %6, !llvm.loop !13

49:                                               ; preds = %17
  %50 = load i64, ptr %2, align 8, !tbaa !5
  %51 = icmp sgt i64 %50, 1
  br i1 %51, label %52, label %61

52:                                               ; preds = %49
  %53 = load i64, ptr %2, align 8, !tbaa !5
  %54 = load i32, ptr @sum, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr @sum, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [40 x i64], ptr @f, i64 0, i64 %56
  store i64 %53, ptr %57, align 8, !tbaa !5
  %58 = load i32, ptr @sum, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [40 x i64], ptr @s, i64 0, i64 %59
  store i64 1, ptr %60, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %52, %49
  call void @_Z3dfsix(i32 noundef 1, i64 noundef 1)
  %62 = load i64, ptr @ans, align 8, !tbaa !5
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %62)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@sum = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i64, align 8
@f = external dso_local local_unnamed_addr global [40 x i64], align 16
@s = external dso_local local_unnamed_addr global [40 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %sum.promoted = load i32, ptr @sum, align 4, !tbaa !9
  %3 = icmp sgt i64 %2, 3
  %4 = icmp sgt i64 %2, 1
  br i1 %3, label %.lr.ph19, label %._crit_edge

._crit_edge:                                      ; preds = %.loopexit, %0
  %5 = phi i32 [ %sum.promoted, %0 ], [ %22, %.loopexit ]
  %.014.lcssa = phi i64 [ %2, %0 ], [ %.2, %.loopexit ]
  %.lcssa = phi i1 [ %4, %0 ], [ %26, %.loopexit ]
  br i1 %.lcssa, label %28, label %33

.lr.ph19:                                         ; preds = %0, %.loopexit
  %.018 = phi i64 [ %23, %.loopexit ], [ 2, %0 ]
  %.01417 = phi i64 [ %.2, %.loopexit ], [ %2, %0 ]
  %6 = phi i32 [ %22, %.loopexit ], [ %sum.promoted, %0 ]
  %7 = urem i64 %.01417, %.018
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %.lr.ph19
  %10 = add nsw i32 %6, 1
  store i32 %10, ptr @sum, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [40 x i64], ptr @f, i64 0, i64 %11
  store i64 %.018, ptr %12, align 8, !tbaa !5
  %13 = srem i64 %.01417, %.018
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9
  %15 = getelementptr inbounds [40 x i64], ptr @s, i64 0, i64 %11
  %.promoted = load i64, ptr %15, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %.lr.ph, %16
  %17 = phi i64 [ %.promoted, %.lr.ph ], [ %19, %16 ]
  %.115 = phi i64 [ %.01417, %.lr.ph ], [ %18, %16 ]
  %18 = sdiv i64 %.115, %.018
  %19 = add nsw i64 %17, 1
  %20 = srem i64 %18, %.018
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %16, label %..loopexit_crit_edge, !llvm.loop !11

..loopexit_crit_edge:                             ; preds = %16
  store i64 %19, ptr %15, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %9, %..loopexit_crit_edge, %.lr.ph19
  %22 = phi i32 [ %6, %.lr.ph19 ], [ %10, %..loopexit_crit_edge ], [ %10, %9 ]
  %.2 = phi i64 [ %.01417, %.lr.ph19 ], [ %18, %..loopexit_crit_edge ], [ %.01417, %9 ]
  %23 = add nuw nsw i64 %.018, 1
  %24 = mul nuw nsw i64 %23, %23
  %25 = icmp sle i64 %24, %.2
  %26 = icmp sgt i64 %.2, 1
  %27 = and i1 %26, %25
  br i1 %27, label %.lr.ph19, label %._crit_edge, !llvm.loop !13

28:                                               ; preds = %._crit_edge
  %29 = add nsw i32 %5, 1
  store i32 %29, ptr @sum, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [40 x i64], ptr @f, i64 0, i64 %30
  store i64 %.014.lcssa, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds [40 x i64], ptr @s, i64 0, i64 %30
  store i64 1, ptr %32, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %28, %._crit_edge
  tail call void @_Z3dfsix(i32 noundef 1, i64 noundef 1)
  %34 = load i64, ptr @ans, align 8, !tbaa !5
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %34)
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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