; LLVM IR from DionysiosB/CodeForces :: 0500-0599 (584B-KolyaAndTanya)

; 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 [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 i64, align 8
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 1000000007, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 1, 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
  br label %10

10:                                               ; preds = %21, %0
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = mul nsw i64 3, %12
  %14 = icmp slt i64 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %24

16:                                               ; preds = %10
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = mul nsw i64 %17, 3
  store i64 %18, ptr %4, align 8, !tbaa !5
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = srem i64 %19, 1000000007
  store i64 %20, ptr %4, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %16
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !9

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 1, 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 %25

25:                                               ; preds = %35, %24
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = icmp slt i64 %26, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %25
  %31 = load i64, ptr %6, align 8, !tbaa !5
  %32 = mul nsw i64 %31, 7
  store i64 %32, ptr %6, align 8, !tbaa !5
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = srem i64 %33, 1000000007
  store i64 %34, ptr %6, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %30
  %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 %25, !llvm.loop !11

38:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = add nsw i64 1000000007, %39
  %41 = load i64, ptr %6, align 8, !tbaa !5
  %42 = sub nsw i64 %40, %41
  %43 = srem i64 %42, 1000000007
  store i64 %43, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %8, align 8, !tbaa !5
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %44)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #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
  ret i32 0
}

; 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 @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 = { 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}


; 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 [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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %5 = mul i64 %3, 3
  %smax = call i64 @llvm.smax.i64(i64 %5, i64 1)
  %xtraiter = and i64 %smax, 3
  %6 = icmp slt i64 %5, 4
  br i1 %6, label %.preheader.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %smax, 9223372036854775804
  br label %.lr.ph

.preheader.unr-lcssa:                             ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa27.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %.015.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.unr-lcssa, %.lr.ph.epil
  %.015.epil = phi i64 [ %8, %.lr.ph.epil ], [ %.015.unr, %.preheader.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader.unr-lcssa ]
  %7 = mul nsw i64 %.015.epil, 3
  %8 = srem i64 %7, 1000000007
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader, label %.lr.ph.epil, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph.epil, %.preheader.unr-lcssa
  %.lcssa27 = phi i64 [ %.lcssa27.ph, %.preheader.unr-lcssa ], [ %8, %.lr.ph.epil ]
  %9 = add nsw i64 %.lcssa27, 1000000007
  br i1 %4, label %.lr.ph19.preheader, label %._crit_edge

.lr.ph19.preheader:                               ; preds = %.preheader
  %xtraiter29 = and i64 %3, 3
  %10 = icmp ult i64 %3, 4
  br i1 %10, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph19.preheader.new

.lr.ph19.preheader.new:                           ; preds = %.lr.ph19.preheader
  %unroll_iter33 = and i64 %3, 9223372036854775804
  br label %.lr.ph19

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.015 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %18, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %11 = mul nsw i64 %.015, 3
  %12 = srem i64 %11, 1000000007
  %13 = mul nsw i64 %12, 3
  %14 = srem i64 %13, 1000000007
  %15 = mul nsw i64 %14, 3
  %16 = srem i64 %15, 1000000007
  %17 = mul nsw i64 %16, 3
  %18 = srem i64 %17, 1000000007
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.unr-lcssa, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph19, %.lr.ph19.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph19.preheader ], [ %31, %.lr.ph19 ]
  %.01217.unr = phi i64 [ 1, %.lr.ph19.preheader ], [ %31, %.lr.ph19 ]
  %lcmp.mod31.not = icmp eq i64 %xtraiter29, 0
  br i1 %lcmp.mod31.not, label %._crit_edge, label %.lr.ph19.epil

.lr.ph19.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph19.epil
  %.01217.epil = phi i64 [ %20, %.lr.ph19.epil ], [ %.01217.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter30 = phi i64 [ %epil.iter30.next, %.lr.ph19.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %19 = mul nsw i64 %.01217.epil, 7
  %20 = srem i64 %19, 1000000007
  %epil.iter30.next = add i64 %epil.iter30, 1
  %epil.iter30.cmp.not = icmp eq i64 %epil.iter30.next, %xtraiter29
  br i1 %epil.iter30.cmp.not, label %._crit_edge, label %.lr.ph19.epil, !llvm.loop !13

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph19.epil, %0, %.preheader
  %.0.lcssa24 = phi i64 [ %9, %.preheader ], [ 1000000008, %0 ], [ %9, %.lr.ph19.epil ], [ %9, %._crit_edge.loopexit.unr-lcssa ]
  %.012.lcssa = phi i64 [ 1, %.preheader ], [ 1, %0 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %20, %.lr.ph19.epil ]
  %21 = sub nsw i64 %.0.lcssa24, %.012.lcssa
  %22 = srem i64 %21, 1000000007
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %22)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0

.lr.ph19:                                         ; preds = %.lr.ph19, %.lr.ph19.preheader.new
  %.01217 = phi i64 [ 1, %.lr.ph19.preheader.new ], [ %31, %.lr.ph19 ]
  %niter34 = phi i64 [ 0, %.lr.ph19.preheader.new ], [ %niter34.next.3, %.lr.ph19 ]
  %24 = mul nsw i64 %.01217, 7
  %25 = srem i64 %24, 1000000007
  %26 = mul nsw i64 %25, 7
  %27 = srem i64 %26, 1000000007
  %28 = mul nsw i64 %27, 7
  %29 = srem i64 %28, 1000000007
  %30 = mul nsw i64 %29, 7
  %31 = srem i64 %30, 1000000007
  %niter34.next.3 = add i64 %niter34, 4
  %niter34.ncmp.3 = icmp eq i64 %niter34.next.3, %unroll_iter33
  br i1 %niter34.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph19, !llvm.loop !14
}

; 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 @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) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !12}


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