; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1132B. Discounts (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 i64], align 16
@.str = external hidden unnamed_addr constant [5 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 i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %15, %0
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = icmp sle i64 %8, %9
  br i1 %10, label %11, label %18

11:                                               ; preds = %7
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %13)
  br label %15

15:                                               ; preds = %11
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = add nsw i64 %16, 1
  store i64 %17, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !9

18:                                               ; preds = %7
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds i64, ptr @arr, i64 %19
  %21 = getelementptr inbounds i64, ptr %20, i64 1
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef @arr, ptr noundef %21)
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %35, %18
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = icmp sle i64 %23, %24
  br i1 %25, label %26, label %38

26:                                               ; preds = %22
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = sub nsw i64 %27, 1
  %29 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = add nsw i64 %33, %30
  store i64 %34, ptr %32, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %26
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = add nsw i64 %36, 1
  store i64 %37, ptr %3, align 8, !tbaa !5
  br label %22, !llvm.loop !11

38:                                               ; preds = %22
  %39 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %63, %38
  %41 = load i64, ptr %3, align 8, !tbaa !5
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = icmp sle i64 %41, %42
  br i1 %43, label %44, label %66

44:                                               ; preds = %40
  %45 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5)
  %46 = load i64, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = load i64, ptr %2, align 8, !tbaa !5
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = sub nsw i64 %49, %50
  %52 = add nsw i64 %51, 1
  %53 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !5
  %55 = sub nsw i64 %48, %54
  %56 = load i64, ptr %2, align 8, !tbaa !5
  %57 = load i64, ptr %5, align 8, !tbaa !5
  %58 = sub nsw i64 %56, %57
  %59 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !5
  %61 = add nsw i64 %55, %60
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %61)
  br label %63

63:                                               ; preds = %44
  %64 = load i64, ptr %3, align 8, !tbaa !5
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %3, align 8, !tbaa !5
  br label %40, !llvm.loop !12

66:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 @_ZSt4sortIPxEvT_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 = !{!"long long", !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 = distinct !{!12, !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 i64], align 16
@.str = external hidden unnamed_addr constant [5 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 i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %.not12 = icmp slt i64 %5, 1
  br i1 %.not12, label %._crit_edge, label %.lr.ph

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

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i64 [ %5, %0 ], [ %9, %.lr.ph ]
  %10 = getelementptr inbounds i64, ptr @arr, i64 %.lcssa
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull @arr, ptr noundef nonnull %11)
  %12 = load i64, ptr %1, align 8, !tbaa !5
  %.not1014 = icmp slt i64 %12, 1
  br i1 %.not1014, label %._crit_edge18, label %.lr.ph17.preheader

.lr.ph17.preheader:                               ; preds = %._crit_edge
  %.pre = load i64, ptr @arr, align 16, !tbaa !5
  %xtraiter = and i64 %12, 3
  %13 = icmp ult i64 %12, 4
  br i1 %13, label %._crit_edge18.loopexit.unr-lcssa, label %.lr.ph17.preheader.new

.lr.ph17.preheader.new:                           ; preds = %.lr.ph17.preheader
  %unroll_iter = and i64 %12, 9223372036854775804
  br label %.lr.ph17

.lr.ph17:                                         ; preds = %.lr.ph17, %.lr.ph17.preheader.new
  %14 = phi i64 [ %.pre, %.lr.ph17.preheader.new ], [ %29, %.lr.ph17 ]
  %.115 = phi i64 [ 1, %.lr.ph17.preheader.new ], [ %30, %.lr.ph17 ]
  %niter = phi i64 [ 0, %.lr.ph17.preheader.new ], [ %niter.next.3, %.lr.ph17 ]
  %15 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %.115
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = add nsw i64 %16, %14
  store i64 %17, ptr %15, align 8, !tbaa !5
  %18 = add nuw nsw i64 %.115, 1
  %19 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = add nsw i64 %20, %17
  store i64 %21, ptr %19, align 8, !tbaa !5
  %22 = add nuw nsw i64 %.115, 2
  %23 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = add nsw i64 %24, %21
  store i64 %25, ptr %23, align 8, !tbaa !5
  %26 = add nuw i64 %.115, 3
  %27 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = add nsw i64 %28, %25
  store i64 %29, ptr %27, align 8, !tbaa !5
  %30 = add nuw i64 %.115, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge18.loopexit.unr-lcssa, label %.lr.ph17, !llvm.loop !11

._crit_edge18.loopexit.unr-lcssa:                 ; preds = %.lr.ph17, %.lr.ph17.preheader
  %.unr = phi i64 [ %.pre, %.lr.ph17.preheader ], [ %29, %.lr.ph17 ]
  %.115.unr = phi i64 [ 1, %.lr.ph17.preheader ], [ %30, %.lr.ph17 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge18, label %.lr.ph17.epil

.lr.ph17.epil:                                    ; preds = %._crit_edge18.loopexit.unr-lcssa, %.lr.ph17.epil
  %31 = phi i64 [ %34, %.lr.ph17.epil ], [ %.unr, %._crit_edge18.loopexit.unr-lcssa ]
  %.115.epil = phi i64 [ %35, %.lr.ph17.epil ], [ %.115.unr, %._crit_edge18.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph17.epil ], [ 0, %._crit_edge18.loopexit.unr-lcssa ]
  %32 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %.115.epil
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = add nsw i64 %33, %31
  store i64 %34, ptr %32, align 8, !tbaa !5
  %35 = add nuw i64 %.115.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge18, label %.lr.ph17.epil, !llvm.loop !12

._crit_edge18:                                    ; preds = %._crit_edge18.loopexit.unr-lcssa, %.lr.ph17.epil, %._crit_edge
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %37 = load i64, ptr %2, align 8, !tbaa !5
  %.not1119 = icmp slt i64 %37, 1
  br i1 %.not1119, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %._crit_edge18, %.lr.ph22
  %.220 = phi i64 [ %52, %.lr.ph22 ], [ 1, %._crit_edge18 ]
  %38 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %39 = load i64, ptr %1, align 8, !tbaa !5
  %40 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = sub nsw i64 %39, %42
  %44 = add nsw i64 %43, 1
  %45 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = sub i64 %41, %46
  %48 = getelementptr inbounds [300005 x i64], ptr @arr, i64 0, i64 %43
  %49 = load i64, ptr %48, align 8, !tbaa !5
  %50 = add nsw i64 %47, %49
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %50)
  %52 = add nuw nsw i64 %.220, 1
  %53 = load i64, ptr %2, align 8, !tbaa !5
  %.not11.not = icmp slt i64 %.220, %53
  br i1 %.not11.not, label %.lr.ph22, label %._crit_edge23, !llvm.loop !14

._crit_edge23:                                    ; preds = %.lr.ph22, %._crit_edge18
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  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 @_ZSt4sortIPxEvT_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

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 = { 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 = !{!"long long", !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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !10}


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