; LLVM IR from tangjz/acm-icpc :: codeforces/gym (100662B)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [1010 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 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
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %71, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @t, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %74

14:                                               ; preds = %9
  store i32 2147483647, ptr @ans, align 4, !tbaa !5
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %26, %14
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %29

21:                                               ; preds = %16
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr @a, i64 %23
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %24)
  br label %26

26:                                               ; preds = %21
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %16, !llvm.loop !9

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %64, %29
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = icmp sle i32 %31, 1000
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %67

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %50, %34
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %53

40:                                               ; preds = %35
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1010 x i32], ptr @a, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = sdiv i32 %45, %46
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = add nsw i32 %48, %47
  store i32 %49, ptr %6, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %40
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %7, align 4, !tbaa !5
  br label %35, !llvm.loop !11

53:                                               ; preds = %39
  %54 = load i32, ptr @ans, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = icmp sgt i32 %54, %57
  br i1 %58, label %59, label %63

59:                                               ; preds = %53
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = add nsw i32 %60, %61
  store i32 %62, ptr @ans, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %59, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %64

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

67:                                               ; preds = %33
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = load i32, ptr @ans, align 4, !tbaa !5
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %68, i32 noundef %69)
  br label %71

71:                                               ; preds = %67
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !13

74:                                               ; preds = %13
  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

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [1010 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %.not29 = icmp slt i32 %2, 1
  br i1 %.not29, label %._crit_edge, label %.lr.ph31

._crit_edge:                                      ; preds = %.split.us, %0
  ret i32 0

.lr.ph31:                                         ; preds = %0, %.split.us
  %.02030 = phi i32 [ %69, %.split.us ], [ 1, %0 ]
  store i32 2147483647, ptr @ans, align 4, !tbaa !5
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.preheader22.thread

.preheader22.thread:                              ; preds = %.lr.ph31
  %ans.promoted42 = load i32, ptr @ans, align 4, !tbaa !5
  br label %.preheader.preheader

.preheader22:                                     ; preds = %.lr.ph
  %6 = icmp sgt i32 %32, 0
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  br i1 %6, label %.preheader.us.preheader, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader22.thread, %.preheader22
  %.ph = phi i32 [ %ans.promoted, %.preheader22 ], [ %ans.promoted42, %.preheader22.thread ]
  br label %.preheader

.preheader.us.preheader:                          ; preds = %.preheader22
  %wide.trip.count = zext nneg i32 %32 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %7 = icmp eq i32 %32, 1
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %10
  %.01828.us = phi i32 [ %12, %10 ], [ 1, %.preheader.us.preheader ]
  %8 = phi i32 [ %11, %10 ], [ %ans.promoted, %.preheader.us.preheader ]
  br i1 %7, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

9:                                                ; preds = %._crit_edge.us
  store i32 %28, ptr @ans, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %9, %._crit_edge.us
  %11 = phi i32 [ %28, %9 ], [ %8, %._crit_edge.us ]
  %12 = add nuw nsw i32 %.01828.us, 1
  %exitcond40.not = icmp eq i32 %12, 1001
  br i1 %exitcond40.not, label %.split.us, label %.preheader.us, !llvm.loop !9

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv36 = phi i64 [ %indvars.iv.next37.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %.01724.us = phi i32 [ %22, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %13 = getelementptr inbounds [1010 x i32], ptr @a, i64 0, i64 %indvars.iv36
  %14 = load i32, ptr %13, align 8, !tbaa !5
  %15 = add nsw i32 %14, -1
  %16 = sdiv i32 %15, %.01828.us
  %17 = add nsw i32 %16, %.01724.us
  %indvars.iv.next37 = or disjoint i64 %indvars.iv36, 1
  %18 = getelementptr inbounds [1010 x i32], ptr @a, i64 0, i64 %indvars.iv.next37
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, -1
  %21 = sdiv i32 %20, %.01828.us
  %22 = add nsw i32 %21, %17
  %indvars.iv.next37.1 = add nuw nsw i64 %indvars.iv36, 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.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !11

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.lcssa54.ph = phi i32 [ poison, %.preheader.us ], [ %22, %.preheader.us.new ]
  %indvars.iv36.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next37.1, %.preheader.us.new ]
  %.01724.us.unr = phi i32 [ 0, %.preheader.us ], [ %22, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %23 = getelementptr inbounds [1010 x i32], ptr @a, i64 0, i64 %indvars.iv36.unr
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, -1
  %26 = sdiv i32 %25, %.01828.us
  %27 = add nsw i32 %26, %.01724.us.unr
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.lcssa54 = phi i32 [ %.lcssa54.ph, %._crit_edge.us.unr-lcssa ], [ %27, %._crit_edge.us.epilog-lcssa ]
  %28 = add nsw i32 %.lcssa54, %.01828.us
  %29 = icmp sgt i32 %8, %28
  br i1 %29, label %9, label %10

.lr.ph:                                           ; preds = %.lr.ph31, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph31 ]
  %30 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %31 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %30)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next, %33
  br i1 %34, label %.lr.ph, label %.preheader22, !llvm.loop !12

.preheader:                                       ; preds = %72, %.preheader.preheader
  %.01828 = phi i32 [ 1, %.preheader.preheader ], [ %73, %72 ]
  %35 = phi i32 [ %.ph, %.preheader.preheader ], [ %spec.select61, %72 ]
  %36 = icmp sgt i32 %35, %.01828
  %37 = select i1 %36, i32 %.01828, i32 %35
  %38 = add nuw nsw i32 %.01828, 1
  %39 = icmp sgt i32 %37, %38
  %40 = select i1 %39, i32 %38, i32 %37
  %41 = xor i1 %36, true
  %42 = xor i1 %39, true
  %43 = xor i1 %41, true
  %44 = xor i1 %42, true
  %45 = or i1 %43, %44
  %46 = add nuw nsw i32 %.01828, 2
  %47 = icmp sgt i32 %40, %46
  %spec.select = select i1 %47, i32 %46, i32 %40
  %48 = xor i1 %45, true
  %49 = xor i1 %47, true
  %50 = xor i1 %48, true
  %51 = xor i1 %49, true
  %52 = or i1 %50, %51
  %53 = add nuw nsw i32 %.01828, 3
  %54 = icmp sgt i32 %spec.select, %53
  %spec.select60 = select i1 %54, i32 %53, i32 %spec.select
  %55 = xor i1 %52, true
  %56 = xor i1 %54, true
  %57 = xor i1 %55, true
  %58 = xor i1 %56, true
  %59 = or i1 %57, %58
  %60 = add nuw nsw i32 %.01828, 4
  %61 = icmp sgt i32 %spec.select60, %60
  %spec.select61 = select i1 %61, i32 %60, i32 %spec.select60
  %62 = xor i1 %59, true
  %63 = xor i1 %61, true
  %64 = xor i1 %62, true
  %65 = xor i1 %63, true
  %66 = or i1 %64, %65
  br i1 %66, label %71, label %72

.split.us:                                        ; preds = %72, %10
  %67 = phi i32 [ %11, %10 ], [ %spec.select61, %72 ]
  %68 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.02030, i32 noundef %67)
  %69 = add nuw nsw i32 %.02030, 1
  %70 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.02030, %70
  br i1 %.not.not, label %.lr.ph31, label %._crit_edge, !llvm.loop !13

71:                                               ; preds = %.preheader
  store i32 %spec.select61, ptr @ans, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %.preheader, %71
  %73 = add nuw nsw i32 %.01828, 5
  %exitcond.not.4 = icmp eq i32 %73, 1001
  br i1 %exitcond.not.4, label %.split.us, label %.preheader, !llvm.loop !9
}

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

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

attributes #0 = { mustprogress nofree 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 = { 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" }

!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,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass