; LLVM IR from Tunghohin/Competitive_Coding :: Codeforces/cf1604_A.ll (Z5solvev)

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

@arr = external dso_local global [110 x i32], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %16, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %19

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %13
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %14)
  br label %16

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

19:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !11
  store i32 0, ptr @arr, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %63, %19
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sub nsw i32 %29, %34
  %36 = icmp sgt i32 %35, 1
  br i1 %36, label %37, label %52

37:                                               ; preds = %25
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sub nsw i32 %41, %46
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = load i64, ptr %3, align 8, !tbaa !11
  %51 = add i64 %50, %49
  store i64 %51, ptr %3, align 8, !tbaa !11
  br label %62

52:                                               ; preds = %25
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sub nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %60
  store i32 %58, ptr %61, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %52, %37
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !13

66:                                               ; preds = %24
  %67 = load i64, ptr %3, align 8, !tbaa !11
  %68 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEy(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %67)
  %69 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %68, i8 noundef signext 10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #0 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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" }
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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!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" }

@arr = external dso_local global [110 x i32], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %.not17 = icmp slt i32 %3, 1
  br i1 %.not17, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %0
  store i32 0, ptr @arr, align 16, !tbaa !5
  br label %._crit_edge24

._crit_edge:                                      ; preds = %.lr.ph
  store i32 0, ptr @arr, align 16, !tbaa !5
  %.not1619 = icmp slt i32 %8, 1
  br i1 %.not1619, label %._crit_edge24, label %.lr.ph23.preheader

.lr.ph23.preheader:                               ; preds = %._crit_edge
  %4 = zext nneg i32 %8 to i64
  %xtraiter = and i64 %4, 1
  %5 = icmp eq i32 %8, 1
  br i1 %5, label %._crit_edge24.loopexit.unr-lcssa, label %.lr.ph23.preheader.new

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

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %6 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %indvars.iv
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %.not.not = icmp slt i64 %indvars.iv, %9
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge24.loopexit.unr-lcssa:                 ; preds = %44, %.lr.ph23.preheader
  %.1.lcssa.ph = phi i64 [ poison, %.lr.ph23.preheader ], [ %.1.1, %44 ]
  %.unr = phi i32 [ 0, %.lr.ph23.preheader ], [ %45, %44 ]
  %indvars.iv28.unr = phi i64 [ 1, %.lr.ph23.preheader ], [ %indvars.iv.next29.1, %44 ]
  %.01320.unr = phi i64 [ 0, %.lr.ph23.preheader ], [ %.1.1, %44 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge24, label %.lr.ph23.epil

.lr.ph23.epil:                                    ; preds = %._crit_edge24.loopexit.unr-lcssa
  %10 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %indvars.iv28.unr
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sub nsw i32 %11, %.unr
  %13 = icmp sgt i32 %12, 1
  br i1 %13, label %16, label %14

14:                                               ; preds = %.lr.ph23.epil
  %15 = add nsw i32 %.unr, 1
  store i32 %15, ptr %10, align 4, !tbaa !5
  br label %._crit_edge24

16:                                               ; preds = %.lr.ph23.epil
  %17 = add nsw i32 %12, -1
  %18 = zext nneg i32 %17 to i64
  %19 = add i64 %.01320.unr, %18
  br label %._crit_edge24

._crit_edge24:                                    ; preds = %._crit_edge24.loopexit.unr-lcssa, %16, %14, %._crit_edge.thread, %._crit_edge
  %.013.lcssa = phi i64 [ 0, %._crit_edge ], [ 0, %._crit_edge.thread ], [ %.1.lcssa.ph, %._crit_edge24.loopexit.unr-lcssa ], [ %19, %16 ], [ %.01320.unr, %14 ]
  %20 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEy(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.013.lcssa)
  %21 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %20, i8 noundef signext 10)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret void

.lr.ph23:                                         ; preds = %44, %.lr.ph23.preheader.new
  %22 = phi i32 [ 0, %.lr.ph23.preheader.new ], [ %45, %44 ]
  %indvars.iv28 = phi i64 [ 1, %.lr.ph23.preheader.new ], [ %indvars.iv.next29.1, %44 ]
  %.01320 = phi i64 [ 0, %.lr.ph23.preheader.new ], [ %.1.1, %44 ]
  %niter = phi i64 [ 0, %.lr.ph23.preheader.new ], [ %niter.next.1, %44 ]
  %23 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %indvars.iv28
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sub nsw i32 %24, %22
  %26 = icmp sgt i32 %25, 1
  br i1 %26, label %27, label %31

27:                                               ; preds = %.lr.ph23
  %28 = add nsw i32 %25, -1
  %29 = zext nneg i32 %28 to i64
  %30 = add i64 %.01320, %29
  br label %.lr.ph23.1

31:                                               ; preds = %.lr.ph23
  %32 = add nsw i32 %22, 1
  store i32 %32, ptr %23, align 4, !tbaa !5
  br label %.lr.ph23.1

.lr.ph23.1:                                       ; preds = %27, %31
  %33 = phi i32 [ %24, %27 ], [ %32, %31 ]
  %.1 = phi i64 [ %30, %27 ], [ %.01320, %31 ]
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %34 = getelementptr inbounds [110 x i32], ptr @arr, i64 0, i64 %indvars.iv.next29
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sub nsw i32 %35, %33
  %37 = icmp sgt i32 %36, 1
  br i1 %37, label %40, label %38

38:                                               ; preds = %.lr.ph23.1
  %39 = add nsw i32 %33, 1
  store i32 %39, ptr %34, align 4, !tbaa !5
  br label %44

40:                                               ; preds = %.lr.ph23.1
  %41 = add nsw i32 %36, -1
  %42 = zext nneg i32 %41 to i64
  %43 = add i64 %.1, %42
  br label %44

44:                                               ; preds = %40, %38
  %45 = phi i32 [ %35, %40 ], [ %39, %38 ]
  %.1.1 = phi i64 [ %43, %40 ], [ %.1, %38 ]
  %indvars.iv.next29.1 = add nuw nsw i64 %indvars.iv28, 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_edge24.loopexit.unr-lcssa, label %.lr.ph23, !llvm.loop !11
}

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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" }
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}


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