; LLVM IR from kazunetakahashi/atcoder :: 2019/0330_exawizards2019 (E2)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@inv = external dso_local global [1000010 x i64], align 16
@B = external dso_local global i64, align 8
@W = external dso_local global i64, align 8
@ans = external dso_local global [200010 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4initv() #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 nounwind uwtable
declare dso_local noundef i64 @_Z1Cii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5powerxx(i64 noundef, i64 noundef) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @_Z4initv()
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @B)
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) @W)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %7 = load i64, ptr @B, align 8, !tbaa !5
  %8 = load i64, ptr @W, align 8, !tbaa !5
  %9 = add nsw i64 %7, %8
  store i64 %9, ptr %2, align 8, !tbaa !5
  %10 = load i64, ptr getelementptr inbounds ([1000010 x i64], ptr @inv, i64 0, i64 2), align 16, !tbaa !5
  store i64 %10, ptr @ans, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %73, %0
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %76

17:                                               ; preds = %11
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %24
  store i64 %22, ptr %25, align 8, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = sub nsw i32 %26, 1
  %28 = load i64, ptr @B, align 8, !tbaa !5
  %29 = sub nsw i64 %28, 1
  %30 = trunc i64 %29 to i32
  %31 = call noundef i64 @_Z1Cii(i32 noundef %27, i32 noundef %30)
  %32 = load i64, ptr getelementptr inbounds ([1000010 x i64], ptr @inv, i64 0, i64 2), align 16, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = call noundef i64 @_Z5powerxx(i64 noundef %32, i64 noundef %35)
  %37 = mul nsw i64 %31, %36
  %38 = srem i64 %37, 1000000007
  %39 = sub nsw i64 1000000007, %38
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = add nsw i64 %43, %39
  store i64 %44, ptr %42, align 8, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = srem i64 %48, 1000000007
  store i64 %49, ptr %47, align 8, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = load i64, ptr @W, align 8, !tbaa !5
  %53 = sub nsw i64 %52, 1
  %54 = trunc i64 %53 to i32
  %55 = call noundef i64 @_Z1Cii(i32 noundef %51, i32 noundef %54)
  %56 = load i64, ptr getelementptr inbounds ([1000010 x i64], ptr @inv, i64 0, i64 2), align 16, !tbaa !5
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = call noundef i64 @_Z5powerxx(i64 noundef %56, i64 noundef %59)
  %61 = mul nsw i64 %55, %60
  %62 = srem i64 %61, 1000000007
  %63 = load i32, ptr %3, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !5
  %67 = add nsw i64 %66, %62
  store i64 %67, ptr %65, align 8, !tbaa !5
  %68 = load i32, ptr %3, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !5
  %72 = srem i64 %71, 1000000007
  store i64 %72, ptr %70, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %17
  %74 = load i32, ptr %3, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %3, align 4, !tbaa !9
  br label %11, !llvm.loop !11

76:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %90, %76
  %78 = load i32, ptr %4, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = load i64, ptr %2, align 8, !tbaa !5
  %81 = icmp slt i64 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %93

83:                                               ; preds = %77
  %84 = load i32, ptr %4, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !5
  %88 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %87)
  %89 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %88, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %90

90:                                               ; preds = %83
  %91 = load i32, ptr %4, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %4, align 4, !tbaa !9
  br label %77, !llvm.loop !13

93:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %94 = load i32, ptr %1, align 4
  ret i32 %94
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #4

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 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 = { 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 #4 = { inlinehint mustprogress 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 #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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@inv = external dso_local local_unnamed_addr global [1000010 x i64], align 16
@B = external dso_local global i64, align 8
@W = external dso_local global i64, align 8
@ans = external dso_local local_unnamed_addr global [200010 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4initv() local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5powerxx(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  tail call void @_Z4initv()
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @B)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) @W)
  %3 = load i64, ptr @B, align 8, !tbaa !5
  %4 = load i64, ptr @W, align 8, !tbaa !5
  %5 = add nsw i64 %4, %3
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @inv, i64 16), align 16, !tbaa !5
  store i64 %6, ptr @ans, align 16, !tbaa !5
  %7 = icmp sgt i64 %5, 1
  br i1 %7, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %0
  %8 = icmp sgt i64 %5, 0
  br i1 %8, label %.lr.ph24, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %9 = phi i64 [ %34, %.lr.ph ], [ %6, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %10 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %indvars.iv
  store i64 %9, ptr %10, align 8, !tbaa !5
  %11 = load i64, ptr @B, align 8, !tbaa !5
  %12 = trunc i64 %11 to i32
  %13 = add i32 %12, -1
  %14 = trunc i64 %indvars.iv to i32
  %15 = add i32 %14, -1
  %16 = tail call noundef i64 @_Z1Cii(i32 noundef %15, i32 noundef %13)
  %17 = load i64, ptr getelementptr inbounds (i8, ptr @inv, i64 16), align 16, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = tail call noundef i64 @_Z5powerxx(i64 noundef %17, i64 noundef %indvars.iv.next)
  %19 = mul nsw i64 %18, %16
  %20 = srem i64 %19, 1000000007
  %21 = load i64, ptr %10, align 8, !tbaa !5
  %reass.sub = add i64 %21, 1000000007
  %22 = sub i64 %reass.sub, %20
  %23 = srem i64 %22, 1000000007
  store i64 %23, ptr %10, align 8, !tbaa !5
  %24 = load i64, ptr @W, align 8, !tbaa !5
  %25 = trunc i64 %24 to i32
  %26 = add i32 %25, -1
  %27 = tail call noundef i64 @_Z1Cii(i32 noundef %15, i32 noundef %26)
  %28 = load i64, ptr getelementptr inbounds (i8, ptr @inv, i64 16), align 16, !tbaa !5
  %29 = tail call noundef i64 @_Z5powerxx(i64 noundef %28, i64 noundef %indvars.iv.next)
  %30 = mul nsw i64 %29, %27
  %31 = srem i64 %30, 1000000007
  %32 = load i64, ptr %10, align 8, !tbaa !5
  %33 = add nsw i64 %31, %32
  %34 = srem i64 %33, 1000000007
  store i64 %34, ptr %10, align 8, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, %5
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph24, %.preheader
  ret i32 0

.lr.ph24:                                         ; preds = %.preheader, %.lr.ph24
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %.lr.ph24 ], [ 0, %.preheader ]
  %35 = getelementptr inbounds [200010 x i64], ptr @ans, i64 0, i64 %indvars.iv26
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %36)
  %38 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %37, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next27, %5
  br i1 %exitcond29.not, label %._crit_edge, label %.lr.ph24, !llvm.loop !11
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #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 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 #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 = { inlinehint mustprogress 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" }

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass