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

; 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
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsiii(i32 noundef, i32 noundef, i32 noundef) #0

; 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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %4

4:                                                ; preds = %72, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @mod)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %81

7:                                                ; preds = %4
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = load i64, ptr @mod, align 8, !tbaa !9
  %11 = mul nsw i64 %10, %9
  store i64 %11, ptr @mod, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %12 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %12, ptr %2, align 4, !tbaa !5
  store i32 0, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %57, %7
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = mul nsw i64 %15, %17
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp sle i64 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %60

23:                                               ; preds = %13
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = srem i32 %24, %25
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %56

28:                                               ; preds = %23
  %29 = load i32, ptr @m, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [9 x i32], ptr @e, i64 0, i64 %30
  store i32 1, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sdiv i32 %33, %32
  store i32 %34, ptr %2, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %41, %28
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = srem i32 %36, %37
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %50

40:                                               ; preds = %35
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr @m, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [9 x i32], ptr @e, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %44, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sdiv i32 %48, %47
  store i32 %49, ptr %2, align 4, !tbaa !5
  br label %35, !llvm.loop !11

50:                                               ; preds = %35
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr @m, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr @m, align 4, !tbaa !5
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %54
  store i32 %51, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %50, %23
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !13

60:                                               ; preds = %22
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = icmp sgt i32 %61, 1
  br i1 %62, label %63, label %72

63:                                               ; preds = %60
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = load i32, ptr @m, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %66
  store i32 %64, ptr %67, align 4, !tbaa !5
  %68 = load i32, ptr @m, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr @m, align 4, !tbaa !5
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds [9 x i32], ptr @e, i64 0, i64 %70
  store i32 1, ptr %71, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %63, %60
  store i32 3, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 1), align 4, !tbaa !14
  store i32 3, ptr @A, align 8, !tbaa !16
  store i64 0, ptr getelementptr inbounds ([3 x [3 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), align 8, !tbaa !9
  store i64 0, ptr getelementptr inbounds ([3 x i64], ptr getelementptr inbounds ([3 x [3 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), i64 0, i64 2), align 8, !tbaa !9
  store i64 0, ptr getelementptr inbounds ([3 x i64], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), align 8, !tbaa !9
  store i64 0, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 8, !tbaa !9
  %73 = load i64, ptr @mod, align 8, !tbaa !9
  %74 = sub nsw i64 %73, 1
  store i64 %74, ptr getelementptr inbounds ([3 x i64], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !9
  store i64 1, ptr getelementptr inbounds ([3 x i64], ptr getelementptr inbounds ([3 x [3 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), i64 0, i64 2), align 8, !tbaa !9
  store i64 1, ptr getelementptr inbounds ([3 x [3 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !9
  store i64 3, ptr getelementptr inbounds ([3 x i64], ptr getelementptr inbounds ([3 x [3 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), i64 0, i64 1), align 8, !tbaa !9
  store i64 2, ptr getelementptr inbounds ([3 x i64], ptr getelementptr inbounds ([3 x [3 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), i64 0, i64 1), align 8, !tbaa !9
  store i64 0, ptr @ans, align 8, !tbaa !9
  call void @_Z3dfsiii(i32 noundef 0, i32 noundef 1, i32 noundef 1)
  %75 = load i64, ptr @ans, align 8, !tbaa !9
  %76 = load i32, ptr @n, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = sdiv i64 %75, %77
  %79 = trunc i64 %78 to i32
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %79)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %4, !llvm.loop !17

81:                                               ; preds = %4
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

declare i32 @printf(ptr 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 = { mustprogress norecurse 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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !6, i64 4}
!15 = !{!"_ZTS6Matrix", !6, i64 0, !6, i64 4, !7, i64 8}
!16 = !{!15, !6, i64 0}
!17 = distinct !{!17, !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.Matrix = type { i32, i32, [3 x [3 x i64]] }

@n = external dso_local 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 global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@A = external dso_local local_unnamed_addr global %struct.Matrix, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @mod)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.lr.ph20, label %._crit_edge21

.lr.ph20:                                         ; preds = %0, %32
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = load i64, ptr @mod, align 8, !tbaa !9
  %6 = mul nsw i64 %5, %4
  store i64 %6, ptr @mod, align 8, !tbaa !9
  store i32 0, ptr @m, align 4, !tbaa !5
  %.not16 = icmp slt i32 %3, 4
  br i1 %.not16, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %23, %.lr.ph20
  %7 = phi i32 [ 0, %.lr.ph20 ], [ %24, %23 ]
  %.015.lcssa = phi i32 [ %3, %.lr.ph20 ], [ %.2, %23 ]
  %8 = icmp sgt i32 %.015.lcssa, 1
  br i1 %8, label %27, label %32

.lr.ph:                                           ; preds = %.lr.ph20, %23
  %indvars.iv = phi i64 [ %indvars.iv.next, %23 ], [ 2, %.lr.ph20 ]
  %.01517 = phi i32 [ %.2, %23 ], [ %3, %.lr.ph20 ]
  %9 = phi i32 [ %24, %23 ], [ 0, %.lr.ph20 ]
  %10 = trunc nuw nsw i64 %indvars.iv to i32
  %11 = srem i32 %.01517, %10
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %23

13:                                               ; preds = %.lr.ph
  %14 = sext i32 %9 to i64
  br label %15

15:                                               ; preds = %15, %13
  %storemerge = phi i32 [ 1, %13 ], [ %18, %15 ]
  %.015.pn = phi i32 [ %.01517, %13 ], [ %.1, %15 ]
  %.1 = sdiv i32 %.015.pn, %10
  %16 = srem i32 %.1, %10
  %17 = icmp eq i32 %16, 0
  %18 = add nuw nsw i32 %storemerge, 1
  br i1 %17, label %15, label %19, !llvm.loop !11

19:                                               ; preds = %15
  %20 = getelementptr inbounds [9 x i32], ptr @e, i64 0, i64 %14
  store i32 %storemerge, ptr %20, align 4, !tbaa !5
  %21 = add nsw i32 %9, 1
  store i32 %21, ptr @m, align 4, !tbaa !5
  %22 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %14
  store i32 %10, ptr %22, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %.lr.ph, %19
  %24 = phi i32 [ %21, %19 ], [ %9, %.lr.ph ]
  %.2 = phi i32 [ %.1, %19 ], [ %.01517, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %26 = sext i32 %.2 to i64
  %.not = icmp sgt i64 %25, %26
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

27:                                               ; preds = %._crit_edge
  %28 = sext i32 %7 to i64
  %29 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %28
  store i32 %.015.lcssa, ptr %29, align 4, !tbaa !5
  %30 = add nsw i32 %7, 1
  store i32 %30, ptr @m, align 4, !tbaa !5
  %31 = getelementptr inbounds [9 x i32], ptr @e, i64 0, i64 %28
  store i32 1, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %27, %._crit_edge
  store i32 3, ptr getelementptr inbounds (i8, ptr @A, i64 4), align 4, !tbaa !14
  store i32 3, ptr @A, align 8, !tbaa !16
  store i64 0, ptr getelementptr inbounds (i8, ptr @A, i64 24), align 8, !tbaa !9
  store i64 0, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 8, !tbaa !9
  %33 = add nsw i64 %6, -1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @A, i64 48), i8 0, i64 16, i1 false)
  store i64 %33, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 8, !tbaa !9
  store i64 1, ptr getelementptr inbounds (i8, ptr @A, i64 72), align 8, !tbaa !9
  store i64 1, ptr getelementptr inbounds (i8, ptr @A, i64 32), align 8, !tbaa !9
  store i64 3, ptr getelementptr inbounds (i8, ptr @A, i64 40), align 8, !tbaa !9
  store i64 2, ptr getelementptr inbounds (i8, ptr @A, i64 64), align 8, !tbaa !9
  store i64 0, ptr @ans, align 8, !tbaa !9
  tail call void @_Z3dfsiii(i32 noundef 0, i32 noundef 1, i32 noundef 1)
  %34 = load i64, ptr @ans, align 8, !tbaa !9
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = sdiv i64 %34, %36
  %38 = trunc i64 %37 to i32
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %38)
  %40 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @mod)
  %41 = icmp eq i32 %40, 2
  br i1 %41, label %.lr.ph20, label %._crit_edge21, !llvm.loop !17

._crit_edge21:                                    ; preds = %32, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 norecurse 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 #2 = { nofree nounwind "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: write) }

!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 = !{!15, !6, i64 4}
!15 = !{!"_ZTS6Matrix", !6, i64 0, !6, i64 4, !7, i64 8}
!16 = !{!15, !6, i64 0}
!17 = distinct !{!17, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass