; LLVM IR from tangjz/acm-icpc :: poj/2888.ll (Z3dfsiii)

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

@A = external dso_local global %struct.Matrix, align 4
@B = external dso_local global %struct.Matrix, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@p = external dso_local global [11 x i32], align 16
@c = external dso_local global [11 x i32], align 16
@ans = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Matrix, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr @cnt, align 4, !tbaa !5
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %52

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 408, ptr %7) #3
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sdiv i32 %15, %16
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %7, ptr noundef nonnull align 4 dereferenceable(408) @A, i32 noundef %17)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @B, ptr align 4 %7, i64 408, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 408, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %38, %14
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %41

23:                                               ; preds = %18
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x [10 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 %25
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [10 x i32], ptr %26, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = add nsw i32 %31, %30
  store i32 %32, ptr %8, align 4, !tbaa !5
  %33 = icmp sge i32 %32, 9973
  br i1 %33, label %34, label %37

34:                                               ; preds = %23
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 9973
  store i32 %36, ptr %8, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %34, %23
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %9, align 4, !tbaa !5
  br label %18, !llvm.loop !11

41:                                               ; preds = %22
  %42 = load i32, ptr @ans, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = mul nsw i64 %45, %47
  %49 = add nsw i64 %43, %48
  %50 = srem i64 %49, 9973
  %51 = trunc i64 %50 to i32
  store i32 %51, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %87

52:                                               ; preds = %3
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %54, i32 noundef %55, i32 noundef %56)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %84, %52
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [11 x i32], ptr @c, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = icmp sle i32 %58, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %87

65:                                               ; preds = %57
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [11 x i32], ptr @p, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = mul nsw i32 %72, %71
  store i32 %73, ptr %5, align 4, !tbaa !5
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [11 x i32], ptr @p, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = load i32, ptr %10, align 4, !tbaa !5
  %79 = icmp eq i32 %78, 1
  %80 = zext i1 %79 to i32
  %81 = sub nsw i32 %77, %80
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = mul nsw i32 %82, %81
  store i32 %83, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %67, i32 noundef %73, i32 noundef %83)
  br label %84

84:                                               ; preds = %65
  %85 = load i32, ptr %10, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %10, align 4, !tbaa !5
  br label %57, !llvm.loop !13

87:                                               ; preds = %64, %41
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Matrix3powEi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(408), i32 noundef) #0 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) #2

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

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree 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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 400, !10}
!10 = !{!7, !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"

%struct.Matrix = type { i32, i32, [10 x [10 x i32]] }

@A = external dso_local global %struct.Matrix, align 4
@B = external dso_local local_unnamed_addr global %struct.Matrix, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [11 x i32], align 16
@c = external dso_local local_unnamed_addr global [11 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.Matrix, align 4
  %5 = load i32, ptr @cnt, align 4, !tbaa !5
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %7, label %36

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 408, ptr nonnull %4) #3
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sdiv i32 %8, %1
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %4, ptr noundef nonnull align 4 dereferenceable(408) @A, i32 noundef %9)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(408) @B, ptr noundef nonnull align 4 dereferenceable(408) %4, i64 408, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 408, ptr nonnull %4) #3
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph35.preheader, label %._crit_edge

.lr.ph35.preheader:                               ; preds = %7
  %wide.trip.count = zext nneg i32 %10 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %12 = icmp eq i32 %10, 1
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph35.preheader.new

.lr.ph35.preheader.new:                           ; preds = %.lr.ph35.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph35

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph35, %.lr.ph35.preheader
  %spec.select.lcssa.ph = phi i32 [ poison, %.lr.ph35.preheader ], [ %spec.select.1, %.lr.ph35 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph35.preheader ], [ %indvars.iv.next.1, %.lr.ph35 ]
  %.02333.unr = phi i32 [ 0, %.lr.ph35.preheader ], [ %spec.select.1, %.lr.ph35 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph35.epil

.lr.ph35.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %13 = getelementptr inbounds [10 x [10 x i32]], ptr getelementptr inbounds (i8, ptr @B, i64 8), i64 0, i64 %indvars.iv.unr, i64 %indvars.iv.unr
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add nsw i32 %14, %.02333.unr
  %16 = icmp sgt i32 %15, 9972
  %17 = add nsw i32 %15, -9973
  %spec.select.epil = select i1 %16, i32 %17, i32 %15
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph35.epil
  %spec.select.lcssa = phi i32 [ %spec.select.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select.epil, %.lr.ph35.epil ]
  %18 = sext i32 %spec.select.lcssa to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %7
  %.023.lcssa = phi i64 [ 0, %7 ], [ %18, %._crit_edge.loopexit ]
  %19 = load i32, ptr @ans, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = sext i32 %2 to i64
  %22 = mul nsw i64 %.023.lcssa, %21
  %23 = add nsw i64 %22, %20
  %24 = srem i64 %23, 9973
  %25 = trunc nsw i64 %24 to i32
  store i32 %25, ptr @ans, align 4, !tbaa !5
  br label %.loopexit

.lr.ph35:                                         ; preds = %.lr.ph35, %.lr.ph35.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph35.preheader.new ], [ %indvars.iv.next.1, %.lr.ph35 ]
  %.02333 = phi i32 [ 0, %.lr.ph35.preheader.new ], [ %spec.select.1, %.lr.ph35 ]
  %niter = phi i64 [ 0, %.lr.ph35.preheader.new ], [ %niter.next.1, %.lr.ph35 ]
  %26 = getelementptr inbounds [10 x [10 x i32]], ptr getelementptr inbounds (i8, ptr @B, i64 8), i64 0, i64 %indvars.iv, i64 %indvars.iv
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %27, %.02333
  %29 = icmp sgt i32 %28, 9972
  %30 = add nsw i32 %28, -9973
  %spec.select = select i1 %29, i32 %30, i32 %28
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %31 = getelementptr inbounds [10 x [10 x i32]], ptr getelementptr inbounds (i8, ptr @B, i64 8), i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %32, %spec.select
  %34 = icmp sgt i32 %33, 9972
  %35 = add nsw i32 %33, -9973
  %spec.select.1 = select i1 %34, i32 %35, i32 %33
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph35, !llvm.loop !11

36:                                               ; preds = %3
  %37 = add nsw i32 %0, 1
  tail call void @_Z3dfsiii(i32 noundef %37, i32 noundef %1, i32 noundef %2)
  %38 = sext i32 %0 to i64
  %39 = getelementptr inbounds [11 x i32], ptr @c, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %.not29 = icmp slt i32 %40, 1
  br i1 %.not29, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %36
  %41 = getelementptr inbounds [11 x i32], ptr @p, i64 0, i64 %38
  br label %42

42:                                               ; preds = %.lr.ph, %42
  %.032 = phi i32 [ 1, %.lr.ph ], [ %48, %42 ]
  %.02431 = phi i32 [ %2, %.lr.ph ], [ %47, %42 ]
  %.02530 = phi i32 [ %1, %.lr.ph ], [ %44, %42 ]
  %43 = load i32, ptr %41, align 4, !tbaa !5
  %44 = mul nsw i32 %43, %.02530
  %45 = icmp eq i32 %.032, 1
  %.neg = sext i1 %45 to i32
  %46 = add i32 %43, %.neg
  %47 = mul nsw i32 %46, %.02431
  tail call void @_Z3dfsiii(i32 noundef %37, i32 noundef %44, i32 noundef %47)
  %48 = add nuw nsw i32 %.032, 1
  %49 = load i32, ptr %39, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.032, %49
  br i1 %.not.not, label %42, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %42, %36, %._crit_edge
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Matrix3powEi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(408), i32 noundef) local_unnamed_addr #0 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) #2

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

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


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