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

; 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]] }

@m = external dso_local global i64, align 8
@a = external dso_local global i64, align 8
@c = external dso_local global i64, align 8
@x0 = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@g = external dso_local global i64, align 8
@ans = external dso_local global %struct.Matrix, align 8
@sum = external dso_local global %struct.Matrix, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.2 = 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @m, ptr noundef @a, ptr noundef @c, ptr noundef @x0, ptr noundef @n, ptr noundef @g)
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = icmp ne i64 %5, 0
  br i1 %6, label %12, label %7

7:                                                ; preds = %0
  %8 = load i64, ptr @x0, align 8, !tbaa !5
  %9 = load i64, ptr @g, align 8, !tbaa !5
  %10 = srem i64 %8, %9
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %10)
  br label %38

12:                                               ; preds = %0
  store i32 1, ptr @ans, align 8, !tbaa !9
  store i32 2, ptr getelementptr inbounds (%struct.Matrix, ptr @ans, i32 0, i32 1), align 4, !tbaa !12
  %13 = load i64, ptr @x0, align 8, !tbaa !5
  %14 = load i64, ptr @m, align 8, !tbaa !5
  %15 = srem i64 %13, %14
  store i64 %15, ptr getelementptr inbounds (%struct.Matrix, ptr @ans, i32 0, i32 2), align 8, !tbaa !5
  %16 = load i64, ptr @c, align 8, !tbaa !5
  %17 = load i64, ptr @m, align 8, !tbaa !5
  %18 = srem i64 %16, %17
  store i64 %18, ptr getelementptr inbounds ([2 x i64], ptr getelementptr inbounds (%struct.Matrix, ptr @ans, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !5
  store i32 2, ptr @sum, align 8, !tbaa !9
  store i32 2, ptr getelementptr inbounds (%struct.Matrix, ptr @sum, i32 0, i32 1), align 4, !tbaa !12
  %19 = load i64, ptr @a, align 8, !tbaa !5
  %20 = load i64, ptr @m, align 8, !tbaa !5
  %21 = srem i64 %19, %20
  store i64 %21, ptr getelementptr inbounds (%struct.Matrix, ptr @sum, i32 0, i32 2), align 8, !tbaa !5
  store i64 1, ptr getelementptr inbounds ([2 x i64], ptr getelementptr inbounds ([2 x [2 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @sum, i32 0, i32 2), i64 0, i64 1), i64 0, i64 1), align 8, !tbaa !5
  store i64 1, ptr getelementptr inbounds ([2 x [2 x i64]], ptr getelementptr inbounds (%struct.Matrix, ptr @sum, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !5
  br label %22

22:                                               ; preds = %30, %12
  %23 = load i64, ptr @n, align 8, !tbaa !5
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %22
  %26 = load i64, ptr @n, align 8, !tbaa !5
  %27 = and i64 %26, 1
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 40, ptr %2) #4
  call void @_ZN6MatrixmLERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %2, ptr noundef nonnull align 8 dereferenceable(40) @ans, ptr noundef nonnull align 8 dereferenceable(40) @sum)
  call void @llvm.lifetime.end.p0(i64 40, ptr %2) #4
  br label %30

30:                                               ; preds = %29, %25
  call void @llvm.lifetime.start.p0(i64 40, ptr %3) #4
  call void @_ZN6MatrixmLERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %3, ptr noundef nonnull align 8 dereferenceable(40) @sum, ptr noundef nonnull align 8 dereferenceable(40) @sum)
  call void @llvm.lifetime.end.p0(i64 40, ptr %3) #4
  %31 = load i64, ptr @n, align 8, !tbaa !5
  %32 = ashr i64 %31, 1
  store i64 %32, ptr @n, align 8, !tbaa !5
  br label %22, !llvm.loop !13

33:                                               ; preds = %22
  %34 = load i64, ptr getelementptr inbounds (%struct.Matrix, ptr @ans, i32 0, i32 2), align 8, !tbaa !5
  %35 = load i64, ptr @g, align 8, !tbaa !5
  %36 = srem i64 %34, %35
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %36)
  br label %38

38:                                               ; preds = %33, %7
  ret i32 0
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6MatrixmLERKS_(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)) #3 align 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 = { 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 #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 = !{!"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 = 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, [2 x [2 x i64]] }

@m = external dso_local global i64, align 8
@a = external dso_local global i64, align 8
@c = external dso_local global i64, align 8
@x0 = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@g = external dso_local global i64, align 8
@ans = external dso_local global %struct.Matrix, align 8
@sum = external dso_local global %struct.Matrix, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.2 = 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 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 @m, ptr noundef nonnull @a, ptr noundef nonnull @c, ptr noundef nonnull @x0, ptr noundef nonnull @n, ptr noundef nonnull @g)
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %5, label %.lr.ph.preheader

5:                                                ; preds = %0
  %6 = load i64, ptr @x0, align 8, !tbaa !5
  %7 = load i64, ptr @g, align 8, !tbaa !5
  %8 = srem i64 %6, %7
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %8)
  br label %26

.lr.ph.preheader:                                 ; preds = %0
  store i32 1, ptr @ans, align 8, !tbaa !9
  store i32 2, ptr getelementptr inbounds (i8, ptr @ans, i64 4), align 4, !tbaa !12
  %10 = load i64, ptr @x0, align 8, !tbaa !5
  %11 = load i64, ptr @m, align 8, !tbaa !5
  %12 = srem i64 %10, %11
  store i64 %12, ptr getelementptr inbounds (i8, ptr @ans, i64 8), align 8, !tbaa !5
  %13 = load i64, ptr @c, align 8, !tbaa !5
  %14 = srem i64 %13, %11
  store i64 %14, ptr getelementptr inbounds (i8, ptr @ans, i64 16), align 8, !tbaa !5
  store i32 2, ptr @sum, align 8, !tbaa !9
  store i32 2, ptr getelementptr inbounds (i8, ptr @sum, i64 4), align 4, !tbaa !12
  %15 = load i64, ptr @a, align 8, !tbaa !5
  %16 = srem i64 %15, %11
  store i64 %16, ptr getelementptr inbounds (i8, ptr @sum, i64 8), align 8, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @sum, i64 32), align 8, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @sum, i64 24), align 8, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %17 = phi i64 [ %22, %20 ], [ %4, %.lr.ph.preheader ]
  %18 = and i64 %17, 1
  %.not2 = icmp eq i64 %18, 0
  br i1 %.not2, label %20, label %19

19:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %1) #4
  call void @_ZN6MatrixmLERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %1, ptr noundef nonnull align 8 dereferenceable(40) @ans, ptr noundef nonnull align 8 dereferenceable(40) @sum)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %1) #4
  br label %20

20:                                               ; preds = %19, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #4
  call void @_ZN6MatrixmLERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %2, ptr noundef nonnull align 8 dereferenceable(40) @sum, ptr noundef nonnull align 8 dereferenceable(40) @sum)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #4
  %21 = load i64, ptr @n, align 8, !tbaa !5
  %22 = ashr i64 %21, 1
  store i64 %22, ptr @n, align 8, !tbaa !5
  %.not1 = icmp ult i64 %21, 2
  br i1 %.not1, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %20
  %.pre = load i64, ptr getelementptr inbounds (i8, ptr @ans, i64 8), align 8, !tbaa !5
  %23 = load i64, ptr @g, align 8, !tbaa !5
  %24 = srem i64 %.pre, %23
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %24)
  br label %26

26:                                               ; preds = %._crit_edge, %5
  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: mustprogress uwtable
declare dso_local void @_ZN6MatrixmLERKS_(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 #3 align 2

attributes #0 = { mustprogress 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 = { 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 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 = !{!"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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass