; LLVM IR from kazunetakahashi/atcoder :: 201411_201509/0412_ABC021/D.ll (Z4initv)

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

@inv = external dso_local global [200010 x i64], align 16
@fact = external dso_local global [200010 x i64], align 16
@factinv = external dso_local global [200010 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4initv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i64 1, ptr getelementptr inbounds ([200010 x i64], ptr @inv, i64 0, i64 1), align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 2, ptr %1, align 4, !tbaa !9
  br label %3

3:                                                ; preds = %22, %0
  %4 = load i32, ptr %1, align 4, !tbaa !9
  %5 = icmp slt i32 %4, 200010
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %25

7:                                                ; preds = %3
  %8 = load i32, ptr %1, align 4, !tbaa !9
  %9 = srem i32 1000000007, %8
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [200010 x i64], ptr @inv, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = sub nsw i64 1000000007, %12
  %14 = load i32, ptr %1, align 4, !tbaa !9
  %15 = sdiv i32 1000000007, %14
  %16 = sext i32 %15 to i64
  %17 = mul nsw i64 %13, %16
  %18 = srem i64 %17, 1000000007
  %19 = load i32, ptr %1, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [200010 x i64], ptr @inv, i64 0, i64 %20
  store i64 %18, ptr %21, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %7
  %23 = load i32, ptr %1, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %1, align 4, !tbaa !9
  br label %3, !llvm.loop !11

25:                                               ; preds = %6
  store i64 1, ptr @factinv, align 16, !tbaa !5
  store i64 1, ptr @fact, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %57, %25
  %27 = load i32, ptr %2, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 200010
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %60

30:                                               ; preds = %26
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [200010 x i64], ptr @fact, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = mul nsw i64 %32, %37
  %39 = srem i64 %38, 1000000007
  %40 = load i32, ptr %2, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200010 x i64], ptr @fact, i64 0, i64 %41
  store i64 %39, ptr %42, align 8, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [200010 x i64], ptr @inv, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !9
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200010 x i64], ptr @factinv, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = mul nsw i64 %46, %51
  %53 = srem i64 %52, 1000000007
  %54 = load i32, ptr %2, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200010 x i64], ptr @factinv, i64 0, i64 %55
  store i64 %53, ptr %56, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %30
  %58 = load i32, ptr %2, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %2, align 4, !tbaa !9
  br label %26, !llvm.loop !13

60:                                               ; preds = %29
  ret void
}

; 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

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 = { 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"

@inv = external dso_local local_unnamed_addr global [200010 x i64], align 16
@fact = external dso_local local_unnamed_addr global [200010 x i64], align 16
@factinv = external dso_local local_unnamed_addr global [200010 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  store i64 1, ptr getelementptr inbounds (i8, ptr @inv, i64 8), align 8, !tbaa !5
  br label %2

1:                                                ; preds = %2
  store i64 1, ptr @factinv, align 16, !tbaa !5
  store i64 1, ptr @fact, align 16, !tbaa !5
  br label %15

2:                                                ; preds = %0, %2
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %2 ]
  %3 = trunc nuw nsw i64 %indvars.iv to i32
  %4 = urem i32 1000000007, %3
  %5 = zext nneg i32 %4 to i64
  %6 = getelementptr inbounds [200010 x i64], ptr @inv, i64 0, i64 %5
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = sub nsw i64 1000000007, %7
  %9 = udiv i32 1000000007, %3
  %10 = zext nneg i32 %9 to i64
  %11 = mul nsw i64 %8, %10
  %12 = srem i64 %11, 1000000007
  %13 = getelementptr inbounds [200010 x i64], ptr @inv, i64 0, i64 %indvars.iv
  store i64 %12, ptr %13, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 200010
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !9

14:                                               ; preds = %15
  ret void

15:                                               ; preds = %1, %15
  %16 = phi i64 [ 1, %1 ], [ %24, %15 ]
  %17 = phi i64 [ 1, %1 ], [ %19, %15 ]
  %indvars.iv17 = phi i64 [ 1, %1 ], [ %indvars.iv.next18, %15 ]
  %18 = mul nsw i64 %17, %indvars.iv17
  %19 = srem i64 %18, 1000000007
  %20 = getelementptr inbounds [200010 x i64], ptr @fact, i64 0, i64 %indvars.iv17
  store i64 %19, ptr %20, align 8, !tbaa !5
  %21 = getelementptr inbounds [200010 x i64], ptr @inv, i64 0, i64 %indvars.iv17
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = mul nsw i64 %16, %22
  %24 = srem i64 %23, 1000000007
  %25 = getelementptr inbounds [200010 x i64], ptr @factinv, i64 0, i64 %indvars.iv17
  store i64 %24, ptr %25, align 8, !tbaa !5
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %exitcond20.not = icmp eq i64 %indvars.iv.next18, 200010
  br i1 %exitcond20.not, label %14, label %15, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass