; LLVM IR from tangjz/acm-icpc :: codeforces/complete (298B)

; 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
@sx = external dso_local global i32, align 4
@sy = external dso_local global i32, align 4
@tx = external dso_local global i32, align 4
@ty = external dso_local global i32, align 4
@ch = external dso_local global [100001 x i8], align 16
@.str = external hidden unnamed_addr constant [14 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t, ptr noundef @sx, ptr noundef @sy, ptr noundef @tx, ptr noundef @ty, ptr noundef @ch)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %74, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %8, label %77

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100001 x i8], ptr @ch, i64 0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = icmp eq i32 %13, 83
  br i1 %14, label %15, label %22

15:                                               ; preds = %8
  %16 = load i32, ptr @sy, align 4, !tbaa !5
  %17 = load i32, ptr @ty, align 4, !tbaa !5
  %18 = icmp sgt i32 %16, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load i32, ptr @sy, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr @sy, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %19, %15, %8
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i8], ptr @ch, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 69
  br i1 %28, label %29, label %36

29:                                               ; preds = %22
  %30 = load i32, ptr @sx, align 4, !tbaa !5
  %31 = load i32, ptr @tx, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = load i32, ptr @sx, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @sx, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %33, %29, %22
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100001 x i8], ptr @ch, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %41, 78
  br i1 %42, label %43, label %50

43:                                               ; preds = %36
  %44 = load i32, ptr @sy, align 4, !tbaa !5
  %45 = load i32, ptr @ty, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %43
  %48 = load i32, ptr @sy, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @sy, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %47, %43, %36
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100001 x i8], ptr @ch, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !9
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 87
  br i1 %56, label %57, label %64

57:                                               ; preds = %50
  %58 = load i32, ptr @sx, align 4, !tbaa !5
  %59 = load i32, ptr @tx, align 4, !tbaa !5
  %60 = icmp sgt i32 %58, %59
  br i1 %60, label %61, label %64

61:                                               ; preds = %57
  %62 = load i32, ptr @sx, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr @sx, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %61, %57, %50
  %65 = load i32, ptr @sx, align 4, !tbaa !5
  %66 = load i32, ptr @tx, align 4, !tbaa !5
  %67 = icmp eq i32 %65, %66
  br i1 %67, label %68, label %73

68:                                               ; preds = %64
  %69 = load i32, ptr @sy, align 4, !tbaa !5
  %70 = load i32, ptr @ty, align 4, !tbaa !5
  %71 = icmp eq i32 %69, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %68
  br label %77

73:                                               ; preds = %68, %64
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !10

77:                                               ; preds = %72, %4
  %78 = load i32, ptr %2, align 4, !tbaa !5
  %79 = load i32, ptr @t, align 4, !tbaa !5
  %80 = icmp slt i32 %78, %79
  br i1 %80, label %81, label %85

81:                                               ; preds = %77
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %83)
  br label %87

85:                                               ; preds = %77
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %87

87:                                               ; preds = %85, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; 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
@sx = external dso_local global i32, align 4
@sy = external dso_local global i32, align 4
@tx = external dso_local global i32, align 4
@ty = external dso_local global i32, align 4
@ch = external dso_local global [100001 x i8], align 16
@.str = external hidden unnamed_addr constant [14 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, ptr noundef nonnull @sx, ptr noundef nonnull @sy, ptr noundef nonnull @tx, ptr noundef nonnull @ty, ptr noundef nonnull @ch)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %sy.promoted = load i32, ptr @sy, align 4, !tbaa !5
  %sx.promoted = load i32, ptr @sx, align 4, !tbaa !5
  %4 = load i32, ptr @tx, align 4
  %5 = load i32, ptr @ty, align 4
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %6

6:                                                ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %7 = phi i32 [ %sx.promoted, %.lr.ph ], [ %28, %31 ]
  %8 = phi i32 [ %sy.promoted, %.lr.ph ], [ %27, %31 ]
  %9 = getelementptr inbounds [100001 x i8], ptr @ch, i64 0, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !9
  switch i8 %10, label %.thread15 [
    i8 83, label %11
    i8 69, label %15
    i8 78, label %19
    i8 87, label %23
  ]

11:                                               ; preds = %6
  %12 = icmp sgt i32 %8, %5
  br i1 %12, label %13, label %.thread15

13:                                               ; preds = %11
  %14 = add nsw i32 %8, -1
  store i32 %14, ptr @sy, align 4, !tbaa !5
  br label %.thread15

15:                                               ; preds = %6
  %16 = icmp slt i32 %7, %4
  br i1 %16, label %17, label %.thread15

17:                                               ; preds = %15
  %18 = add nsw i32 %7, 1
  store i32 %18, ptr @sx, align 4, !tbaa !5
  br label %.thread15

19:                                               ; preds = %6
  %20 = icmp slt i32 %8, %5
  br i1 %20, label %21, label %.thread15

21:                                               ; preds = %19
  %22 = add nsw i32 %8, 1
  store i32 %22, ptr @sy, align 4, !tbaa !5
  br label %.thread15

23:                                               ; preds = %6
  %24 = icmp sgt i32 %7, %4
  br i1 %24, label %25, label %.thread15

25:                                               ; preds = %23
  %26 = add nsw i32 %7, -1
  store i32 %26, ptr @sx, align 4, !tbaa !5
  br label %.thread15

.thread15:                                        ; preds = %6, %11, %13, %15, %17, %19, %21, %25, %23
  %27 = phi i32 [ %8, %6 ], [ %8, %11 ], [ %14, %13 ], [ %8, %15 ], [ %8, %17 ], [ %8, %19 ], [ %22, %21 ], [ %8, %25 ], [ %8, %23 ]
  %28 = phi i32 [ %7, %6 ], [ %7, %11 ], [ %7, %13 ], [ %7, %15 ], [ %18, %17 ], [ %7, %19 ], [ %7, %21 ], [ %26, %25 ], [ %7, %23 ]
  %29 = icmp eq i32 %28, %4
  %30 = icmp eq i32 %27, %5
  %or.cond = select i1 %29, i1 %30, i1 false
  br i1 %or.cond, label %32, label %31

31:                                               ; preds = %.thread15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %6, !llvm.loop !10

32:                                               ; preds = %.thread15
  %33 = trunc nuw nsw i64 %indvars.iv to i32
  %34 = add nuw nsw i32 %33, 1
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %34)
  br label %37

._crit_edge:                                      ; preds = %31, %0
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %37

37:                                               ; preds = %._crit_edge, %32
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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