; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/0114/ARC039_B.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 [1000010 x i64], align 16
@fact = external dso_local global [1000010 x i64], align 16
@factinv = external dso_local global [1000010 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 ([1000010 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, 1000010
  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 = sext i32 %8 to i64
  %10 = srem i64 1000000007, %9
  %11 = getelementptr inbounds [1000010 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 = sext i32 %14 to i64
  %16 = sdiv i64 1000000007, %15
  %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 [1000010 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, 1000010
  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 [1000010 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 [1000010 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 [1000010 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 [1000010 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 [1000010 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 [1000010 x i64], align 16
@fact = external dso_local local_unnamed_addr global [1000010 x i64], align 16
@factinv = external dso_local local_unnamed_addr global [1000010 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 %13

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
  %.zext = zext nneg i32 %4 to i64
  %5 = getelementptr inbounds [1000010 x i64], ptr @inv, i64 0, i64 %.zext
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = sub nsw i64 1000000007, %6
  %8 = udiv i32 1000000007, %3
  %.zext15 = zext nneg i32 %8 to i64
  %9 = mul nsw i64 %7, %.zext15
  %10 = srem i64 %9, 1000000007
  %11 = getelementptr inbounds [1000010 x i64], ptr @inv, i64 0, i64 %indvars.iv
  store i64 %10, ptr %11, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1000010
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !9

12:                                               ; preds = %13
  ret void

13:                                               ; preds = %1, %13
  %14 = phi i64 [ 1, %1 ], [ %22, %13 ]
  %15 = phi i64 [ 1, %1 ], [ %17, %13 ]
  %indvars.iv19 = phi i64 [ 1, %1 ], [ %indvars.iv.next20, %13 ]
  %16 = mul nsw i64 %15, %indvars.iv19
  %17 = srem i64 %16, 1000000007
  %18 = getelementptr inbounds [1000010 x i64], ptr @fact, i64 0, i64 %indvars.iv19
  store i64 %17, ptr %18, align 8, !tbaa !5
  %19 = getelementptr inbounds [1000010 x i64], ptr @inv, i64 0, i64 %indvars.iv19
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = mul nsw i64 %14, %20
  %22 = srem i64 %21, 1000000007
  %23 = getelementptr inbounds [1000010 x i64], ptr @factinv, i64 0, i64 %indvars.iv19
  store i64 %22, ptr %23, align 8, !tbaa !5
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %exitcond22.not = icmp eq i64 %indvars.iv.next20, 1000010
  br i1 %exitcond22.not, label %12, label %13, !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,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass