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

; 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
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@flag = external dso_local global i32, align 4
@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 [5 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
@.str.4 = external hidden unnamed_addr constant [18 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 @t)
  br label %3

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

7:                                                ; preds = %3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m)
  store i32 0, ptr @flag, align 4, !tbaa !5
  store i32 0, ptr @y, align 4, !tbaa !5
  store i32 0, ptr @x, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %48, %7
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @m, align 4, !tbaa !5
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %49

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @op, ptr noundef @k)
  %15 = load i8, ptr @op, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  switch i32 %16, label %33 [
    i32 85, label %17
    i32 68, label %21
    i32 76, label %25
    i32 82, label %29
  ]

17:                                               ; preds = %13
  %18 = load i32, ptr @k, align 4, !tbaa !5
  %19 = load i32, ptr @x, align 4, !tbaa !5
  %20 = sub nsw i32 %19, %18
  store i32 %20, ptr @x, align 4, !tbaa !5
  br label %33

21:                                               ; preds = %13
  %22 = load i32, ptr @k, align 4, !tbaa !5
  %23 = load i32, ptr @x, align 4, !tbaa !5
  %24 = add nsw i32 %23, %22
  store i32 %24, ptr @x, align 4, !tbaa !5
  br label %33

25:                                               ; preds = %13
  %26 = load i32, ptr @k, align 4, !tbaa !5
  %27 = load i32, ptr @y, align 4, !tbaa !5
  %28 = sub nsw i32 %27, %26
  store i32 %28, ptr @y, align 4, !tbaa !5
  br label %33

29:                                               ; preds = %13
  %30 = load i32, ptr @k, align 4, !tbaa !5
  %31 = load i32, ptr @y, align 4, !tbaa !5
  %32 = add nsw i32 %31, %30
  store i32 %32, ptr @y, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %29, %25, %21, %17, %13
  %34 = load i32, ptr @x, align 4, !tbaa !5
  %35 = icmp sge i32 %34, 0
  br i1 %35, label %36, label %47

36:                                               ; preds = %33
  %37 = load i32, ptr @x, align 4, !tbaa !5
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = load i32, ptr @y, align 4, !tbaa !5
  %42 = icmp sge i32 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %40
  %44 = load i32, ptr @y, align 4, !tbaa !5
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43, %40, %36, %33
  store i32 1, ptr @flag, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %47, %43
  br label %9, !llvm.loop !10

49:                                               ; preds = %9
  %50 = load i32, ptr @flag, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %60, label %52

52:                                               ; preds = %49
  %53 = load i32, ptr @y, align 4, !tbaa !5
  %54 = load i32, ptr @n, align 4, !tbaa !5
  %55 = mul nsw i32 %53, %54
  %56 = load i32, ptr @x, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = add nsw i32 %57, 1
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %58)
  br label %62

60:                                               ; preds = %49
  %61 = call i32 @puts(ptr noundef @.str.4)
  br label %62

62:                                               ; preds = %60, %52
  br label %3, !llvm.loop !12

63:                                               ; preds = %3
  ret i32 0
}

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

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

declare i32 @puts(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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; 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
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local local_unnamed_addr global i32, align 4
@y = external dso_local local_unnamed_addr global i32, align 4
@k = external dso_local global i32, align 4
@flag = external dso_local local_unnamed_addr global i32, align 4
@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 [5 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
@.str.4 = external hidden unnamed_addr constant [18 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)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not8 = icmp eq i32 %2, 0
  br i1 %.not8, label %._crit_edge11, label %.lr.ph10

.lr.ph10:                                         ; preds = %0, %48
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m)
  store i32 0, ptr @flag, align 4, !tbaa !5
  store i32 0, ptr @y, align 4, !tbaa !5
  store i32 0, ptr @x, align 4, !tbaa !5
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @m, align 4, !tbaa !5
  %.not47 = icmp eq i32 %5, 0
  br i1 %.not47, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph10, %36
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @op, ptr noundef nonnull @k)
  %8 = load i8, ptr @op, align 1, !tbaa !9
  switch i8 %8, label %thread-pre-split [
    i8 85, label %9
    i8 68, label %13
    i8 76, label %17
    i8 82, label %21
  ]

9:                                                ; preds = %.lr.ph
  %10 = load i32, ptr @k, align 4, !tbaa !5
  %11 = load i32, ptr @x, align 4, !tbaa !5
  %12 = sub nsw i32 %11, %10
  store i32 %12, ptr @x, align 4, !tbaa !5
  br label %25

13:                                               ; preds = %.lr.ph
  %14 = load i32, ptr @k, align 4, !tbaa !5
  %15 = load i32, ptr @x, align 4, !tbaa !5
  %16 = add nsw i32 %15, %14
  store i32 %16, ptr @x, align 4, !tbaa !5
  br label %25

17:                                               ; preds = %.lr.ph
  %18 = load i32, ptr @k, align 4, !tbaa !5
  %19 = load i32, ptr @y, align 4, !tbaa !5
  %20 = sub nsw i32 %19, %18
  br label %thread-pre-split.sink.split

21:                                               ; preds = %.lr.ph
  %22 = load i32, ptr @k, align 4, !tbaa !5
  %23 = load i32, ptr @y, align 4, !tbaa !5
  %24 = add nsw i32 %23, %22
  br label %thread-pre-split.sink.split

thread-pre-split.sink.split:                      ; preds = %21, %17
  %.sink = phi i32 [ %20, %17 ], [ %24, %21 ]
  store i32 %.sink, ptr @y, align 4, !tbaa !5
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %thread-pre-split.sink.split, %.lr.ph
  %.pr = load i32, ptr @x, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %thread-pre-split, %13, %9
  %26 = phi i32 [ %.pr, %thread-pre-split ], [ %16, %13 ], [ %12, %9 ]
  %27 = icmp sgt i32 %26, -1
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp slt i32 %26, %29
  %31 = load i32, ptr @y, align 4
  %32 = icmp sgt i32 %31, -1
  %33 = icmp slt i32 %31, %29
  %34 = and i1 %32, %33
  %or.cond6 = select i1 %30, i1 %34, i1 false
  br i1 %or.cond6, label %36, label %35

35:                                               ; preds = %28, %25
  store i32 1, ptr @flag, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %28, %35
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr @m, align 4, !tbaa !5
  %.not4 = icmp eq i32 %37, 0
  br i1 %.not4, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %36
  %.pre = load i32, ptr @flag, align 4, !tbaa !5
  %.not5 = icmp eq i32 %.pre, 0
  br i1 %.not5, label %._crit_edge.thread, label %46

._crit_edge.thread:                               ; preds = %.lr.ph10, %._crit_edge
  %39 = phi i32 [ %26, %._crit_edge ], [ 0, %.lr.ph10 ]
  %40 = load i32, ptr @y, align 4, !tbaa !5
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = mul nsw i32 %41, %40
  %43 = add i32 %39, 1
  %44 = add i32 %43, %42
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %44)
  br label %48

46:                                               ; preds = %._crit_edge
  %47 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %48

48:                                               ; preds = %46, %._crit_edge.thread
  %49 = load i32, ptr @t, align 4, !tbaa !5
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %49, 0
  br i1 %.not, label %._crit_edge11, label %.lr.ph10, !llvm.loop !12

._crit_edge11:                                    ; preds = %48, %0
  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: nofree nounwind
declare noundef i32 @puts(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"}
!12 = distinct !{!12, !11}


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