; LLVM IR from tangjz/acm-icpc :: zoj (3558)

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

@n = external dso_local global i32, align 4
@sqn = external dso_local global i32, align 4
@ans1 = external dso_local global i32, align 4
@ans2 = 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 [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %4

4:                                                ; preds = %78, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %7, label %96

7:                                                ; preds = %4
  store i32 0, ptr @ans2, align 4, !tbaa !5
  store i32 0, ptr @ans1, align 4, !tbaa !5
  store i32 1, ptr @sqn, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %18, %7
  %9 = load i32, ptr @sqn, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = load i32, ptr @sqn, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = mul nsw i64 %10, %12
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = icmp sle i64 %13, %15
  br i1 %16, label %17, label %21

17:                                               ; preds = %8
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr @sqn, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @sqn, align 4, !tbaa !5
  br label %8, !llvm.loop !9

21:                                               ; preds = %8
  %22 = load i32, ptr @sqn, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr @sqn, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %34, %21
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr @sqn, align 4, !tbaa !5
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %37

29:                                               ; preds = %24
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sdiv i32 %30, %31
  %33 = srem i32 %32, 100000007
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %33)
  br label %34

34:                                               ; preds = %29
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %2, align 4, !tbaa !5
  br label %24, !llvm.loop !11

37:                                               ; preds = %28
  %38 = load i32, ptr @ans1, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %38)
  %39 = load i32, ptr @sqn, align 4, !tbaa !5
  %40 = load i32, ptr @sqn, align 4, !tbaa !5
  %41 = mul nsw i32 %39, %40
  %42 = srem i32 %41, 100000007
  call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %42)
  %43 = load i32, ptr @ans1, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %44, %46
  %48 = srem i64 %47, 100000007
  %49 = trunc i64 %48 to i32
  store i32 %49, ptr @ans1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %75, %37
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr @sqn, align 4, !tbaa !5
  %53 = icmp sle i32 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %78

55:                                               ; preds = %50
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = load i32, ptr @n, align 4, !tbaa !5
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sdiv i32 %59, %60
  %62 = add nsw i32 %58, %61
  %63 = sext i32 %62 to i64
  %64 = mul nsw i64 %57, %63
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = sdiv i32 %65, %66
  %68 = add nsw i32 %67, 1
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sub nsw i32 %68, %69
  %71 = sext i32 %70 to i64
  %72 = mul nsw i64 %64, %71
  %73 = srem i64 %72, 100000007
  %74 = trunc i64 %73 to i32
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) @ans2, i32 noundef %74)
  br label %75

75:                                               ; preds = %55
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %3, align 4, !tbaa !5
  br label %50, !llvm.loop !12

78:                                               ; preds = %54
  %79 = load i32, ptr @sqn, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = load i32, ptr @sqn, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = mul nsw i64 %80, %83
  %85 = load i32, ptr @sqn, align 4, !tbaa !5
  %86 = mul nsw i32 2, %85
  %87 = add nsw i32 %86, 1
  %88 = sext i32 %87 to i64
  %89 = mul nsw i64 %84, %88
  %90 = sdiv i64 %89, 6
  %91 = srem i64 %90, 100000007
  %92 = trunc i64 %91 to i32
  call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) @ans2, i32 noundef %92)
  %93 = load i32, ptr @ans2, align 4, !tbaa !5
  call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %93)
  %94 = load i32, ptr @ans1, align 4, !tbaa !5
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %94)
  br label %4, !llvm.loop !13

