; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1213A. Chips Moving (main)

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

@arr = external dso_local global [105 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 norecurse uwtable
define dso_local noundef i32 @main() #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
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  br label %7

7:                                                ; preds = %59, %0
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %9 = icmp ne i32 %8, -1
  br i1 %9, label %10, label %62

10:                                               ; preds = %7
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %20, %10
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %11
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [105 x i32], ptr @arr, i64 0, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %18)
  br label %20

20:                                               ; preds = %15
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !9

23:                                               ; preds = %11
  store i32 1000000007, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %56, %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %59

28:                                               ; preds = %24
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %50, %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %53

33:                                               ; preds = %29
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [105 x i32], ptr @arr, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [105 x i32], ptr @arr, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sub nsw i32 %37, %41
  %43 = call i32 @llvm.abs.i32(i32 %42, i1 true)
  %44 = and i32 %43, 1
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %33
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %6, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %46, %33
  br label %50

50:                                               ; preds = %49
  %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 %29, !llvm.loop !11

53:                                               ; preds = %29
  %54 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %55 = load i32, ptr %54, align 4, !tbaa !5
  store i32 %55, ptr %5, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %53
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !12

59:                                               ; preds = %24
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %60)
  br label %7, !llvm.loop !13

62:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

; 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 speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4

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

; 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 = { "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 = { inlinehint mustprogress 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 #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 = 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"

@arr = external dso_local global [105 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 norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not20 = icmp eq i32 %4, -1
  br i1 %.not20, label %._crit_edge21, label %.preheader

.preheader:                                       ; preds = %0, %._crit_edge19
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader
  store i32 1000000007, ptr %2, align 4, !tbaa !5
  br label %._crit_edge19

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

._crit_edge:                                      ; preds = %.lr.ph
  store i32 1000000007, ptr %2, align 4, !tbaa !5
  %12 = icmp sgt i32 %9, 0
  br i1 %12, label %.lr.ph18, label %._crit_edge19

.lr.ph18:                                         ; preds = %._crit_edge, %._crit_edge15
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %._crit_edge15 ], [ 0, %._crit_edge ]
  %13 = phi i32 [ %44, %._crit_edge15 ], [ %9, %._crit_edge ]
  store i32 0, ptr %3, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph14, label %._crit_edge15

.lr.ph14:                                         ; preds = %.lr.ph18
  %15 = getelementptr inbounds [105 x i32], ptr @arr, i64 0, i64 %indvars.iv26
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %13 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %17 = icmp eq i32 %13, 1
  br i1 %17, label %._crit_edge15.loopexit.unr-lcssa, label %.lr.ph14.new

.lr.ph14.new:                                     ; preds = %.lr.ph14
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %18

18:                                               ; preds = %34, %.lr.ph14.new
  %indvars.iv23 = phi i64 [ 0, %.lr.ph14.new ], [ %indvars.iv.next24.1, %34 ]
  %19 = phi i32 [ 0, %.lr.ph14.new ], [ %35, %34 ]
  %niter = phi i64 [ 0, %.lr.ph14.new ], [ %niter.next.1, %34 ]
  %20 = getelementptr inbounds [105 x i32], ptr @arr, i64 0, i64 %indvars.iv23
  %21 = load i32, ptr %20, align 8, !tbaa !5
  %22 = sub nsw i32 %16, %21
  %23 = and i32 %22, 1
  %.not10 = icmp eq i32 %23, 0
  br i1 %.not10, label %26, label %24

24:                                               ; preds = %18
  %25 = add nsw i32 %19, 1
  store i32 %25, ptr %3, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %18, %24
  %27 = phi i32 [ %19, %18 ], [ %25, %24 ]
  %indvars.iv.next24 = or disjoint i64 %indvars.iv23, 1
  %28 = getelementptr inbounds [105 x i32], ptr @arr, i64 0, i64 %indvars.iv.next24
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sub nsw i32 %16, %29
  %31 = and i32 %30, 1
  %.not10.1 = icmp eq i32 %31, 0
  br i1 %.not10.1, label %34, label %32

32:                                               ; preds = %26
  %33 = add nsw i32 %27, 1
  store i32 %33, ptr %3, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %32, %26
  %35 = phi i32 [ %27, %26 ], [ %33, %32 ]
  %indvars.iv.next24.1 = add nuw nsw i64 %indvars.iv23, 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_edge15.loopexit.unr-lcssa, label %18, !llvm.loop !11

._crit_edge15.loopexit.unr-lcssa:                 ; preds = %34, %.lr.ph14
  %indvars.iv23.unr = phi i64 [ 0, %.lr.ph14 ], [ %indvars.iv.next24.1, %34 ]
  %.unr = phi i32 [ 0, %.lr.ph14 ], [ %35, %34 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge15, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge15.loopexit.unr-lcssa
  %36 = getelementptr inbounds [105 x i32], ptr @arr, i64 0, i64 %indvars.iv23.unr
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sub nsw i32 %16, %37
  %39 = and i32 %38, 1
  %.not10.epil = icmp eq i32 %39, 0
  br i1 %.not10.epil, label %._crit_edge15, label %40

40:                                               ; preds = %.epil.preheader
  %41 = add nsw i32 %.unr, 1
  store i32 %41, ptr %3, align 4, !tbaa !5
  br label %._crit_edge15

._crit_edge15:                                    ; preds = %._crit_edge15.loopexit.unr-lcssa, %40, %.epil.preheader, %.lr.ph18
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %43 = load i32, ptr %42, align 4, !tbaa !5
  store i32 %43, ptr %2, align 4, !tbaa !5
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = icmp slt i64 %indvars.iv.next27, %45
  br i1 %46, label %.lr.ph18, label %._crit_edge19, !llvm.loop !12

._crit_edge19:                                    ; preds = %._crit_edge15, %._crit_edge.thread, %._crit_edge
  %47 = phi i32 [ 1000000007, %._crit_edge ], [ 1000000007, %._crit_edge.thread ], [ %43, %._crit_edge15 ]
  %48 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %47)
  %49 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %49, -1
  br i1 %.not, label %._crit_edge21, label %.preheader, !llvm.loop !13

._crit_edge21:                                    ; preds = %._crit_edge19, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  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: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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

attributes #0 = { mustprogress norecurse 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 = { inlinehint mustprogress 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 #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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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