; LLVM IR from tangjz/acm-icpc :: 51nod (1770)

; 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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 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
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %7

7:                                                ; preds = %118, %0
  %8 = load i32, ptr @t, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @t, align 4, !tbaa !5
  %10 = icmp ne i32 %8, 0
  br i1 %10, label %11, label %121

11:                                               ; preds = %7
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @a, ptr noundef @b, ptr noundef @d, ptr noundef @n)
  %13 = load i32, ptr @a, align 4, !tbaa !5
  %14 = load i32, ptr @b, align 4, !tbaa !5
  %15 = mul nsw i32 %13, %14
  %16 = sdiv i32 %15, 10
  store i32 %16, ptr @x, align 4, !tbaa !5
  %17 = load i32, ptr @a, align 4, !tbaa !5
  %18 = load i32, ptr @b, align 4, !tbaa !5
  %19 = mul nsw i32 %17, %18
  %20 = srem i32 %19, 10
  store i32 %20, ptr @y, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  %21 = load i32, ptr @x, align 4, !tbaa !5
  %22 = load i32, ptr @y, align 4, !tbaa !5
  %23 = add nsw i32 %21, %22
  %24 = icmp slt i32 %23, 10
  br i1 %24, label %25, label %57

25:                                               ; preds = %11
  %26 = load i32, ptr @x, align 4, !tbaa !5
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load i32, ptr @x, align 4, !tbaa !5
  %30 = load i32, ptr @d, align 4, !tbaa !5
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %32, label %35

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

35:                                               ; preds = %32, %28, %25
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp sgt i32 %36, 1
  br i1 %37, label %38, label %49

38:                                               ; preds = %35
  %39 = load i32, ptr @x, align 4, !tbaa !5
  %40 = load i32, ptr @y, align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  %42 = load i32, ptr @d, align 4, !tbaa !5
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %49

44:                                               ; preds = %38
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 1
  %47 = load i32, ptr @ans, align 4, !tbaa !5
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr @ans, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %44, %38, %35
  %50 = load i32, ptr @y, align 4, !tbaa !5
  %51 = load i32, ptr @d, align 4, !tbaa !5
  %52 = icmp eq i32 %50, %51
  br i1 %52, label %53, label %56

53:                                               ; preds = %49
  %54 = load i32, ptr @ans, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr @ans, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %53, %49
  br label %118

57:                                               ; preds = %11
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = icmp sgt i32 %58, 1
  br i1 %59, label %60, label %102

60:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %61 = load i32, ptr @x, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %63 = load i32, ptr @x, align 4, !tbaa !5
  %64 = load i32, ptr @y, align 4, !tbaa !5
  %65 = add nsw i32 %63, %64
  %66 = sub nsw i32 %65, 9
  store i32 %66, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %67 = load i32, ptr @x, align 4, !tbaa !5
  %68 = load i32, ptr @y, align 4, !tbaa !5
  %69 = add nsw i32 %67, %68
  %70 = sub nsw i32 %69, 10
  store i32 %70, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %71 = load i32, ptr @y, align 4, !tbaa !5
  store i32 %71, ptr %5, align 4, !tbaa !5
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = load i32, ptr @d, align 4, !tbaa !5
  %74 = icmp eq i32 %72, %73
  br i1 %74, label %75, label %78

75:                                               ; preds = %60
  %76 = load i32, ptr @ans, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr @ans, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %75, %60
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = load i32, ptr @d, align 4, !tbaa !5
  %81 = icmp eq i32 %79, %80
  br i1 %81, label %82, label %87

82:                                               ; preds = %78
  %83 = load i32, ptr @n, align 4, !tbaa !5
  %84 = sub nsw i32 %83, 2
  %85 = load i32, ptr @ans, align 4, !tbaa !5
  %86 = add nsw i32 %85, %84
  store i32 %86, ptr @ans, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %82, %78
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = load i32, ptr @d, align 4, !tbaa !5
  %90 = icmp eq i32 %88, %89
  br i1 %90, label %91, label %94

91:                                               ; preds = %87
  %92 = load i32, ptr @ans, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr @ans, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %91, %87
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = load i32, ptr @d, align 4, !tbaa !5
  %97 = icmp eq i32 %95, %96
  br i1 %97, label %98, label %101

98:                                               ; preds = %94
  %99 = load i32, ptr @ans, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr @ans, align 4, !tbaa !5
  br label %101

101:                                              ; preds = %98, %94
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %117

102:                                              ; preds = %57
  %103 = load i32, ptr @x, align 4, !tbaa !5
  %104 = load i32, ptr @d, align 4, !tbaa !5
  %105 = icmp eq i32 %103, %104
  br i1 %105, label %106, label %109

106:                                              ; preds = %102
  %107 = load i32, ptr @ans, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr @ans, align 4, !tbaa !5
  br label %109

109:                                              ; preds = %106, %102
  %110 = load i32, ptr @y, align 4, !tbaa !5
  %111 = load i32, ptr @d, align 4, !tbaa !5
  %112 = icmp eq i32 %110, %111
  br i1 %112, label %113, label %116

113:                                              ; preds = %109
  %114 = load i32, ptr @ans, align 4, !tbaa !5
  %115 = add nsw i32 %114, 1
  store i32 %115, ptr @ans, align 4, !tbaa !5
  br label %116

116:                                              ; preds = %113, %109
  br label %117

117:                                              ; preds = %116, %101
  br label %118

118:                                              ; preds = %117, %56
  %119 = load i32, ptr @ans, align 4, !tbaa !5
  %120 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %119)
  br label %7, !llvm.loop !9

121:                                              ; preds = %7
  ret i32 0
}

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

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

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

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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"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
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@n = 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
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 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)
  %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_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %51
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @d, ptr noundef nonnull @n)
  %5 = load i32, ptr @a, align 4, !tbaa !5
  %6 = load i32, ptr @b, align 4, !tbaa !5
  %7 = mul nsw i32 %6, %5
  %8 = sdiv i32 %7, 10
  store i32 %8, ptr @x, align 4, !tbaa !5
  %9 = srem i32 %7, 10
  store i32 %9, ptr @y, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  %10 = add nsw i32 %8, %9
  %11 = icmp slt i32 %10, 10
  br i1 %11, label %12, label %27

12:                                               ; preds = %.lr.ph
  %13 = icmp sgt i32 %7, 9
  %14 = load i32, ptr @d, align 4
  %15 = icmp eq i32 %8, %14
  %or.cond = select i1 %13, i1 %15, i1 false
  br i1 %or.cond, label %16, label %condstore.split

16:                                               ; preds = %12
  store i32 1, ptr @ans, align 4, !tbaa !5
  br label %condstore.split

condstore.split:                                  ; preds = %16, %12
  %17 = phi i32 [ 1, %16 ], [ 0, %12 ]
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = icmp sgt i32 %18, 1
  %20 = icmp eq i32 %10, %14
  %or.cond7.not.not = select i1 %19, i1 %20, i1 false
  %21 = add nsw i32 %18, -1
  %22 = select i1 %or.cond7.not.not, i32 %21, i32 0
  %23 = add nuw nsw i32 %17, %22
  %24 = icmp eq i32 %9, %14
  %25 = zext i1 %24 to i32
  %.ph = add nuw nsw i32 %23, %25
  %26 = or i1 %or.cond7.not.not, %24
  br i1 %26, label %.sink.split, label %51

27:                                               ; preds = %.lr.ph
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, 1
  br i1 %29, label %condstore.split9, label %condstore.split12

condstore.split9:                                 ; preds = %27
  %30 = add nsw i32 %8, 1
  %31 = add nsw i32 %10, -9
  %32 = add nsw i32 %10, -10
  %33 = load i32, ptr @d, align 4, !tbaa !5
  %34 = icmp eq i32 %30, %33
  %35 = zext i1 %34 to i32
  %.not16 = icmp eq i32 %31, %33
  %36 = add nsw i32 %28, -2
  %37 = select i1 %.not16, i32 %36, i32 0
  %38 = add nuw nsw i32 %37, %35
  %39 = or i1 %34, %.not16
  %40 = icmp eq i32 %32, %33
  %41 = zext i1 %40 to i32
  %spec.select = add nuw nsw i32 %38, %41
  %42 = or i1 %39, %40
  %43 = icmp eq i32 %9, %33
  %44 = zext i1 %43 to i32
  %spec.select11 = add nuw nsw i32 %spec.select, %44
  %45 = or i1 %42, %43
  br i1 %45, label %.sink.split, label %51

condstore.split12:                                ; preds = %27
  %46 = load i32, ptr @d, align 4, !tbaa !5
  %47 = icmp eq i32 %8, %46
  %48 = zext i1 %47 to i32
  %.not15 = icmp eq i32 %9, %46
  %49 = select i1 %47, i32 2, i32 1
  %.ph13 = select i1 %.not15, i32 %49, i32 %48
  %50 = or i1 %47, %.not15
  br i1 %50, label %.sink.split, label %51

.sink.split:                                      ; preds = %condstore.split12, %condstore.split9, %condstore.split
  %.ph13.sink = phi i32 [ %.ph, %condstore.split ], [ %spec.select11, %condstore.split9 ], [ %.ph13, %condstore.split12 ]
  store i32 %.ph13.sink, ptr @ans, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %.sink.split, %condstore.split12, %condstore.split9, %condstore.split
  %52 = phi i32 [ %.ph, %condstore.split ], [ %spec.select11, %condstore.split9 ], [ %.ph13, %condstore.split12 ], [ %.ph13.sink, %.sink.split ]
  %53 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %52)
  %54 = load i32, ptr @t, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %54, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %51, %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

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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