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

; 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
@v = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@f = external dso_local global [45001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @v, ptr noundef @n)
  store i8 1, ptr @f, align 16, !tbaa !5
  br label %6

6:                                                ; preds = %39, %0
  %7 = load i32, ptr @n, align 4, !tbaa !9
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @n, align 4, !tbaa !9
  %9 = icmp ne i32 %7, 0
  br i1 %9, label %10, label %40

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %12 = load i32, ptr @v, align 4, !tbaa !9
  store i32 %12, ptr %2, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %36, %10
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = load i32, ptr @x, align 4, !tbaa !9
  %16 = icmp sge i32 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !9
  %20 = load i32, ptr @x, align 4, !tbaa !9
  %21 = sub nsw i32 %19, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [45001 x i8], ptr @f, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !5, !range !11, !noundef !12
  %25 = trunc i8 %24 to i1
  %26 = zext i1 %25 to i32
  %27 = load i32, ptr %2, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [45001 x i8], ptr @f, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !5, !range !11, !noundef !12
  %31 = trunc i8 %30 to i1
  %32 = zext i1 %31 to i32
  %33 = or i32 %32, %26
  %34 = icmp ne i32 %33, 0
  %35 = zext i1 %34 to i8
  store i8 %35, ptr %29, align 1, !tbaa !5
  br label %36

36:                                               ; preds = %18
  %37 = load i32, ptr %2, align 4, !tbaa !9
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %2, align 4, !tbaa !9
  br label %13, !llvm.loop !13

39:                                               ; preds = %17
  br label %6, !llvm.loop !15

40:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %41 = load i32, ptr @v, align 4, !tbaa !9
  store i32 %41, ptr %3, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %56, %40
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = icmp sge i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %42
  store i32 7, ptr %4, align 4
  br label %59

46:                                               ; preds = %42
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [45001 x i8], ptr @f, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !5, !range !11, !noundef !12
  %51 = trunc i8 %50 to i1
  br i1 %51, label %52, label %55

52:                                               ; preds = %46
  %53 = load i32, ptr %3, align 4, !tbaa !9
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %53)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %59

55:                                               ; preds = %46
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %3, align 4, !tbaa !9
  br label %42, !llvm.loop !16

59:                                               ; preds = %52, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %60 = load i32, ptr %4, align 4
  switch i32 %60, label %63 [
    i32 7, label %61
    i32 1, label %61
  ]

61:                                               ; preds = %59, %59
  %62 = load i32, ptr %1, align 4
  ret i32 %62

63:                                               ; preds = %59
  unreachable
}

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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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
@v = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [45001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 @v, ptr noundef nonnull @n)
  store i8 1, ptr @f, align 16, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !9
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !9
  %.not17 = icmp eq i32 %2, 0
  br i1 %.not17, label %.._crit_edge_crit_edge, label %.lr.ph18

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = load i32, ptr @v, align 4, !tbaa !9
  br label %._crit_edge

.loopexit13:                                      ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %.lr.ph18
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @n, align 4, !tbaa !9
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph18, !llvm.loop !11

.lr.ph18:                                         ; preds = %0, %.loopexit13
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x)
  %7 = load i32, ptr @v, align 4, !tbaa !9
  %8 = load i32, ptr @x, align 4, !tbaa !9
  %.not1215 = icmp slt i32 %7, %8
  br i1 %.not1215, label %.loopexit13, label %iter.check

