; LLVM IR from tangjz/acm-icpc :: lydsy/3113.ll (Z3dfsiii)

; 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 { i32, i32, [3 x [3 x i64]] }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@p = external dso_local global [9 x i32], align 16
@e = external dso_local global [9 x i32], align 16
@mod = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@A = external dso_local global %struct.Matrix, align 8
@B = external dso_local global %struct.Matrix, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Matrix, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %13, label %30

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 80, ptr %7) #4
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sdiv i32 %14, %15
  %17 = sext i32 %16 to i64
  call void @_ZNK6Matrix3powEx(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %7, ptr noundef nonnull align 8 dereferenceable(80) @A, i64 noundef %17)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @B, ptr align 8 %7, i64 80, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 80, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %18 = load i64, ptr getelementptr inbounds ([3 x [3 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !11
  %19 = load i64, ptr getelementptr inbounds ([3 x [3 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 2), align 8, !tbaa !11
  %20 = load i64, ptr @mod, align 8, !tbaa !11
  %21 = call noundef i64 @_Z7mod_addxxx(i64 noundef %18, i64 noundef %19, i64 noundef %20)
  store i64 %21, ptr %8, align 8, !tbaa !11
  %22 = load i64, ptr @ans, align 8, !tbaa !11
  %23 = load i64, ptr %8, align 8, !tbaa !11
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = load i64, ptr @mod, align 8, !tbaa !11
  %27 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %23, i64 noundef %25, i64 noundef %26)
  %28 = load i64, ptr @mod, align 8, !tbaa !11
  %29 = call noundef i64 @_Z7mod_addxxx(i64 noundef %22, i64 noundef %27, i64 noundef %28)
  store i64 %29, ptr @ans, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %64

30:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %61, %30
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [9 x i32], ptr @e, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp sle i32 %32, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %64

39:                                               ; preds = %31
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %41, i32 noundef %42, i32 noundef %43)
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = mul nsw i32 %48, %47
  store i32 %49, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  %56 = xor i1 %55, true
  %57 = zext i1 %56 to i32
  %58 = sub nsw i32 %53, %57
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = mul nsw i32 %59, %58
  store i32 %60, ptr %6, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %39
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %9, align 4, !tbaa !5
  br label %31, !llvm.loop !13

64:                                               ; preds = %38, %13
  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: mustprogress uwtable
declare dso_local void @_ZNK6Matrix3powEx(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(80), i64 noundef) #0 align 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) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_addxxx(i64 noundef, i64 noundef, i64 noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_mulxxx(i64 noundef, i64 noundef, i64 noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 72, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%struct.Matrix = type { i32, i32, [3 x [3 x i64]] }

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [9 x i32], align 16
@e = external dso_local local_unnamed_addr global [9 x i32], align 16
@mod = external dso_local local_unnamed_addr global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@A = external dso_local global %struct.Matrix, align 8
@B = external dso_local local_unnamed_addr global %struct.Matrix, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.Matrix, align 8
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %12, label %.preheader

.preheader:                                       ; preds = %3
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [9 x i32], ptr @e, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not19 = icmp slt i32 %9, 0
  br i1 %.not19, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %10 = add nsw i32 %0, 1
  %11 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %7
  br label %26

12:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %4) #4
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sdiv i32 %13, %1
  %15 = sext i32 %14 to i64
  call void @_ZNK6Matrix3powEx(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %4, ptr noundef nonnull align 8 dereferenceable(80) @A, i64 noundef %15)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(80) @B, ptr noundef nonnull align 8 dereferenceable(80) %4, i64 80, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %4) #4
  %16 = load i64, ptr getelementptr inbounds (i8, ptr @B, i64 32), align 8, !tbaa !11
  %17 = load i64, ptr getelementptr inbounds (i8, ptr @B, i64 56), align 8, !tbaa !11
  %18 = load i64, ptr @mod, align 8, !tbaa !11
  %19 = call noundef i64 @_Z7mod_addxxx(i64 noundef %16, i64 noundef %17, i64 noundef %18)
  %20 = load i64, ptr @ans, align 8, !tbaa !11
  %21 = sext i32 %2 to i64
  %22 = load i64, ptr @mod, align 8, !tbaa !11
  %23 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %19, i64 noundef %21, i64 noundef %22)
  %24 = load i64, ptr @mod, align 8, !tbaa !11
  %25 = call noundef i64 @_Z7mod_addxxx(i64 noundef %20, i64 noundef %23, i64 noundef %24)
  store i64 %25, ptr @ans, align 8, !tbaa !11
  br label %.loopexit

26:                                               ; preds = %.lr.ph, %26
  %.022 = phi i32 [ 0, %.lr.ph ], [ %31, %26 ]
  %.01521 = phi i32 [ %1, %.lr.ph ], [ %28, %26 ]
  %.01620 = phi i32 [ %2, %.lr.ph ], [ %30, %26 ]
  tail call void @_Z3dfsiii(i32 noundef %10, i32 noundef %.01521, i32 noundef %.01620)
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = mul nsw i32 %27, %.01521
  %.not18 = icmp eq i32 %.022, 0
  %.neg = sext i1 %.not18 to i32
  %29 = add i32 %27, %.neg
  %30 = mul nsw i32 %29, %.01620
  %31 = add nuw nsw i32 %.022, 1
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.022, %32
  br i1 %.not.not, label %26, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %26, %.preheader, %12
  ret void
}

; 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 uwtable
declare dso_local void @_ZNK6Matrix3powEx(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(80), i64 noundef) local_unnamed_addr #0 align 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) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_addxxx(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_mulxxx(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass