; LLVM IR from tangjz/acm-icpc :: codeforces/gym (101955K)

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

8:                                                ; preds = %73, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @t, 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) #4
  br label %76

13:                                               ; preds = %8
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m, ptr noundef @dt)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %15 = load i64, ptr @n, align 8, !tbaa !9
  %16 = load i64, ptr @m, align 8, !tbaa !9
  %17 = sub nsw i64 %15, %16
  store i64 %17, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 -1, ptr %4, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %67, %13
  %19 = load i64, ptr %3, align 8, !tbaa !9
  %20 = load i64, ptr @n, align 8, !tbaa !9
  %21 = icmp slt i64 %19, %20
  br i1 %21, label %22, label %68

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %23 = load i64, ptr @n, align 8, !tbaa !9
  %24 = load i64, ptr %3, align 8, !tbaa !9
  %25 = sub nsw i64 %23, %24
  store i64 %25, ptr %5, align 8, !tbaa !9
  %26 = load i64, ptr @dt, align 8, !tbaa !9
  %27 = icmp sgt i64 %26, 1
  br i1 %27, label %28, label %39

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %29 = load i64, ptr %3, align 8, !tbaa !9
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = sub nsw i64 %29, %30
  %32 = sub nsw i64 %31, 1
  %33 = load i64, ptr @dt, align 8, !tbaa !9
  %34 = sub nsw i64 %33, 1
  %35 = sdiv i64 %32, %34
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %6, align 8, !tbaa !9
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %38 = load i64, ptr %37, align 8, !tbaa !9
  store i64 %38, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %39

39:                                               ; preds = %28, %22
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = load i64, ptr %3, align 8, !tbaa !9
  %42 = add nsw i64 %41, %40
  store i64 %42, ptr %3, align 8, !tbaa !9
  %43 = load i64, ptr @dt, align 8, !tbaa !9
  %44 = load i64, ptr %3, align 8, !tbaa !9
  %45 = icmp sle i64 %43, %44
  br i1 %45, label %46, label %61

46:                                               ; preds = %39
  %47 = load i64, ptr %5, align 8, !tbaa !9
  %48 = load i64, ptr @dt, align 8, !tbaa !9
  %49 = mul nsw i64 %47, %48
  %50 = load i64, ptr %4, align 8, !tbaa !9
  %51 = add nsw i64 %50, %49
  store i64 %51, ptr %4, align 8, !tbaa !9
  %52 = load i64, ptr %3, align 8, !tbaa !9
  %53 = icmp sge i64 %51, %52
  br i1 %53, label %54, label %59

54:                                               ; preds = %46
  %55 = load i64, ptr %3, align 8, !tbaa !9
  %56 = load i64, ptr %4, align 8, !tbaa !9
  %57 = sub nsw i64 %56, %55
  store i64 %57, ptr %4, align 8, !tbaa !9
  %58 = icmp ne i64 %57, 0
  br label %59

59:                                               ; preds = %54, %46
  %60 = phi i1 [ false, %46 ], [ %58, %54 ]
  br label %67

61:                                               ; preds = %39
  %62 = load i64, ptr %4, align 8, !tbaa !9
  %63 = load i64, ptr @dt, align 8, !tbaa !9
  %64 = add nsw i64 %62, %63
  %65 = load i64, ptr %3, align 8, !tbaa !9
  %66 = srem i64 %64, %65
  store i64 %66, ptr %4, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %61, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %18, !llvm.loop !11

68:                                               ; preds = %18
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = load i64, ptr %4, align 8, !tbaa !9
  %71 = add nsw i64 %70, 1
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %69, i64 noundef %71)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %73

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

76:                                               ; preds = %12
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

; 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 = { inlinehint mustprogress 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 #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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 i64, align 8
@m = external dso_local global i64, align 8
@dt = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %4 = load i32, ptr @t, align 4, !tbaa !5
  %.not27 = icmp slt i32 %4, 1
  br i1 %.not27, label %._crit_edge31, label %.lr.ph30

._crit_edge31:                                    ; preds = %._crit_edge, %0
  ret i32 0

.lr.ph30:                                         ; preds = %0, %._crit_edge
  %.01728 = phi i32 [ %46, %._crit_edge ], [ 1, %0 ]
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @dt)
  %6 = load i64, ptr @n, align 8, !tbaa !9
  %7 = load i64, ptr @m, align 8, !tbaa !9
  %8 = icmp sgt i64 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph30
  %9 = load i64, ptr @dt, align 8, !tbaa !9
  %10 = icmp sgt i64 %9, 1
  br i1 %10, label %.lr.ph.split.preheader, label %.lr.ph.split.us

.lr.ph.split.preheader:                           ; preds = %.lr.ph
  %11 = sub nsw i64 %6, %7
  br label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %.not23.us.peel = icmp sgt i64 %9, %6
  br i1 %.not23.us.peel, label %16, label %12

12:                                               ; preds = %.lr.ph.split.us
  %13 = mul nsw i64 %9, %7
  %.not24.us.peel.not = icmp sgt i64 %13, %6
  %14 = xor i64 %6, -1
  %15 = select i1 %.not24.us.peel.not, i64 %14, i64 -1
  %spec.select.us.peel = add i64 %15, %13
  br label %._crit_edge.loopexit32

16:                                               ; preds = %.lr.ph.split.us
  %.nonneg = sub i64 1, %9
  %.nonneg39 = sub i64 0, %6
  %17 = urem i64 %.nonneg, %.nonneg39
  %.neg = sub i64 0, %17
  br label %._crit_edge.loopexit32

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader, %41
  %18 = phi i64 [ %31, %41 ], [ %9, %.lr.ph.split.preheader ]
  %19 = phi i64 [ %42, %41 ], [ %6, %.lr.ph.split.preheader ]
  %.026 = phi i64 [ %.1, %41 ], [ -1, %.lr.ph.split.preheader ]
  %.01625 = phi i64 [ %33, %41 ], [ %11, %.lr.ph.split.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %20 = sub nsw i64 %19, %.01625
  store i64 %20, ptr %1, align 8, !tbaa !9
  %21 = icmp sgt i64 %18, 1
  br i1 %21, label %22, label %30

22:                                               ; preds = %.lr.ph.split
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %23 = xor i64 %.026, -1
  %24 = add i64 %.01625, %23
  %25 = add nsw i64 %18, -1
  %26 = sdiv i64 %24, %25
  %27 = add nsw i64 %26, 1
  store i64 %27, ptr %2, align 8, !tbaa !9
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %29 = load i64, ptr %28, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %.pre = load i64, ptr @dt, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %22, %.lr.ph.split
  %31 = phi i64 [ %.pre, %22 ], [ %18, %.lr.ph.split ]
  %32 = phi i64 [ %29, %22 ], [ %20, %.lr.ph.split ]
  %33 = add nsw i64 %32, %.01625
  %.not23 = icmp sgt i64 %31, %33
  br i1 %.not23, label %38, label %34

34:                                               ; preds = %30
  %35 = mul nsw i64 %31, %32
  %36 = add nsw i64 %35, %.026
  %.not24 = icmp slt i64 %36, %33
  %37 = select i1 %.not24, i64 0, i64 %33
  %spec.select = sub nsw i64 %36, %37
  br label %41

38:                                               ; preds = %30
  %39 = add nsw i64 %31, %.026
  %40 = srem i64 %39, %33
  br label %41

41:                                               ; preds = %34, %38
  %.1 = phi i64 [ %40, %38 ], [ %spec.select, %34 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  %42 = load i64, ptr @n, align 8, !tbaa !9
  %43 = icmp slt i64 %33, %42
  br i1 %43, label %.lr.ph.split, label %._crit_edge, !llvm.loop !11

._crit_edge.loopexit32:                           ; preds = %12, %16
  %.1.us.peel = phi i64 [ %.neg, %16 ], [ %spec.select.us.peel, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  br label %._crit_edge

._crit_edge:                                      ; preds = %41, %._crit_edge.loopexit32, %.lr.ph30
  %.0.lcssa = phi i64 [ -1, %.lr.ph30 ], [ %.1.us.peel, %._crit_edge.loopexit32 ], [ %.1, %41 ]
  %44 = add nsw i64 %.0.lcssa, 1
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.01728, i64 noundef %44)
  %46 = add nuw nsw i32 %.01728, 1
  %47 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01728, %47
  br i1 %.not.not, label %.lr.ph30, label %._crit_edge31, !llvm.loop !14
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

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

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

attributes #0 = { mustprogress 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" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint mustprogress 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 #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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.unswitch.partial.disable"}
!14 = distinct !{!14, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass