; LLVM IR from manishbisht/Competitive-Programming :: Codeforces/Codeforces Round #376 (Div. 2) (Coupons and Discounts)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@n = external dso_local global i64, align 8
@a = external dso_local global [200005 x i64], align 16
@i = external dso_local global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @n)
  store i64 0, ptr @i, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %11, %0
  %4 = load i64, ptr @i, align 8, !tbaa !5
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = icmp slt i64 %4, %5
  br i1 %6, label %7, label %14

7:                                                ; preds = %3
  %8 = load i64, ptr @i, align 8, !tbaa !5
  %9 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %8
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %9)
  br label %11

11:                                               ; preds = %7
  %12 = load i64, ptr @i, align 8, !tbaa !5
  %13 = add nsw i64 %12, 1
  store i64 %13, ptr @i, align 8, !tbaa !5
  br label %3, !llvm.loop !9

14:                                               ; preds = %3
  store i64 0, ptr @i, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %61, %14
  %16 = load i64, ptr @i, align 8, !tbaa !5
  %17 = load i64, ptr @n, align 8, !tbaa !5
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %19, label %64

19:                                               ; preds = %15
  %20 = load i64, ptr @i, align 8, !tbaa !5
  %21 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = srem i64 %22, 2
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %19
  %26 = load i64, ptr @i, align 8, !tbaa !5
  %27 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %26
  store i64 0, ptr %27, align 8, !tbaa !5
  br label %60

28:                                               ; preds = %19
  %29 = load i64, ptr @i, align 8, !tbaa !5
  %30 = add nsw i64 %29, 1
  %31 = load i64, ptr @n, align 8, !tbaa !5
  %32 = icmp slt i64 %30, %31
  br i1 %32, label %33, label %56

33:                                               ; preds = %28
  %34 = load i64, ptr @i, align 8, !tbaa !5
  %35 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = load i64, ptr @i, align 8, !tbaa !5
  %38 = add nsw i64 %37, 1
  %39 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = icmp sle i64 %36, %40
  br i1 %41, label %42, label %56

42:                                               ; preds = %33
  %43 = load i64, ptr @i, align 8, !tbaa !5
  %44 = add nsw i64 %43, 1
  %45 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = load i64, ptr @i, align 8, !tbaa !5
  %48 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !5
  %50 = sub nsw i64 %46, %49
  %51 = load i64, ptr @i, align 8, !tbaa !5
  %52 = add nsw i64 %51, 1
  %53 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %52
  store i64 %50, ptr %53, align 8, !tbaa !5
  %54 = load i64, ptr @i, align 8, !tbaa !5
  %55 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %54
  store i64 0, ptr %55, align 8, !tbaa !5
  br label %59

56:                                               ; preds = %33, %28
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str)
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %57, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  store i32 0, ptr %1, align 4
  br label %67

59:                                               ; preds = %42
  br label %60

60:                                               ; preds = %59, %25
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr @i, align 8, !tbaa !5
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr @i, align 8, !tbaa !5
  br label %15, !llvm.loop !11

64:                                               ; preds = %15
  %65 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.1)
  %66 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %65, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  store i32 0, ptr %1, align 4
  br label %67

67:                                               ; preds = %64, %56
  %68 = load i32, ptr %1, align 4
  ret i32 %68
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #2

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 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 = { 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" }

!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}


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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@n = external dso_local global i64, align 8
@a = external dso_local global [200005 x i64], align 16
@i = external dso_local local_unnamed_addr global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @n)
  store i64 0, ptr @i, align 8, !tbaa !5
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %3 = icmp sgt i64 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %4 = icmp sgt i64 %9, 0
  br i1 %4, label %.lr.ph10, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %storemerge7 = phi i64 [ %8, %.lr.ph ], [ 0, %0 ]
  %5 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %storemerge7
  %6 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %7 = load i64, ptr @i, align 8, !tbaa !5
  %8 = add nsw i64 %7, 1
  store i64 %8, ptr @i, align 8, !tbaa !5
  %9 = load i64, ptr @n, align 8, !tbaa !5
  %10 = icmp slt i64 %8, %9
  br i1 %10, label %.lr.ph, label %.preheader, !llvm.loop !9

.lr.ph10:                                         ; preds = %.preheader, %.lr.ph10._crit_edge
  %storemerge69 = phi i64 [ %.pre, %.lr.ph10._crit_edge ], [ 0, %.preheader ]
  %11 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %storemerge69
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = and i64 %12, 1
  %14 = icmp eq i64 %13, 0
  %.pre = add nuw nsw i64 %storemerge69, 1
  br i1 %14, label %.lr.ph10._crit_edge, label %15

15:                                               ; preds = %.lr.ph10
  %16 = icmp slt i64 %.pre, %9
  br i1 %16, label %17, label %._crit_edge

17:                                               ; preds = %15
  %18 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %.pre
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %.not = icmp sgt i64 %12, %19
  br i1 %.not, label %._crit_edge, label %20

20:                                               ; preds = %17
  %21 = sub nsw i64 %19, %12
  store i64 %21, ptr %18, align 8, !tbaa !5
  br label %.lr.ph10._crit_edge

.lr.ph10._crit_edge:                              ; preds = %.lr.ph10, %20
  store i64 0, ptr %11, align 8, !tbaa !5
  %exitcond.not = icmp eq i64 %.pre, %9
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph10, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph10._crit_edge, %15, %17, %.preheader, %0
  %storemerge6.lcssa.sink = phi i64 [ 0, %.preheader ], [ 0, %0 ], [ %storemerge69, %17 ], [ %storemerge69, %15 ], [ %9, %.lr.ph10._crit_edge ]
  %.str.1.sink = phi ptr [ @.str.1, %.preheader ], [ @.str.1, %0 ], [ @.str, %17 ], [ @.str, %15 ], [ @.str.1, %.lr.ph10._crit_edge ]
  store i64 %storemerge6.lcssa.sink, ptr @i, align 8, !tbaa !5
  %22 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull %.str.1.sink)
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #2

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 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 = { 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" }

!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}


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