; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/153 Division 2/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
@x = external dso_local global [100000 x i32], align 16
@d = external dso_local global i32, align 4
@res = external dso_local global i64, align 8
@p1 = external dso_local global i64, align 8
@p2 = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @d)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %15, %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) #5
  br label %18

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 @x, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %13)
  br label %15

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

18:                                               ; preds = %9
  store i64 0, ptr @p2, align 8, !tbaa !11
  store i64 0, ptr @p1, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %61, %18
  %20 = load i64, ptr @p1, align 8, !tbaa !11
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %20, %22
  br i1 %23, label %24, label %64

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %42, %24
  %26 = load i64, ptr @p2, align 8, !tbaa !11
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %26, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %25
  %31 = load i64, ptr @p2, align 8, !tbaa !11
  %32 = getelementptr inbounds [100000 x i32], ptr @x, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load i64, ptr @p1, align 8, !tbaa !11
  %35 = getelementptr inbounds [100000 x i32], ptr @x, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sub nsw i32 %33, %36
  %38 = load i32, ptr @d, align 4, !tbaa !5
  %39 = icmp sle i32 %37, %38
  br label %40

40:                                               ; preds = %30, %25
  %41 = phi i1 [ false, %25 ], [ %39, %30 ]
  br i1 %41, label %42, label %45

42:                                               ; preds = %40
  %43 = load i64, ptr @p2, align 8, !tbaa !11
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr @p2, align 8, !tbaa !11
  br label %25, !llvm.loop !13

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %46 = load i64, ptr @p2, align 8, !tbaa !11
  %47 = load i64, ptr @p1, align 8, !tbaa !11
  %48 = sub nsw i64 %46, %47
  %49 = sub nsw i64 %48, 1
  store i64 %49, ptr %3, align 8, !tbaa !11
  %50 = load i64, ptr %3, align 8, !tbaa !11
  %51 = icmp sgt i64 %50, 1
  br i1 %51, label %52, label %60

52:                                               ; preds = %45
  %53 = load i64, ptr %3, align 8, !tbaa !11
  %54 = load i64, ptr %3, align 8, !tbaa !11
  %55 = sub nsw i64 %54, 1
  %56 = mul nsw i64 %53, %55
  %57 = sdiv i64 %56, 2
  %58 = load i64, ptr @res, align 8, !tbaa !11
  %59 = add nsw i64 %58, %57
  store i64 %59, ptr @res, align 8, !tbaa !11
  br label %60

60:                                               ; preds = %52, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %61

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

64:                                               ; preds = %19
  %65 = load i64, ptr @res, align 8, !tbaa !11
  %66 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %65)
  %67 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %66, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  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: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3 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)) #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 = { "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 = { 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 = { 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 #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
@x = external dso_local global [100000 x i32], align 16
@d = external dso_local global i32, align 4
@res = external dso_local local_unnamed_addr global i64, align 8
@p1 = external dso_local local_unnamed_addr global i64, align 8
@p2 = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; 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, ptr noundef nonnull @d)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  store i64 0, ptr @p2, align 8, !tbaa !9
  br label %._crit_edge.._crit_edge22_crit_edge

._crit_edge:                                      ; preds = %.lr.ph
  %4 = icmp sgt i32 %8, 0
  store i64 0, ptr @p2, align 8, !tbaa !9
  br i1 %4, label %.preheader.lr.ph, label %._crit_edge.._crit_edge22_crit_edge

._crit_edge.._crit_edge22_crit_edge:              ; preds = %._crit_edge.thread, %._crit_edge
  %.pre = load i64, ptr @res, align 8, !tbaa !9
  br label %._crit_edge22

.preheader.lr.ph:                                 ; preds = %._crit_edge
  %res.promoted = load i64, ptr @res, align 8, !tbaa !9
  %5 = load i32, ptr @d, align 4
  br label %.preheader

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

.preheader:                                       ; preds = %.preheader.lr.ph, %29
  %storemerge21 = phi i64 [ 0, %.preheader.lr.ph ], [ %31, %29 ]
  %p2.promoted1720 = phi i64 [ 0, %.preheader.lr.ph ], [ %p2.promoted15, %29 ]
  %11 = phi i64 [ %res.promoted, %.preheader.lr.ph ], [ %30, %29 ]
  %12 = icmp slt i64 %p2.promoted1720, %9
  br i1 %12, label %.lr.ph10, label %.critedge

.lr.ph10:                                         ; preds = %.preheader
  %13 = getelementptr inbounds [100000 x i32], ptr @x, i64 0, i64 %storemerge21
  %14 = load i32, ptr %13, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %.lr.ph10, %19
  %p2.promoted16 = phi i64 [ %p2.promoted1720, %.lr.ph10 ], [ %20, %19 ]
  %16 = getelementptr inbounds [100000 x i32], ptr @x, i64 0, i64 %p2.promoted16
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sub nsw i32 %17, %14
  %.not = icmp sgt i32 %18, %5
  br i1 %.not, label %.critedge, label %19

19:                                               ; preds = %15
  %20 = add i64 %p2.promoted16, 1
  store i64 %20, ptr @p2, align 8, !tbaa !9
  %exitcond.not = icmp eq i64 %20, %9
  br i1 %exitcond.not, label %.critedge, label %15, !llvm.loop !13

.critedge:                                        ; preds = %15, %19, %.preheader
  %p2.promoted15 = phi i64 [ %p2.promoted1720, %.preheader ], [ %9, %19 ], [ %p2.promoted16, %15 ]
  %21 = xor i64 %storemerge21, -1
  %22 = add i64 %p2.promoted15, %21
  %23 = icmp sgt i64 %22, 1
  br i1 %23, label %24, label %29

24:                                               ; preds = %.critedge
  %25 = add nsw i64 %22, -1
  %26 = mul nsw i64 %25, %22
  %27 = lshr i64 %26, 1
  %28 = add nsw i64 %11, %27
  store i64 %28, ptr @res, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %24, %.critedge
  %30 = phi i64 [ %28, %24 ], [ %11, %.critedge ]
  %31 = add nuw nsw i64 %storemerge21, 1
  %exitcond26.not = icmp eq i64 %31, %9
  br i1 %exitcond26.not, label %._crit_edge22, label %.preheader, !llvm.loop !14

._crit_edge22:                                    ; preds = %29, %._crit_edge.._crit_edge22_crit_edge
  %32 = phi i64 [ %.pre, %._crit_edge.._crit_edge22_crit_edge ], [ %30, %29 ]
  %storemerge.lcssa = phi i64 [ 0, %._crit_edge.._crit_edge22_crit_edge ], [ %9, %29 ]
  store i64 %storemerge.lcssa, ptr @p1, align 8, !tbaa !9
  %33 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %32)
  %34 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %33, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

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

; 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 #2 align 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 #2 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)) #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 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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