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

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@mx = external dso_local global i32, align 4
@f = external dso_local global [1000001 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_ZZ4mainE3buf = external hidden global [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

4:                                                ; preds = %70, %0
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %76

8:                                                ; preds = %4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  br label %10

10:                                               ; preds = %67, %8
  %11 = load i32, ptr @mx, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %70

15:                                               ; preds = %10
  %16 = load i32, ptr @mx, align 4, !tbaa !5
  %17 = srem i32 %16, 7
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %56

19:                                               ; preds = %15
  %20 = load i32, ptr @mx, align 4, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @_ZZ4mainE3buf, ptr noundef @.str, i32 noundef %20) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %37, %19
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [7 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %40

28:                                               ; preds = %22
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [7 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 55
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  br label %40

36:                                               ; preds = %28
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !10

40:                                               ; preds = %35, %22
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [7 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = icmp ne i8 %44, 0
  br i1 %45, label %55, label %46

46:                                               ; preds = %40
  %47 = load i32, ptr @mx, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = load i32, ptr @mx, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = mul nsw i64 %48, %50
  %52 = load i32, ptr @mx, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %53
  store i64 %51, ptr %54, align 8, !tbaa !12
  br label %55

55:                                               ; preds = %46, %40
  br label %56

56:                                               ; preds = %55, %15
  %57 = load i32, ptr @mx, align 4, !tbaa !5
  %58 = sub nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !12
  %62 = load i32, ptr @mx, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !12
  %66 = add nsw i64 %65, %61
  store i64 %66, ptr %64, align 8, !tbaa !12
  br label %67

67:                                               ; preds = %56
  %68 = load i32, ptr @mx, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr @mx, align 4, !tbaa !5
  br label %10, !llvm.loop !14

70:                                               ; preds = %14
  %71 = load i32, ptr @n, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %72
  %74 = load i64, ptr %73, align 8, !tbaa !12
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %74)
  br label %4, !llvm.loop !15

76:                                               ; preds = %4
  ret i32 0
}

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

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

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #3

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

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

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


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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@mx = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [1000001 x i64], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_ZZ4mainE3buf = external hidden global [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not12 = icmp eq i32 %2, 0
  br i1 %.not12, label %._crit_edge15, label %.lr.ph14

.lr.ph14:                                         ; preds = %0, %._crit_edge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @mx, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not711 = icmp sgt i32 %5, %6
  br i1 %.not711, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.loopexit, %.lr.ph14
  %.lcssa = phi i32 [ %6, %.lr.ph14 ], [ %36, %.loopexit ]
  %7 = sext i32 %.lcssa to i64
  %8 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %9)
  %11 = load i32, ptr @t, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %._crit_edge15, label %.lr.ph14, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph14, %.loopexit
  %13 = phi i32 [ %35, %.loopexit ], [ %5, %.lr.ph14 ]
  %14 = srem i32 %13, 7
  %.not8 = icmp eq i32 %14, 0
  br i1 %.not8, label %.loopexit, label %15

15:                                               ; preds = %.lr.ph
  %16 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @_ZZ4mainE3buf, ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %13) #2
  br label %17

17:                                               ; preds = %20, %15
  %indvars.iv = phi i64 [ %indvars.iv.next, %20 ], [ 0, %15 ]
  %18 = getelementptr inbounds [7 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %indvars.iv
  %19 = load i8, ptr %18, align 1, !tbaa !13
  switch i8 %19, label %20 [
    i8 0, label %21
    i8 55, label %.loopexit.loopexit
  ]

20:                                               ; preds = %17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %17, !llvm.loop !14

21:                                               ; preds = %17
  %22 = load i32, ptr @mx, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %23, %23
  %25 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %23
  store i64 %24, ptr %25, align 8, !tbaa !9
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %17
  %.pre = load i32, ptr @mx, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %21, %.lr.ph
  %26 = phi i32 [ %.pre, %.loopexit.loopexit ], [ %22, %21 ], [ %13, %.lr.ph ]
  %27 = add nsw i32 %26, -1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = sext i32 %26 to i64
  %32 = getelementptr inbounds [1000001 x i64], ptr @f, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = add nsw i64 %33, %30
  store i64 %34, ptr %32, align 8, !tbaa !9
  %35 = add nsw i32 %26, 1
  store i32 %35, ptr @mx, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %.not7.not = icmp slt i32 %26, %36
  br i1 %.not7.not, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge15:                                    ; preds = %._crit_edge, %0
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

attributes #0 = { mustprogress nofree 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 #1 = { 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 #2 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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