; LLVM IR from tangjz/acm-icpc :: codeforces/complete (701A)

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

@n = external dso_local global i32, align 4
@a = external dso_local global [101 x i32], align 16
@sum = external dso_local global i32, align 4
@vis = external dso_local global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  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 = %23, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, 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 %26

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr @a, i64 %14
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %15)
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr @sum, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr @sum, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %12
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

26:                                               ; preds = %11
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = ashr i32 %27, 1
  %29 = load i32, ptr @sum, align 4, !tbaa !5
  %30 = sdiv i32 %29, %28
  store i32 %30, ptr @sum, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %85, %26
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %31
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [101 x i8], ptr @vis, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11, !range !13, !noundef !14
  %41 = trunc i8 %40 to i1
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  br label %85

43:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %5, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %80, %43
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 8, ptr %4, align 4
  br label %83

51:                                               ; preds = %46
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [101 x i8], ptr @vis, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !11, !range !13, !noundef !14
  %56 = trunc i8 %55 to i1
  br i1 %56, label %79, label %57

57:                                               ; preds = %51
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = add nsw i32 %61, %65
  %67 = load i32, ptr @sum, align 4, !tbaa !5
  %68 = icmp eq i32 %66, %67
  br i1 %68, label %69, label %79

69:                                               ; preds = %57
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [101 x i8], ptr @vis, i64 0, i64 %71
  store i8 1, ptr %72, align 1, !tbaa !11
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [101 x i8], ptr @vis, i64 0, i64 %74
  store i8 1, ptr %75, align 1, !tbaa !11
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %76, i32 noundef %77)
  store i32 8, ptr %4, align 4
  br label %83

79:                                               ; preds = %57, %51
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !5
  br label %46, !llvm.loop !15

83:                                               ; preds = %69, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84, %42
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %3, align 4, !tbaa !5
  br label %31, !llvm.loop !16

88:                                               ; preds = %35
  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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !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"

@n = external dso_local global i32, align 4
@a = external dso_local global [101 x i32], align 16
@sum = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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 @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not24 = icmp slt i32 %2, 1
  br i1 %.not24, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %0
  %.pre = load i32, ptr @sum, align 4, !tbaa !5
  %3 = ashr i32 %2, 1
  %4 = sdiv i32 %.pre, %3
  store i32 %4, ptr @sum, align 4, !tbaa !5
  br label %._crit_edge35

._crit_edge:                                      ; preds = %.lr.ph
  %5 = ashr i32 %12, 1
  %6 = sdiv i32 %11, %5
  store i32 %6, ptr @sum, align 4, !tbaa !5
  %.not2031 = icmp slt i32 %12, 1
  br i1 %.not2031, label %._crit_edge35, label %.lr.ph34

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

._crit_edge35:                                    ; preds = %.loopexit, %._crit_edge.thread, %._crit_edge
  ret i32 0

.lr.ph34:                                         ; preds = %._crit_edge, %.loopexit
  %14 = phi i32 [ %37, %.loopexit ], [ %12, %._crit_edge ]
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.loopexit ], [ 1, %._crit_edge ]
  %15 = getelementptr inbounds [101 x i8], ptr @vis, i64 0, i64 %indvars.iv40
  %16 = load i8, ptr %15, align 1, !tbaa !11, !range !13, !noundef !14
  %17 = trunc nuw i8 %16 to i1
  %18 = sext i32 %14 to i64
  %.not21.not28 = icmp sge i64 %indvars.iv40, %18
  %or.cond.not = or i1 %.not21.not28, %17
  br i1 %or.cond.not, label %.loopexit, label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph34
  %19 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv40
  %20 = load i32, ptr @sum, align 4
  %wide.trip.count = zext i32 %14 to i64
  br label %21

21:                                               ; preds = %.lr.ph30, %36
  %indvars.iv42 = phi i64 [ %indvars.iv40, %.lr.ph30 ], [ %indvars.iv.next43, %36 ]
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %22 = getelementptr inbounds [101 x i8], ptr @vis, i64 0, i64 %indvars.iv.next43
  %23 = load i8, ptr %22, align 1, !tbaa !11, !range !13, !noundef !14
  %24 = trunc nuw i8 %23 to i1
  br i1 %24, label %36, label %25

25:                                               ; preds = %21
  %26 = load i32, ptr %19, align 4, !tbaa !5
  %27 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv.next43
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %28, %26
  %30 = icmp eq i32 %29, %20
  br i1 %30, label %31, label %36

31:                                               ; preds = %25
  %32 = getelementptr inbounds [101 x i8], ptr @vis, i64 0, i64 %indvars.iv.next43
  %33 = trunc nuw i64 %indvars.iv.next43 to i32
  store i8 1, ptr %32, align 1, !tbaa !11
  store i8 1, ptr %15, align 1, !tbaa !11
  %34 = trunc nuw nsw i64 %indvars.iv40 to i32
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %34, i32 noundef %33)
  %.pre46 = load i32, ptr @n, align 4, !tbaa !5
  br label %.loopexit

36:                                               ; preds = %21, %25
  %exitcond.not = icmp eq i64 %indvars.iv.next43, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %21, !llvm.loop !15

.loopexit:                                        ; preds = %36, %31, %.lr.ph34
  %37 = phi i32 [ %.pre46, %31 ], [ %14, %.lr.ph34 ], [ %14, %36 ]
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %38 = sext i32 %37 to i64
  %.not20.not = icmp slt i64 %indvars.iv40, %38
  br i1 %.not20.not, label %.lr.ph34, label %._crit_edge35, !llvm.loop !16
}

; 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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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