; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1106C. Lunar New Year and Number Division (main)

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

@arr = external dso_local global [300005 x i32], align 16
@.str = external hidden unnamed_addr constant [3 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
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  br label %5

5:                                                ; preds = %62, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %7 = icmp ne i32 %6, -1
  br i1 %7, label %8, label %65

8:                                                ; preds = %5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %18, %8
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %21

13:                                               ; preds = %9
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %16)
  br label %18

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

21:                                               ; preds = %9
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr @arr, i64 %23
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @arr, ptr noundef %24)
  store i64 0, ptr %4, align 8, !tbaa !11
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %59, %21
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sdiv i32 %27, 2
  %29 = icmp slt i32 %26, %28
  br i1 %29, label %30, label %62

30:                                               ; preds = %25
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sub nsw i32 %35, %36
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = add nsw i32 %34, %41
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sub nsw i32 %47, %48
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %46, %53
  %55 = mul nsw i32 %42, %54
  %56 = sext i32 %55 to i64
  %57 = load i64, ptr %4, align 8, !tbaa !11
  %58 = add nsw i64 %57, %56
  store i64 %58, ptr %4, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %30
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %3, align 4, !tbaa !5
  br label %25, !llvm.loop !13

62:                                               ; preds = %25
  %63 = load i64, ptr %4, align 8, !tbaa !11
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %63)
  br label %5, !llvm.loop !14

65:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #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"

@arr = external dso_local global [300005 x i32], align 16
@.str = external hidden unnamed_addr constant [3 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() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not20 = icmp eq i32 %2, -1
  br i1 %.not20, label %._crit_edge21, label %.preheader

.preheader:                                       ; preds = %0, %._crit_edge18
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.preheader.._crit_edge_crit_edge

.preheader.._crit_edge_crit_edge:                 ; preds = %.preheader
  %.pre = sext i32 %3 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %5 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %indvars.iv
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = icmp slt i64 %indvars.iv.next, %8
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader.._crit_edge_crit_edge ], [ %8, %.lr.ph ]
  %10 = getelementptr inbounds i32, ptr @arr, i64 %.pre-phi
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @arr, ptr noundef nonnull %10)
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 1
  br i1 %12, label %.lr.ph17.preheader, label %._crit_edge18

.lr.ph17.preheader:                               ; preds = %._crit_edge
  %13 = lshr i32 %11, 1
  %14 = zext nneg i32 %11 to i64
  %wide.trip.count = zext nneg i32 %13 to i64
  %min.iters.check = icmp ult i32 %11, 8
  br i1 %min.iters.check, label %.lr.ph17.preheader35, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph17.preheader
  %n.vec = and i64 %wide.trip.count, 1073741820
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %28, %vector.body ]
  %vec.phi30 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %29, %vector.body ]
  %15 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %wide.load = load <2 x i32>, ptr %15, align 16, !tbaa !5
  %wide.load31 = load <2 x i32>, ptr %16, align 8, !tbaa !5
  %17 = xor i64 %index, -1
  %18 = add nsw i64 %14, %17
  %19 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %18
  %20 = getelementptr inbounds i8, ptr %19, i64 -4
  %21 = getelementptr inbounds i8, ptr %19, i64 -12
  %wide.load32 = load <2 x i32>, ptr %20, align 4, !tbaa !5
  %reverse = shufflevector <2 x i32> %wide.load32, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  %wide.load33 = load <2 x i32>, ptr %21, align 4, !tbaa !5
  %reverse34 = shufflevector <2 x i32> %wide.load33, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  %22 = add nsw <2 x i32> %reverse, %wide.load
  %23 = add nsw <2 x i32> %reverse34, %wide.load31
  %24 = mul nsw <2 x i32> %22, %22
  %25 = mul nsw <2 x i32> %23, %23
  %26 = zext nneg <2 x i32> %24 to <2 x i64>
  %27 = zext nneg <2 x i32> %25 to <2 x i64>
  %28 = add <2 x i64> %vec.phi, %26
  %29 = add <2 x i64> %vec.phi30, %27
  %index.next = add nuw i64 %index, 4
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %29, %28
  %31 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge18, label %.lr.ph17.preheader35

.lr.ph17.preheader35:                             ; preds = %middle.block, %.lr.ph17.preheader
  %indvars.iv25.ph = phi i64 [ 0, %.lr.ph17.preheader ], [ %n.vec, %middle.block ]
  %.015.ph = phi i64 [ 0, %.lr.ph17.preheader ], [ %31, %middle.block ]
  br label %.lr.ph17

.lr.ph17:                                         ; preds = %.lr.ph17.preheader35, %.lr.ph17
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %.lr.ph17 ], [ %indvars.iv25.ph, %.lr.ph17.preheader35 ]
  %.015 = phi i64 [ %41, %.lr.ph17 ], [ %.015.ph, %.lr.ph17.preheader35 ]
  %32 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %indvars.iv25
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = xor i64 %indvars.iv25, -1
  %35 = add nsw i64 %14, %34
  %36 = getelementptr inbounds [300005 x i32], ptr @arr, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %37, %33
  %39 = mul nsw i32 %38, %38
  %40 = zext nneg i32 %39 to i64
  %41 = add nuw nsw i64 %.015, %40
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge18, label %.lr.ph17, !llvm.loop !14

._crit_edge18:                                    ; preds = %.lr.ph17, %middle.block, %._crit_edge
  %.0.lcssa = phi i64 [ 0, %._crit_edge ], [ %31, %middle.block ], [ %41, %.lr.ph17 ]
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.0.lcssa)
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %43, -1
  br i1 %.not, label %._crit_edge21, label %.preheader, !llvm.loop !15

._crit_edge21:                                    ; preds = %._crit_edge18, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 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: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { inlinehint 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10, !13, !12}
!15 = distinct !{!15, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass