; LLVM IR from DionysiosB/CodeForces :: 1300-1399 (1391C-CyclicPermutations)

; 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 [5 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 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 1, 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 = icmp sle i64 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = mul nsw i64 %17, %16
  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 = %15
  %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 = %14
  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 1, 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, 2
  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 3000000021, %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.1, 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 [5 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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %.not15 = icmp slt i64 %3, 1
  br i1 %.not15, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %4 = add nsw i64 %3, -1
  %xtraiter = and i64 %3, 3
  %5 = icmp ult i64 %3, 4
  br i1 %5, label %.preheader.unr-lcssa, label %.lr.ph.preheader.new

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

.preheader.unr-lcssa:                             ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa29.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %22, %.lr.ph ]
  %.017.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %22, %.lr.ph ]
  %.01416.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %23, %.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
  %.017.epil = phi i64 [ %7, %.lr.ph.epil ], [ %.017.unr, %.preheader.unr-lcssa ]
  %.01416.epil = phi i64 [ %8, %.lr.ph.epil ], [ %.01416.unr, %.preheader.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader.unr-lcssa ]
  %6 = mul nsw i64 %.017.epil, %.01416.epil
  %7 = srem i64 %6, 1000000007
  %8 = add nuw i64 %.01416.epil, 1
  %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
  %.lcssa29 = phi i64 [ %.lcssa29.ph, %.preheader.unr-lcssa ], [ %7, %.lr.ph.epil ]
  %9 = add nsw i64 %.lcssa29, 3000000021
  %.not = icmp eq i64 %3, 1
  br i1 %.not, label %._crit_edge, label %.lr.ph21.preheader

.lr.ph21.preheader:                               ; preds = %.preheader
  %10 = add nsw i64 %3, -2
  %xtraiter31 = and i64 %4, 3
  %11 = icmp ult i64 %10, 3
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph21.preheader.new

.lr.ph21.preheader.new:                           ; preds = %.lr.ph21.preheader
  %unroll_iter35 = and i64 %4, -4
  br label %.lr.ph21

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.017 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %22, %.lr.ph ]
  %.01416 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %23, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %12 = mul nsw i64 %.017, %.01416
  %13 = srem i64 %12, 1000000007
  %14 = add nuw nsw i64 %.01416, 1
  %15 = mul nsw i64 %13, %14
  %16 = srem i64 %15, 1000000007
  %17 = add nuw nsw i64 %.01416, 2
  %18 = mul nsw i64 %16, %17
  %19 = srem i64 %18, 1000000007
  %20 = add nuw i64 %.01416, 3
  %21 = mul nsw i64 %19, %20
  %22 = srem i64 %21, 1000000007
  %23 = add nuw i64 %.01416, 4
  %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.ph21, %.lr.ph21.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph21.preheader ], [ %36, %.lr.ph21 ]
  %.01319.unr = phi i64 [ 1, %.lr.ph21.preheader ], [ %36, %.lr.ph21 ]
  %lcmp.mod33.not = icmp eq i64 %xtraiter31, 0
  br i1 %lcmp.mod33.not, label %._crit_edge, label %.lr.ph21.epil

.lr.ph21.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph21.epil
  %.01319.epil = phi i64 [ %25, %.lr.ph21.epil ], [ %.01319.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter32 = phi i64 [ %epil.iter32.next, %.lr.ph21.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %24 = shl nsw i64 %.01319.epil, 1
  %25 = srem i64 %24, 1000000007
  %epil.iter32.next = add i64 %epil.iter32, 1
  %epil.iter32.cmp.not = icmp eq i64 %epil.iter32.next, %xtraiter31
  br i1 %epil.iter32.cmp.not, label %._crit_edge, label %.lr.ph21.epil, !llvm.loop !13

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph21.epil, %0, %.preheader
  %.0.lcssa26 = phi i64 [ %9, %.preheader ], [ 3000000022, %0 ], [ %9, %.lr.ph21.epil ], [ %9, %._crit_edge.loopexit.unr-lcssa ]
  %.013.lcssa = phi i64 [ 1, %.preheader ], [ 1, %0 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %25, %.lr.ph21.epil ]
  %26 = sub nsw i64 %.0.lcssa26, %.013.lcssa
  %27 = srem i64 %26, 1000000007
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %27)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i32 0

.lr.ph21:                                         ; preds = %.lr.ph21, %.lr.ph21.preheader.new
  %.01319 = phi i64 [ 1, %.lr.ph21.preheader.new ], [ %36, %.lr.ph21 ]
  %niter36 = phi i64 [ 0, %.lr.ph21.preheader.new ], [ %niter36.next.3, %.lr.ph21 ]
  %29 = shl nsw i64 %.01319, 1
  %30 = srem i64 %29, 1000000007
  %31 = shl nsw i64 %30, 1
  %32 = srem i64 %31, 1000000007
  %33 = shl nsw i64 %32, 1
  %34 = srem i64 %33, 1000000007
  %35 = shl nsw i64 %34, 1
  %36 = srem i64 %35, 1000000007
  %niter36.next.3 = add i64 %niter36, 4
  %niter36.ncmp.3 = icmp eq i64 %niter36.next.3, %unroll_iter35
  br i1 %niter36.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph21, !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

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