; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/225 Division 1/Problem A (A)

; 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_ostream" = type { ptr, %"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 }

@n = external dso_local global i32, align 4
@a = external dso_local global [200100 x i32], align 16
@zero = external dso_local global [200100 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.1 = external hidden unnamed_addr constant [2 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 i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %17, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %20

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %14
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %15)
  br label %17

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

20:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !11
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sub nsw i32 1, %24
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %50, %20
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = icmp sge i32 %32, 1
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %53

35:                                               ; preds = %31
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sub nsw i32 1, %44
  %46 = add nsw i32 %40, %45
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %35
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %4, align 4, !tbaa !5
  br label %31, !llvm.loop !13

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

54:                                               ; preds = %74, %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = load i32, ptr @n, align 4, !tbaa !5
  %57 = icmp sle i32 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %77

59:                                               ; preds = %54
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = icmp eq i32 %63, 1
  br i1 %64, label %65, label %73

65:                                               ; preds = %59
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = load i64, ptr %3, align 8, !tbaa !11
  %72 = add nsw i64 %71, %70
  store i64 %72, ptr %3, align 8, !tbaa !11
  br label %73

73:                                               ; preds = %65, %59
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %5, align 4, !tbaa !5
  br label %54, !llvm.loop !14

77:                                               ; preds = %58
  %78 = load i64, ptr %3, align 8, !tbaa !11
  %79 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %78)
  %80 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %79, ptr noundef @.str.1)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #4 align 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!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"

%"class.std::basic_ostream" = type { ptr, %"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 }

@n = external dso_local global i32, align 4
@a = external dso_local global [200100 x i32], align 16
@zero = external dso_local local_unnamed_addr global [200100 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not19 = icmp slt i32 %2, 1
  br i1 %.not19, label %.preheader.thread, label %.lr.ph

.preheader.thread:                                ; preds = %0
  %.pre38 = sext i32 %2 to i64
  %3 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %.pre38
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = sub nsw i32 1, %4
  %6 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %.pre38
  store i32 %5, ptr %6, align 4, !tbaa !5
  br label %._crit_edge28

._crit_edge:                                      ; preds = %.lr.ph
  %7 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %16
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sub nsw i32 1, %8
  %10 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %16
  store i32 %9, ptr %10, align 4, !tbaa !5
  %11 = icmp sgt i32 %15, 1
  br i1 %11, label %.lr.ph23.preheader, label %.preheader

.lr.ph23.preheader:                               ; preds = %._crit_edge
  %12 = zext nneg i32 %15 to i64
  %.phi.trans.insert = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %12
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %.lr.ph23

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

.preheader:                                       ; preds = %.lr.ph23, %._crit_edge
  %.not1824 = icmp slt i32 %15, 1
  br i1 %.not1824, label %._crit_edge28, label %.lr.ph27.preheader

.lr.ph27.preheader:                               ; preds = %.preheader
  %17 = zext nneg i32 %15 to i64
  %xtraiter = and i64 %17, 1
  %18 = icmp eq i32 %15, 1
  br i1 %18, label %._crit_edge28.loopexit.unr-lcssa, label %.lr.ph27.preheader.new

.lr.ph27.preheader.new:                           ; preds = %.lr.ph27.preheader
  %unroll_iter = and i64 %17, 2147483646
  br label %.lr.ph27

.lr.ph23:                                         ; preds = %.lr.ph23.preheader, %.lr.ph23
  %19 = phi i32 [ %.pre, %.lr.ph23.preheader ], [ %22, %.lr.ph23 ]
  %indvars.iv32 = phi i64 [ %12, %.lr.ph23.preheader ], [ %indvars.iv.next33, %.lr.ph23 ]
  %indvars.iv.next33 = add nsw i64 %indvars.iv32, -1
  %20 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv.next33
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %reass.sub = add i32 %19, 1
  %22 = sub i32 %reass.sub, %21
  %23 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %indvars.iv.next33
  store i32 %22, ptr %23, align 4, !tbaa !5
  %24 = icmp ugt i64 %indvars.iv32, 2
  br i1 %24, label %.lr.ph23, label %.preheader, !llvm.loop !11

._crit_edge28.loopexit.unr-lcssa:                 ; preds = %51, %.lr.ph27.preheader
  %.1.lcssa.ph = phi i64 [ poison, %.lr.ph27.preheader ], [ %.1.1, %51 ]
  %indvars.iv35.unr = phi i64 [ 1, %.lr.ph27.preheader ], [ %indvars.iv.next36.1, %51 ]
  %.01525.unr = phi i64 [ 0, %.lr.ph27.preheader ], [ %.1.1, %51 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge28, label %.lr.ph27.epil

.lr.ph27.epil:                                    ; preds = %._crit_edge28.loopexit.unr-lcssa
  %25 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv35.unr
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %._crit_edge28

28:                                               ; preds = %.lr.ph27.epil
  %29 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %indvars.iv35.unr
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = add nsw i64 %.01525.unr, %31
  br label %._crit_edge28

._crit_edge28:                                    ; preds = %._crit_edge28.loopexit.unr-lcssa, %28, %.lr.ph27.epil, %.preheader.thread, %.preheader
  %.015.lcssa = phi i64 [ 0, %.preheader ], [ 0, %.preheader.thread ], [ %.1.lcssa.ph, %._crit_edge28.loopexit.unr-lcssa ], [ %32, %28 ], [ %.01525.unr, %.lr.ph27.epil ]
  %33 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.015.lcssa)
  %34 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %33, ptr noundef nonnull @.str.1)
  ret i32 0

.lr.ph27:                                         ; preds = %51, %.lr.ph27.preheader.new
  %indvars.iv35 = phi i64 [ 1, %.lr.ph27.preheader.new ], [ %indvars.iv.next36.1, %51 ]
  %.01525 = phi i64 [ 0, %.lr.ph27.preheader.new ], [ %.1.1, %51 ]
  %niter = phi i64 [ 0, %.lr.ph27.preheader.new ], [ %niter.next.1, %51 ]
  %35 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv35
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %.lr.ph27.1

38:                                               ; preds = %.lr.ph27
  %39 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %indvars.iv35
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = add nsw i64 %.01525, %41
  br label %.lr.ph27.1

.lr.ph27.1:                                       ; preds = %.lr.ph27, %38
  %.1 = phi i64 [ %42, %38 ], [ %.01525, %.lr.ph27 ]
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %43 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv.next36
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %51

46:                                               ; preds = %.lr.ph27.1
  %47 = getelementptr inbounds [200100 x i32], ptr @zero, i64 0, i64 %indvars.iv.next36
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = add nsw i64 %.1, %49
  br label %51

51:                                               ; preds = %46, %.lr.ph27.1
  %.1.1 = phi i64 [ %50, %46 ], [ %.1, %.lr.ph27.1 ]
  %indvars.iv.next36.1 = add nuw nsw i64 %indvars.iv35, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge28.loopexit.unr-lcssa, label %.lr.ph27, !llvm.loop !12
}

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

; 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 @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #3 align 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 = { 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 #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" }
attributes #3 = { 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 = !{!"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 = distinct !{!12, !10}


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