; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/0825_ARC059/E.ll (Z1fii)

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

@M = external dso_local global i64, align 8
@x = external dso_local global [410 x i64], align 16
@memo = external dso_local global [410 x [410 x i64]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1fii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [410 x [410 x i64]], ptr @memo, i64 0, i64 %8
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [410 x i64], ptr %9, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = icmp ne i64 %13, -1
  br i1 %14, label %15, label %23

15:                                               ; preds = %2
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [410 x [410 x i64]], ptr @memo, i64 0, i64 %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [410 x i64], ptr %18, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  store i64 %22, ptr %3, align 8
  br label %59

23:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %51

27:                                               ; preds = %23
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i64 1, ptr %6, align 8, !tbaa !9
  br label %50

31:                                               ; preds = %27
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [410 x i64], ptr @x, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = call noundef i64 @_Z1fii(i32 noundef %37, i32 noundef %39)
  %41 = mul nsw i64 %36, %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 1
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = call noundef i64 @_Z1fii(i32 noundef %43, i32 noundef %44)
  %46 = add nsw i64 %41, %45
  store i64 %46, ptr %6, align 8, !tbaa !9
  %47 = load i64, ptr @M, align 8, !tbaa !9
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = srem i64 %48, %47
  store i64 %49, ptr %6, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %31, %30
  br label %51

51:                                               ; preds = %50, %26
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [410 x [410 x i64]], ptr @memo, i64 0, i64 %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [410 x i64], ptr %55, i64 0, i64 %57
  store i64 %52, ptr %58, align 8, !tbaa !9
  store i64 %52, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %59

59:                                               ; preds = %51, %15
  %60 = load i64, ptr %3, align 8
  ret i64 %60
}

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

@M = external dso_local local_unnamed_addr global i64, align 8
@x = external dso_local local_unnamed_addr global [410 x i64], align 16
@memo = external dso_local local_unnamed_addr global [410 x [410 x i64]], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z1fii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [410 x [410 x i64]], ptr @memo, i64 0, i64 %3, i64 %4
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %6, -1
  br i1 %.not, label %7, label %24

7:                                                ; preds = %2
  %8 = icmp eq i32 %0, 0
  br i1 %8, label %23, label %9

9:                                                ; preds = %7
  %10 = icmp eq i32 %1, 0
  br i1 %10, label %23, label %11

11:                                               ; preds = %9
  %12 = add nsw i32 %0, -1
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [410 x i64], ptr @x, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = add nsw i32 %1, -1
  %17 = tail call noundef i64 @_Z1fii(i32 noundef %0, i32 noundef %16)
  %18 = mul nsw i64 %17, %15
  %19 = tail call noundef i64 @_Z1fii(i32 noundef %12, i32 noundef %1)
  %20 = add nsw i64 %18, %19
  %21 = load i64, ptr @M, align 8, !tbaa !5
  %22 = srem i64 %20, %21
  br label %23

23:                                               ; preds = %9, %7, %11
  %.0 = phi i64 [ %22, %11 ], [ 0, %7 ], [ 1, %9 ]
  store i64 %.0, ptr %5, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %2, %23
  %.016 = phi i64 [ %.0, %23 ], [ %6, %2 ]
  ret i64 %.016
}

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


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