; LLVM IR from lzyrapx/Competitive-Programming :: 51Nod/1242（斐波那契数列）（矩阵快速幂）.ll (Z3mul3MatS_)

; 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.Mat = type { [2 x [2 x i64]] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3mul3MatS_(ptr dead_on_unwind noalias writable sret(%struct.Mat) align 8 %0, ptr noundef byval(%struct.Mat) align 8 %1, ptr noundef byval(%struct.Mat) align 8 %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %73, %3
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 2
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %76

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %69, %12
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 2
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %72

17:                                               ; preds = %13
  %18 = getelementptr inbounds %struct.Mat, ptr %0, i32 0, i32 0
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [2 x [2 x i64]], ptr %18, i64 0, i64 %20
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2 x i64], ptr %21, i64 0, i64 %23
  store i64 0, ptr %24, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %56, %17
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 2
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %59

29:                                               ; preds = %25
  %30 = getelementptr inbounds %struct.Mat, ptr %1, i32 0, i32 0
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2 x [2 x i64]], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [2 x i64], ptr %33, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.Mat, ptr %2, i32 0, i32 0
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2 x [2 x i64]], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [2 x i64], ptr %41, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = mul nsw i64 %37, %45
  %47 = getelementptr inbounds %struct.Mat, ptr %0, i32 0, i32 0
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2 x [2 x i64]], ptr %47, i64 0, i64 %49
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [2 x i64], ptr %50, i64 0, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = add nsw i64 %54, %46
  store i64 %55, ptr %53, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %29
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %7, align 4, !tbaa !5
  br label %25, !llvm.loop !11

59:                                               ; preds = %28
  %60 = getelementptr inbounds %struct.Mat, ptr %0, i32 0, i32 0
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2 x [2 x i64]], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2 x i64], ptr %63, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !9
  %68 = srem i64 %67, 1000000009
  store i64 %68, ptr %66, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %59
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !5
  br label %13, !llvm.loop !13

72:                                               ; preds = %16
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !14

76:                                               ; preds = %11
  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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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.Mat = type { [2 x [2 x i64]] }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_Z3mul3MatS_(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.Mat) align 8 %0, ptr nocapture noundef readonly byval(%struct.Mat) align 8 %1, ptr nocapture noundef readonly byval(%struct.Mat) align 8 %2) local_unnamed_addr #0 {
.preheader:
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = load i64, ptr %2, align 8, !tbaa !5
  %5 = mul nsw i64 %4, %3
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = mul nsw i64 %9, %7
  %11 = add nsw i64 %5, %10
  %12 = srem i64 %11, 1000000009
  store i64 %12, ptr %0, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = mul nsw i64 %15, %3
  %17 = getelementptr inbounds i8, ptr %2, i64 24
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = mul nsw i64 %18, %7
  %20 = add nsw i64 %16, %19
  %21 = srem i64 %20, 1000000009
  store i64 %21, ptr %13, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %1, i64 16
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load i64, ptr %22, align 8, !tbaa !5
  %25 = mul nsw i64 %4, %24
  %26 = getelementptr inbounds i8, ptr %1, i64 24
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = mul nsw i64 %9, %27
  %29 = add nsw i64 %25, %28
  %30 = srem i64 %29, 1000000009
  store i64 %30, ptr %23, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  %32 = mul nsw i64 %15, %24
  %33 = mul nsw i64 %18, %27
  %34 = add nsw i64 %32, %33
  %35 = srem i64 %34, 1000000009
  store i64 %35, ptr %31, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass