; LLVM IR from tangjz/acm-icpc :: lydsy/1009.ll (Z3pow6Matrixi)

; 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, [30 x [30 x i32]] }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3pow6Matrixi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4 %0, ptr noundef byval(%struct.Matrix) align 8 %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.Matrix, align 4
  %7 = alloca %struct.Matrix, align 4
  store i32 %2, ptr %4, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 4 %0, i8 0, i64 3608, i1 false)
  %8 = getelementptr inbounds %struct.Matrix, ptr %1, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.Matrix, ptr %0, i32 0, i32 1
  store i32 %9, ptr %10, align 4, !tbaa !11
  %11 = getelementptr inbounds %struct.Matrix, ptr %0, i32 0, i32 0
  store i32 %9, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %26, %3
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = getelementptr inbounds %struct.Matrix, ptr %1, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %29

18:                                               ; preds = %12
  %19 = getelementptr inbounds %struct.Matrix, ptr %0, i32 0, i32 2
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [30 x [30 x i32]], ptr %19, i64 0, i64 %21
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [30 x i32], ptr %22, i64 0, i64 %24
  store i32 1, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %18
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !12

29:                                               ; preds = %17
  br label %30

30:                                               ; preds = %38, %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %30
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = and i32 %34, 1
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 3608, ptr %6) #3
  call void @_ZN6MatrixmLERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %6, ptr noundef nonnull align 4 dereferenceable(3608) %0, ptr noundef nonnull align 4 dereferenceable(3608) %1)
  call void @llvm.lifetime.end.p0(i64 3608, ptr %6) #3
  br label %38

38:                                               ; preds = %37, %33
  call void @llvm.lifetime.start.p0(i64 3608, ptr %7) #3
  call void @_ZN6MatrixmLERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %7, ptr noundef nonnull align 4 dereferenceable(3608) %1, ptr noundef nonnull align 4 dereferenceable(3608) %1)
  call void @llvm.lifetime.end.p0(i64 3608, ptr %7) #3
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = ashr i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !5
  br label %30, !llvm.loop !14

41:                                               ; preds = %30
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6MatrixmLERKS_(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(3608), ptr noundef nonnull align 4 dereferenceable(3608)) #0 align 2

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


; 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, [30 x [30 x i32]] }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3pow6Matrixi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4 %0, ptr noundef byval(%struct.Matrix) align 8 %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.Matrix, align 4
  %5 = alloca %struct.Matrix, align 4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(3608) %6, i8 0, i64 3600, i1 false)
  %7 = load i32, ptr %1, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %7, ptr %8, align 4, !tbaa !10
  store i32 %7, ptr %0, align 4, !tbaa !5
  %9 = icmp sgt i32 %7, 0
  br i1 %9, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %wide.trip.count = zext nneg i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %11 = icmp ult i32 %7, 4
  br i1 %11, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %13

.preheader.loopexit.unr-lcssa:                    ; preds = %13, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %13 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.epil.preheader

.epil.preheader:                                  ; preds = %.preheader.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.preheader.loopexit.unr-lcssa ]
  %12 = getelementptr inbounds [30 x [30 x i32]], ptr %10, i64 0, i64 %indvars.iv.epil, i64 %indvars.iv.epil
  store i32 1, ptr %12, align 4, !tbaa !11
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader, label %.epil.preheader, !llvm.loop !12

.preheader:                                       ; preds = %.preheader.loopexit.unr-lcssa, %.epil.preheader, %3
  %.not10 = icmp eq i32 %2, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph12

13:                                               ; preds = %13, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %13 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %13 ]
  %14 = getelementptr inbounds [30 x [30 x i32]], ptr %10, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i32 1, ptr %14, align 4, !tbaa !11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %15 = getelementptr inbounds [30 x [30 x i32]], ptr %10, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next
  store i32 1, ptr %15, align 4, !tbaa !11
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %16 = getelementptr inbounds [30 x [30 x i32]], ptr %10, i64 0, i64 %indvars.iv.next.1, i64 %indvars.iv.next.1
  store i32 1, ptr %16, align 4, !tbaa !11
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %17 = getelementptr inbounds [30 x [30 x i32]], ptr %10, i64 0, i64 %indvars.iv.next.2, i64 %indvars.iv.next.2
  store i32 1, ptr %17, align 4, !tbaa !11
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.loopexit.unr-lcssa, label %13, !llvm.loop !14

.lr.ph12:                                         ; preds = %.preheader, %20
  %.0711 = phi i32 [ %21, %20 ], [ %2, %.preheader ]
  %18 = and i32 %.0711, 1
  %.not8 = icmp eq i32 %18, 0
  br i1 %.not8, label %20, label %19

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

20:                                               ; preds = %19, %.lr.ph12
  call void @llvm.lifetime.start.p0(i64 3608, ptr nonnull %5) #3
  call void @_ZN6MatrixmLERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %5, ptr noundef nonnull align 4 dereferenceable(3608) %1, ptr noundef nonnull align 4 dereferenceable(3608) %1)
  call void @llvm.lifetime.end.p0(i64 3608, ptr nonnull %5) #3
  %21 = ashr i32 %.0711, 1
  %.not = icmp ult i32 %.0711, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph12, !llvm.loop !16

._crit_edge:                                      ; preds = %20, %.preheader
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6MatrixmLERKS_(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(3608), ptr noundef nonnull align 4 dereferenceable(3608)) local_unnamed_addr #0 align 2

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass