; LLVM IR from ahr9n/psolving-paradigms :: 4.dynamic-programming/15.dp-speed-up-with-matrix-power/Gym 102875G - Grid Coloring._d3382b55 (Z3fibxxx)

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

%struct.Matrix = type <{ [15 x [15 x i64]], i32, [4 x i8] }>

@mod = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6MatrixC2Ei(ptr noundef nonnull align 8 dereferenceable(1804), i32 noundef) unnamed_addr #0 align 2

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5power6Matrixxi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef byval(%struct.Matrix) align 8, i64 noundef, i32 noundef) #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: mustprogress uwtable
define dso_local noundef i64 @_Z3fibxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.Matrix, align 8
  %8 = alloca %struct.Matrix, align 8
  %9 = alloca %struct.Matrix, align 8
  %10 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1808, ptr %7) #4
  call void @_ZN6MatrixC2Ei(ptr noundef nonnull align 8 dereferenceable(1804) %7, i32 noundef 2)
  %11 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 0
  %12 = getelementptr inbounds [15 x [15 x i64]], ptr %11, i64 0, i64 0
  %13 = getelementptr inbounds [15 x i64], ptr %12, i64 0, i64 0
  store i64 1, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 0
  %15 = getelementptr inbounds [15 x [15 x i64]], ptr %14, i64 0, i64 0
  %16 = getelementptr inbounds [15 x i64], ptr %15, i64 0, i64 1
  store i64 1, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 0
  %18 = getelementptr inbounds [15 x [15 x i64]], ptr %17, i64 0, i64 1
  %19 = getelementptr inbounds [15 x i64], ptr %18, i64 0, i64 0
  store i64 1, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 0
  %21 = getelementptr inbounds [15 x [15 x i64]], ptr %20, i64 0, i64 1
  %22 = getelementptr inbounds [15 x i64], ptr %21, i64 0, i64 1
  store i64 0, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1808, ptr %8) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %7, i64 1808, i1 false), !tbaa.struct !9
  %23 = load i64, ptr %6, align 8, !tbaa !5
  %24 = sub nsw i64 %23, 1
  call void @_Z5power6Matrixxi(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %8, ptr noundef byval(%struct.Matrix) align 8 %9, i64 noundef %24, i32 noundef 2)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %8, i64 1804, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 1808, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %25 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 0
  %26 = getelementptr inbounds [15 x [15 x i64]], ptr %25, i64 0, i64 1
  %27 = getelementptr inbounds [15 x i64], ptr %26, i64 0, i64 0
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = mul nsw i64 %28, %29
  %31 = load i64, ptr @mod, align 8, !tbaa !5
  %32 = srem i64 %30, %31
  %33 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 0
  %34 = getelementptr inbounds [15 x [15 x i64]], ptr %33, i64 0, i64 1
  %35 = getelementptr inbounds [15 x i64], ptr %34, i64 0, i64 1
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = mul nsw i64 %36, %37
  %39 = load i64, ptr @mod, align 8, !tbaa !5
  %40 = srem i64 %38, %39
  %41 = add nsw i64 %32, %40
  store i64 %41, ptr %10, align 8, !tbaa !5
  %42 = load i64, ptr %10, align 8, !tbaa !5
  %43 = load i64, ptr @mod, align 8, !tbaa !5
  %44 = srem i64 %42, %43
  %45 = load i64, ptr @mod, align 8, !tbaa !5
  %46 = add nsw i64 %44, %45
  %47 = load i64, ptr @mod, align 8, !tbaa !5
  %48 = srem i64 %46, %47
  store i64 %48, ptr %10, align 8, !tbaa !5
  %49 = load i64, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1808, ptr %7) #4
  ret i64 %49
}

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 = { 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 #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 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 1800, !10, i64 1800, i64 4, !11}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

%struct.Matrix = type <{ [15 x [15 x i64]], i32, [4 x i8] }>

@mod = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6MatrixC2Ei(ptr noundef nonnull align 8 dereferenceable(1804), i32 noundef) unnamed_addr #0 align 2

; 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 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 void @_Z5power6Matrixxi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef byval(%struct.Matrix) align 8, i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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: mustprogress uwtable
define dso_local noundef i64 @_Z3fibxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.Matrix, align 8
  %5 = alloca %struct.Matrix, align 8
  call void @llvm.lifetime.start.p0(i64 1808, ptr nonnull %4) #4
  call void @_ZN6MatrixC2Ei(ptr noundef nonnull align 8 dereferenceable(1804) %4, i32 noundef 2)
  store i64 1, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 1, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %4, i64 120
  store i64 1, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 128
  store i64 0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1808, ptr nonnull %5) #4
  %9 = add nsw i64 %2, -1
  call void @_Z5power6Matrixxi(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %5, ptr noundef nonnull byval(%struct.Matrix) align 8 %4, i64 noundef %9, i32 noundef 2)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1804) %4, ptr noundef nonnull align 8 dereferenceable(1804) %5, i64 1804, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 1808, ptr nonnull %5) #4
  %10 = load i64, ptr %7, align 8, !tbaa !5
  %11 = mul nsw i64 %10, %1
  %12 = load i64, ptr @mod, align 8, !tbaa !5
  %13 = srem i64 %11, %12
  %14 = load i64, ptr %8, align 8, !tbaa !5
  %15 = mul nsw i64 %14, %0
  %16 = srem i64 %15, %12
  %17 = add nsw i64 %16, %13
  %18 = srem i64 %17, %12
  %19 = add nsw i64 %18, %12
  %20 = srem i64 %19, %12
  call void @llvm.lifetime.end.p0(i64 1808, ptr nonnull %4) #4
  ret i64 %20
}

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,ReassociatePass,SROAPass