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

; 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
@x = external dso_local global i32, align 4
@cnt = external dso_local global [2000001 x i32], align 16
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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
  store i32 0, ptr %1, align 4
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @n)
  br label %5

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

9:                                                ; preds = %5
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @x)
  %10 = load i32, ptr @x, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !5
  br label %5, !llvm.loop !9

15:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %68, %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 2000001
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %16
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %20
  br label %68

27:                                               ; preds = %20
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %32, %38
  %40 = load i64, ptr @ans, align 8, !tbaa !11
  %41 = add nsw i64 %40, %39
  store i64 %41, ptr @ans, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  store i32 %44, ptr %4, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %63, %27
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = icmp slt i32 %46, 2000001
  br i1 %47, label %49, label %48

48:                                               ; preds = %45
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %67

49:                                               ; preds = %45
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %54, %59
  %61 = load i64, ptr @ans, align 8, !tbaa !11
  %62 = add nsw i64 %61, %60
  store i64 %62, ptr @ans, align 8, !tbaa !11
  br label %63

63:                                               ; preds = %49
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = add nsw i32 %65, %64
  store i32 %66, ptr %4, align 4, !tbaa !5
  br label %45, !llvm.loop !13

67:                                               ; preds = %48
  br label %68

68:                                               ; preds = %67, %26
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %2, align 4, !tbaa !5
  br label %16, !llvm.loop !14

71:                                               ; preds = %19
  %72 = load i64, ptr @ans, align 8, !tbaa !11
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %72)
  ret i32 0
}

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

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

@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@cnt = external dso_local local_unnamed_addr global [2000001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @n)
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = add nsw i32 %1, -1
  store i32 %2, ptr @n, align 4, !tbaa !5
  %.not15 = icmp eq i32 %1, 0
  br i1 %.not15, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %0
  %ans.promoted18 = load i64, ptr @ans, align 8, !tbaa !9
  br label %12

.lr.ph:                                           ; preds = %0, %.lr.ph
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @x)
  %3 = load i32, ptr @x, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !11

10:                                               ; preds = %.loopexit
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %29)
  ret i32 0

12:                                               ; preds = %.preheader, %.loopexit
  %indvars.iv25 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next26, %.loopexit ]
  %indvars.iv = phi i64 [ 2, %.preheader ], [ %indvars.iv.next, %.loopexit ]
  %.lcssa2022 = phi i64 [ %ans.promoted18, %.preheader ], [ %29, %.loopexit ]
  %13 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %indvars.iv25
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not14 = icmp eq i32 %14, 0
  br i1 %.not14, label %.loopexit, label %15

15:                                               ; preds = %12
  %16 = sext i32 %14 to i64
  %17 = add nsw i32 %14, -1
  %18 = sext i32 %17 to i64
  %19 = mul nsw i64 %18, %16
  %20 = add nsw i64 %.lcssa2022, %19
  store i64 %20, ptr @ans, align 8, !tbaa !9
  %21 = icmp ult i64 %indvars.iv25, 1000001
  br i1 %21, label %.lr.ph17, label %.loopexit

.lr.ph17:                                         ; preds = %15, %.lr.ph17
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.lr.ph17 ], [ %indvars.iv, %15 ]
  %22 = phi i64 [ %27, %.lr.ph17 ], [ %20, %15 ]
  %23 = getelementptr inbounds [2000001 x i32], ptr @cnt, i64 0, i64 %indvars.iv27
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = mul nsw i64 %25, %16
  %27 = add nsw i64 %26, %22
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, %indvars.iv25
  %28 = icmp ult i64 %indvars.iv.next28, 2000001
  br i1 %28, label %.lr.ph17, label %..loopexit_crit_edge, !llvm.loop !13

..loopexit_crit_edge:                             ; preds = %.lr.ph17
  store i64 %27, ptr @ans, align 8, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %15, %..loopexit_crit_edge, %12
  %29 = phi i64 [ %.lcssa2022, %12 ], [ %27, %..loopexit_crit_edge ], [ %20, %15 ]
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not = icmp eq i64 %indvars.iv.next26, 2000001
  br i1 %exitcond.not, label %10, label %12, !llvm.loop !14
}

; 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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