; LLVM IR from DionysiosB/CodeForces :: 0800-0899 (839B-GameOfRows)

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

@.str = external hidden unnamed_addr constant [8 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 [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %35, %0
  %14 = load i64, ptr %7, align 8, !tbaa !5
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %38

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %8)
  %20 = load i64, ptr %8, align 8, !tbaa !5
  %21 = sdiv i64 %20, 4
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = add nsw i64 %22, %21
  store i64 %23, ptr %4, align 8, !tbaa !5
  %24 = load i64, ptr %8, align 8, !tbaa !5
  %25 = srem i64 %24, 4
  store i64 %25, ptr %8, align 8, !tbaa !5
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = sdiv i64 %26, 2
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = add nsw i64 %28, %27
  store i64 %29, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = srem i64 %30, 2
  store i64 %31, ptr %8, align 8, !tbaa !5
  %32 = load i64, ptr %8, align 8, !tbaa !5
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = add nsw i64 %33, %32
  store i64 %34, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %35

35:                                               ; preds = %18
  %36 = load i64, ptr %7, align 8, !tbaa !5
  %37 = add nsw i64 %36, 1
  store i64 %37, ptr %7, align 8, !tbaa !5
  br label %13, !llvm.loop !9

38:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %39 = load i64, ptr %2, align 8, !tbaa !5
  %40 = mul nsw i64 2, %39
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = icmp sge i64 %41, %42
  %44 = zext i1 %43 to i64
  %45 = select i1 %43, i32 1, i32 2
  %46 = sext i32 %45 to i64
  %47 = load i64, ptr %2, align 8, !tbaa !5
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = sub nsw i64 %47, %48
  %50 = mul nsw i64 %46, %49
  %51 = add nsw i64 %40, %50
  store i64 %51, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %52 = load i64, ptr %2, align 8, !tbaa !5
  %53 = load i64, ptr %4, align 8, !tbaa !5
  %54 = icmp sge i64 %52, %53
  %55 = zext i1 %54 to i64
  %56 = load i64, ptr %2, align 8, !tbaa !5
  %57 = load i64, ptr %4, align 8, !tbaa !5
  %58 = sub nsw i64 %56, %57
  %59 = mul nsw i64 %55, %58
  %60 = load i64, ptr %9, align 8, !tbaa !5
  %61 = load i64, ptr %5, align 8, !tbaa !5
  %62 = icmp sgt i64 %60, %61
  %63 = zext i1 %62 to i64
  %64 = load i64, ptr %9, align 8, !tbaa !5
  %65 = load i64, ptr %5, align 8, !tbaa !5
  %66 = sub nsw i64 %64, %65
  %67 = mul nsw i64 %63, %66
  %68 = add nsw i64 %59, %67
  store i64 %68, ptr %10, align 8, !tbaa !5
  %69 = load i64, ptr %5, align 8, !tbaa !5
  %70 = load i64, ptr %9, align 8, !tbaa !5
  %71 = icmp sgt i64 %69, %70
  %72 = zext i1 %71 to i32
  %73 = mul nsw i32 2, %72
  %74 = sext i32 %73 to i64
  %75 = load i64, ptr %5, align 8, !tbaa !5
  %76 = load i64, ptr %9, align 8, !tbaa !5
  %77 = sub nsw i64 %75, %76
  %78 = mul nsw i64 %74, %77
  %79 = load i64, ptr %6, align 8, !tbaa !5
  %80 = add nsw i64 %79, %78
  store i64 %80, ptr %6, align 8, !tbaa !5
  %81 = load i64, ptr %6, align 8, !tbaa !5
  %82 = load i64, ptr %10, align 8, !tbaa !5
  %83 = icmp sgt i64 %81, %82
  br i1 %83, label %84, label %86

84:                                               ; preds = %38
  %85 = call i32 @puts(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %11, align 4
  br label %88

86:                                               ; preds = %38
  %87 = call i32 @puts(ptr noundef @.str.3)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %11, align 4
  br label %88

88:                                               ; preds = %86, %84
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %89 = load i32, ptr %1, align 4
  ret i32 %89
}

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

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

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

declare i32 @puts(ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #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 = !{!"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"

@.str = external hidden unnamed_addr constant [8 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 [4 x i8], align 1

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

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.024.lcssa = phi i64 [ 0, %0 ], [ %31, %.lr.ph ]
  %.023.lcssa = phi i64 [ 0, %0 ], [ %33, %.lr.ph ]
  %.021.lcssa = phi i64 [ 0, %0 ], [ %28, %.lr.ph ]
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = shl nsw i64 %7, 1
  %.not = icmp slt i64 %7, %.021.lcssa
  %9 = sub nsw i64 %7, %.021.lcssa
  %10 = zext i1 %.not to i64
  %11 = shl i64 %9, %10
  %12 = add nsw i64 %11, %8
  %13 = select i1 %.not, i64 0, i64 %9
  %14 = icmp sgt i64 %12, %.024.lcssa
  %15 = sub nsw i64 %12, %.024.lcssa
  %16 = select i1 %14, i64 %15, i64 0
  %17 = add nsw i64 %16, %13
  %18 = icmp sgt i64 %.024.lcssa, %12
  %19 = select i1 %18, i64 2, i64 0
  %20 = sub nsw i64 %.024.lcssa, %12
  %21 = mul nsw i64 %19, %20
  %22 = add nsw i64 %21, %.023.lcssa
  %23 = icmp sgt i64 %22, %17
  %.str.2..str.3 = select i1 %23, ptr @.str.2, ptr @.str.3
  %24 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.2..str.3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i32 0

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.02130 = phi i64 [ %28, %.lr.ph ], [ 0, %0 ]
  %.02229 = phi i64 [ %34, %.lr.ph ], [ 0, %0 ]
  %.02328 = phi i64 [ %33, %.lr.ph ], [ 0, %0 ]
  %.02427 = phi i64 [ %31, %.lr.ph ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = sdiv i64 %26, 4
  %28 = add nsw i64 %27, %.02130
  %29 = srem i64 %26, 4
  %.lhs.trunc = trunc nsw i64 %29 to i8
  %30 = sdiv i8 %.lhs.trunc, 2
  %.sext = sext i8 %30 to i64
  %31 = add nsw i64 %.02427, %.sext
  %32 = srem i8 %.lhs.trunc, 2
  %.sext26 = sext i8 %32 to i64
  %33 = add nsw i64 %.02328, %.sext26
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %34 = add nuw nsw i64 %.02229, 1
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = icmp slt i64 %34, %35
  br i1 %36, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"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: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass