; LLVM IR from tangjz/acm-icpc :: lydsy (1529)

; 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
@fa = external dso_local global [1000001 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 [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4findi(i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %5

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

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1000001 x i32], ptr @fa, i64 0, i64 %12
  store i32 %10, ptr %13, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %9
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

17:                                               ; preds = %5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %30, %17
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %22, label %33

22:                                               ; preds = %18
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = call noundef i32 @_Z4findi(i32 noundef %24)
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = call noundef i32 @_Z4findi(i32 noundef %26)
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000001 x i32], ptr @fa, i64 0, i64 %28
  store i32 %25, ptr %29, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %22
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %18, !llvm.loop !11

33:                                               ; preds = %18
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %46, %33
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %38, label %49

38:                                               ; preds = %34
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = call noundef i32 @_Z4findi(i32 noundef %40)
  %42 = icmp eq i32 %39, %41
  %43 = zext i1 %42 to i32
  %44 = load i32, ptr @ans, align 4, !tbaa !5
  %45 = add nsw i32 %44, %43
  store i32 %45, ptr @ans, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %38
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %2, align 4, !tbaa !5
  br label %34, !llvm.loop !12

49:                                               ; preds = %34
  %50 = load i32, ptr @ans, align 4, !tbaa !5
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %50)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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}


; 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
@fa = external dso_local local_unnamed_addr global [1000001 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 [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4findi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not14 = icmp slt i32 %3, 1
  br i1 %.not14, label %.preheader.._crit_edge_crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %4 = add nuw i32 %3, 1
  %wide.trip.count = zext i32 %4 to i64
  %5 = zext nneg i32 %3 to i64
  %min.iters.check = icmp ult i32 %3, 8
  br i1 %min.iters.check, label %.lr.ph.preheader28, label %vector.ph

.lr.ph.preheader28:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %5, 2147483640
  %ind.end = or disjoint i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %offset.idx = or disjoint i64 %index, 1
  %6 = getelementptr inbounds [1000001 x i32], ptr @fa, i64 0, i64 %offset.idx
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  store <4 x i32> %vec.ind, ptr %6, align 4, !tbaa !5
  store <4 x i32> %step.add, ptr %7, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %8 = icmp eq i64 %index.next, %n.vec
  br i1 %8, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %5
  br i1 %cmp.n, label %.preheader13, label %.lr.ph.preheader28

.preheader13:                                     ; preds = %.lr.ph, %middle.block
  br i1 %.not14, label %.preheader.._crit_edge_crit_edge, label %.lr.ph18

.lr.ph:                                           ; preds = %.lr.ph.preheader28, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader28 ]
  %9 = getelementptr inbounds [1000001 x i32], ptr @fa, i64 0, i64 %indvars.iv
  %10 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %10, ptr %9, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader13, label %.lr.ph, !llvm.loop !13

.preheader:                                       ; preds = %.lr.ph18
  %11 = icmp slt i32 %19, 1
  br i1 %11, label %.preheader.._crit_edge_crit_edge, label %.lr.ph21

.preheader.._crit_edge_crit_edge:                 ; preds = %0, %.preheader13, %.preheader
  %.pre = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge

.lr.ph18:                                         ; preds = %.preheader13, %.lr.ph18
  %.117 = phi i32 [ %18, %.lr.ph18 ], [ 1, %.preheader13 ]
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = call noundef i32 @_Z4findi(i32 noundef %13)
  %15 = call noundef i32 @_Z4findi(i32 noundef %.117)
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1000001 x i32], ptr @fa, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !5
  %18 = add nuw nsw i32 %.117, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %.not11.not = icmp slt i32 %.117, %19
  br i1 %.not11.not, label %.lr.ph18, label %.preheader, !llvm.loop !14

.lr.ph21:                                         ; preds = %.preheader, %.lr.ph21
  %.220 = phi i32 [ %25, %.lr.ph21 ], [ 1, %.preheader ]
  %20 = call noundef i32 @_Z4findi(i32 noundef %.220)
  %21 = icmp eq i32 %.220, %20
  %22 = zext i1 %21 to i32
  %23 = load i32, ptr @ans, align 4, !tbaa !5
  %24 = add nsw i32 %23, %22
  store i32 %24, ptr @ans, align 4, !tbaa !5
  %25 = add nuw nsw i32 %.220, 1
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %.not12.not = icmp slt i32 %.220, %26
  br i1 %.not12.not, label %.lr.ph21, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph21, %.preheader.._crit_edge_crit_edge
  %27 = phi i32 [ %.pre, %.preheader.._crit_edge_crit_edge ], [ %24, %.lr.ph21 ]
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %27)
  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) #2

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass