; LLVM IR from kazunetakahashi/atcoder :: 2017/0408_ARC071/F.ll (Z2dpi)

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

@N = external dso_local global i64, align 8
@DP = external dso_local global [1000010 x i64], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3sumi(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z2dpi(i32 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  store i64 1, ptr %2, align 8
  br label %56

8:                                                ; preds = %1
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [1000010 x i64], ptr @DP, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = icmp ne i64 %12, -1
  br i1 %13, label %14, label %19

14:                                               ; preds = %8
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1000010 x i64], ptr @DP, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !9
  store i64 %18, ptr %2, align 8
  br label %56

19:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %20 = load i64, ptr @N, align 8, !tbaa !9
  %21 = sub nsw i64 %20, 1
  %22 = load i64, ptr @N, align 8, !tbaa !9
  %23 = sub nsw i64 %22, 1
  %24 = mul nsw i64 %21, %23
  store i64 %24, ptr %4, align 8, !tbaa !9
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = srem i64 %25, 1000000007
  store i64 %26, ptr %4, align 8, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 1
  %29 = call noundef i64 @_Z2dpi(i32 noundef %28)
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = add nsw i64 %30, %29
  store i64 %31, ptr %4, align 8, !tbaa !9
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = srem i64 %32, 1000000007
  store i64 %33, ptr %4, align 8, !tbaa !9
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 2
  %36 = sub nsw i32 %35, 1
  %37 = add nsw i32 %36, 1
  %38 = call noundef i64 @_Z3sumi(i32 noundef %37)
  %39 = add nsw i64 %38, 1000000007
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = load i64, ptr @N, align 8, !tbaa !9
  %43 = sub nsw i64 %41, %42
  %44 = sub nsw i64 %43, 1
  %45 = trunc i64 %44 to i32
  %46 = call noundef i64 @_Z3sumi(i32 noundef %45)
  %47 = sub nsw i64 %39, %46
  %48 = load i64, ptr %4, align 8, !tbaa !9
  %49 = add nsw i64 %48, %47
  store i64 %49, ptr %4, align 8, !tbaa !9
  %50 = load i64, ptr %4, align 8, !tbaa !9
  %51 = srem i64 %50, 1000000007
  store i64 %51, ptr %4, align 8, !tbaa !9
  %52 = load i64, ptr %4, align 8, !tbaa !9
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1000010 x i64], ptr @DP, i64 0, i64 %54
  store i64 %52, ptr %55, align 8, !tbaa !9
  store i64 %52, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %56

56:                                               ; preds = %19, %14, %7
  %57 = load i64, ptr %2, align 8
  ret i64 %57
}

; 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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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

@N = external dso_local local_unnamed_addr global i64, align 8
@DP = external dso_local local_unnamed_addr global [1000010 x i64], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z2dpi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 0
  br i1 %2, label %common.ret16, label %3

3:                                                ; preds = %1
  %4 = zext nneg i32 %0 to i64
  %5 = getelementptr inbounds [1000010 x i64], ptr @DP, i64 0, i64 %4
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %6, -1
  br i1 %.not, label %7, label %common.ret16

common.ret16:                                     ; preds = %3, %1, %7
  %common.ret16.op = phi i64 [ %26, %7 ], [ 1, %1 ], [ %6, %3 ]
  ret i64 %common.ret16.op

7:                                                ; preds = %3
  %8 = load i64, ptr @N, align 8, !tbaa !5
  %9 = add nsw i64 %8, -1
  %10 = mul nsw i64 %9, %9
  %11 = urem i64 %10, 1000000007
  %12 = add nsw i32 %0, -1
  %13 = tail call noundef i64 @_Z2dpi(i32 noundef %12)
  %14 = add nsw i64 %11, %13
  %15 = srem i64 %14, 1000000007
  %16 = add nsw i32 %0, -2
  %17 = tail call noundef i64 @_Z3sumi(i32 noundef %16)
  %18 = add nsw i64 %17, 1000000007
  %19 = load i64, ptr @N, align 8, !tbaa !5
  %20 = trunc i64 %19 to i32
  %21 = xor i32 %20, -1
  %22 = add i32 %21, %0
  %23 = tail call noundef i64 @_Z3sumi(i32 noundef %22)
  %24 = sub i64 %18, %23
  %25 = add nsw i64 %24, %15
  %26 = srem i64 %25, 1000000007
  store i64 %26, ptr %5, align 8, !tbaa !5
  br label %common.ret16
}

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass