; LLVM IR from abhisheknaiidu/dsa :: Other/SPOJ/mpow-power-of-matrix.ll (Z5powerPA101_xxx)

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

@I = external dso_local global [101 x [101 x i64]], align 16

; 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 nounwind uwtable
declare dso_local void @_Z3mulPA101_xS0_x(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5powerPA101_xxx(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 1, ptr %7, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %42, %3
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = icmp sle i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %45

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 1, ptr %9, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %38, %17
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = icmp sle i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %41

23:                                               ; preds = %18
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = icmp eq i64 %24, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %23
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %28
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = getelementptr inbounds [101 x i64], ptr %29, i64 0, i64 %30
  store i64 1, ptr %31, align 8, !tbaa !9
  br label %37

32:                                               ; preds = %23
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %33
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds [101 x i64], ptr %34, i64 0, i64 %35
  store i64 0, ptr %36, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %32, %27
  br label %38

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

41:                                               ; preds = %22
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %7, align 8, !tbaa !9
  br label %12, !llvm.loop !13

45:                                               ; preds = %16
  br label %46

46:                                               ; preds = %64, %45
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %65

49:                                               ; preds = %46
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = srem i64 %50, 2
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %49
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load i64, ptr %5, align 8, !tbaa !9
  call void @_Z3mulPA101_xS0_x(ptr noundef @I, ptr noundef %54, i64 noundef %55)
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = add nsw i64 %56, -1
  store i64 %57, ptr %6, align 8, !tbaa !9
  br label %64

58:                                               ; preds = %49
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i64, ptr %5, align 8, !tbaa !9
  call void @_Z3mulPA101_xS0_x(ptr noundef %59, ptr noundef %60, i64 noundef %61)
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = sdiv i64 %62, 2
  store i64 %63, ptr %6, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %58, %53
  br label %46, !llvm.loop !14

65:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 1, ptr %10, align 8, !tbaa !9
  br label %66

66:                                               ; preds = %92, %65
  %67 = load i64, ptr %10, align 8, !tbaa !9
  %68 = load i64, ptr %5, align 8, !tbaa !9
  %69 = icmp sle i64 %67, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %66
  store i32 10, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %95

71:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 1, ptr %11, align 8, !tbaa !9
  br label %72

72:                                               ; preds = %88, %71
  %73 = load i64, ptr %11, align 8, !tbaa !9
  %74 = load i64, ptr %5, align 8, !tbaa !9
  %75 = icmp sle i64 %73, %74
  br i1 %75, label %77, label %76

76:                                               ; preds = %72
  store i32 13, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %91

77:                                               ; preds = %72
  %78 = load i64, ptr %10, align 8, !tbaa !9
  %79 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %78
  %80 = load i64, ptr %11, align 8, !tbaa !9
  %81 = getelementptr inbounds [101 x i64], ptr %79, i64 0, i64 %80
  %82 = load i64, ptr %81, align 8, !tbaa !9
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = load i64, ptr %10, align 8, !tbaa !9
  %85 = getelementptr inbounds [101 x i64], ptr %83, i64 %84
  %86 = load i64, ptr %11, align 8, !tbaa !9
  %87 = getelementptr inbounds [101 x i64], ptr %85, i64 0, i64 %86
  store i64 %82, ptr %87, align 8, !tbaa !9
  br label %88

88:                                               ; preds = %77
  %89 = load i64, ptr %11, align 8, !tbaa !9
  %90 = add nsw i64 %89, 1
  store i64 %90, ptr %11, align 8, !tbaa !9
  br label %72, !llvm.loop !15

91:                                               ; preds = %76
  br label %92

92:                                               ; preds = %91
  %93 = load i64, ptr %10, align 8, !tbaa !9
  %94 = add nsw i64 %93, 1
  store i64 %94, ptr %10, align 8, !tbaa !9
  br label %66, !llvm.loop !16

95:                                               ; preds = %70
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"any pointer", !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}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !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"

@I = external dso_local global [101 x [101 x i64]], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5powerPA101_xxx(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %0 to i64
  %.not47 = icmp slt i64 %1, 1
  br i1 %.not47, label %.preheader43, label %.preheader44.preheader

.preheader44.preheader:                           ; preds = %3
  %min.iters.check = icmp ult i64 %1, 4
  %n.vec = and i64 %1, 9223372036854775804
  %ind.end = or disjoint i64 %n.vec, 1
  %cmp.n = icmp eq i64 %n.vec, %1
  br label %.preheader44

.preheader44:                                     ; preds = %.preheader44.preheader, %._crit_edge
  %.03348 = phi i64 [ %12, %._crit_edge ], [ 1, %.preheader44.preheader ]
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader44
  %.03246.ph = phi i64 [ 1, %.preheader44 ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.preheader44
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %.03348, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 1, i64 2>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %offset.idx = or disjoint i64 %index, 1
  %5 = icmp eq <2 x i64> %broadcast.splat, %vec.ind
  %6 = icmp eq <2 x i64> %broadcast.splat, %step.add
  %7 = zext <2 x i1> %5 to <2 x i64>
  %8 = zext <2 x i1> %6 to <2 x i64>
  %9 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %.03348, i64 %offset.idx
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  store <2 x i64> %7, ptr %9, align 8
  store <2 x i64> %8, ptr %10, align 8
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %11 = icmp eq i64 %index.next, %n.vec
  br i1 %11, label %middle.block, label %vector.body, !llvm.loop !5

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

.preheader43:                                     ; preds = %._crit_edge, %3
  %.not3749 = icmp eq i64 %2, 0
  br i1 %.not3749, label %.preheader42, label %.lr.ph

._crit_edge:                                      ; preds = %scalar.ph, %middle.block
  %12 = add nuw i64 %.03348, 1
  %exitcond58.not = icmp eq i64 %.03348, %1
  br i1 %exitcond58.not, label %.preheader43, label %.preheader44, !llvm.loop !9

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.03246 = phi i64 [ %15, %scalar.ph ], [ %.03246.ph, %scalar.ph.preheader ]
  %13 = icmp eq i64 %.03348, %.03246
  %spec.select = zext i1 %13 to i64
  %14 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %.03348, i64 %.03246
  store i64 %spec.select, ptr %14, align 8
  %15 = add nuw i64 %.03246, 1
  %exitcond.not = icmp eq i64 %.03246, %1
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !10

.preheader42:                                     ; preds = %23, %.preheader43
  br i1 %.not47, label %._crit_edge57, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader42
  %16 = sub i64 %4, ptrtoint (ptr @I to i64)
  %17 = add nuw i64 %1, 1
  %min.iters.check65 = icmp ult i64 %1, 4
  %diff.check = icmp ult i64 %16, 32
  %or.cond = or i1 %min.iters.check65, %diff.check
  %n.vec68 = and i64 %1, 9223372036854775804
  %ind.end69 = or disjoint i64 %n.vec68, 1
  %cmp.n76 = icmp eq i64 %n.vec68, %1
  br label %.preheader

.lr.ph:                                           ; preds = %.preheader43, %23
  %.03450 = phi i64 [ %.1, %23 ], [ %2, %.preheader43 ]
  %18 = and i64 %.03450, 1
  %.not40 = icmp eq i64 %18, 0
  br i1 %.not40, label %21, label %19

19:                                               ; preds = %.lr.ph
  tail call void @_Z3mulPA101_xS0_x(ptr noundef nonnull @I, ptr noundef %0, i64 noundef %1)
  %20 = add nsw i64 %.03450, -1
  br label %23

21:                                               ; preds = %.lr.ph
  tail call void @_Z3mulPA101_xS0_x(ptr noundef %0, ptr noundef %0, i64 noundef %1)
  %22 = ashr exact i64 %.03450, 1
  br label %23

23:                                               ; preds = %21, %19
  %.1 = phi i64 [ %20, %19 ], [ %22, %21 ]
  %.not37 = icmp eq i64 %.1, 0
  br i1 %.not37, label %.preheader42, label %.lr.ph, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge54
  %.03156 = phi i64 [ %36, %._crit_edge54 ], [ 1, %.preheader.preheader ]
  br i1 %or.cond, label %scalar.ph64.preheader, label %vector.body71

scalar.ph64.preheader:                            ; preds = %middle.block63, %.preheader
  %.052.ph = phi i64 [ 1, %.preheader ], [ %ind.end69, %middle.block63 ]
  %24 = sub i64 %17, %.052.ph
  %25 = sub i64 %1, %.052.ph
  %xtraiter = and i64 %24, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph64.prol.loopexit, label %scalar.ph64.prol

scalar.ph64.prol:                                 ; preds = %scalar.ph64.preheader, %scalar.ph64.prol
  %.052.prol = phi i64 [ %29, %scalar.ph64.prol ], [ %.052.ph, %scalar.ph64.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph64.prol ], [ 0, %scalar.ph64.preheader ]
  %26 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %.03156, i64 %.052.prol
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds [101 x i64], ptr %0, i64 %.03156, i64 %.052.prol
  store i64 %27, ptr %28, align 8, !tbaa !12
  %29 = add nuw i64 %.052.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph64.prol.loopexit, label %scalar.ph64.prol, !llvm.loop !16

scalar.ph64.prol.loopexit:                        ; preds = %scalar.ph64.prol, %scalar.ph64.preheader
  %.052.unr = phi i64 [ %.052.ph, %scalar.ph64.preheader ], [ %29, %scalar.ph64.prol ]
  %30 = icmp ult i64 %25, 3
  br i1 %30, label %._crit_edge54, label %scalar.ph64

vector.body71:                                    ; preds = %.preheader, %vector.body71
  %index72 = phi i64 [ %index.next75, %vector.body71 ], [ 0, %.preheader ]
  %offset.idx73 = or disjoint i64 %index72, 1
  %31 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %.03156, i64 %offset.idx73
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  %wide.load = load <2 x i64>, ptr %31, align 8, !tbaa !12
  %wide.load74 = load <2 x i64>, ptr %32, align 8, !tbaa !12
  %33 = getelementptr inbounds [101 x i64], ptr %0, i64 %.03156, i64 %offset.idx73
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  store <2 x i64> %wide.load, ptr %33, align 8, !tbaa !12
  store <2 x i64> %wide.load74, ptr %34, align 8, !tbaa !12
  %index.next75 = add nuw i64 %index72, 4
  %35 = icmp eq i64 %index.next75, %n.vec68
  br i1 %35, label %middle.block63, label %vector.body71, !llvm.loop !18

middle.block63:                                   ; preds = %vector.body71
  br i1 %cmp.n76, label %._crit_edge54, label %scalar.ph64.preheader

._crit_edge57:                                    ; preds = %._crit_edge54, %.preheader42
  ret void

._crit_edge54:                                    ; preds = %scalar.ph64.prol.loopexit, %scalar.ph64, %middle.block63
  %36 = add nuw i64 %.03156, 1
  %exitcond61.not = icmp eq i64 %.03156, %1
  br i1 %exitcond61.not, label %._crit_edge57, label %.preheader, !llvm.loop !19

scalar.ph64:                                      ; preds = %scalar.ph64.prol.loopexit, %scalar.ph64
  %.052 = phi i64 [ %52, %scalar.ph64 ], [ %.052.unr, %scalar.ph64.prol.loopexit ]
  %37 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %.03156, i64 %.052
  %38 = load i64, ptr %37, align 8, !tbaa !12
  %39 = getelementptr inbounds [101 x i64], ptr %0, i64 %.03156, i64 %.052
  store i64 %38, ptr %39, align 8, !tbaa !12
  %40 = add nuw i64 %.052, 1
  %41 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %.03156, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !12
  %43 = getelementptr inbounds [101 x i64], ptr %0, i64 %.03156, i64 %40
  store i64 %42, ptr %43, align 8, !tbaa !12
  %44 = add nuw i64 %.052, 2
  %45 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %.03156, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !12
  %47 = getelementptr inbounds [101 x i64], ptr %0, i64 %.03156, i64 %44
  store i64 %46, ptr %47, align 8, !tbaa !12
  %48 = add nuw i64 %.052, 3
  %49 = getelementptr inbounds [101 x [101 x i64]], ptr @I, i64 0, i64 %.03156, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !12
  %51 = getelementptr inbounds [101 x i64], ptr %0, i64 %.03156, i64 %48
  store i64 %50, ptr %51, align 8, !tbaa !12
  %52 = add nuw i64 %.052, 4
  %exitcond60.not.3 = icmp eq i64 %48, %1
  br i1 %exitcond60.not.3, label %._crit_edge54, label %scalar.ph64, !llvm.loop !20
}

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

!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 = distinct !{!5, !6, !7, !8}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!"llvm.loop.isvectorized", i32 1}
!8 = !{!"llvm.loop.unroll.runtime.disable"}
!9 = distinct !{!9, !6}
!10 = distinct !{!10, !6, !8, !7}
!11 = distinct !{!11, !6}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !14, i64 0}
!14 = !{!"omnipotent char", !15, i64 0}
!15 = !{!"Simple C++ TBAA"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}
!18 = distinct !{!18, !6, !7, !8}
!19 = distinct !{!19, !6}
!20 = distinct !{!20, !6, !7}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass