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

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

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

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

10:                                               ; preds = %5
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = and i32 %12, 1
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %10
  %16 = load i32, ptr @od, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @od, align 4, !tbaa !5
  br label %21

18:                                               ; preds = %10
  %19 = load i32, ptr @ev, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @ev, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %18, %15
  %22 = phi ptr [ @od, %15 ], [ @ev, %18 ]
  br label %23

23:                                               ; preds = %21
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

26:                                               ; preds = %9
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = sub nsw i32 %27, %28
  %30 = ashr i32 %29, 1
  store i32 %30, ptr @fi, align 4, !tbaa !5
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = load i32, ptr @m, align 4, !tbaa !5
  %33 = sub nsw i32 %31, %32
  %34 = load i32, ptr @fi, align 4, !tbaa !5
  %35 = sub nsw i32 %33, %34
  store i32 %35, ptr @se, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = icmp eq i32 %36, %37
  br i1 %38, label %39, label %44

39:                                               ; preds = %26
  %40 = load i32, ptr @od, align 4, !tbaa !5
  %41 = xor i32 %40, -1
  %42 = and i32 %41, 1
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %85, label %44

44:                                               ; preds = %39, %26
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %83

48:                                               ; preds = %44
  %49 = load i32, ptr @od, align 4, !tbaa !5
  %50 = load i32, ptr @fi, align 4, !tbaa !5
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %81, label %52

52:                                               ; preds = %48
  %53 = load i32, ptr @m, align 4, !tbaa !5
  %54 = xor i32 %53, -1
  %55 = and i32 %54, 1
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %61

57:                                               ; preds = %52
  %58 = load i32, ptr @ev, align 4, !tbaa !5
  %59 = load i32, ptr @fi, align 4, !tbaa !5
  %60 = icmp sle i32 %58, %59
  br i1 %60, label %81, label %61

61:                                               ; preds = %57, %52
  %62 = load i32, ptr @n, align 4, !tbaa !5
  %63 = load i32, ptr @m, align 4, !tbaa !5
  %64 = sub nsw i32 %62, %63
  %65 = xor i32 %64, -1
  %66 = and i32 %65, 1
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %79

68:                                               ; preds = %61
  %69 = load i32, ptr @m, align 4, !tbaa !5
  %70 = xor i32 %69, -1
  %71 = and i32 %70, 1
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %77, label %73

73:                                               ; preds = %68
  %74 = load i32, ptr @se, align 4, !tbaa !5
  %75 = load i32, ptr @ev, align 4, !tbaa !5
  %76 = icmp slt i32 %74, %75
  br label %77

77:                                               ; preds = %73, %68
  %78 = phi i1 [ true, %68 ], [ %76, %73 ]
  br label %79

79:                                               ; preds = %77, %61
  %80 = phi i1 [ false, %61 ], [ %78, %77 ]
  br label %81

81:                                               ; preds = %79, %57, %48
  %82 = phi i1 [ true, %57 ], [ true, %48 ], [ %80, %79 ]
  br label %83

83:                                               ; preds = %81, %44
  %84 = phi i1 [ false, %44 ], [ %82, %81 ]
  br label %85

85:                                               ; preds = %83, %39
  %86 = phi i1 [ true, %39 ], [ %84, %83 ]
  %87 = zext i1 %86 to i64
  %88 = select i1 %86, ptr @.str.2, ptr @.str.3
  %89 = call i32 @puts(ptr noundef %88)
  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 @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" }
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"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@od = external dso_local local_unnamed_addr global i32, align 4
@ev = external dso_local local_unnamed_addr global i32, align 4
@fi = external dso_local local_unnamed_addr global i32, align 4
@se = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i32 [ %3, %0 ], [ %17, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = sub i32 %.lcssa, %5
  %7 = ashr i32 %6, 1
  store i32 %7, ptr @fi, align 4, !tbaa !5
  %8 = add i32 %5, %7
  %9 = sub i32 %.lcssa, %8
  store i32 %9, ptr @se, align 4, !tbaa !5
  %10 = icmp eq i32 %.lcssa, %5
  br i1 %10, label %19, label %22

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.010 = phi i32 [ %16, %.lr.ph ], [ 0, %0 ]
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = and i32 %12, 1
  %.not7 = icmp eq i32 %13, 0
  %ev.od = select i1 %.not7, ptr @ev, ptr @od
  %14 = load i32, ptr %ev.od, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %ev.od, align 4, !tbaa !5
  %16 = add nuw nsw i32 %.010, 1
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !9

19:                                               ; preds = %._crit_edge
  %20 = load i32, ptr @od, align 4, !tbaa !5
  %21 = and i32 %20, 1
  %.not.not = icmp eq i32 %21, 0
  br i1 %.not.not, label %36, label %22

22:                                               ; preds = %19, %._crit_edge
  %23 = icmp slt i32 %5, %.lcssa
  br i1 %23, label %24, label %36

24:                                               ; preds = %22
  %25 = load i32, ptr @od, align 4, !tbaa !5
  %.not = icmp sgt i32 %25, %7
  br i1 %.not, label %26, label %36

26:                                               ; preds = %24
  %27 = and i32 %5, 1
  %.not4.not = icmp ne i32 %27, 0
  %28 = load i32, ptr @ev, align 4
  %.not5 = icmp sgt i32 %28, %7
  %or.cond = select i1 %.not4.not, i1 true, i1 %.not5
  br i1 %or.cond, label %29, label %36

29:                                               ; preds = %26
  %30 = and i32 %6, 1
  %.not6.not = icmp eq i32 %30, 0
  br i1 %.not6.not, label %31, label %36

31:                                               ; preds = %29
  %32 = icmp eq i32 %27, 0
  %33 = icmp slt i32 %9, %28
  %34 = select i1 %32, i1 true, i1 %33
  %35 = select i1 %34, ptr @.str.2, ptr @.str.3
  br label %36

36:                                               ; preds = %26, %22, %29, %31, %24, %19
  %37 = phi ptr [ @.str.2, %19 ], [ @.str.3, %22 ], [ @.str.2, %24 ], [ @.str.3, %29 ], [ %35, %31 ], [ @.str.2, %26 ]
  %38 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %37)
  ret i32 0
}

; 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: 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 @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" }
attributes #2 = { mustprogress 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"}


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