; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1170)

; 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
@m = external dso_local global i32, align 4
@a = external dso_local global [200001 x i32], align 16
@x = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 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 uwtable
declare dso_local void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4)) #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
  br label %4

4:                                                ; preds = %51, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %52

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

8:                                                ; preds = %17, %7
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %20

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [200001 x i32], ptr @a, i64 0, i64 %15
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) %16)
  br label %17

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

20:                                               ; preds = %12
  br label %21

21:                                               ; preds = %50, %20
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr @m, align 4, !tbaa !5
  %24 = icmp ne i32 %22, 0
  br i1 %24, label %25, label %51

25:                                               ; preds = %21
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @x)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr @a, i64 %27
  %29 = getelementptr inbounds i32, ptr %28, i64 1
  %30 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef getelementptr inbounds (i32, ptr @a, i64 1), ptr noundef %29, ptr noundef nonnull align 4 dereferenceable(4) @x)
  %31 = ptrtoint ptr %30 to i64
  %32 = sub i64 %31, ptrtoint (ptr @a to i64)
  %33 = sdiv exact i64 %32, 4
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp sgt i32 %35, %36
  br i1 %37, label %45, label %38

38:                                               ; preds = %25
  %39 = load i32, ptr @x, align 4, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200001 x i32], ptr @a, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = icmp ne i32 %39, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %38, %25
  %46 = call i32 @puts(ptr noundef @.str.1)
  br label %50

47:                                               ; preds = %38
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %48)
  br label %50

50:                                               ; preds = %47, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %21, !llvm.loop !11

51:                                               ; preds = %21
  br label %4, !llvm.loop !12

52:                                               ; preds = %4
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #4

declare i32 @puts(ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #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 = { "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #5 = { 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
@m = external dso_local global i32, align 4
@a = external dso_local global [200001 x i32], align 16
@x = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 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 uwtable
declare dso_local void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4)) 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 @n, ptr noundef nonnull @m)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.preheader9, label %._crit_edge

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

.preheader9:                                      ; preds = %0, %.loopexit
  %5 = load i32, ptr @n, align 4, !tbaa !7
  %.not10 = icmp slt i32 %5, 1
  br i1 %.not10, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %.preheader9
  %6 = load i32, ptr @m, align 4, !tbaa !7
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @m, align 4, !tbaa !7
  %.not712 = icmp eq i32 %6, 0
  br i1 %.not712, label %.loopexit, label %.lr.ph13

.lr.ph:                                           ; preds = %.preheader9, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader9 ]
  %8 = getelementptr inbounds [200001 x i32], ptr @a, i64 0, i64 %indvars.iv
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = load i32, ptr @n, align 4, !tbaa !7
  %10 = sext i32 %9 to i64
  %.not.not = icmp slt i64 %indvars.iv, %10
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !11

.lr.ph13:                                         ; preds = %.preheader, %29
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @x)
  %11 = load i32, ptr @n, align 4, !tbaa !7
  %12 = sext i32 %11 to i64
  %gep = getelementptr i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), i64 %12
  %13 = tail call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 4), ptr noundef nonnull %gep, ptr noundef nonnull align 4 dereferenceable(4) @x)
  %14 = ptrtoint ptr %13 to i64
  %15 = sub i64 %14, ptrtoint (ptr @a to i64)
  %16 = lshr exact i64 %15, 2
  %17 = trunc i64 %16 to i32
  %18 = load i32, ptr @n, align 4, !tbaa !7
  %19 = icmp slt i32 %18, %17
  br i1 %19, label %25, label %20

20:                                               ; preds = %.lr.ph13
  %21 = load i32, ptr @x, align 4, !tbaa !7
  %sext = shl i64 %15, 30
  %22 = ashr i64 %sext, 32
  %23 = getelementptr inbounds [200001 x i32], ptr @a, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !7
  %.not8 = icmp eq i32 %21, %24
  br i1 %.not8, label %27, label %25

25:                                               ; preds = %20, %.lr.ph13
  %26 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %29

27:                                               ; preds = %20
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %17)
  br label %29

29:                                               ; preds = %27, %25
  %30 = load i32, ptr @m, align 4, !tbaa !7
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr @m, align 4, !tbaa !7
  %.not7 = icmp eq i32 %30, 0
  br i1 %.not7, label %.loopexit, label %.lr.ph13, !llvm.loop !12

._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: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { inlinehint 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" }

!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 = distinct !{!12, !6}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass