; LLVM IR from tangjz/acm-icpc :: codeforces/complete (963A)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = call noundef i32 @_Z7mod_powii(i32 noundef %15, i32 noundef 1000000007)
  %17 = sext i32 %16 to i64
  %18 = mul nsw i64 %14, %17
  %19 = srem i64 %18, 1000000009
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = call noundef i32 @_Z7mod_powii(i32 noundef %21, i32 noundef %22)
  store i32 %23, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %32

26:                                               ; preds = %0
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sdiv i32 %28, %29
  %31 = sext i32 %30 to i64
  br label %47

32:                                               ; preds = %0
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sdiv i32 %35, %36
  %38 = call noundef i32 @_Z7mod_powii(i32 noundef %33, i32 noundef %37)
  %39 = sext i32 %38 to i64
  %40 = sub nsw i64 %39, 1
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  %43 = call noundef i32 @_Z7mod_powii(i32 noundef %42, i32 noundef 1000000007)
  %44 = sext i32 %43 to i64
  %45 = mul nsw i64 %40, %44
  %46 = srem i64 %45, 1000000009
  br label %47

47:                                               ; preds = %32, %26
  %48 = phi i64 [ %31, %26 ], [ %46, %32 ]
  %49 = trunc i64 %48 to i32
  store i32 %49, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %90, %47
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %93

55:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %56 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %11)
  %57 = load i8, ptr %11, align 1, !tbaa !9
  %58 = sext i8 %57 to i32
  %59 = icmp eq i32 %58, 43
  br i1 %59, label %60, label %71

60:                                               ; preds = %55
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = add nsw i32 %62, %61
  store i32 %63, ptr %9, align 4, !tbaa !5
  %64 = icmp sge i32 %63, 1000000009
  br i1 %64, label %65, label %69

65:                                               ; preds = %60
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = sub nsw i32 %66, 1000000009
  store i32 %67, ptr %9, align 4, !tbaa !5
  %68 = icmp ne i32 %67, 0
  br label %69

69:                                               ; preds = %65, %60
  %70 = phi i1 [ false, %60 ], [ %68, %65 ]
  br label %82

71:                                               ; preds = %55
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = sub nsw i32 %73, %72
  store i32 %74, ptr %9, align 4, !tbaa !5
  %75 = icmp slt i32 %74, 0
  br i1 %75, label %76, label %80

76:                                               ; preds = %71
  %77 = load i32, ptr %9, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1000000009
  store i32 %78, ptr %9, align 4, !tbaa !5
  %79 = icmp ne i32 %78, 0
  br label %80

80:                                               ; preds = %76, %71
  %81 = phi i1 [ false, %71 ], [ %79, %76 ]
  br label %82

82:                                               ; preds = %80, %69
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = mul nsw i64 %84, %86
  %88 = srem i64 %87, 1000000009
  %89 = trunc i64 %88 to i32
  store i32 %89, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  br label %90

90:                                               ; preds = %82
  %91 = load i32, ptr %10, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %10, align 4, !tbaa !5
  br label %50, !llvm.loop !10

93:                                               ; preds = %54
  %94 = load i32, ptr %9, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = load i32, ptr %2, align 4, !tbaa !5
  %98 = call noundef i32 @_Z7mod_powii(i32 noundef %96, i32 noundef %97)
  %99 = sext i32 %98 to i64
  %100 = mul nsw i64 %95, %99
  %101 = srem i64 %100, 1000000009
  %102 = trunc i64 %101 to i32
  store i32 %102, ptr %9, align 4, !tbaa !5
  %103 = load i32, ptr %9, align 4, !tbaa !5
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %103)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

declare i32 @printf(ptr noundef, ...) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = call noundef i32 @_Z7mod_powii(i32 noundef %9, i32 noundef 1000000007)
  %11 = sext i32 %10 to i64
  %12 = mul nsw i64 %11, %8
  %13 = srem i64 %12, 1000000009
  %14 = trunc nsw i64 %13 to i32
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call noundef i32 @_Z7mod_powii(i32 noundef %14, i32 noundef %15)
  %17 = icmp eq i32 %16, 1
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sdiv i32 %19, %20
  br i1 %17, label %32, label %22

22:                                               ; preds = %0
  %23 = call noundef i32 @_Z7mod_powii(i32 noundef %16, i32 noundef %21)
  %24 = sext i32 %23 to i64
  %25 = add nsw i64 %24, -1
  %26 = add nsw i32 %16, -1
  %27 = call noundef i32 @_Z7mod_powii(i32 noundef %26, i32 noundef 1000000007)
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %25, %28
  %30 = srem i64 %29, 1000000009
  %31 = trunc nsw i64 %30 to i32
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %0, %22
  %33 = phi i32 [ %.pre, %22 ], [ %20, %0 ]
  %34 = phi i32 [ %31, %22 ], [ %21, %0 ]
  %35 = icmp sgt i32 %33, 0
  br i1 %35, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %56
  %36 = sext i32 %.1 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %32
  %.016.lcssa = phi i64 [ 0, %32 ], [ %36, %._crit_edge.loopexit ]
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = load i32, ptr %1, align 4, !tbaa !5
  %39 = call noundef i32 @_Z7mod_powii(i32 noundef %37, i32 noundef %38)
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %.016.lcssa, %40
  %42 = srem i64 %41, 1000000009
  %43 = trunc nsw i64 %42 to i32
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %43)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0

.lr.ph:                                           ; preds = %32, %56
  %.026 = phi i32 [ %61, %56 ], [ 0, %32 ]
  %.01625 = phi i32 [ %.1, %56 ], [ 0, %32 ]
  %.01724 = phi i32 [ %60, %56 ], [ %34, %32 ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #4
  %45 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %5)
  %46 = load i8, ptr %5, align 1, !tbaa !9
  %47 = icmp eq i8 %46, 43
  br i1 %47, label %48, label %52

48:                                               ; preds = %.lr.ph
  %49 = add nsw i32 %.01625, %.01724
  %50 = icmp sgt i32 %49, 1000000008
  %51 = add nsw i32 %49, -1000000009
  %spec.select = select i1 %50, i32 %51, i32 %49
  br label %56

52:                                               ; preds = %.lr.ph
  %53 = sub nsw i32 %.01625, %.01724
  %54 = icmp slt i32 %53, 0
  %55 = add nsw i32 %53, 1000000009
  %spec.select23 = select i1 %54, i32 %55, i32 %53
  br label %56

56:                                               ; preds = %52, %48
  %.1 = phi i32 [ %spec.select, %48 ], [ %spec.select23, %52 ]
  %57 = sext i32 %.01724 to i64
  %58 = mul nsw i64 %13, %57
  %59 = srem i64 %58, 1000000009
  %60 = trunc nsw i64 %59 to i32
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #4
  %61 = add nuw nsw i32 %.026, 1
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !10
}

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

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

attributes #0 = { mustprogress 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 = { mustprogress 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 #3 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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