; LLVM IR from tangjz/acm-icpc :: codeforces (1190A)

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

6:                                                ; preds = %39, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %42

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %12 = load i64, ptr @x, align 8, !tbaa !9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = sub nsw i64 %12, %14
  %16 = sub nsw i64 %15, 1
  %17 = load i64, ptr @m, align 8, !tbaa !9
  %18 = sdiv i64 %16, %17
  %19 = add nsw i64 %18, 1
  store i64 %19, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %20 = load i64, ptr %3, align 8, !tbaa !9
  %21 = load i64, ptr @m, align 8, !tbaa !9
  %22 = mul nsw i64 %20, %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = add nsw i64 %22, %24
  store i64 %25, ptr %4, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %37, %11
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %2, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %38

31:                                               ; preds = %26
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x)
  %33 = load i64, ptr @x, align 8, !tbaa !9
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = icmp sgt i64 %33, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  br label %38

37:                                               ; preds = %31
  br label %26, !llvm.loop !11

38:                                               ; preds = %36, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr @ans, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr @ans, align 4, !tbaa !5
  br label %6, !llvm.loop !13

42:                                               ; preds = %10
  %43 = load i32, ptr @ans, align 4, !tbaa !5
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %43)
  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 = !{!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"

@n = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local global i64, align 8
@x = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 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 @n, ptr noundef nonnull @m, ptr noundef nonnull @x)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph.preheader, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre10 = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %.pre = load i64, ptr @x, align 8, !tbaa !9
  br label %.lr.ph

._crit_edge:                                      ; preds = %split, %.._crit_edge_crit_edge
  %4 = phi i32 [ %.pre10, %.._crit_edge_crit_edge ], [ %30, %split ]
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %4)
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph.preheader, %split
  %6 = phi i64 [ %28, %split ], [ %.pre, %.lr.ph.preheader ]
  %.07 = phi i32 [ %26, %split ], [ 0, %.lr.ph.preheader ]
  %7 = sext i32 %.07 to i64
  %8 = xor i64 %7, -1
  %9 = add i64 %6, %8
  %10 = load i64, ptr @m, align 8, !tbaa !9
  %11 = sdiv i64 %9, %10
  %12 = add nsw i64 %11, 1
  %13 = mul nsw i64 %12, %10
  %14 = add nsw i64 %13, %7
  %15 = add nsw i32 %.07, 1
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph25, label %split

18:                                               ; preds = %.lr.ph25
  %19 = add nsw i32 %22, 1
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %.lr.ph25, label %split, !llvm.loop !11

.lr.ph25:                                         ; preds = %.lr.ph, %18
  %22 = phi i32 [ %19, %18 ], [ %15, %.lr.ph ]
  %23 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x)
  %24 = load i64, ptr @x, align 8, !tbaa !9
  %25 = icmp sgt i64 %24, %14
  br i1 %25, label %._crit_edge8, label %18, !llvm.loop !11

._crit_edge8:                                     ; preds = %.lr.ph25
  %.pre9 = load i32, ptr @n, align 4, !tbaa !5
  br label %split

split:                                            ; preds = %18, %.lr.ph, %._crit_edge8
  %26 = phi i32 [ %22, %._crit_edge8 ], [ %15, %.lr.ph ], [ %19, %18 ]
  %27 = phi i32 [ %.pre9, %._crit_edge8 ], [ %16, %.lr.ph ], [ %20, %18 ]
  %28 = phi i64 [ %24, %._crit_edge8 ], [ %6, %.lr.ph ], [ %24, %18 ]
  %29 = load i32, ptr @ans, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @ans, align 4, !tbaa !5
  %31 = icmp slt i32 %26, %27
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

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


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