; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/18 Beta Division 2/Problem C (C)

; 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 [100000 x i32], align 16
@s = external dso_local global [100000 x i32], align 16
@sum = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@.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 i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %21, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100000 x i32], ptr @a, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %13)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100000 x i32], ptr @a, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr @sum, align 4, !tbaa !5
  %20 = add nsw i32 %19, %18
  store i32 %20, ptr @sum, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %10
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

24:                                               ; preds = %9
  %25 = load i32, ptr @a, align 16, !tbaa !5
  store i32 %25, ptr @s, align 16, !tbaa !5
  %26 = load i32, ptr @s, align 16, !tbaa !5
  %27 = load i32, ptr @s, align 16, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = load i32, ptr @sum, align 4, !tbaa !5
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %37

31:                                               ; preds = %24
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp sgt i32 %32, 1
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load i32, ptr @cnt, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr @cnt, align 4, !tbaa !5
  br label %37

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

38:                                               ; preds = %73, %37
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 1
  %42 = icmp slt i32 %39, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %76

44:                                               ; preds = %38
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100000 x i32], ptr @a, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100000 x i32], ptr @s, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %48, %53
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100000 x i32], ptr @s, i64 0, i64 %56
  store i32 %54, ptr %57, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100000 x i32], ptr @s, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100000 x i32], ptr @s, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = add nsw i32 %61, %65
  %67 = load i32, ptr @sum, align 4, !tbaa !5
  %68 = icmp eq i32 %66, %67
  br i1 %68, label %69, label %72

69:                                               ; preds = %44
  %70 = load i32, ptr @cnt, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr @cnt, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %69, %44
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %3, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %3, align 4, !tbaa !5
  br label %38, !llvm.loop !11

76:                                               ; preds = %43
  %77 = load i32, ptr @cnt, align 4, !tbaa !5
  %78 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %77)
  %79 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %78, ptr noundef @.str.1)
  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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #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 = { "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 = { 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}


; 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 [100000 x i32], align 16
@s = external dso_local local_unnamed_addr global [100000 x i32], align 16
@sum = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@.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
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  %.pre = load i32, ptr @sum, align 4, !tbaa !5
  %4 = load i32, ptr @a, align 16, !tbaa !5
  store i32 %4, ptr @s, align 16, !tbaa !5
  br label %._crit_edge._crit_edge

._crit_edge:                                      ; preds = %.lr.ph
  %5 = load i32, ptr @a, align 16, !tbaa !5
  store i32 %5, ptr @s, align 16, !tbaa !5
  %6 = shl nsw i32 %5, 1
  %7 = icmp eq i32 %6, %15
  %8 = icmp sgt i32 %16, 1
  %or.cond = and i1 %8, %7
  br i1 %or.cond, label %19, label %._crit_edge._crit_edge

._crit_edge._crit_edge:                           ; preds = %._crit_edge.thread, %._crit_edge
  %9 = phi i32 [ %4, %._crit_edge.thread ], [ %5, %._crit_edge ]
  %.lcssa27 = phi i32 [ %2, %._crit_edge.thread ], [ %16, %._crit_edge ]
  %10 = phi i32 [ %.pre, %._crit_edge.thread ], [ %15, %._crit_edge ]
  %cnt.promoted.pre = load i32, ptr @cnt, align 4, !tbaa !5
  br label %22

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

19:                                               ; preds = %._crit_edge
  %20 = load i32, ptr @cnt, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @cnt, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %._crit_edge._crit_edge, %19
  %23 = phi i32 [ %9, %._crit_edge._crit_edge ], [ %5, %19 ]
  %.lcssa26 = phi i32 [ %.lcssa27, %._crit_edge._crit_edge ], [ %16, %19 ]
  %24 = phi i32 [ %10, %._crit_edge._crit_edge ], [ %15, %19 ]
  %cnt.promoted = phi i32 [ %cnt.promoted.pre, %._crit_edge._crit_edge ], [ %21, %19 ]
  %25 = icmp sgt i32 %.lcssa26, 2
  br i1 %25, label %.lr.ph16.preheader, label %._crit_edge17

.lr.ph16.preheader:                               ; preds = %22
  %26 = add nsw i32 %.lcssa26, -1
  %wide.trip.count = zext i32 %26 to i64
  %27 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %27, 1
  %28 = icmp eq i32 %26, 2
  br i1 %28, label %._crit_edge17.loopexit.unr-lcssa, label %.lr.ph16.preheader.new

.lr.ph16.preheader.new:                           ; preds = %.lr.ph16.preheader
  %unroll_iter = and i64 %27, -2
  br label %.lr.ph16

._crit_edge17.loopexit.unr-lcssa:                 ; preds = %59, %.lr.ph16.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph16.preheader ], [ %60, %59 ]
  %.unr = phi i32 [ %23, %.lr.ph16.preheader ], [ %53, %59 ]
  %indvars.iv20.unr = phi i64 [ 1, %.lr.ph16.preheader ], [ %indvars.iv.next21.1, %59 ]
  %.unr34 = phi i32 [ %cnt.promoted, %.lr.ph16.preheader ], [ %60, %59 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge17, label %.lr.ph16.epil

.lr.ph16.epil:                                    ; preds = %._crit_edge17.loopexit.unr-lcssa
  %29 = getelementptr inbounds [100000 x i32], ptr @a, i64 0, i64 %indvars.iv20.unr
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 %.unr, %30
  %32 = getelementptr inbounds [100000 x i32], ptr @s, i64 0, i64 %indvars.iv20.unr
  store i32 %31, ptr %32, align 4, !tbaa !5
  %33 = shl nsw i32 %31, 1
  %34 = icmp eq i32 %33, %24
  br i1 %34, label %35, label %._crit_edge17

35:                                               ; preds = %.lr.ph16.epil
  %36 = add nsw i32 %.unr34, 1
  store i32 %36, ptr @cnt, align 4, !tbaa !5
  br label %._crit_edge17

._crit_edge17:                                    ; preds = %._crit_edge17.loopexit.unr-lcssa, %35, %.lr.ph16.epil, %22
  %37 = phi i32 [ %cnt.promoted, %22 ], [ %.lcssa.ph, %._crit_edge17.loopexit.unr-lcssa ], [ %.unr34, %.lr.ph16.epil ], [ %36, %35 ]
  %38 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %37)
  %39 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %38, ptr noundef nonnull @.str.1)
  ret i32 0

.lr.ph16:                                         ; preds = %59, %.lr.ph16.preheader.new
  %40 = phi i32 [ %23, %.lr.ph16.preheader.new ], [ %53, %59 ]
  %indvars.iv20 = phi i64 [ 1, %.lr.ph16.preheader.new ], [ %indvars.iv.next21.1, %59 ]
  %41 = phi i32 [ %cnt.promoted, %.lr.ph16.preheader.new ], [ %60, %59 ]
  %niter = phi i64 [ 0, %.lr.ph16.preheader.new ], [ %niter.next.1, %59 ]
  %42 = getelementptr inbounds [100000 x i32], ptr @a, i64 0, i64 %indvars.iv20
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %40, %43
  %45 = getelementptr inbounds [100000 x i32], ptr @s, i64 0, i64 %indvars.iv20
  store i32 %44, ptr %45, align 4, !tbaa !5
  %46 = shl nsw i32 %44, 1
  %47 = icmp eq i32 %46, %24
  br i1 %47, label %48, label %.lr.ph16.1

48:                                               ; preds = %.lr.ph16
  %49 = add nsw i32 %41, 1
  store i32 %49, ptr @cnt, align 4, !tbaa !5
  br label %.lr.ph16.1

.lr.ph16.1:                                       ; preds = %.lr.ph16, %48
  %50 = phi i32 [ %41, %.lr.ph16 ], [ %49, %48 ]
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %51 = getelementptr inbounds [100000 x i32], ptr @a, i64 0, i64 %indvars.iv.next21
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = add nsw i32 %44, %52
  %54 = getelementptr inbounds [100000 x i32], ptr @s, i64 0, i64 %indvars.iv.next21
  store i32 %53, ptr %54, align 4, !tbaa !5
  %55 = shl nsw i32 %53, 1
  %56 = icmp eq i32 %55, %24
  br i1 %56, label %57, label %59

57:                                               ; preds = %.lr.ph16.1
  %58 = add nsw i32 %50, 1
  store i32 %58, ptr @cnt, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %57, %.lr.ph16.1
  %60 = phi i32 [ %50, %.lr.ph16.1 ], [ %58, %57 ]
  %indvars.iv.next21.1 = add nuw nsw i64 %indvars.iv20, 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_edge17.loopexit.unr-lcssa, label %.lr.ph16, !llvm.loop !11
}

; 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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #3

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


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