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

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

@L = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@l = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@vis = external dso_local global [10001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 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
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @L, ptr noundef @M)
  br label %3

3:                                                ; preds = %18, %0
  %4 = load i32, ptr @M, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @M, align 4, !tbaa !5
  %6 = icmp ne i32 %4, 0
  br i1 %6, label %7, label %19

7:                                                ; preds = %3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @l, ptr noundef @r)
  br label %9

9:                                                ; preds = %13, %7
  %10 = load i32, ptr @l, align 4, !tbaa !5
  %11 = load i32, ptr @r, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %9
  %14 = load i32, ptr @l, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @l, align 4, !tbaa !5
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %16
  store i8 1, ptr %17, align 1, !tbaa !9
  br label %9, !llvm.loop !11

18:                                               ; preds = %9
  br label %3, !llvm.loop !13

19:                                               ; preds = %3
  br label %20

20:                                               ; preds = %23, %19
  %21 = load i32, ptr @L, align 4, !tbaa !5
  %22 = icmp sge i32 %21, 0
  br i1 %22, label %23, label %34

23:                                               ; preds = %20
  %24 = load i32, ptr @L, align 4, !tbaa !5
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr @L, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !14, !noundef !15
  %29 = trunc i8 %28 to i1
  %30 = zext i1 %29 to i32
  %31 = xor i32 %30, 1
  %32 = load i32, ptr @ans, align 4, !tbaa !5
  %33 = add nsw i32 %32, %31
  store i32 %33, ptr @ans, align 4, !tbaa !5
  br label %20, !llvm.loop !16

34:                                               ; preds = %20
  %35 = load i32, ptr @ans, align 4, !tbaa !5
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %35)
  %37 = load i32, ptr %1, align 4
  ret i32 %37
}

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

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

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


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

@L = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@l = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@vis = external dso_local local_unnamed_addr global [10001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 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 @L, ptr noundef nonnull @M)
  %2 = load i32, ptr @M, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @M, align 4, !tbaa !5
  %.not4 = icmp eq i32 %2, 0
  br i1 %.not4, label %.preheader, label %.lr.ph5

.loopexit:                                        ; preds = %.lr.ph.preheader, %.lr.ph5
  %4 = load i32, ptr @M, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @M, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.preheader, label %.lr.ph5, !llvm.loop !9

.preheader:                                       ; preds = %.loopexit, %0
  %L.promoted = load i32, ptr @L, align 4, !tbaa !5
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %6 = icmp sgt i32 %L.promoted, -1
  br i1 %6, label %.lr.ph6.preheader, label %36

.lr.ph6.preheader:                                ; preds = %.preheader
  %7 = zext nneg i32 %L.promoted to i64
  %8 = add nuw nsw i64 %7, 1
  %min.iters.check = icmp ult i32 %L.promoted, 7
  br i1 %min.iters.check, label %.lr.ph6.preheader17, label %vector.ph

.lr.ph6.preheader17:                              ; preds = %middle.block, %.lr.ph6.preheader
  %indvars.iv.ph = phi i64 [ %7, %.lr.ph6.preheader ], [ %ind.end, %middle.block ]
  %.ph = phi i32 [ %ans.promoted, %.lr.ph6.preheader ], [ %22, %middle.block ]
  br label %.lr.ph6

vector.ph:                                        ; preds = %.lr.ph6.preheader
  %n.vec = and i64 %8, 4294967288
  %ind.end = sub nsw i64 %7, %n.vec
  %9 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %ans.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> [ %9, %vector.ph ], [ %19, %vector.body ]
  %vec.phi14 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %20, %vector.body ]
  %offset.idx = sub i64 %7, %index
  %10 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %offset.idx
  %11 = getelementptr inbounds i8, ptr %10, i64 -3
  %12 = getelementptr inbounds i8, ptr %10, i64 -7
  %wide.load = load <4 x i8>, ptr %11, align 1, !tbaa !11
  %wide.load15 = load <4 x i8>, ptr %12, align 1, !tbaa !11
  %13 = xor <4 x i8> %wide.load, <i8 1, i8 1, i8 1, i8 1>
  %14 = shufflevector <4 x i8> %13, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %15 = xor <4 x i8> %wide.load15, <i8 1, i8 1, i8 1, i8 1>
  %16 = shufflevector <4 x i8> %15, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %17 = zext <4 x i8> %14 to <4 x i32>
  %18 = zext <4 x i8> %16 to <4 x i32>
  %19 = add <4 x i32> %vec.phi, %17
  %20 = add <4 x i32> %vec.phi14, %18
  %index.next = add nuw i64 %index, 8
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %20, %19
  %22 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %8, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph6.preheader17

.lr.ph5:                                          ; preds = %0, %.loopexit
  %23 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @l, ptr noundef nonnull @r)
  %24 = load i32, ptr @r, align 4, !tbaa !5
  %l.promoted = load i32, ptr @l, align 4, !tbaa !5
  %.not23 = icmp sgt i32 %l.promoted, %24
  br i1 %.not23, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph5
  %25 = sext i32 %l.promoted to i64
  %scevgep = getelementptr i8, ptr @vis, i64 %25
  %26 = sub i32 %24, %l.promoted
  %27 = zext i32 %26 to i64
  %28 = add nuw nsw i64 %27, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %scevgep, i8 1, i64 %28, i1 false), !tbaa !11
  %29 = add i32 %24, 1
  store i32 %29, ptr @l, align 4, !tbaa !5
  br label %.loopexit

.lr.ph6:                                          ; preds = %.lr.ph6.preheader17, %.lr.ph6
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph6 ], [ %indvars.iv.ph, %.lr.ph6.preheader17 ]
  %30 = phi i32 [ %35, %.lr.ph6 ], [ %.ph, %.lr.ph6.preheader17 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %31 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %indvars.iv
  %32 = load i8, ptr %31, align 1, !tbaa !11, !range !16, !noundef !17
  %33 = xor i8 %32, 1
  %34 = zext nneg i8 %33 to i32
  %35 = add nsw i32 %30, %34
  %.not13 = icmp eq i64 %indvars.iv, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph6, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph6, %middle.block
  %.lcssa = phi i32 [ %22, %middle.block ], [ %35, %.lr.ph6 ]
  store i32 -1, ptr @L, align 4, !tbaa !5
  store i32 %.lcssa, ptr @ans, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %._crit_edge, %.preheader
  %37 = phi i32 [ %.lcssa, %._crit_edge ], [ %ans.promoted, %.preheader ]
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %37)
  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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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 nounwind willreturn memory(argmem: write) }
attributes #3 = { 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}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = distinct !{!13, !10, !14, !15}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !10, !15, !14}


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