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

; 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 { i64, i64 }

@n = external dso_local global [1000010 x i8], align 16
@m = external dso_local global [1000010 x i8], align 16
@a = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@c = external dso_local global i64, align 8
@d = external dso_local global i64, align 8
@nlen = external dso_local global i64, align 8
@mlen = 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
@SA = external dso_local global %struct.Matrix, align 8
@SB = external dso_local global %struct.Matrix, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5init1RxPc(ptr noundef nonnull align 8 dereferenceable(8), ptr 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 nounwind uwtable
declare dso_local void @_Z5init2RxPc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Matrix, align 8
  %3 = alloca %struct.Matrix, align 8
  %4 = alloca %struct.Matrix, align 8
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @a, ptr noundef @b, ptr noundef @c, ptr noundef @d)
  %6 = load i64, ptr @a, align 8, !tbaa !5
  %7 = icmp eq i64 %6, 1
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  call void @_Z5init1RxPc(ptr noundef nonnull align 8 dereferenceable(8) @nlen, ptr noundef @n)
  br label %10

9:                                                ; preds = %0
  call void @_Z5init2RxPc(ptr noundef nonnull align 8 dereferenceable(8) @nlen, ptr noundef @n)
  br label %10

10:                                               ; preds = %9, %8
  %11 = load i64, ptr @c, align 8, !tbaa !5
  %12 = icmp eq i64 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  call void @_Z5init1RxPc(ptr noundef nonnull align 8 dereferenceable(8) @mlen, ptr noundef @m)
  br label %15

14:                                               ; preds = %10
  call void @_Z5init2RxPc(ptr noundef nonnull align 8 dereferenceable(8) @mlen, ptr noundef @m)
  br label %15

15:                                               ; preds = %14, %13
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #5
  %16 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 0
  %17 = load i64, ptr @a, align 8, !tbaa !5
  store i64 %17, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 1
  %19 = load i64, ptr @b, align 8, !tbaa !5
  store i64 %19, ptr %18, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @A, ptr align 8 %2, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #5
  %20 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 0
  %21 = load i64, ptr @c, align 8, !tbaa !5
  store i64 %21, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 1
  %23 = load i64, ptr @d, align 8, !tbaa !5
  store i64 %23, ptr %22, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @B, ptr align 8 %3, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  %24 = getelementptr inbounds %struct.Matrix, ptr %4, i32 0, i32 0
  store i64 1, ptr %24, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Matrix, ptr %4, i32 0, i32 1
  store i64 0, ptr %25, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @SB, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @SA, ptr align 8 @SB, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #5
  br label %26

26:                                               ; preds = %34, %15
  %27 = load i64, ptr @mlen, align 8, !tbaa !5
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %37

29:                                               ; preds = %26
  %30 = load i64, ptr @mlen, align 8, !tbaa !5
  %31 = and i64 %30, 1
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @SA, ptr noundef nonnull align 8 dereferenceable(16) @A)
  br label %34

34:                                               ; preds = %33, %29
  call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @A, ptr noundef nonnull align 8 dereferenceable(16) @A)
  %35 = load i64, ptr @mlen, align 8, !tbaa !5
  %36 = ashr i64 %35, 1
  store i64 %36, ptr @mlen, align 8, !tbaa !5
  br label %26, !llvm.loop !13

37:                                               ; preds = %26
  call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @B, ptr noundef nonnull align 8 dereferenceable(16) @SA)
  br label %38

38:                                               ; preds = %46, %37
  %39 = load i64, ptr @nlen, align 8, !tbaa !5
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %49

41:                                               ; preds = %38
  %42 = load i64, ptr @nlen, align 8, !tbaa !5
  %43 = and i64 %42, 1
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @SB, ptr noundef nonnull align 8 dereferenceable(16) @B)
  br label %46

46:                                               ; preds = %45, %41
  call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @B, ptr noundef nonnull align 8 dereferenceable(16) @B)
  %47 = load i64, ptr @nlen, align 8, !tbaa !5
  %48 = ashr i64 %47, 1
  store i64 %48, ptr @nlen, align 8, !tbaa !5
  br label %38, !llvm.loop !15

49:                                               ; preds = %38
  call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @SA, ptr noundef nonnull align 8 dereferenceable(16) @SB)
  %50 = load i64, ptr @SA, align 8, !tbaa !9
  %51 = load i64, ptr getelementptr inbounds (%struct.Matrix, ptr @SA, i32 0, i32 1), align 8, !tbaa !11
  %52 = add nsw i64 %50, %51
  %53 = srem i64 %52, 1000000007
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %53)
  %55 = load i32, ptr %1, align 4
  ret i32 %55
}

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

; 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) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

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

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 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS6Matrix", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 { i64, i64 }

@n = external dso_local global [1000010 x i8], align 16
@m = external dso_local global [1000010 x i8], align 16
@a = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@c = external dso_local global i64, align 8
@d = external dso_local global i64, align 8
@nlen = external dso_local global i64, align 8
@mlen = 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
@SA = external dso_local global %struct.Matrix, align 8
@SB = external dso_local global %struct.Matrix, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5init1RxPc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5init2RxPc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind 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 @m, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c, ptr noundef nonnull @d)
  %2 = load i64, ptr @a, align 8, !tbaa !5
  %3 = icmp eq i64 %2, 1
  br i1 %3, label %4, label %5

4:                                                ; preds = %0
  tail call void @_Z5init1RxPc(ptr noundef nonnull align 8 dereferenceable(8) @nlen, ptr noundef nonnull @n)
  br label %6

5:                                                ; preds = %0
  tail call void @_Z5init2RxPc(ptr noundef nonnull align 8 dereferenceable(8) @nlen, ptr noundef nonnull @n)
  br label %6

6:                                                ; preds = %5, %4
  %7 = load i64, ptr @c, align 8, !tbaa !5
  %8 = icmp eq i64 %7, 1
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  tail call void @_Z5init1RxPc(ptr noundef nonnull align 8 dereferenceable(8) @mlen, ptr noundef nonnull @m)
  br label %11

10:                                               ; preds = %6
  tail call void @_Z5init2RxPc(ptr noundef nonnull align 8 dereferenceable(8) @mlen, ptr noundef nonnull @m)
  br label %11

11:                                               ; preds = %10, %9
  %12 = load i64, ptr @a, align 8, !tbaa !5
  %13 = load i64, ptr @b, align 8, !tbaa !5
  store i64 %12, ptr @A, align 8, !tbaa !5
  store i64 %13, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 8, !tbaa !5
  %14 = load i64, ptr @c, align 8, !tbaa !5
  %15 = load i64, ptr @d, align 8, !tbaa !5
  store i64 %14, ptr @B, align 8, !tbaa !5
  store i64 %15, ptr getelementptr inbounds (i8, ptr @B, i64 8), align 8, !tbaa !5
  store i64 1, ptr @SB, align 8, !tbaa !5
  store i64 0, ptr getelementptr inbounds (i8, ptr @SB, i64 8), align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) @SA, ptr noundef nonnull align 8 dereferenceable(16) @SB, i64 16, i1 false), !tbaa.struct !9
  %.pr = load i64, ptr @mlen, align 8, !tbaa !5
  %.not10 = icmp eq i64 %.pr, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11, %19
  %16 = phi i64 [ %21, %19 ], [ %.pr, %11 ]
  %17 = and i64 %16, 1
  %.not8 = icmp eq i64 %17, 0
  br i1 %.not8, label %19, label %18

18:                                               ; preds = %.lr.ph
  tail call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @SA, ptr noundef nonnull align 8 dereferenceable(16) @A)
  br label %19

19:                                               ; preds = %18, %.lr.ph
  tail call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @A, ptr noundef nonnull align 8 dereferenceable(16) @A)
  %20 = load i64, ptr @mlen, align 8, !tbaa !5
  %21 = ashr i64 %20, 1
  store i64 %21, ptr @mlen, align 8, !tbaa !5
  %.not = icmp ult i64 %20, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %19, %11
  tail call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @B, ptr noundef nonnull align 8 dereferenceable(16) @SA)
  %.pr9 = load i64, ptr @nlen, align 8, !tbaa !5
  %.not611 = icmp eq i64 %.pr9, 0
  br i1 %.not611, label %._crit_edge14, label %.lr.ph13

.lr.ph13:                                         ; preds = %._crit_edge, %25
  %22 = phi i64 [ %27, %25 ], [ %.pr9, %._crit_edge ]
  %23 = and i64 %22, 1
  %.not7 = icmp eq i64 %23, 0
  br i1 %.not7, label %25, label %24

24:                                               ; preds = %.lr.ph13
  tail call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @SB, ptr noundef nonnull align 8 dereferenceable(16) @B)
  br label %25

25:                                               ; preds = %24, %.lr.ph13
  tail call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @B, ptr noundef nonnull align 8 dereferenceable(16) @B)
  %26 = load i64, ptr @nlen, align 8, !tbaa !5
  %27 = ashr i64 %26, 1
  store i64 %27, ptr @nlen, align 8, !tbaa !5
  %.not6 = icmp ult i64 %26, 2
  br i1 %.not6, label %._crit_edge14, label %.lr.ph13, !llvm.loop !12

._crit_edge14:                                    ; preds = %25, %._crit_edge
  tail call void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16) @SA, ptr noundef nonnull align 8 dereferenceable(16) @SB)
  %28 = load i64, ptr @SA, align 8, !tbaa !13
  %29 = load i64, ptr getelementptr inbounds (i8, ptr @SA, i64 8), align 8, !tbaa !15
  %30 = add nsw i64 %29, %28
  %31 = srem i64 %30, 1000000007
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %31)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) 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 nounwind uwtable
declare dso_local void @_ZN6MatrixmLERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

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

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 norecurse 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 8, !5, i64 8, i64 8, !5}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS6Matrix", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}


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