; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/2016 Astar Contest - Round 2A (1001-All X)

; 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"

@T = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@a = external dso_local global [4 x [4 x i32]], align 16
@b = external dso_local global [4 x [4 x i32]], align 16
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4multPA4_iS0_(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @T)
  br label %3

3:                                                ; preds = %35, %0
  %4 = load i32, ptr @T, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @T, align 4, !tbaa !5
  %6 = icmp ne i32 %4, 0
  br i1 %6, label %7, label %36

7:                                                ; preds = %3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m, ptr noundef @mod, ptr noundef @c)
  store i32 10, ptr getelementptr inbounds ([4 x i32], ptr getelementptr inbounds ([4 x [4 x i32]], ptr @a, i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([4 x i32], ptr getelementptr inbounds ([4 x [4 x i32]], ptr @b, i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([4 x i32], ptr getelementptr inbounds ([4 x [4 x i32]], ptr @a, i64 0, i64 2), i64 0, i64 2), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([4 x i32], ptr getelementptr inbounds ([4 x [4 x i32]], ptr @a, i64 0, i64 1), i64 0, i64 2), align 8, !tbaa !5
  store i32 0, ptr getelementptr inbounds ([4 x i32], ptr getelementptr inbounds ([4 x [4 x i32]], ptr @b, i64 0, i64 1), i64 0, i64 2), align 8, !tbaa !5
  store i32 0, ptr getelementptr inbounds ([4 x i32], ptr getelementptr inbounds ([4 x [4 x i32]], ptr @a, i64 0, i64 2), i64 0, i64 1), align 4, !tbaa !5
  br label %9

9:                                                ; preds = %17, %7
  %10 = load i64, ptr @m, align 8, !tbaa !9
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %20

12:                                               ; preds = %9
  %13 = load i64, ptr @m, align 8, !tbaa !9
  %14 = and i64 %13, 1
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  call void @_Z4multPA4_iS0_(ptr noundef @b, ptr noundef @a)
  br label %17

17:                                               ; preds = %16, %12
  call void @_Z4multPA4_iS0_(ptr noundef @a, ptr noundef @a)
  %18 = load i64, ptr @m, align 8, !tbaa !9
  %19 = ashr i64 %18, 1
  store i64 %19, ptr @m, align 8, !tbaa !9
  br label %9, !llvm.loop !11

20:                                               ; preds = %9
  %21 = load i32, ptr @t, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @t, align 4, !tbaa !5
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %22)
  %24 = load i32, ptr getelementptr inbounds ([4 x i32], ptr getelementptr inbounds ([4 x [4 x i32]], ptr @b, i64 0, i64 1), i64 0, i64 2), align 8, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = mul nsw i32 %24, %25
  %27 = load i32, ptr @mod, align 4, !tbaa !5
  %28 = srem i32 %26, %27
  %29 = load i32, ptr @c, align 4, !tbaa !5
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %20
  %32 = call i32 @puts(ptr noundef @.str.3)
  br label %35

33:                                               ; preds = %20
  %34 = call i32 @puts(ptr noundef @.str.4)
  br label %35

35:                                               ; preds = %33, %31
  br label %3, !llvm.loop !13

36:                                               ; preds = %3
  ret i32 0
}

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

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

declare i32 @puts(ptr noundef) #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 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" }

!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}


; 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"

@T = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@t = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [4 x [4 x i32]], align 16
@b = external dso_local global [4 x [4 x i32]], align 16
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4multPA4_iS0_(ptr noundef, 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 @T)
  %2 = load i32, ptr @T, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @T, align 4, !tbaa !5
  %.not4 = icmp eq i32 %2, 0
  br i1 %.not4, label %._crit_edge7, label %.lr.ph6

.lr.ph6:                                          ; preds = %0, %._crit_edge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @mod, ptr noundef nonnull @c)
  store i32 10, ptr getelementptr inbounds (i8, ptr @a, i64 20), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @b, i64 20), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @a, i64 40), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @a, i64 24), align 8, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @b, i64 24), align 8, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @a, i64 36), align 4, !tbaa !5
  %.pr = load i64, ptr @m, align 8, !tbaa !9
  %.not13 = icmp eq i64 %.pr, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph6, %8
  %5 = phi i64 [ %10, %8 ], [ %.pr, %.lr.ph6 ]
  %6 = and i64 %5, 1
  %.not2 = icmp eq i64 %6, 0
  br i1 %.not2, label %8, label %7

7:                                                ; preds = %.lr.ph
  tail call void @_Z4multPA4_iS0_(ptr noundef nonnull @b, ptr noundef nonnull @a)
  br label %8

8:                                                ; preds = %7, %.lr.ph
  tail call void @_Z4multPA4_iS0_(ptr noundef nonnull @a, ptr noundef nonnull @a)
  %9 = load i64, ptr @m, align 8, !tbaa !9
  %10 = ashr i64 %9, 1
  store i64 %10, ptr @m, align 8, !tbaa !9
  %.not1 = icmp ult i64 %9, 2
  br i1 %.not1, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %8, %.lr.ph6
  %11 = load i32, ptr @t, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @t, align 4, !tbaa !5
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %12)
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @b, i64 24), align 8, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = mul nsw i32 %15, %14
  %17 = load i32, ptr @mod, align 4, !tbaa !5
  %18 = srem i32 %16, %17
  %19 = load i32, ptr @c, align 4, !tbaa !5
  %20 = icmp eq i32 %18, %19
  %.str.3..str.4 = select i1 %20, ptr @.str.3, ptr @.str.4
  %21 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.3..str.4)
  %22 = load i32, ptr @T, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr @T, align 4, !tbaa !5
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %._crit_edge7, label %.lr.ph6, !llvm.loop !13

._crit_edge7:                                     ; preds = %._crit_edge, %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: nofree nounwind
declare noundef i32 @puts(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" }

!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}


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