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

; 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, [2 x [2 x i64]] }

@A = external dso_local global %struct.Matrix, align 8
@B = external dso_local global %struct.Matrix, align 8
@b = external dso_local global i64, align 8
@d = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@nn = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Matrix, align 8
  %3 = alloca %struct.Matrix, align 8
  %4 = alloca %struct.Matrix, align 8
  %5 = alloca %struct.Matrix, align 8
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @b, ptr noundef @d, ptr noundef @n)
  %7 = load i64, ptr @n, align 8, !tbaa !5
  store i64 %7, ptr @nn, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %2) #6
  %8 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 0
  store i32 1, ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 1
  store i32 2, ptr %9, align 4, !tbaa !12
  %10 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 2
  store i64 2, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i64, ptr %10, i64 1
  %12 = load i64, ptr @b, align 8, !tbaa !5
  store i64 %12, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds [2 x i64], ptr %10, i64 1
  %14 = getelementptr inbounds [2 x i64], ptr %10, i64 2
  br label %15

15:                                               ; preds = %15, %0
  %16 = phi ptr [ %13, %0 ], [ %17, %15 ]
  call void @llvm.memset.p0.i64(ptr align 8 %16, i8 0, i64 16, i1 false)
  %17 = getelementptr inbounds [2 x i64], ptr %16, i64 1
  %18 = icmp eq ptr %17, %14
  br i1 %18, label %19, label %15

19:                                               ; preds = %15
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @A, ptr align 8 %2, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 40, ptr %3) #6
  %20 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 0
  store i32 2, ptr %20, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 1
  store i32 2, ptr %21, align 4, !tbaa !12
  %22 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 2
  store i64 0, ptr %22, align 8, !tbaa !5
  %23 = getelementptr inbounds i64, ptr %22, i64 1
  %24 = load i64, ptr @d, align 8, !tbaa !5
  %25 = load i64, ptr @b, align 8, !tbaa !5
  %26 = load i64, ptr @b, align 8, !tbaa !5
  %27 = mul i64 %25, %26
  %28 = sub i64 %24, %27
  %29 = lshr i64 %28, 2
  store i64 %29, ptr %23, align 8, !tbaa !5
  %30 = getelementptr inbounds [2 x i64], ptr %22, i64 1
  store i64 1, ptr %30, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr %30, i64 1
  %32 = load i64, ptr @b, align 8, !tbaa !5
  store i64 %32, ptr %31, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @B, ptr align 8 %3, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %3) #6
  br label %33

33:                                               ; preds = %41, %19
  %34 = load i64, ptr @n, align 8, !tbaa !5
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %44

36:                                               ; preds = %33
  %37 = load i64, ptr @n, align 8, !tbaa !5
  %38 = and i64 %37, 1
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 40, ptr %4) #6
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %4, ptr noundef nonnull align 8 dereferenceable(40) @A, ptr noundef nonnull align 8 dereferenceable(40) @B)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @A, ptr align 8 %4, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %4) #6
  br label %41

41:                                               ; preds = %40, %36
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #6
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %5, ptr noundef nonnull align 8 dereferenceable(40) @B, ptr noundef nonnull align 8 dereferenceable(40) @B)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @B, ptr align 8 %5, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %5) #6
  %42 = load i64, ptr @n, align 8, !tbaa !5
  %43 = lshr i64 %42, 1
  store i64 %43, ptr @n, align 8, !tbaa !5
  br label %33, !llvm.loop !16

44:                                               ; preds = %33
  %45 = load i64, ptr @d, align 8, !tbaa !5
  %46 = load i64, ptr @b, align 8, !tbaa !5
  %47 = load i64, ptr @b, align 8, !tbaa !5
  %48 = mul i64 %46, %47
  %49 = icmp ne i64 %45, %48
  br i1 %49, label %50, label %64

50:                                               ; preds = %44
  %51 = load i64, ptr @nn, align 8, !tbaa !5
  %52 = xor i64 %51, -1
  %53 = and i64 %52, 1
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %64

55:                                               ; preds = %50
  %56 = load i64, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 8, !tbaa !5
  %57 = add i64 %56, -1
  store i64 %57, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 8, !tbaa !5
  %58 = load i64, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 8, !tbaa !5
  %59 = icmp ult i64 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %55
  %61 = load i64, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 8, !tbaa !5
  %62 = add i64 %61, 7528443412579576937
  store i64 %62, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 8, !tbaa !5
  br label %63

63:                                               ; preds = %60, %55
  br label %64

64:                                               ; preds = %63, %50, %44
  %65 = load i64, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 8, !tbaa !5
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %65)
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 @_ZNK6MatrixmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(40)) #5 align 2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { 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, !11, i64 0}
!10 = !{!"_ZTS6Matrix", !11, i64 0, !11, i64 4, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !14, i64 8, i64 32, !15}
!14 = !{!11, !11, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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, [2 x [2 x i64]] }

@A = external dso_local global %struct.Matrix, align 8
@B = external dso_local global %struct.Matrix, align 8
@b = external dso_local global i64, align 8
@d = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@nn = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca %struct.Matrix, align 8
  %2 = alloca %struct.Matrix, align 8
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @b, ptr noundef nonnull @d, ptr noundef nonnull @n)
  %4 = load i64, ptr @n, align 8, !tbaa !5
  store i64 %4, ptr @nn, align 8, !tbaa !5
  %5 = load i64, ptr @b, align 8, !tbaa !5
  store i32 1, ptr @A, align 8, !tbaa !9
  store i32 2, ptr getelementptr inbounds (i8, ptr @A, i64 4), align 4, !tbaa !9
  store i64 2, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 8
  store i64 %5, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @A, i64 24), i8 0, i64 16, i1 false)
  %6 = load i64, ptr @d, align 8, !tbaa !5
  %7 = mul i64 %5, %5
  %8 = sub i64 %6, %7
  %9 = lshr i64 %8, 2
  store i32 2, ptr @B, align 8, !tbaa !9
  store i32 2, ptr getelementptr inbounds (i8, ptr @B, i64 4), align 4, !tbaa !9
  store i64 0, ptr getelementptr inbounds (i8, ptr @B, i64 8), align 8
  store i64 %9, ptr getelementptr inbounds (i8, ptr @B, i64 16), align 8
  store i64 1, ptr getelementptr inbounds (i8, ptr @B, i64 24), align 8
  store i64 %5, ptr getelementptr inbounds (i8, ptr @B, i64 32), align 8, !tbaa !11
  %.not6 = icmp eq i64 %4, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %13
  %10 = phi i64 [ %15, %13 ], [ %4, %0 ]
  %11 = and i64 %10, 1
  %.not5 = icmp eq i64 %11, 0
  br i1 %.not5, label %13, label %12

12:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %1) #6
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %1, ptr noundef nonnull align 8 dereferenceable(40) @A, ptr noundef nonnull align 8 dereferenceable(40) @B)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) @A, ptr noundef nonnull align 8 dereferenceable(40) %1, i64 40, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %1) #6
  br label %13

13:                                               ; preds = %12, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #6
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %2, ptr noundef nonnull align 8 dereferenceable(40) @B, ptr noundef nonnull align 8 dereferenceable(40) @B)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) @B, ptr noundef nonnull align 8 dereferenceable(40) %2, i64 40, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #6
  %14 = load i64, ptr @n, align 8, !tbaa !5
  %15 = lshr i64 %14, 1
  store i64 %15, ptr @n, align 8, !tbaa !5
  %.not = icmp ult i64 %14, 2
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !13

._crit_edge.loopexit:                             ; preds = %13
  %.pre = load i64, ptr @d, align 8, !tbaa !5
  %.pre7 = load i64, ptr @b, align 8, !tbaa !5
  %.pre10 = mul i64 %.pre7, %.pre7
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.pre-phi = phi i64 [ %.pre10, %._crit_edge.loopexit ], [ %7, %0 ]
  %16 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %6, %0 ]
  %.not3 = icmp eq i64 %16, %.pre-phi
  br i1 %.not3, label %._crit_edge._crit_edge, label %17

._crit_edge._crit_edge:                           ; preds = %._crit_edge
  %.pre8 = load i64, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 8, !tbaa !5
  br label %22

17:                                               ; preds = %._crit_edge
  %18 = load i64, ptr @nn, align 8, !tbaa !5
  %19 = and i64 %18, 1
  %.not4.not = icmp eq i64 %19, 0
  %.pre9 = load i64, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 8, !tbaa !5
  br i1 %.not4.not, label %20, label %22

20:                                               ; preds = %17
  %21 = add i64 %.pre9, -1
  store i64 %21, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 8, !tbaa !5
  br label %22

22:                                               ; preds = %._crit_edge._crit_edge, %20, %17
  %23 = phi i64 [ %.pre8, %._crit_edge._crit_edge ], [ %21, %20 ], [ %.pre9, %17 ]
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %23)
  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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #5 align 2

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

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


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass