; LLVM IR from tangjz/acm-icpc :: codeforces/complete/1466B.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"

@_ZZ5solvevE1a = external hidden global [100001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  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 %1, 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) #3
  br label %20

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr @_ZZ5solvevE1a, 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 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %21

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

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %57

26:                                               ; preds = %21
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %39

33:                                               ; preds = %26
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %36, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %33, %26
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100001 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp slt i32 %40, %44
  br i1 %45, label %46, label %53

46:                                               ; preds = %39
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100001 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  store i32 %50, ptr %3, align 4, !tbaa !5
  %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 %53

53:                                               ; preds = %46, %39
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !5
  br label %21, !llvm.loop !11

57:                                               ; preds = %25
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

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

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

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

declare i32 @printf(ptr noundef, ...) #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 = { 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"

@_ZZ5solvevE1a = external hidden global [100001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree nounwind 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 i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %.not21 = icmp slt i32 %3, 1
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.not1923 = icmp slt i32 %8, 1
  br i1 %.not1923, label %._crit_edge, label %.lr.ph27.preheader

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

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

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %6 = getelementptr inbounds i32, ptr @_ZZ5solvevE1a, i64 %indvars.iv
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %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 %.preheader, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %32, %.lr.ph27.preheader
  %spec.select20.lcssa.ph = phi i32 [ poison, %.lr.ph27.preheader ], [ %spec.select20.1, %32 ]
  %indvars.iv31.unr = phi i64 [ 1, %.lr.ph27.preheader ], [ %indvars.iv.next32.1, %32 ]
  %.01325.unr = phi i32 [ 0, %.lr.ph27.preheader ], [ %spec.select20.1, %32 ]
  %.01424.unr = phi i32 [ 0, %.lr.ph27.preheader ], [ %spec.select.1, %32 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph27.epil

.lr.ph27.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %10 = getelementptr inbounds [100001 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %indvars.iv31.unr
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, %.01424.unr
  br i1 %12, label %13, label %._crit_edge.loopexit.epilog-lcssa

13:                                               ; preds = %.lr.ph27.epil
  %14 = add nuw nsw i32 %.01424.unr, 1
  store i32 %14, ptr %10, align 4, !tbaa !5
  br label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %13, %.lr.ph27.epil
  %15 = phi i32 [ %14, %13 ], [ %11, %.lr.ph27.epil ]
  %16 = icmp slt i32 %.01424.unr, %15
  %17 = zext i1 %16 to i32
  %spec.select20.epil = add nuw nsw i32 %.01325.unr, %17
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %0, %.preheader
  %.013.lcssa = phi i32 [ 0, %.preheader ], [ 0, %0 ], [ %spec.select20.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select20.epil, %._crit_edge.loopexit.epilog-lcssa ]
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.013.lcssa)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret void

.lr.ph27:                                         ; preds = %32, %.lr.ph27.preheader.new
  %indvars.iv31 = phi i64 [ 1, %.lr.ph27.preheader.new ], [ %indvars.iv.next32.1, %32 ]
  %.01325 = phi i32 [ 0, %.lr.ph27.preheader.new ], [ %spec.select20.1, %32 ]
  %.01424 = phi i32 [ 0, %.lr.ph27.preheader.new ], [ %spec.select.1, %32 ]
  %niter = phi i64 [ 0, %.lr.ph27.preheader.new ], [ %niter.next.1, %32 ]
  %19 = getelementptr inbounds [100001 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %indvars.iv31
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp eq i32 %20, %.01424
  br i1 %21, label %22, label %.lr.ph27.1

22:                                               ; preds = %.lr.ph27
  %23 = add nuw nsw i32 %.01424, 1
  store i32 %23, ptr %19, align 4, !tbaa !5
  br label %.lr.ph27.1

.lr.ph27.1:                                       ; preds = %22, %.lr.ph27
  %24 = phi i32 [ %23, %22 ], [ %20, %.lr.ph27 ]
  %25 = icmp slt i32 %.01424, %24
  %spec.select = call i32 @llvm.smax.i32(i32 %.01424, i32 %24)
  %26 = zext i1 %25 to i32
  %spec.select20 = add nuw nsw i32 %.01325, %26
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %27 = getelementptr inbounds [100001 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %indvars.iv.next32
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp eq i32 %28, %spec.select
  br i1 %29, label %30, label %32

30:                                               ; preds = %.lr.ph27.1
  %31 = add nuw nsw i32 %spec.select, 1
  store i32 %31, ptr %27, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %30, %.lr.ph27.1
  %33 = phi i32 [ %31, %30 ], [ %28, %.lr.ph27.1 ]
  %34 = icmp slt i32 %spec.select, %33
  %spec.select.1 = call i32 @llvm.smax.i32(i32 %spec.select, i32 %33)
  %35 = zext i1 %34 to i32
  %spec.select20.1 = add nuw nsw i32 %spec.select20, %35
  %indvars.iv.next32.1 = add nuw nsw i64 %indvars.iv31, 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_edge.loopexit.unr-lcssa, label %.lr.ph27, !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

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

attributes #0 = { mustprogress nofree nounwind 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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass