; LLVM IR from kazunetakahashi/atcoder :: 2018/0805_ABC104/D2.ll (Z4calcic)

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

@DP = external dso_local global [100010 x [4 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4calcic(i32 noundef %0, i8 noundef signext %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load i8, ptr %4, align 1, !tbaa !9
  %8 = sext i8 %7 to i32
  %9 = sub nsw i32 %8, 65
  store i32 %9, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %39, %2
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = icmp sle i32 %11, 3
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %10
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %17
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4 x i64], ptr %18, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !10
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %24
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [4 x i64], ptr %25, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !10
  %30 = add nsw i64 %29, %22
  store i64 %30, ptr %28, align 8, !tbaa !10
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %32
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [4 x i64], ptr %33, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !10
  %38 = srem i64 %37, 1000000007
  store i64 %38, ptr %36, align 8, !tbaa !10
  br label %39

39:                                               ; preds = %14
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !5
  br label %10, !llvm.loop !12

42:                                               ; preds = %13
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [4 x i64], ptr %46, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !10
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %52
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [4 x i64], ptr %53, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !10
  %59 = add nsw i64 %58, %50
  store i64 %59, ptr %57, align 8, !tbaa !10
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %61
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [4 x i64], ptr %62, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !10
  %68 = srem i64 %67, 1000000007
  store i64 %68, ptr %66, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@DP = external dso_local local_unnamed_addr global [100010 x [4 x i64]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4calcic(i32 noundef %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %3 = add nsw i32 %0, -1
  %4 = sext i32 %3 to i64
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %4, i64 0
  %7 = load i64, ptr %6, align 16, !tbaa !5
  %8 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %5, i64 0
  %9 = load i64, ptr %8, align 16, !tbaa !5
  %10 = add nsw i64 %9, %7
  %11 = srem i64 %10, 1000000007
  store i64 %11, ptr %8, align 16, !tbaa !5
  %12 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %4, i64 1
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %5, i64 1
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = add nsw i64 %15, %13
  %17 = srem i64 %16, 1000000007
  store i64 %17, ptr %14, align 8, !tbaa !5
  %18 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %4, i64 2
  %19 = load i64, ptr %18, align 16, !tbaa !5
  %20 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %5, i64 2
  %21 = load i64, ptr %20, align 16, !tbaa !5
  %22 = add nsw i64 %21, %19
  %23 = srem i64 %22, 1000000007
  store i64 %23, ptr %20, align 16, !tbaa !5
  %24 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %4, i64 3
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %5, i64 3
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = add nsw i64 %27, %25
  %29 = srem i64 %28, 1000000007
  store i64 %29, ptr %26, align 8, !tbaa !5
  %30 = sext i8 %1 to i32
  %31 = add nsw i32 %30, -65
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %4, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = add nsw i32 %30, -64
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100010 x [4 x i64]], ptr @DP, i64 0, i64 %5, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = add nsw i64 %38, %34
  %40 = srem i64 %39, 1000000007
  store i64 %40, ptr %37, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass