; LLVM IR from tangjz/acm-icpc :: 51nod (1317)

; 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
@ch = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = 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 noundef i32 @_Z3dfsi(i32 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @ch)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %5 = load i32, ptr @ch, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = call noundef i32 @_Z3dfsi(i32 noundef %9)
  %11 = sext i32 %10 to i64
  %12 = mul nsw i64 %8, %11
  %13 = add nsw i64 %6, %12
  %14 = srem i64 %13, 1000000007
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %63, %0
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = mul nsw i32 %17, %18
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %66

23:                                               ; preds = %16
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = srem i32 %24, %25
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %62

28:                                               ; preds = %23
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = call noundef i32 @_Z3dfsi(i32 noundef %33)
  %35 = sext i32 %34 to i64
  %36 = mul nsw i64 %32, %35
  %37 = add nsw i64 %30, %36
  %38 = srem i64 %37, 1000000007
  %39 = trunc i64 %38 to i32
  store i32 %39, ptr %2, align 4, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = mul nsw i32 %40, %41
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %61

45:                                               ; preds = %28
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sdiv i32 %48, %49
  %51 = sext i32 %50 to i64
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sdiv i32 %52, %53
  %55 = call noundef i32 @_Z3dfsi(i32 noundef %54)
  %56 = sext i32 %55 to i64
  %57 = mul nsw i64 %51, %56
  %58 = add nsw i64 %47, %57
  %59 = srem i64 %58, 1000000007
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr %2, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %45, %28
  br label %62

62:                                               ; preds = %61, %23
  br label %63

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

66:                                               ; preds = %22
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %67)
  call void @llvm.lifetime.end.p0(i64 4, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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
@ch = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsi(i32 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, ptr noundef nonnull @ch)
  %2 = load i32, ptr @ch, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = tail call noundef i32 @_Z3dfsi(i32 noundef %4)
  %7 = sext i32 %6 to i64
  %8 = mul nsw i64 %7, %5
  %9 = add nsw i64 %8, %3
  %10 = srem i64 %9, 1000000007
  %11 = trunc nsw i64 %10 to i32
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %.not17 = icmp slt i32 %12, 4
  br i1 %.not17, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %38, %0
  %.013.lcssa = phi i32 [ %11, %0 ], [ %.1, %38 ]
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.013.lcssa)
  ret i32 0

.lr.ph:                                           ; preds = %0, %38
  %14 = phi i32 [ %39, %38 ], [ %12, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %38 ], [ 2, %0 ]
  %15 = phi i32 [ %41, %38 ], [ 4, %0 ]
  %.01318 = phi i32 [ %.1, %38 ], [ %11, %0 ]
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  %17 = srem i32 %14, %16
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %38

19:                                               ; preds = %.lr.ph
  %20 = sext i32 %.01318 to i64
  %21 = tail call noundef i32 @_Z3dfsi(i32 noundef %16)
  %22 = sext i32 %21 to i64
  %23 = mul nsw i64 %indvars.iv, %22
  %24 = add nsw i64 %23, %20
  %25 = srem i64 %24, 1000000007
  %26 = trunc nsw i64 %25 to i32
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = icmp slt i32 %15, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %19
  %30 = sdiv i32 %27, %16
  %31 = sext i32 %30 to i64
  %32 = tail call noundef i32 @_Z3dfsi(i32 noundef %30)
  %33 = sext i32 %32 to i64
  %34 = mul nsw i64 %33, %31
  %35 = add nsw i64 %34, %25
  %36 = srem i64 %35, 1000000007
  %37 = trunc nsw i64 %36 to i32
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %.lr.ph, %29, %19
  %39 = phi i32 [ %.pre, %29 ], [ %27, %19 ], [ %14, %.lr.ph ]
  %.1 = phi i32 [ %37, %29 ], [ %26, %19 ], [ %.01318, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %41 = trunc nuw i64 %40 to i32
  %.not = icmp slt i32 %39, %41
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

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


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