; LLVM IR from tangjz/acm-icpc :: self_training/2014-12-26 (D)

; 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.Mat = type { i32, i32, [4 x [4 x i64]] }

@A = external dso_local global %struct.Mat, align 8
@B = external dso_local global %struct.Mat, align 8
@C = external dso_local global %struct.Mat, 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 [8 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.Mat, align 8
  %9 = alloca %struct.Mat, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %11

11:                                               ; preds = %15, %0
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr %2, align 4, !tbaa !5
  %14 = icmp ne i32 %12, 0
  br i1 %14, label %15, label %30

15:                                               ; preds = %11
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7)
  store i32 1, ptr @A, align 8, !tbaa !9
  store i32 4, ptr getelementptr inbounds (%struct.Mat, ptr @A, i32 0, i32 1), align 4, !tbaa !11
  store i64 0, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds (%struct.Mat, ptr @A, i32 0, i32 2), i64 0, i64 2), align 8, !tbaa !12
  store i64 0, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds (%struct.Mat, ptr @A, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !12
  store i64 0, ptr getelementptr inbounds (%struct.Mat, ptr @A, i32 0, i32 2), align 8, !tbaa !12
  store i64 1, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds (%struct.Mat, ptr @A, i32 0, i32 2), i64 0, i64 3), align 8, !tbaa !12
  store i32 4, ptr @B, align 8, !tbaa !9
  store i32 4, ptr getelementptr inbounds (%struct.Mat, ptr @B, i32 0, i32 1), align 4, !tbaa !11
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  store i64 %18, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds (%struct.Mat, ptr @B, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !12
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  store i64 %20, ptr getelementptr inbounds ([4 x [4 x i64]], ptr getelementptr inbounds (%struct.Mat, ptr @B, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !12
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  store i64 %22, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds ([4 x [4 x i64]], ptr getelementptr inbounds (%struct.Mat, ptr @B, i32 0, i32 2), i64 0, i64 1), i64 0, i64 1), align 8, !tbaa !12
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  store i64 %24, ptr getelementptr inbounds ([4 x [4 x i64]], ptr getelementptr inbounds (%struct.Mat, ptr @B, i32 0, i32 2), i64 0, i64 2), align 8, !tbaa !12
  store i64 1, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds ([4 x [4 x i64]], ptr getelementptr inbounds (%struct.Mat, ptr @B, i32 0, i32 2), i64 0, i64 3), i64 0, i64 3), align 8, !tbaa !12
  store i64 1, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds ([4 x [4 x i64]], ptr getelementptr inbounds (%struct.Mat, ptr @B, i32 0, i32 2), i64 0, i64 3), i64 0, i64 2), align 8, !tbaa !12
  store i64 1, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds ([4 x [4 x i64]], ptr getelementptr inbounds (%struct.Mat, ptr @B, i32 0, i32 2), i64 0, i64 2), i64 0, i64 2), align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 136, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 136, ptr %9) #5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  call void @_ZN3Mat3powEi(ptr dead_on_unwind writable sret(%struct.Mat) align 8 %9, ptr noundef nonnull align 8 dereferenceable(136) @B, i32 noundef %25)
  call void @_ZNK3MatmlERKS_(ptr dead_on_unwind writable sret(%struct.Mat) align 8 %8, ptr noundef nonnull align 8 dereferenceable(136) @A, ptr noundef nonnull align 8 dereferenceable(136) %9)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @C, ptr align 8 %8, i64 136, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 136, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 136, ptr %8) #5
  %26 = load i64, ptr getelementptr inbounds (%struct.Mat, ptr @C, i32 0, i32 2), align 8, !tbaa !12
  %27 = load i64, ptr getelementptr inbounds ([4 x i64], ptr getelementptr inbounds (%struct.Mat, ptr @C, i32 0, i32 2), i64 0, i64 1), align 8, !tbaa !12
  %28 = add nsw i64 %26, %27
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %28)
  br label %11, !llvm.loop !16

30:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK3MatmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.Mat) align 8, ptr noundef nonnull align 8 dereferenceable(136), ptr noundef nonnull align 8 dereferenceable(136)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3Mat3powEi(ptr dead_on_unwind noalias writable sret(%struct.Mat) align 8, ptr noundef nonnull align 8 dereferenceable(136), i32 noundef) #3 align 2

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS3Mat", !6, i64 0, !6, i64 4, !7, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 128, !15}
!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.Mat = type { i32, i32, [4 x [4 x i64]] }

@A = external dso_local global %struct.Mat, align 8
@B = external dso_local global %struct.Mat, align 8
@C = external dso_local local_unnamed_addr global %struct.Mat, 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 [8 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Mat, align 8
  %8 = alloca %struct.Mat, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #6
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %1, align 4, !tbaa !5
  %.not1 = icmp eq i32 %10, 0
  br i1 %.not1, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6)
  store i32 1, ptr @A, align 8, !tbaa !9
  store i32 4, ptr getelementptr inbounds (i8, ptr @A, i64 4), align 4, !tbaa !11
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @A, i64 8), i8 0, i64 24, i1 false)
  store i64 1, ptr getelementptr inbounds (i8, ptr @A, i64 32), align 8, !tbaa !12
  store i32 4, ptr @B, align 8, !tbaa !9
  store i32 4, ptr getelementptr inbounds (i8, ptr @B, i64 4), align 4, !tbaa !11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  store i64 %14, ptr getelementptr inbounds (i8, ptr @B, i64 16), align 8, !tbaa !12
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  store i64 %16, ptr getelementptr inbounds (i8, ptr @B, i64 40), align 8, !tbaa !12
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  store i64 %18, ptr getelementptr inbounds (i8, ptr @B, i64 48), align 8, !tbaa !12
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  store i64 %20, ptr getelementptr inbounds (i8, ptr @B, i64 72), align 8, !tbaa !12
  store i64 1, ptr getelementptr inbounds (i8, ptr @B, i64 128), align 8, !tbaa !12
  store i64 1, ptr getelementptr inbounds (i8, ptr @B, i64 120), align 8, !tbaa !12
  store i64 1, ptr getelementptr inbounds (i8, ptr @B, i64 88), align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 136, ptr nonnull %7) #6
  call void @llvm.lifetime.start.p0(i64 136, ptr nonnull %8) #6
  %21 = load i32, ptr %6, align 4, !tbaa !5
  call void @_ZN3Mat3powEi(ptr dead_on_unwind nonnull writable sret(%struct.Mat) align 8 %8, ptr noundef nonnull align 8 dereferenceable(136) @B, i32 noundef %21)
  call void @_ZNK3MatmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Mat) align 8 %7, ptr noundef nonnull align 8 dereferenceable(136) @A, ptr noundef nonnull align 8 dereferenceable(136) %8)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(136) @C, ptr noundef nonnull align 8 dereferenceable(136) %7, i64 136, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 136, ptr nonnull %8) #6
  call void @llvm.lifetime.end.p0(i64 136, ptr nonnull %7) #6
  %22 = load i64, ptr getelementptr inbounds (i8, ptr @C, i64 8), align 8, !tbaa !12
  %23 = load i64, ptr getelementptr inbounds (i8, ptr @C, i64 16), align 8, !tbaa !12
  %24 = add nsw i64 %23, %22
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %24)
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK3MatmlERKS_(ptr dead_on_unwind noalias writable sret(%struct.Mat) align 8, ptr noundef nonnull align 8 dereferenceable(136), ptr noundef nonnull align 8 dereferenceable(136)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3Mat3powEi(ptr dead_on_unwind noalias writable sret(%struct.Mat) align 8, ptr noundef nonnull align 8 dereferenceable(136), i32 noundef) local_unnamed_addr #3 align 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) #4

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS3Mat", !6, i64 0, !6, i64 4, !7, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 128, !15}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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