; LLVM IR from manishbisht/Competitive-Programming :: Coding Blocks/Competitive Warriors Challenge 3.0 (Vivek and Factors)

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

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_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 [110000 x i64], align 16
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 880000, ptr %2) #5
  call void @llvm.memset.p0.i64(ptr align 16 %2, i8 0, i64 880000, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %27, %0
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = icmp slt i64 %9, 110000
  br i1 %10, label %11, label %30

11:                                               ; preds = %8
  %12 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %12, ptr %4, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %22, %11
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = icmp slt i64 %14, 110000
  br i1 %15, label %16, label %26

16:                                               ; preds = %13
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds [110000 x i64], ptr %2, 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
  br label %22

22:                                               ; preds = %16
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = add nsw i64 %24, %23
  store i64 %25, ptr %4, align 8, !tbaa !5
  br label %13, !llvm.loop !9

26:                                               ; preds = %13
  br label %27

27:                                               ; preds = %26
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = add nsw i64 %28, 1
  store i64 %29, ptr %3, align 8, !tbaa !5
  br label %8, !llvm.loop !11

30:                                               ; preds = %8
  %31 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %6)
  br label %32

32:                                               ; preds = %51, %30
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %56

35:                                               ; preds = %32
  store i64 -1, ptr %7, align 8, !tbaa !5
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %48, %35
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = icmp slt i64 %37, 110000
  br i1 %38, label %39, label %51

39:                                               ; preds = %36
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds [110000 x i64], ptr %2, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = load i64, ptr %6, align 8, !tbaa !5
  %44 = icmp eq i64 %42, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %39
  %46 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %46, ptr %7, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %39
  br label %48

48:                                               ; preds = %47
  %49 = load i64, ptr %3, align 8, !tbaa !5
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr %3, align 8, !tbaa !5
  br label %36, !llvm.loop !12

51:                                               ; preds = %36
  %52 = load i64, ptr %7, align 8, !tbaa !5
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %52)
  %54 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %53, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %55 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %6)
  br label %32, !llvm.loop !13

56:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 880000, ptr %2) #5
  %57 = load i32, ptr %1, align 4
  ret i32 %57
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(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

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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}
!13 = distinct !{!13, !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" }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_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 = alloca [110000 x i64], align 16
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 880000, ptr nonnull %1) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(880000) %1, i8 0, i64 880000, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  br label %.preheader17

.preheader17:                                     ; preds = %16, %0
  %.01419 = phi i64 [ 1, %0 ], [ %17, %16 ]
  br label %3

3:                                                ; preds = %.preheader17, %3
  %.01618 = phi i64 [ %.01419, %.preheader17 ], [ %7, %3 ]
  %4 = getelementptr inbounds [110000 x i64], ptr %1, i64 0, i64 %.01618
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = add nsw i64 %5, %.01419
  store i64 %6, ptr %4, align 8, !tbaa !5
  %7 = add nuw nsw i64 %.01618, %.01419
  %8 = icmp ult i64 %7, 110000
  br i1 %8, label %3, label %9, !llvm.loop !9

9:                                                ; preds = %3
  %10 = add nuw nsw i64 %.01419, 1
  %exitcond.not = icmp eq i64 %10, 110000
  br i1 %exitcond.not, label %18, label %.preheader17.1, !llvm.loop !11

.preheader17.1:                                   ; preds = %9, %.preheader17.1
  %.01618.1 = phi i64 [ %14, %.preheader17.1 ], [ %10, %9 ]
  %11 = getelementptr inbounds [110000 x i64], ptr %1, i64 0, i64 %.01618.1
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = add nsw i64 %12, %10
  store i64 %13, ptr %11, align 8, !tbaa !5
  %14 = add nuw nsw i64 %.01618.1, %10
  %15 = icmp ult i64 %14, 110000
  br i1 %15, label %.preheader17.1, label %16, !llvm.loop !9

16:                                               ; preds = %.preheader17.1
  %17 = add nuw nsw i64 %.01419, 2
  br label %.preheader17

18:                                               ; preds = %9
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %.not22 = icmp eq i64 %20, 0
  br i1 %.not22, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %18, %40
  %21 = phi i64 [ %44, %40 ], [ %20, %18 ]
  br label %22

22:                                               ; preds = %35, %.preheader
  %.021 = phi i64 [ -1, %.preheader ], [ %spec.select.3, %35 ]
  %.11520 = phi i64 [ 1, %.preheader ], [ %39, %35 ]
  %23 = getelementptr inbounds [110000 x i64], ptr %1, i64 0, i64 %.11520
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = icmp eq i64 %24, %21
  %spec.select = select i1 %25, i64 %.11520, i64 %.021
  %26 = add nuw nsw i64 %.11520, 1
  %27 = getelementptr inbounds [110000 x i64], ptr %1, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = icmp eq i64 %28, %21
  %spec.select.1 = select i1 %29, i64 %26, i64 %spec.select
  %30 = add nuw nsw i64 %.11520, 2
  %31 = getelementptr inbounds [110000 x i64], ptr %1, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = icmp eq i64 %32, %21
  %spec.select.2 = select i1 %33, i64 %30, i64 %spec.select.1
  %34 = add nuw nsw i64 %.11520, 3
  %exitcond23.not.2 = icmp eq i64 %34, 110000
  br i1 %exitcond23.not.2, label %40, label %35, !llvm.loop !12

35:                                               ; preds = %22
  %36 = getelementptr inbounds [110000 x i64], ptr %1, i64 0, i64 %34
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = icmp eq i64 %37, %21
  %spec.select.3 = select i1 %38, i64 %34, i64 %spec.select.2
  %39 = add nuw nsw i64 %.11520, 4
  br label %22

40:                                               ; preds = %22
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %spec.select.2)
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %41, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %43 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %44 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %44, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !13

._crit_edge:                                      ; preds = %40, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 880000, ptr nonnull %1) #5
  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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #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) local_unnamed_addr #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

; 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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}
!13 = distinct !{!13, !10}


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