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

; 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
@m = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = and i32 %3, 1
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %21

6:                                                ; preds = %0
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = and i32 %7, 1
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %18

10:                                               ; preds = %6
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sub nsw i32 %11, 1
  %13 = load i32, ptr @m, align 4, !tbaa !5
  %14 = sdiv i32 %12, %13
  %15 = add nsw i32 %14, 1
  %16 = or i32 %15, 1
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %16)
  br label %20

18:                                               ; preds = %6
  %19 = call i32 @puts(ptr noundef @.str.2)
  br label %20

20:                                               ; preds = %18, %10
  br label %65

21:                                               ; preds = %0
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %23 = and i32 %22, 1
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %49

25:                                               ; preds = %21
  %26 = load i32, ptr @m, align 4, !tbaa !5
  %27 = shl i32 %26, 1
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %30, label %38

30:                                               ; preds = %25
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = sdiv i32 %32, %33
  %35 = add nsw i32 %34, 2
  %36 = and i32 %35, -2
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %36)
  br label %48

38:                                               ; preds = %25
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = load i32, ptr @m, align 4, !tbaa !5
  %43 = sub nsw i32 %41, %42
  %44 = sdiv i32 %40, %43
  %45 = add nsw i32 %44, 2
  %46 = and i32 %45, -2
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %46)
  br label %48

48:                                               ; preds = %38, %30
  br label %64

49:                                               ; preds = %21
  %50 = load i32, ptr @m, align 4, !tbaa !5
  %51 = shl i32 %50, 1
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = icmp sle i32 %51, %52
  br i1 %53, label %54, label %61

54:                                               ; preds = %49
  %55 = load i32, ptr @n, align 4, !tbaa !5
  %56 = sub nsw i32 %55, 1
  %57 = load i32, ptr @m, align 4, !tbaa !5
  %58 = sdiv i32 %56, %57
  %59 = add nsw i32 %58, 1
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %59)
  br label %63

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

63:                                               ; preds = %61, %54
  br label %64

64:                                               ; preds = %63, %48
  br label %65

65:                                               ; preds = %64, %20
  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"}


; 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
@m = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = and i32 %2, 1
  %.not = icmp eq i32 %3, 0
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %5 = and i32 %4, 1
  %.not1 = icmp eq i32 %5, 0
  br i1 %.not, label %15, label %6

6:                                                ; preds = %0
  br i1 %.not1, label %13, label %7

7:                                                ; preds = %6
  %8 = add nsw i32 %2, -1
  %9 = sdiv i32 %8, %4
  %10 = add nsw i32 %9, 1
  %11 = or i32 %10, 1
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %11)
  br label %38

13:                                               ; preds = %6
  %14 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %38

15:                                               ; preds = %0
  %16 = shl i32 %4, 1
  %.not2 = icmp sgt i32 %16, %2
  br i1 %.not1, label %30, label %17

17:                                               ; preds = %15
  %18 = add nsw i32 %2, -1
  br i1 %.not2, label %24, label %19

19:                                               ; preds = %17
  %20 = sdiv i32 %18, %4
  %21 = and i32 %20, -2
  %22 = add nsw i32 %21, 2
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %22)
  br label %38

24:                                               ; preds = %17
  %25 = sub nsw i32 %2, %4
  %26 = sdiv i32 %18, %25
  %27 = and i32 %26, -2
  %28 = add nsw i32 %27, 2
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %28)
  br label %38

30:                                               ; preds = %15
  br i1 %.not2, label %36, label %31

31:                                               ; preds = %30
  %32 = add nsw i32 %2, -1
  %33 = sdiv i32 %32, %4
  %34 = add nsw i32 %33, 1
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %34)
  br label %38

36:                                               ; preds = %30
  %37 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %38

38:                                               ; preds = %24, %19, %36, %31, %7, %13
  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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass