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

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

@p = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@fa = external dso_local global [30001 x i32], align 16
@size = external dso_local global [30001 x i32], align 16
@dist = external dso_local global [30001 x i32], align 16
@op = external dso_local global [2 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %3

3:                                                ; preds = %81, %0
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @p)
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %82

6:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %22, %6
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 30001
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %25

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [30001 x i32], ptr @fa, i64 0, i64 %14
  store i32 %12, ptr %15, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %17
  store i32 1, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [30001 x i32], ptr @dist, i64 0, i64 %20
  store i32 0, ptr %21, align 4, !tbaa !5
  br label %22

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

25:                                               ; preds = %10
  br label %26

26:                                               ; preds = %80, %25
  %27 = load i32, ptr @p, align 4, !tbaa !5
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr @p, align 4, !tbaa !5
  %29 = icmp ne i32 %27, 0
  br i1 %29, label %30, label %81

30:                                               ; preds = %26
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @op)
  %32 = load i8, ptr @op, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 77
  br i1 %34, label %35, label %66

35:                                               ; preds = %30
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @x, ptr noundef @y)
  %37 = load i32, ptr @x, align 4, !tbaa !5
  %38 = call noundef i32 @_Z4findi(i32 noundef %37)
  store i32 %38, ptr @x, align 4, !tbaa !5
  %39 = load i32, ptr @y, align 4, !tbaa !5
  %40 = call noundef i32 @_Z4findi(i32 noundef %39)
  store i32 %40, ptr @y, align 4, !tbaa !5
  %41 = load i32, ptr @x, align 4, !tbaa !5
  %42 = load i32, ptr @y, align 4, !tbaa !5
  %43 = icmp ne i32 %41, %42
  br i1 %43, label %44, label %65

44:                                               ; preds = %35
  %45 = load i32, ptr @x, align 4, !tbaa !5
  %46 = load i32, ptr @y, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [30001 x i32], ptr @fa, i64 0, i64 %47
  store i32 %45, ptr %48, align 4, !tbaa !5
  %49 = load i32, ptr @x, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr @y, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [30001 x i32], ptr @dist, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !5
  %56 = load i32, ptr @y, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr @x, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = add nsw i32 %63, %59
  store i32 %64, ptr %62, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %44, %35
  br label %80

66:                                               ; preds = %30
  %67 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %68 = load i32, ptr @x, align 4, !tbaa !5
  %69 = call noundef i32 @_Z4findi(i32 noundef %68)
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = load i32, ptr @x, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [30001 x i32], ptr @dist, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = sub nsw i32 %72, %76
  %78 = sub nsw i32 %77, 1
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %78)
  br label %80

80:                                               ; preds = %66, %65
  br label %26, !llvm.loop !12

81:                                               ; preds = %26
  br label %3, !llvm.loop !13

82:                                               ; preds = %3
  ret i32 0
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@p = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@fa = external dso_local local_unnamed_addr global [30001 x i32], align 16
@size = external dso_local local_unnamed_addr global [30001 x i32], align 16
@dist = external dso_local local_unnamed_addr global [30001 x i32], align 16
@op = external dso_local global [2 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @p)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.preheader9, label %._crit_edge

.loopexit:                                        ; preds = %50, %.preheader
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @p)
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %.preheader9, label %._crit_edge, !llvm.loop !5

.preheader9:                                      ; preds = %0, %.loopexit
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(120000) getelementptr inbounds (i8, ptr @dist, i64 4), i8 0, i64 120000, i1 false), !tbaa !7
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %.preheader9
  %index = phi i64 [ 0, %.preheader9 ], [ %index.next.1, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %.preheader9 ], [ %vec.ind.next.1, %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
  %5 = getelementptr inbounds [30001 x i32], ptr @fa, i64 0, i64 %offset.idx
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  store <4 x i32> %vec.ind, ptr %5, align 4, !tbaa !7
  store <4 x i32> %step.add, ptr %6, align 4, !tbaa !7
  %7 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %offset.idx
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %7, align 4, !tbaa !7
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %8, align 4, !tbaa !7
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %step.add.1 = add <4 x i32> %vec.ind, <i32 12, i32 12, i32 12, i32 12>
  %offset.idx.1 = or disjoint i64 %index, 9
  %9 = getelementptr inbounds [30001 x i32], ptr @fa, i64 0, i64 %offset.idx.1
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  store <4 x i32> %vec.ind.next, ptr %9, align 4, !tbaa !7
  store <4 x i32> %step.add.1, ptr %10, align 4, !tbaa !7
  %11 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %offset.idx.1
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %11, align 4, !tbaa !7
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %12, align 4, !tbaa !7
  %index.next.1 = add nuw nsw i64 %index, 16
  %vec.ind.next.1 = add <4 x i32> %vec.ind, <i32 16, i32 16, i32 16, i32 16>
  %13 = icmp eq i64 %index.next.1, 30000
  br i1 %13, label %.preheader, label %vector.body, !llvm.loop !11

.preheader:                                       ; preds = %vector.body
  %14 = load i32, ptr @p, align 4, !tbaa !7
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @p, align 4, !tbaa !7
  %.not11 = icmp eq i32 %14, 0
  br i1 %.not11, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %50
  %16 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @op)
  %17 = load i8, ptr @op, align 1, !tbaa !14
  %18 = icmp eq i8 %17, 77
  br i1 %18, label %19, label %36

19:                                               ; preds = %.lr.ph
  %20 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @x, ptr noundef nonnull @y)
  %21 = load i32, ptr @x, align 4, !tbaa !7
  %22 = tail call noundef i32 @_Z4findi(i32 noundef %21)
  store i32 %22, ptr @x, align 4, !tbaa !7
  %23 = load i32, ptr @y, align 4, !tbaa !7
  %24 = tail call noundef i32 @_Z4findi(i32 noundef %23)
  store i32 %24, ptr @y, align 4, !tbaa !7
  %25 = load i32, ptr @x, align 4, !tbaa !7
  %.not8 = icmp eq i32 %25, %24
  br i1 %.not8, label %50, label %26

26:                                               ; preds = %19
  %27 = sext i32 %24 to i64
  %28 = getelementptr inbounds [30001 x i32], ptr @fa, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !7
  %29 = sext i32 %25 to i64
  %30 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !7
  %32 = getelementptr inbounds [30001 x i32], ptr @dist, i64 0, i64 %27
  store i32 %31, ptr %32, align 4, !tbaa !7
  %33 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %27
  %34 = load i32, ptr %33, align 4, !tbaa !7
  %35 = add nsw i32 %34, %31
  store i32 %35, ptr %30, align 4, !tbaa !7
  br label %50

36:                                               ; preds = %.lr.ph
  %37 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %38 = load i32, ptr @x, align 4, !tbaa !7
  %39 = tail call noundef i32 @_Z4findi(i32 noundef %38)
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [30001 x i32], ptr @size, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !7
  %43 = load i32, ptr @x, align 4, !tbaa !7
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [30001 x i32], ptr @dist, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !7
  %47 = xor i32 %46, -1
  %48 = add i32 %42, %47
  %49 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %48)
  br label %50

50:                                               ; preds = %19, %26, %36
  %51 = load i32, ptr @p, align 4, !tbaa !7
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr @p, align 4, !tbaa !7
  %.not = icmp eq i32 %51, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.loopexit, %0
  ret i32 0
}

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

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

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

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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = !{!9, !9, i64 0}
!15 = distinct !{!15, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass