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

; 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 i64, align 8
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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 @n, ptr noundef @m)
  br label %3

3:                                                ; preds = %33, %0
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = icmp ne i64 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = load i64, ptr @m, align 8, !tbaa !5
  %8 = icmp ne i64 %7, 0
  br label %9

9:                                                ; preds = %6, %3
  %10 = phi i1 [ false, %3 ], [ %8, %6 ]
  br i1 %10, label %11, label %34

11:                                               ; preds = %9
  %12 = load i64, ptr @n, align 8, !tbaa !5
  %13 = load i64, ptr @m, align 8, !tbaa !5
  %14 = mul nsw i64 %13, 2
  %15 = icmp sge i64 %12, %14
  br i1 %15, label %16, label %21

16:                                               ; preds = %11
  %17 = load i64, ptr @m, align 8, !tbaa !5
  %18 = mul nsw i64 %17, 2
  %19 = load i64, ptr @n, align 8, !tbaa !5
  %20 = srem i64 %19, %18
  store i64 %20, ptr @n, align 8, !tbaa !5
  br label %33

21:                                               ; preds = %11
  %22 = load i64, ptr @m, align 8, !tbaa !5
  %23 = load i64, ptr @n, align 8, !tbaa !5
  %24 = mul nsw i64 %23, 2
  %25 = icmp sge i64 %22, %24
  br i1 %25, label %26, label %31

26:                                               ; preds = %21
  %27 = load i64, ptr @n, align 8, !tbaa !5
  %28 = mul nsw i64 %27, 2
  %29 = load i64, ptr @m, align 8, !tbaa !5
  %30 = srem i64 %29, %28
  store i64 %30, ptr @m, align 8, !tbaa !5
  br label %32

31:                                               ; preds = %21
  br label %34

32:                                               ; preds = %26
  br label %33

33:                                               ; preds = %32, %16
  br label %3, !llvm.loop !9

34:                                               ; preds = %31, %9
  %35 = load i64, ptr @n, align 8, !tbaa !5
  %36 = load i64, ptr @m, align 8, !tbaa !5
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %35, i64 noundef %36)
  ret i32 0
}

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

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" }

!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 = !{!"long long", !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"

@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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)
  %n.promoted = load i64, ptr @n, align 8, !tbaa !5
  %m.promoted = load i64, ptr @m, align 8
  %2 = icmp ne i64 %n.promoted, 0
  %3 = icmp ne i64 %m.promoted, 0
  %4 = select i1 %2, i1 %3, i1 false
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %14
  %5 = phi i64 [ %16, %14 ], [ %n.promoted, %0 ]
  %6 = phi i64 [ %15, %14 ], [ %m.promoted, %0 ]
  %7 = shl nsw i64 %6, 1
  %.not = icmp slt i64 %5, %7
  br i1 %.not, label %10, label %8

8:                                                ; preds = %.lr.ph
  %9 = srem i64 %5, %7
  store i64 %9, ptr @n, align 8, !tbaa !5
  br label %14

10:                                               ; preds = %.lr.ph
  %11 = shl nsw i64 %5, 1
  %.not4 = icmp slt i64 %6, %11
  br i1 %.not4, label %._crit_edge, label %12

12:                                               ; preds = %10
  %13 = srem i64 %6, %11
  store i64 %13, ptr @m, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %12, %8
  %15 = phi i64 [ %13, %12 ], [ %6, %8 ]
  %16 = phi i64 [ %5, %12 ], [ %9, %8 ]
  %17 = icmp ne i64 %16, 0
  %18 = icmp ne i64 %15, 0
  %19 = and i1 %17, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %14, %10, %0
  %.lcssa5 = phi i64 [ %n.promoted, %0 ], [ %5, %10 ], [ %16, %14 ]
  %.lcssa = phi i64 [ %m.promoted, %0 ], [ %6, %10 ], [ %15, %14 ]
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.lcssa5, i64 noundef %.lcssa)
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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