; LLVM IR from tangjz/acm-icpc :: luogu (1031)

; 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
@x = external dso_local global i32, align 4
@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 [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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %21, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %10, label %9

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

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

21:                                               ; preds = %10
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

24:                                               ; preds = %9
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = load i32, ptr @x, align 4, !tbaa !5
  %27 = sdiv i32 %26, %25
  store i32 %27, ptr @x, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %56, %24
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %28
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr @x, align 4, !tbaa !5
  %40 = icmp ne i32 %38, %39
  %41 = zext i1 %40 to i32
  %42 = load i32, ptr @ans, align 4, !tbaa !5
  %43 = add nsw i32 %42, %41
  store i32 %43, ptr @ans, align 4, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr @x, align 4, !tbaa !5
  %49 = sub nsw i32 %47, %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = add nsw i32 %54, %49
  store i32 %55, ptr %53, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %34
  %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 %28, !llvm.loop !11

59:                                               ; preds = %33
  %60 = load i32, ptr @ans, align 4, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %60)
  %62 = load i32, ptr %1, align 4
  ret i32 %62
}

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}


; 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
@x = external dso_local local_unnamed_addr global i32, align 4
@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 [4 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
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge.thread

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

._crit_edge:                                      ; preds = %.lr.ph
  %5 = sdiv i32 %13, %14
  store i32 %5, ptr @x, align 4, !tbaa !5
  %6 = icmp sgt i32 %14, 1
  br i1 %6, label %.lr.ph15, label %._crit_edge._crit_edge

._crit_edge._crit_edge:                           ; preds = %._crit_edge.thread, %._crit_edge
  %.pre25 = load i32, ptr @ans, align 4, !tbaa !5
  br label %25

.lr.ph15:                                         ; preds = %._crit_edge
  %7 = add nsw i32 %14, -1
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %7 to i64
  %.pre24 = load i32, ptr @a, align 16, !tbaa !5
  %xtraiter = and i64 %wide.trip.count, 1
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %._crit_edge16.unr-lcssa, label %.lr.ph15.new

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

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

._crit_edge16.unr-lcssa.loopexit:                 ; preds = %28
  %17 = add nuw nsw i64 %indvars.iv21, 3
  br label %._crit_edge16.unr-lcssa

._crit_edge16.unr-lcssa:                          ; preds = %._crit_edge16.unr-lcssa.loopexit, %.lr.ph15
  %.lcssa.ph = phi i32 [ poison, %.lr.ph15 ], [ %40, %._crit_edge16.unr-lcssa.loopexit ]
  %.unr = phi i32 [ %.pre24, %.lr.ph15 ], [ %44, %._crit_edge16.unr-lcssa.loopexit ]
  %indvars.iv21.unr = phi i64 [ 1, %.lr.ph15 ], [ %17, %._crit_edge16.unr-lcssa.loopexit ]
  %.unr33 = phi i32 [ %ans.promoted, %.lr.ph15 ], [ %40, %._crit_edge16.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge16, label %._crit_edge16.epilog-lcssa

._crit_edge16.epilog-lcssa:                       ; preds = %._crit_edge16.unr-lcssa
  %18 = icmp ne i32 %.unr, %5
  %19 = zext i1 %18 to i32
  %20 = add nsw i32 %.unr33, %19
  %21 = sub i32 %.unr, %5
  %22 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv21.unr
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = add nsw i32 %21, %23
  store i32 %24, ptr %22, align 4, !tbaa !5
  br label %._crit_edge16

._crit_edge16:                                    ; preds = %._crit_edge16.unr-lcssa, %._crit_edge16.epilog-lcssa
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge16.unr-lcssa ], [ %20, %._crit_edge16.epilog-lcssa ]
  store i32 %.lcssa, ptr @ans, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %._crit_edge._crit_edge, %._crit_edge16
  %26 = phi i32 [ %.pre25, %._crit_edge._crit_edge ], [ %.lcssa, %._crit_edge16 ]
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %26)
  ret i32 0

28:                                               ; preds = %28, %.lr.ph15.new
  %29 = phi i32 [ %.pre24, %.lr.ph15.new ], [ %44, %28 ]
  %indvars.iv21 = phi i64 [ 0, %.lr.ph15.new ], [ %indvars.iv.next22.1, %28 ]
  %30 = phi i32 [ %ans.promoted, %.lr.ph15.new ], [ %40, %28 ]
  %niter = phi i64 [ 0, %.lr.ph15.new ], [ %niter.next.1, %28 ]
  %31 = icmp ne i32 %29, %5
  %32 = zext i1 %31 to i32
  %33 = add nsw i32 %30, %32
  %34 = sub i32 %29, %5
  %indvars.iv.next22 = or disjoint i64 %indvars.iv21, 1
  %35 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv.next22
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %34, %36
  store i32 %37, ptr %35, align 4, !tbaa !5
  %38 = icmp ne i32 %37, %5
  %39 = zext i1 %38 to i32
  %40 = add nsw i32 %33, %39
  %41 = sub i32 %37, %5
  %indvars.iv.next22.1 = add nuw nsw i64 %indvars.iv21, 2
  %42 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv.next22.1
  %43 = load i32, ptr %42, align 8, !tbaa !5
  %44 = add nsw i32 %41, %43
  store i32 %44, ptr %42, align 8, !tbaa !5
  %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_edge16.unr-lcssa.loopexit, label %28, !llvm.loop !11
}

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


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