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

; 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 [1001 x i32], align 16
@sg = 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
@.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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %5

5:                                                ; preds = %52, %0
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @t, align 4, !tbaa !5
  %8 = icmp ne i32 %6, 0
  br i1 %8, label %9, label %56

9:                                                ; preds = %5
  store i32 0, ptr @sg, align 4, !tbaa !5
  %10 = 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 %11

11:                                               ; preds = %21, %9
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr @a, i64 %18
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %19)
  br label %21

21:                                               ; preds = %16
  %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 %11, !llvm.loop !9

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = sub nsw i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %44, %24
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp sge i32 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %47

31:                                               ; preds = %27
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sub nsw i32 %36, %40
  %42 = load i32, ptr @sg, align 4, !tbaa !5
  %43 = xor i32 %42, %41
  store i32 %43, ptr @sg, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %31
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 2
  store i32 %46, ptr %3, align 4, !tbaa !5
  br label %27, !llvm.loop !11

47:                                               ; preds = %30
  %48 = load i32, ptr @sg, align 4, !tbaa !5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  br label %52

51:                                               ; preds = %47
  br label %52

52:                                               ; preds = %51, %50
  %53 = phi ptr [ @.str.1, %50 ], [ @.str.2, %51 ]
  %54 = getelementptr inbounds [4 x i8], ptr %53, i64 0, i64 0
  %55 = call i32 @puts(ptr noundef %54)
  br label %5, !llvm.loop !12

56:                                               ; preds = %5
  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 @puts(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}


; 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 [1001 x i32], align 16
@sg = 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
@.str.2 = 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not18 = icmp eq i32 %2, 0
  br i1 %.not18, label %._crit_edge21, label %.lr.ph20

.lr.ph20:                                         ; preds = %0, %28
  store i32 0, ptr @sg, align 4, !tbaa !5
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not911 = icmp slt i32 %5, 1
  br i1 %.not911, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %.lr.ph20
  %sg.promoted29 = load i32, ptr @sg, align 4, !tbaa !5
  br label %28

._crit_edge:                                      ; preds = %.lr.ph
  %sg.promoted = load i32, ptr @sg, align 4, !tbaa !5
  %6 = icmp sgt i32 %26, 0
  br i1 %6, label %.lr.ph15.preheader, label %28

.lr.ph15.preheader:                               ; preds = %._crit_edge
  %7 = add nsw i32 %26, -1
  %8 = zext i32 %7 to i64
  %9 = lshr i64 %8, 1
  %10 = add nuw nsw i64 %9, 1
  %min.iters.check = icmp ult i32 %26, 15
  br i1 %min.iters.check, label %.lr.ph15.preheader40, label %vector.ph

.lr.ph15.preheader40:                             ; preds = %middle.block, %.lr.ph15.preheader
  %indvars.iv25.ph = phi i64 [ %8, %.lr.ph15.preheader ], [ %ind.end, %middle.block ]
  %.ph = phi i32 [ %sg.promoted, %.lr.ph15.preheader ], [ %23, %middle.block ]
  br label %.lr.ph15

vector.ph:                                        ; preds = %.lr.ph15.preheader
  %n.vec = and i64 %10, 4294967288
  %11 = shl nuw nsw i64 %n.vec, 1
  %ind.end = sub nsw i64 %8, %11
  %12 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %sg.promoted, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ %12, %vector.ph ], [ %20, %vector.body ]
  %vec.phi32 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %21, %vector.body ]
  %13 = shl i64 %index, 1
  %offset.idx = sub i64 %8, %13
  %14 = add nuw nsw i64 %offset.idx, 1
  %15 = add i64 %offset.idx, -7
  %gep = getelementptr [1001 x i32], ptr getelementptr (i8, ptr @a, i64 -28), i64 0, i64 %14
  %gep47 = getelementptr [1001 x i32], ptr getelementptr (i8, ptr @a, i64 -28), i64 0, i64 %15
  %wide.vec = load <8 x i32>, ptr %gep, align 4, !tbaa !5
  %wide.vec33 = load <8 x i32>, ptr %gep47, align 4, !tbaa !5
  %strided.vec = shufflevector <8 x i32> %wide.vec, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec34 = shufflevector <8 x i32> %wide.vec33, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec36 = shufflevector <8 x i32> %wide.vec, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %strided.vec38 = shufflevector <8 x i32> %wide.vec33, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %16 = sub nsw <4 x i32> %strided.vec36, %strided.vec
  %17 = shufflevector <4 x i32> %16, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %18 = sub nsw <4 x i32> %strided.vec38, %strided.vec34
  %19 = shufflevector <4 x i32> %18, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %20 = xor <4 x i32> %vec.phi, %17
  %21 = xor <4 x i32> %vec.phi32, %19
  %index.next = add nuw i64 %index, 8
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = xor <4 x i32> %21, %20
  %23 = tail call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %10, %n.vec
  br i1 %cmp.n, label %._crit_edge16, label %.lr.ph15.preheader40

.lr.ph:                                           ; preds = %.lr.ph20, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.lr.ph20 ]
  %24 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %25 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %24)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %.not9.not = icmp slt i64 %indvars.iv, %27
  br i1 %.not9.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge16:                                    ; preds = %.lr.ph15, %middle.block
  %.lcssa31 = phi i32 [ %23, %middle.block ], [ %41, %.lr.ph15 ]
  store i32 %.lcssa31, ptr @sg, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %._crit_edge.thread, %._crit_edge16, %._crit_edge
  %29 = phi i32 [ %.lcssa31, %._crit_edge16 ], [ %sg.promoted, %._crit_edge ], [ %sg.promoted29, %._crit_edge.thread ]
  %.not10 = icmp eq i32 %29, 0
  %30 = select i1 %.not10, ptr @.str.2, ptr @.str.1
  %31 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %30)
  %32 = load i32, ptr @t, align 4, !tbaa !5
  %33 = add nsw i32 %32, -1
  store i32 %33, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %._crit_edge21, label %.lr.ph20, !llvm.loop !14

.lr.ph15:                                         ; preds = %.lr.ph15.preheader40, %.lr.ph15
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %.lr.ph15 ], [ %indvars.iv25.ph, %.lr.ph15.preheader40 ]
  %34 = phi i32 [ %41, %.lr.ph15 ], [ %.ph, %.lr.ph15.preheader40 ]
  %35 = add nuw nsw i64 %indvars.iv25, 1
  %36 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %indvars.iv25
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sub nsw i32 %37, %39
  %41 = xor i32 %34, %40
  %indvars.iv.next26 = add nsw i64 %indvars.iv25, -2
  %42 = icmp ugt i64 %indvars.iv25, 1
  br i1 %42, label %.lr.ph15, label %._crit_edge16, !llvm.loop !15

._crit_edge21:                                    ; preds = %28, %0
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32>) #2

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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !12, !11}


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