; LLVM IR from DionysiosB/CodeForces :: 0100-0199 (150B-QuantityOfStrings)

; 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 [15 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 1, ptr %6, align 8, !tbaa !5
  %10 = load i64, ptr %5, align 8, !tbaa !5
  %11 = icmp eq i64 %10, 1
  br i1 %11, label %16, label %12

12:                                               ; preds = %0
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = icmp sgt i64 %13, %14
  br i1 %15, label %16, label %31

16:                                               ; preds = %12, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %27, %16
  %18 = load i64, ptr %7, align 8, !tbaa !5
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %17
  %23 = load i64, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = mul nsw i64 %23, %24
  %26 = srem i64 %25, 1000000007
  store i64 %26, ptr %6, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %22
  %28 = load i64, ptr %7, align 8, !tbaa !5
  %29 = add nsw i64 %28, 1
  store i64 %29, ptr %7, align 8, !tbaa !5
  br label %17, !llvm.loop !9

30:                                               ; preds = %21
  br label %70

31:                                               ; preds = %12
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = icmp eq i64 %32, %33
  br i1 %34, label %35, label %52

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %48, %35
  %37 = load i64, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = add nsw i64 %38, 1
  %40 = sdiv i64 %39, 2
  %41 = icmp slt i64 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %51

43:                                               ; preds = %36
  %44 = load i64, ptr %6, align 8, !tbaa !5
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = mul nsw i64 %44, %45
  %47 = srem i64 %46, 1000000007
  store i64 %47, ptr %6, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %43
  %49 = load i64, ptr %8, align 8, !tbaa !5
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr %8, align 8, !tbaa !5
  br label %36, !llvm.loop !11

51:                                               ; preds = %42
  br label %69

52:                                               ; preds = %31
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = srem i64 %53, 2
  %55 = icmp eq i64 %54, 1
  br i1 %55, label %56, label %61

56:                                               ; preds = %52
  %57 = load i64, ptr %4, align 8, !tbaa !5
  %58 = load i64, ptr %4, align 8, !tbaa !5
  %59 = mul nsw i64 %57, %58
  %60 = srem i64 %59, 1000000007
  store i64 %60, ptr %6, align 8, !tbaa !5
  br label %68

61:                                               ; preds = %52
  %62 = load i64, ptr %5, align 8, !tbaa !5
  %63 = srem i64 %62, 2
  %64 = icmp eq i64 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %61
  %66 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %66, ptr %6, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %65, %61
  br label %68

68:                                               ; preds = %67, %56
  br label %69

69:                                               ; preds = %68, %51
  br label %70

70:                                               ; preds = %69, %30
  %71 = load i64, ptr %6, align 8, !tbaa !5
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %71)
  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
  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 [15 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 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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %5 = load i64, ptr %3, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 1
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  %7 = icmp sgt i64 %5, %.pre
  %or.cond = select i1 %6, i1 true, i1 %7
  br i1 %or.cond, label %8, label %21

8:                                                ; preds = %0
  %9 = icmp sgt i64 %.pre, 0
  br i1 %9, label %.lr.ph17, label %.loopexit

.lr.ph17:                                         ; preds = %8
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %xtraiter30 = and i64 %.pre, 3
  %11 = icmp ult i64 %.pre, 4
  br i1 %11, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph17.new

.lr.ph17.new:                                     ; preds = %.lr.ph17
  %unroll_iter34 = and i64 %.pre, 9223372036854775804
  br label %12

12:                                               ; preds = %12, %.lr.ph17.new
  %.0815 = phi i64 [ 1, %.lr.ph17.new ], [ %20, %12 ]
  %niter35 = phi i64 [ 0, %.lr.ph17.new ], [ %niter35.next.3, %12 ]
  %13 = mul nsw i64 %10, %.0815
  %14 = srem i64 %13, 1000000007
  %15 = mul nsw i64 %10, %14
  %16 = srem i64 %15, 1000000007
  %17 = mul nsw i64 %10, %16
  %18 = srem i64 %17, 1000000007
  %19 = mul nsw i64 %10, %18
  %20 = srem i64 %19, 1000000007
  %niter35.next.3 = add i64 %niter35, 4
  %niter35.ncmp.3 = icmp eq i64 %niter35.next.3, %unroll_iter34
  br i1 %niter35.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %12, !llvm.loop !9

21:                                               ; preds = %0
  %22 = icmp eq i64 %5, %.pre
  br i1 %22, label %.preheader, label %38

.preheader:                                       ; preds = %21
  %23 = icmp sgt i64 %5, 0
  br i1 %23, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %24 = add nuw nsw i64 %5, 1
  %25 = lshr i64 %24, 1
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = add nsw i64 %25, -1
  %xtraiter = and i64 %25, 3
  %28 = icmp ult i64 %27, 3
  br i1 %28, label %.loopexit.loopexit26.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %25, 4611686018427387900
  br label %29

29:                                               ; preds = %29, %.lr.ph.new
  %.113 = phi i64 [ 1, %.lr.ph.new ], [ %37, %29 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %29 ]
  %30 = mul nsw i64 %26, %.113
  %31 = srem i64 %30, 1000000007
  %32 = mul nsw i64 %26, %31
  %33 = srem i64 %32, 1000000007
  %34 = mul nsw i64 %26, %33
  %35 = srem i64 %34, 1000000007
  %36 = mul nsw i64 %26, %35
  %37 = srem i64 %36, 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 %.loopexit.loopexit26.unr-lcssa, label %29, !llvm.loop !11

38:                                               ; preds = %21
  %39 = srem i64 %5, 2
  switch i64 %39, label %.loopexit [
    i64 1, label %40
    i64 0, label %44
  ]

40:                                               ; preds = %38
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = mul nsw i64 %41, %41
  %43 = urem i64 %42, 1000000007
  br label %.loopexit

44:                                               ; preds = %38
  %45 = load i64, ptr %2, align 8, !tbaa !5
  br label %.loopexit

.loopexit.loopexit.unr-lcssa:                     ; preds = %12, %.lr.ph17
  %.lcssa.ph = phi i64 [ poison, %.lr.ph17 ], [ %20, %12 ]
  %.0815.unr = phi i64 [ 1, %.lr.ph17 ], [ %20, %12 ]
  %lcmp.mod32.not = icmp eq i64 %xtraiter30, 0
  br i1 %lcmp.mod32.not, label %.loopexit, label %.epil.preheader29

.epil.preheader29:                                ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader29
  %.0815.epil = phi i64 [ %47, %.epil.preheader29 ], [ %.0815.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter31 = phi i64 [ %epil.iter31.next, %.epil.preheader29 ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %46 = mul nsw i64 %10, %.0815.epil
  %47 = srem i64 %46, 1000000007
  %epil.iter31.next = add i64 %epil.iter31, 1
  %epil.iter31.cmp.not = icmp eq i64 %epil.iter31.next, %xtraiter30
  br i1 %epil.iter31.cmp.not, label %.loopexit, label %.epil.preheader29, !llvm.loop !12

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

.epil.preheader:                                  ; preds = %.loopexit.loopexit26.unr-lcssa, %.epil.preheader
  %.113.epil = phi i64 [ %49, %.epil.preheader ], [ %.113.unr, %.loopexit.loopexit26.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit26.unr-lcssa ]
  %48 = mul nsw i64 %26, %.113.epil
  %49 = srem i64 %48, 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 %.loopexit, label %.epil.preheader, !llvm.loop !14

.loopexit:                                        ; preds = %.loopexit.loopexit26.unr-lcssa, %.epil.preheader, %.loopexit.loopexit.unr-lcssa, %.epil.preheader29, %.preheader, %8, %38, %44, %40
  %.2 = phi i64 [ %43, %40 ], [ %45, %44 ], [ 1, %38 ], [ 1, %8 ], [ 1, %.preheader ], [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %47, %.epil.preheader29 ], [ %.lcssa27.ph, %.loopexit.loopexit26.unr-lcssa ], [ %49, %.epil.preheader ]
  %50 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #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
}

; 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.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !13}


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