; LLVM IR from lzyrapx/Competitive-Programming :: Codeforces/Math (1254B1)

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

@a = external dso_local global [1000123 x i64], align 16
@sum = external dso_local global [1000123 x i64], align 16
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4costx(i64 noundef) #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

; 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(i32 noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %36, %2
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %39

18:                                               ; preds = %13
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1000123 x i64], ptr @a, i64 0, i64 %20
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %21)
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1000123 x i64], ptr @sum, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1000123 x i64], ptr @a, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !11
  %32 = add nsw i64 %27, %31
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000123 x i64], ptr @sum, i64 0, i64 %34
  store i64 %32, ptr %35, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %18
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %6, align 4, !tbaa !5
  br label %13, !llvm.loop !13

39:                                               ; preds = %17
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000123 x i64], ptr @sum, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = icmp eq i64 %43, 1
  br i1 %44, label %45, label %47

45:                                               ; preds = %39
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %3, align 4
  br label %92

47:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 1000000000000000000, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000123 x i64], ptr @sum, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !11
  store i64 %51, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 2, ptr %9, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %78, %47
  %53 = load i64, ptr %9, align 8, !tbaa !11
  %54 = load i64, ptr %9, align 8, !tbaa !11
  %55 = mul nsw i64 %53, %54
  %56 = load i64, ptr %8, align 8, !tbaa !11
  %57 = icmp sle i64 %55, %56
  br i1 %57, label %58, label %81

58:                                               ; preds = %52
  %59 = load i64, ptr %8, align 8, !tbaa !11
  %60 = load i64, ptr %9, align 8, !tbaa !11
  %61 = srem i64 %59, %60
  %62 = icmp eq i64 %61, 0
  br i1 %62, label %63, label %78

63:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %64 = load i64, ptr %9, align 8, !tbaa !11
  %65 = call noundef i64 @_Z4costx(i64 noundef %64)
  store i64 %65, ptr %10, align 8, !tbaa !11
  %66 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %67 = load i64, ptr %66, align 8, !tbaa !11
  store i64 %67, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %68

68:                                               ; preds = %73, %63
  %69 = load i64, ptr %8, align 8, !tbaa !11
  %70 = load i64, ptr %9, align 8, !tbaa !11
  %71 = srem i64 %69, %70
  %72 = icmp eq i64 %71, 0
  br i1 %72, label %73, label %77

73:                                               ; preds = %68
  %74 = load i64, ptr %9, align 8, !tbaa !11
  %75 = load i64, ptr %8, align 8, !tbaa !11
  %76 = sdiv i64 %75, %74
  store i64 %76, ptr %8, align 8, !tbaa !11
  br label %68, !llvm.loop !15

77:                                               ; preds = %68
  br label %78

78:                                               ; preds = %77, %58
  %79 = load i64, ptr %9, align 8, !tbaa !11
  %80 = add nsw i64 %79, 1
  store i64 %80, ptr %9, align 8, !tbaa !11
  br label %52, !llvm.loop !16

81:                                               ; preds = %52
  %82 = load i64, ptr %8, align 8, !tbaa !11
  %83 = icmp sgt i64 %82, 1
  br i1 %83, label %84, label %89

84:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %85 = load i64, ptr %8, align 8, !tbaa !11
  %86 = call noundef i64 @_Z4costx(i64 noundef %85)
  store i64 %86, ptr %11, align 8, !tbaa !11
  %87 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %11)
  %88 = load i64, ptr %87, align 8, !tbaa !11
  store i64 %88, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %89

89:                                               ; preds = %84, %81
  %90 = load i64, ptr %7, align 8, !tbaa !11
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %90)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %92

92:                                               ; preds = %89, %45
  %93 = load i32, ptr %3, align 4
  ret i32 %93
}

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

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

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 = { inlinehint 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 #3 = { 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 #4 = { "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 #5 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@a = external dso_local global [1000123 x i64], align 16
@sum = external dso_local local_unnamed_addr global [1000123 x i64], align 16
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4costx(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: mustprogress 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(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #3 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %.not25 = icmp slt i32 %7, 1
  br i1 %.not25, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %2
  %.pre = sext i32 %7 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %20, %.lr.ph ]
  %8 = getelementptr inbounds [1000123 x i64], ptr @sum, i64 0, i64 %.pre-phi
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp eq i64 %9, 1
  br i1 %10, label %21, label %23

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %2 ]
  %11 = getelementptr inbounds [1000123 x i64], ptr @a, i64 0, i64 %indvars.iv
  %12 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %11)
  %13 = add nsw i64 %indvars.iv, -1
  %14 = getelementptr inbounds [1000123 x i64], ptr @sum, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = load i64, ptr %11, align 8, !tbaa !9
  %17 = add nsw i64 %16, %15
  %18 = getelementptr inbounds [1000123 x i64], ptr @sum, i64 0, i64 %indvars.iv
  store i64 %17, ptr %18, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %.not.not = icmp slt i64 %indvars.iv, %20
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

21:                                               ; preds = %._crit_edge
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %45

23:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  store i64 1000000000000000000, ptr %3, align 8, !tbaa !9
  %.not2431 = icmp slt i64 %9, 4
  br i1 %.not2431, label %._crit_edge36, label %.lr.ph35

.lr.ph35:                                         ; preds = %23, %.loopexit
  %24 = phi i64 [ %33, %.loopexit ], [ 1000000000000000000, %23 ]
  %.033 = phi i64 [ %34, %.loopexit ], [ 2, %23 ]
  %.02032 = phi i64 [ %.2, %.loopexit ], [ %9, %23 ]
  %25 = srem i64 %.02032, %.033
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %.lr.ph29.preheader, label %.loopexit

.lr.ph29.preheader:                               ; preds = %.lr.ph35
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %27 = call noundef i64 @_Z4costx(i64 noundef %.033)
  store i64 %27, ptr %4, align 8, !tbaa !9
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %29 = load i64, ptr %28, align 8, !tbaa !9
  store i64 %29, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  br label %.lr.ph29

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %.lr.ph29
  %.127 = phi i64 [ %30, %.lr.ph29 ], [ %.02032, %.lr.ph29.preheader ]
  %30 = sdiv i64 %.127, %.033
  %31 = srem i64 %30, %.033
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %.lr.ph29, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph29, %.lr.ph35
  %33 = phi i64 [ %24, %.lr.ph35 ], [ %29, %.lr.ph29 ]
  %.2 = phi i64 [ %.02032, %.lr.ph35 ], [ %30, %.lr.ph29 ]
  %34 = add nuw nsw i64 %.033, 1
  %35 = mul nuw nsw i64 %34, %34
  %.not24 = icmp sgt i64 %35, %.2
  br i1 %.not24, label %._crit_edge36, label %.lr.ph35, !llvm.loop !14

._crit_edge36:                                    ; preds = %.loopexit, %23
  %36 = phi i64 [ 1000000000000000000, %23 ], [ %33, %.loopexit ]
  %.020.lcssa = phi i64 [ %9, %23 ], [ %.2, %.loopexit ]
  %37 = icmp sgt i64 %.020.lcssa, 1
  br i1 %37, label %38, label %42

38:                                               ; preds = %._crit_edge36
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %39 = call noundef i64 @_Z4costx(i64 noundef %.020.lcssa)
  store i64 %39, ptr %5, align 8, !tbaa !9
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %41 = load i64, ptr %40, align 8, !tbaa !9
  store i64 %41, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  br label %42

42:                                               ; preds = %38, %._crit_edge36
  %43 = phi i64 [ %41, %38 ], [ %36, %._crit_edge36 ]
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br label %45

45:                                               ; preds = %42, %21
  ret i32 0
}

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

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 #4 = { 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 #5 = { 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 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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