; LLVM IR from kazunetakahashi/atcoder :: 2019/0611_ABC129/A.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"

%class.mint = type { i64 }

@_ZN4mint3MODE = external dso_local global i64, align 8
@inv = external dso_local global [1000010 x %class.mint], align 16
@fact = external dso_local global [1000010 x %class.mint], align 16
@factinv = external dso_local global [1000010 x %class.mint], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initv() #0 {
  %1 = alloca %class.mint, align 8
  %2 = alloca i32, align 4
  %3 = alloca %class.mint, align 8
  %4 = alloca %class.mint, align 8
  %5 = alloca %class.mint, align 8
  %6 = alloca %class.mint, align 8
  %7 = alloca i32, align 4
  %8 = alloca %class.mint, align 8
  %9 = alloca %class.mint, align 8
  %10 = alloca %class.mint, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef 1)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 getelementptr inbounds ([1000010 x %class.mint], ptr @inv, i64 0, i64 1), ptr align 8 %1, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !10
  br label %11

11:                                               ; preds = %32, %0
  %12 = load i32, ptr %2, align 4, !tbaa !10
  %13 = icmp slt i32 %12, 1000010
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %35

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %16 = load i64, ptr @_ZN4mint3MODE, align 8, !tbaa !6
  %17 = load i32, ptr %2, align 4, !tbaa !10
  %18 = sext i32 %17 to i64
  %19 = srem i64 %16, %18
  %20 = getelementptr inbounds [1000010 x %class.mint], ptr @inv, i64 0, i64 %19
  %21 = call i64 @_ZNK4mintngEv(ptr noundef nonnull align 8 dereferenceable(8) %20)
  %22 = getelementptr inbounds %class.mint, ptr %4, i32 0, i32 0
  store i64 %21, ptr %22, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %23 = load i64, ptr @_ZN4mint3MODE, align 8, !tbaa !6
  %24 = load i32, ptr %2, align 4, !tbaa !10
  %25 = sext i32 %24 to i64
  %26 = sdiv i64 %23, %25
  call void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef %26)
  %27 = call i64 @_ZNK4mintmlERKS_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %28 = getelementptr inbounds %class.mint, ptr %3, i32 0, i32 0
  store i64 %27, ptr %28, align 8
  %29 = load i32, ptr %2, align 4, !tbaa !10
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1000010 x %class.mint], ptr @inv, i64 0, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %31, ptr align 8 %3, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %32

32:                                               ; preds = %15
  %33 = load i32, ptr %2, align 4, !tbaa !10
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !10
  br label %11, !llvm.loop !12

35:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8) %6, i64 noundef 1)
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @factinv, ptr align 8 %6, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @fact, ptr align 8 @factinv, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !10
  br label %36

36:                                               ; preds = %64, %35
  %37 = load i32, ptr %7, align 4, !tbaa !10
  %38 = icmp slt i32 %37, 1000010
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %67

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %41 = load i32, ptr %7, align 4, !tbaa !10
  %42 = sext i32 %41 to i64
  call void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8) %9, i64 noundef %42)
  %43 = load i32, ptr %7, align 4, !tbaa !10
  %44 = sub nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1000010 x %class.mint], ptr @fact, i64 0, i64 %45
  %47 = call i64 @_ZNK4mintmlERKS_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %46)
  %48 = getelementptr inbounds %class.mint, ptr %8, i32 0, i32 0
  store i64 %47, ptr %48, align 8
  %49 = load i32, ptr %7, align 4, !tbaa !10
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000010 x %class.mint], ptr @fact, i64 0, i64 %50
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %51, ptr align 8 %8, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %52 = load i32, ptr %7, align 4, !tbaa !10
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1000010 x %class.mint], ptr @inv, i64 0, i64 %53
  %55 = load i32, ptr %7, align 4, !tbaa !10
  %56 = sub nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000010 x %class.mint], ptr @factinv, i64 0, i64 %57
  %59 = call i64 @_ZNK4mintmlERKS_(ptr noundef nonnull align 8 dereferenceable(8) %54, ptr noundef nonnull align 8 dereferenceable(8) %58)
  %60 = getelementptr inbounds %class.mint, ptr %10, i32 0, i32 0
  store i64 %59, ptr %60, align 8
  %61 = load i32, ptr %7, align 4, !tbaa !10
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1000010 x %class.mint], ptr @factinv, i64 0, i64 %62
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %63, ptr align 8 %10, i64 8, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %64

64:                                               ; preds = %40
  %65 = load i32, ptr %7, align 4, !tbaa !10
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %7, align 4, !tbaa !10
  br label %36, !llvm.loop !14

67:                                               ; preds = %39
  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: mustprogress nounwind uwtable
declare dso_local void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) unnamed_addr #2 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZNK4mintngEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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.mint = type { i64 }

@_ZN4mint3MODE = external dso_local local_unnamed_addr global i64, align 8
@inv = external dso_local global [1000010 x %class.mint], align 16
@fact = external dso_local global [1000010 x %class.mint], align 16
@factinv = external dso_local global [1000010 x %class.mint], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  %1 = alloca %class.mint, align 8
  %2 = alloca %class.mint, align 8
  %3 = alloca %class.mint, align 8
  %4 = alloca %class.mint, align 8
  %5 = alloca %class.mint, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef 1)
  %6 = load i64, ptr %1, align 8, !tbaa !5
  store i64 %6, ptr getelementptr inbounds (i8, ptr @inv, i64 8), align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  br label %9

7:                                                ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef 1)
  %8 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %8, ptr @factinv, align 16, !tbaa !5
  store i64 %8, ptr @fact, align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %19

9:                                                ; preds = %0, %9
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %9 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %10 = load i64, ptr @_ZN4mint3MODE, align 8, !tbaa !5
  %11 = srem i64 %10, %indvars.iv
  %12 = getelementptr inbounds [1000010 x %class.mint], ptr @inv, i64 0, i64 %11
  %13 = call i64 @_ZNK4mintngEv(ptr noundef nonnull align 8 dereferenceable(8) %12)
  store i64 %13, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %14 = load i64, ptr @_ZN4mint3MODE, align 8, !tbaa !5
  %15 = sdiv i64 %14, %indvars.iv
  call void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %15)
  %16 = call i64 @_ZNK4mintmlERKS_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %17 = getelementptr inbounds [1000010 x %class.mint], ptr @inv, i64 0, i64 %indvars.iv
  store i64 %16, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1000010
  br i1 %exitcond.not, label %7, label %9, !llvm.loop !9

18:                                               ; preds = %19
  ret void

19:                                               ; preds = %7, %19
  %indvars.iv19 = phi i64 [ 1, %7 ], [ %indvars.iv.next20, %19 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef %indvars.iv19)
  %20 = add nsw i64 %indvars.iv19, -1
  %21 = getelementptr inbounds [1000010 x %class.mint], ptr @fact, i64 0, i64 %20
  %22 = call i64 @_ZNK4mintmlERKS_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %21)
  %23 = getelementptr inbounds [1000010 x %class.mint], ptr @fact, i64 0, i64 %indvars.iv19
  store i64 %22, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  %24 = getelementptr inbounds [1000010 x %class.mint], ptr @inv, i64 0, i64 %indvars.iv19
  %25 = getelementptr inbounds [1000010 x %class.mint], ptr @factinv, i64 0, i64 %20
  %26 = call i64 @_ZNK4mintmlERKS_(ptr noundef nonnull align 8 dereferenceable(8) %24, ptr noundef nonnull align 8 dereferenceable(8) %25)
  %27 = getelementptr inbounds [1000010 x %class.mint], ptr @factinv, i64 0, i64 %indvars.iv19
  store i64 %26, ptr %27, 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 %18, label %19, !llvm.loop !11
}

; 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 nounwind uwtable
declare dso_local void @_ZN4mintC2Ex(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) unnamed_addr #2 align 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: mustprogress uwtable
declare dso_local i64 @_ZNK4mintngEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass