; LLVM IR from DionysiosB/CodeForces :: 0400-0499 (478D-RedGreenTowers)

; 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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 [400007 x i64], align 16
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 1000000007, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 400007, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %25, %0
  %16 = load i64, ptr %6, align 8, !tbaa !5
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = add nsw i64 %17, 1
  %19 = mul nsw i64 %16, %18
  %20 = sdiv i64 %19, 2
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = add nsw i64 %21, %22
  %24 = icmp sle i64 %20, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %15
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = add nsw i64 %26, 1
  store i64 %27, ptr %6, align 8, !tbaa !5
  br label %15, !llvm.loop !9

28:                                               ; preds = %15
  %29 = load i64, ptr %6, align 8, !tbaa !5
  %30 = add nsw i64 %29, -1
  store i64 %30, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 3200056, ptr %7) #4
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 3200056, i1 false)
  %31 = getelementptr inbounds [400007 x i64], ptr %7, i64 0, i64 0
  store i64 1, ptr %31, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 1, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %62, %28
  %33 = load i64, ptr %8, align 8, !tbaa !5
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = icmp sle i64 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 4, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %65

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %38 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %38, ptr %10, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %58, %37
  %40 = load i64, ptr %10, align 8, !tbaa !5
  %41 = icmp sge i64 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %39
  store i32 7, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %61

43:                                               ; preds = %39
  %44 = load i64, ptr %8, align 8, !tbaa !5
  %45 = load i64, ptr %10, align 8, !tbaa !5
  %46 = add nsw i64 %44, %45
  %47 = getelementptr inbounds [400007 x i64], ptr %7, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = load i64, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds [400007 x i64], ptr %7, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = add nsw i64 %48, %51
  %53 = srem i64 %52, 1000000007
  %54 = load i64, ptr %8, align 8, !tbaa !5
  %55 = load i64, ptr %10, align 8, !tbaa !5
  %56 = add nsw i64 %54, %55
  %57 = getelementptr inbounds [400007 x i64], ptr %7, i64 0, i64 %56
  store i64 %53, ptr %57, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %43
  %59 = load i64, ptr %10, align 8, !tbaa !5
  %60 = add nsw i64 %59, -1
  store i64 %60, ptr %10, align 8, !tbaa !5
  br label %39, !llvm.loop !11

61:                                               ; preds = %42
  br label %62

62:                                               ; preds = %61
  %63 = load i64, ptr %8, align 8, !tbaa !5
  %64 = add nsw i64 %63, 1
  store i64 %64, ptr %8, align 8, !tbaa !5
  br label %32, !llvm.loop !12

65:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %66 = load i64, ptr %6, align 8, !tbaa !5
  %67 = load i64, ptr %6, align 8, !tbaa !5
  %68 = add nsw i64 %67, 1
  %69 = mul nsw i64 %66, %68
  %70 = sdiv i64 %69, 2
  %71 = load i64, ptr %5, align 8, !tbaa !5
  %72 = sub nsw i64 %70, %71
  store i64 %72, ptr %12, align 8, !tbaa !5
  %73 = load i64, ptr %12, align 8, !tbaa !5
  %74 = icmp slt i64 %73, 0
  br i1 %74, label %75, label %76

75:                                               ; preds = %65
  store i64 0, ptr %12, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %75, %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %77 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %77, ptr %13, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %90, %76
  %79 = load i64, ptr %13, align 8, !tbaa !5
  %80 = load i64, ptr %4, align 8, !tbaa !5
  %81 = icmp sle i64 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %78
  store i32 10, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %93

83:                                               ; preds = %78
  %84 = load i64, ptr %11, align 8, !tbaa !5
  %85 = load i64, ptr %13, align 8, !tbaa !5
  %86 = getelementptr inbounds [400007 x i64], ptr %7, i64 0, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !5
  %88 = add nsw i64 %84, %87
  %89 = srem i64 %88, 1000000007
  store i64 %89, ptr %11, align 8, !tbaa !5
  br label %90

90:                                               ; preds = %83
  %91 = load i64, ptr %13, align 8, !tbaa !5
  %92 = add nsw i64 %91, 1
  store i64 %92, ptr %13, align 8, !tbaa !5
  br label %78, !llvm.loop !13

93:                                               ; preds = %82
  %94 = load i64, ptr %11, align 8, !tbaa !5
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %94)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 3200056, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %96 = load i32, ptr %1, align 4
  ret i32 %96
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

declare i32 @printf(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; 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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 [400007 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = add nsw i64 %6, %5
  br label %8

8:                                                ; preds = %8, %0
  %.027 = phi i64 [ 0, %0 ], [ %9, %8 ]
  %9 = add nuw nsw i64 %.027, 1
  %10 = mul nuw nsw i64 %9, %.027
  %11 = lshr i64 %10, 1
  %.not = icmp sgt i64 %11, %7
  br i1 %.not, label %12, label %8, !llvm.loop !9

12:                                               ; preds = %8
  %13 = add nsw i64 %.027, -1
  call void @llvm.lifetime.start.p0(i64 3200056, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(3200056) %3, i8 0, i64 3200056, i1 false)
  store i64 1, ptr %3, align 16, !tbaa !5
  %.not29.not33 = icmp ugt i64 %.027, 1
  %14 = icmp sgt i64 %5, -1
  %or.cond = and i1 %.not29.not33, %14
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge35

.preheader.us.preheader:                          ; preds = %12
  %15 = and i64 %5, 1
  %lcmp.mod.not.not = icmp eq i64 %15, 0
  %16 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %5
  %17 = add nsw i64 %5, -1
  %18 = icmp eq i64 %5, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.02634.us = phi i64 [ %42, %._crit_edge.us ], [ 1, %.preheader.us.preheader ]
  br i1 %lcmp.mod.not.not, label %.prol.loopexit.unr-lcssa, label %.prol.loopexit

.prol.loopexit.unr-lcssa:                         ; preds = %.preheader.us
  %19 = add nuw nsw i64 %5, %.02634.us
  %20 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = load i64, ptr %16, align 8, !tbaa !5
  %23 = add nsw i64 %22, %21
  %24 = srem i64 %23, 1000000007
  store i64 %24, ptr %20, align 8, !tbaa !5
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.preheader.us
  %.02532.us.unr = phi i64 [ %5, %.preheader.us ], [ %17, %.prol.loopexit.unr-lcssa ]
  br i1 %18, label %._crit_edge.us, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.prol.loopexit, %.preheader.us.new
  %.02532.us = phi i64 [ %40, %.preheader.us.new ], [ %.02532.us.unr, %.prol.loopexit ]
  %25 = add nuw nsw i64 %.02532.us, %.02634.us
  %26 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %.02532.us
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = add nsw i64 %29, %27
  %31 = srem i64 %30, 1000000007
  store i64 %31, ptr %26, align 8, !tbaa !5
  %32 = add nsw i64 %.02532.us, -1
  %33 = add nuw nsw i64 %32, %.02634.us
  %34 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %32
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = add nsw i64 %37, %35
  %39 = srem i64 %38, 1000000007
  store i64 %39, ptr %34, align 8, !tbaa !5
  %40 = add nsw i64 %.02532.us, -2
  %41 = icmp sgt i64 %.02532.us, 1
  br i1 %41, label %.preheader.us.new, label %._crit_edge.us, !llvm.loop !11

._crit_edge.us:                                   ; preds = %.preheader.us.new, %.prol.loopexit
  %42 = add nuw nsw i64 %.02634.us, 1
  %exitcond.not = icmp eq i64 %42, %.027
  br i1 %exitcond.not, label %._crit_edge35, label %.preheader.us, !llvm.loop !12

._crit_edge35:                                    ; preds = %._crit_edge.us, %12
  %43 = mul nsw i64 %13, %.027
  %44 = sdiv i64 %43, 2
  %45 = sub nsw i64 %44, %6
  %spec.store.select = call i64 @llvm.smax.i64(i64 %45, i64 0)
  %.not3036 = icmp sgt i64 %spec.store.select, %5
  br i1 %.not3036, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %._crit_edge35
  %46 = add i64 %5, 1
  %47 = sub i64 %46, %spec.store.select
  %xtraiter42 = and i64 %47, 1
  %48 = icmp eq i64 %5, %spec.store.select
  br i1 %48, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %47, -2
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %62, %.lr.ph ]
  %.038.unr = phi i64 [ %spec.store.select, %.lr.ph.preheader ], [ %63, %.lr.ph ]
  %.02437.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %62, %.lr.ph ]
  %lcmp.mod43.not = icmp eq i64 %xtraiter42, 0
  br i1 %lcmp.mod43.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %49 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %.038.unr
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = add nsw i64 %50, %.02437.unr
  %52 = srem i64 %51, 1000000007
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %._crit_edge35
  %.024.lcssa = phi i64 [ 0, %._crit_edge35 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %52, %.lr.ph.epil ]
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.024.lcssa)
  call void @llvm.lifetime.end.p0(i64 3200056, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.038 = phi i64 [ %spec.store.select, %.lr.ph.preheader.new ], [ %63, %.lr.ph ]
  %.02437 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %62, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %54 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %.038
  %55 = load i64, ptr %54, align 8, !tbaa !5
  %56 = add nsw i64 %55, %.02437
  %57 = srem i64 %56, 1000000007
  %58 = add nuw i64 %.038, 1
  %59 = getelementptr inbounds [400007 x i64], ptr %3, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !5
  %61 = add nsw i64 %60, %57
  %62 = srem i64 %61, 1000000007
  %63 = add nuw i64 %.038, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #4

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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