iter.check:                                       ; preds = %.lr.ph18
  %9 = sext i32 %7 to i64
  %10 = sext i32 %8 to i64
  %11 = add nsw i64 %9, 1
  %12 = sub nsw i64 %11, %10
  %min.iters.check = icmp ult i64 %12, 4
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %iter.check
  %13 = sub nsw i64 %9, %10
  %scevgep = getelementptr i8, ptr @f, i64 %9
  %14 = sub nsw i64 0, %13
  %15 = getelementptr i8, ptr %scevgep, i64 %14
  %16 = icmp ugt ptr %15, %scevgep
  %scevgep29 = getelementptr i8, ptr @f, i64 %13
  %17 = icmp ult ptr %scevgep29, @f
  %18 = or i1 %16, %17
  br i1 %18, label %.lr.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %scevgep33 = getelementptr i8, ptr @f, i64 %10
  %scevgep34 = getelementptr i8, ptr getelementptr inbounds (i8, ptr @f, i64 1), i64 %9
  %19 = sub nsw i64 %9, %10
  %scevgep35 = getelementptr i8, ptr getelementptr inbounds (i8, ptr @f, i64 1), i64 %19
  %bound0 = icmp ult ptr %scevgep33, %scevgep35
  %bound1 = icmp ugt ptr %scevgep34, @f
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.memcheck
  %min.iters.check36 = icmp ult i64 %12, 16
  br i1 %min.iters.check36, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %12, -16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %9, %index
  %20 = sub nsw i64 %offset.idx, %10
  %gep = getelementptr [45001 x i8], ptr getelementptr (i8, ptr @f, i64 -15), i64 0, i64 %20
  %wide.load = load <16 x i8>, ptr %gep, align 1, !tbaa !5, !alias.scope !13
  %gep54 = getelementptr [45001 x i8], ptr getelementptr (i8, ptr @f, i64 -15), i64 0, i64 %offset.idx
  %wide.load37 = load <16 x i8>, ptr %gep54, align 1, !tbaa !5, !alias.scope !16, !noalias !13
  %21 = or <16 x i8> %wide.load37, %wide.load
  store <16 x i8> %21, ptr %gep54, align 1, !tbaa !5, !alias.scope !16, !noalias !13
  %index.next = add nuw i64 %index, 16
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %12, %n.vec
  br i1 %cmp.n, label %.loopexit13, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end42 = sub nsw i64 %9, %n.vec
  %n.vec.remaining = and i64 %12, 12
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec41 = and i64 %12, -4
  %ind.end = sub nsw i64 %9, %n.vec41
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index43 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next50, %vec.epilog.vector.body ]
  %offset.idx44 = sub i64 %9, %index43
  %23 = sub nsw i64 %offset.idx44, %10
  %gep55 = getelementptr [45001 x i8], ptr getelementptr (i8, ptr @f, i64 -3), i64 0, i64 %23
  %wide.load45 = load <4 x i8>, ptr %gep55, align 1, !tbaa !5, !alias.scope !21
  %gep56 = getelementptr [45001 x i8], ptr getelementptr (i8, ptr @f, i64 -3), i64 0, i64 %offset.idx44
  %wide.load47 = load <4 x i8>, ptr %gep56, align 1, !tbaa !5, !alias.scope !24, !noalias !21
  %24 = or <4 x i8> %wide.load47, %wide.load45
  store <4 x i8> %24, ptr %gep56, align 1, !tbaa !5, !alias.scope !24, !noalias !21
  %index.next50 = add nuw i64 %index43, 4
  %25 = icmp eq i64 %index.next50, %n.vec41
  br i1 %25, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !26

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n51 = icmp eq i64 %12, %n.vec41
  br i1 %cmp.n51, label %.loopexit13, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %vector.memcheck, %vector.scevcheck, %iter.check, %vec.epilog.iter.check
  %indvars.iv.ph = phi i64 [ %9, %iter.check ], [ %9, %vector.memcheck ], [ %9, %vector.scevcheck ], [ %ind.end42, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader ]
  %26 = sub nsw i64 %indvars.iv, %10
  %27 = getelementptr inbounds [45001 x i8], ptr @f, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !5, !range !27, !noundef !28
  %29 = getelementptr inbounds [45001 x i8], ptr @f, i64 0, i64 %indvars.iv
  %30 = load i8, ptr %29, align 1, !tbaa !5, !range !27, !noundef !28
  %31 = or i8 %30, %28
  store i8 %31, ptr %29, align 1, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not12.not = icmp sgt i64 %indvars.iv, %10
  br i1 %.not12.not, label %.lr.ph, label %.loopexit13, !llvm.loop !29

._crit_edge:                                      ; preds = %.loopexit13, %.._crit_edge_crit_edge
  %32 = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %7, %.loopexit13 ]
  %33 = icmp sgt i32 %32, -1
  br i1 %33, label %.lr.ph21.preheader, label %.loopexit

.lr.ph21.preheader:                               ; preds = %._crit_edge
  %34 = zext nneg i32 %32 to i64
  br label %.lr.ph21

.lr.ph21:                                         ; preds = %.lr.ph21.preheader, %41
  %indvars.iv24 = phi i64 [ %34, %.lr.ph21.preheader ], [ %indvars.iv.next25, %41 ]
  %35 = getelementptr inbounds [45001 x i8], ptr @f, i64 0, i64 %indvars.iv24
  %36 = load i8, ptr %35, align 1, !tbaa !5, !range !27, !noundef !28
  %37 = trunc nuw i8 %36 to i1
  br i1 %37, label %38, label %41

38:                                               ; preds = %.lr.ph21
  %39 = trunc nuw nsw i64 %indvars.iv24 to i32
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %39)
  br label %.loopexit

41:                                               ; preds = %.lr.ph21
  %indvars.iv.next25 = add nsw i64 %indvars.iv24, -1
  %42 = icmp sgt i64 %indvars.iv24, 0
  br i1 %42, label %.lr.ph21, label %.loopexit, !llvm.loop !30

.loopexit:                                        ; preds = %41, %._crit_edge, %38
  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 @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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14}
!14 = distinct !{!14, !15}
!15 = distinct !{!15, !"LVerDomain"}
!16 = !{!17}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !12, !19, !20}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = !{!22}
!22 = distinct !{!22, !23}
!23 = distinct !{!23, !"LVerDomain"}
!24 = !{!25}
!25 = distinct !{!25, !23}
!26 = distinct !{!26, !12, !19, !20}
!27 = !{i8 0, i8 2}
!28 = !{}
!29 = distinct !{!29, !12, !19}
!30 = distinct !{!30, !12}


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