96:                                               ; preds = %4
  ret i32 0
}

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

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

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

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

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 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@n = external dso_local global i32, align 4
@sqn = external dso_local local_unnamed_addr global i32, align 4
@ans1 = external dso_local global i32, align 4
@ans2 = 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 [4 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse nounwind 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 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %0, %._crit_edge21
  store i32 0, ptr @ans2, align 4, !tbaa !5
  store i32 0, ptr @ans1, align 4, !tbaa !5
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  br label %5

5:                                                ; preds = %5, %.lr.ph23
  %indvars.iv = phi i64 [ %indvars.iv.next, %5 ], [ 1, %.lr.ph23 ]
  %6 = mul nuw nsw i64 %indvars.iv, %indvars.iv
  %.not = icmp sgt i64 %6, %4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not, label %7, label %5, !llvm.loop !9

7:                                                ; preds = %5
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @sqn, align 4, !tbaa !5
  %.not1215 = icmp ult i64 %indvars.iv, 2
  br i1 %.not1215, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr @ans1, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %7
  %10 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ 0, %7 ]
  tail call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %10)
  %11 = load i32, ptr @sqn, align 4, !tbaa !5
  %12 = mul nsw i32 %11, %11
  %13 = urem i32 %12, 100000007
  tail call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %13)
  %14 = load i32, ptr @ans1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = mul nsw i64 %17, %15
  %19 = srem i64 %18, 100000007
  %20 = trunc nsw i64 %19 to i32
  store i32 %20, ptr @ans1, align 4, !tbaa !5
  %21 = load i32, ptr @sqn, align 4, !tbaa !5
  %.not1317 = icmp slt i32 %21, 1
  br i1 %.not1317, label %._crit_edge.._crit_edge21_crit_edge, label %.lr.ph20

._crit_edge.._crit_edge21_crit_edge:              ; preds = %._crit_edge
  %.pre30 = sext i32 %21 to i64
  br label %._crit_edge21

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.01016 = phi i32 [ %25, %.lr.ph ], [ 1, %7 ]
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = sdiv i32 %22, %.01016
  %24 = srem i32 %23, 100000007
  tail call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %24)
  %25 = add nuw nsw i32 %.01016, 1
  %26 = load i32, ptr @sqn, align 4, !tbaa !5
  %.not12.not = icmp slt i32 %.01016, %26
  br i1 %.not12.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11

._crit_edge21:                                    ; preds = %.lr.ph20, %._crit_edge.._crit_edge21_crit_edge
  %.pre-phi = phi i64 [ %.pre30, %._crit_edge.._crit_edge21_crit_edge ], [ %54, %.lr.ph20 ]
  %.lcssa = phi i32 [ %21, %._crit_edge.._crit_edge21_crit_edge ], [ %53, %.lr.ph20 ]
  %27 = add nsw i32 %.lcssa, 1
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %.pre-phi, %28
  %30 = shl nsw i32 %.lcssa, 1
  %31 = or disjoint i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = mul nsw i64 %29, %32
  %34 = sdiv i64 %33, 6
  %35 = srem i64 %34, 100000007
  %36 = trunc nsw i64 %35 to i32
  tail call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) @ans2, i32 noundef %36)
  %37 = load i32, ptr @ans2, align 4, !tbaa !5
  tail call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %37)
  %38 = load i32, ptr @ans1, align 4, !tbaa !5
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %38)
  %40 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %.lr.ph23, label %._crit_edge24, !llvm.loop !12

.lr.ph20:                                         ; preds = %._crit_edge, %.lr.ph20
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.lr.ph20 ], [ 1, %._crit_edge ]
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = trunc nuw nsw i64 %indvars.iv27 to i32
  %44 = sdiv i32 %42, %43
  %45 = add nsw i32 %44, %43
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %indvars.iv27, %46
  %reass.sub = sub i32 %44, %43
  %48 = add i32 %reass.sub, 1
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %47, %49
  %51 = srem i64 %50, 100000007
  %52 = trunc nsw i64 %51 to i32
  tail call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) @ans2, i32 noundef %52)
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %53 = load i32, ptr @sqn, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %.not13.not = icmp slt i64 %indvars.iv27, %54
  br i1 %.not13.not, label %.lr.ph20, label %._crit_edge21, !llvm.loop !13

._crit_edge24:                                    ; preds = %._crit_edge21, %0
  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 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 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 #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 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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