; LLVM IR from libxsmm/libxsmm :: src (generator_common)

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

; 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: nounwind uwtable
define dso_local i32 @libxsmm_compute_equalized_blocking(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = icmp ult i32 %22, 1
  br i1 %23, label %24, label %25

24:                                               ; preds = %6
  br label %27

25:                                               ; preds = %6
  %26 = load i32, ptr %7, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %25, %24
  %28 = phi i32 [ 1, %24 ], [ %26, %25 ]
  store i32 %28, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %29 = load i32, ptr %13, align 4, !tbaa !5
  %30 = sub i32 %29, 1
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = udiv i32 %30, %31
  %33 = add i32 %32, 1
  store i32 %33, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %34 = load i32, ptr %13, align 4, !tbaa !5
  %35 = load i32, ptr %14, align 4, !tbaa !5
  %36 = urem i32 %34, %35
  store i32 %36, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %37 = load i32, ptr %13, align 4, !tbaa !5
  %38 = load i32, ptr %14, align 4, !tbaa !5
  %39 = udiv i32 %37, %38
  store i32 %39, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  %40 = load i32, ptr %16, align 4, !tbaa !5
  %41 = add i32 %40, 1
  store i32 %41, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #2
  store i32 0, ptr %18, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #2
  store i32 0, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #2
  store i32 0, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #2
  store i32 0, ptr %21, align 4, !tbaa !5
  %42 = load i32, ptr %17, align 4, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = icmp ugt i32 %42, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %27
  %46 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %46, ptr %17, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %45, %27
  store i32 0, ptr %20, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %65, %47
  %49 = load i32, ptr %20, align 4, !tbaa !5
  %50 = load i32, ptr %14, align 4, !tbaa !5
  %51 = icmp ult i32 %49, %50
  br i1 %51, label %52, label %68

52:                                               ; preds = %48
  %53 = load i32, ptr %20, align 4, !tbaa !5
  %54 = load i32, ptr %15, align 4, !tbaa !5
  %55 = icmp ult i32 %53, %54
  br i1 %55, label %56, label %60

56:                                               ; preds = %52
  %57 = load i32, ptr %17, align 4, !tbaa !5
  %58 = load i32, ptr %19, align 4, !tbaa !5
  %59 = add i32 %58, %57
  store i32 %59, ptr %19, align 4, !tbaa !5
  br label %64

60:                                               ; preds = %52
  %61 = load i32, ptr %16, align 4, !tbaa !5
  %62 = load i32, ptr %18, align 4, !tbaa !5
  %63 = add i32 %62, %61
  store i32 %63, ptr %18, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %60, %56
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %20, align 4, !tbaa !5
  %67 = add i32 %66, 1
  store i32 %67, ptr %20, align 4, !tbaa !5
  br label %48, !llvm.loop !11

68:                                               ; preds = %48
  %69 = load i32, ptr %15, align 4, !tbaa !5
  %70 = icmp eq i32 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %72, ptr %17, align 4, !tbaa !5
  %73 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %73, ptr %19, align 4, !tbaa !5
  store i32 0, ptr %16, align 4, !tbaa !5
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %71, %68
  %75 = load i32, ptr %19, align 4, !tbaa !5
  %76 = load i32, ptr %17, align 4, !tbaa !5
  %77 = urem i32 %75, %76
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %74
  store i32 1, ptr %21, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %79, %74
  %81 = load i32, ptr %16, align 4, !tbaa !5
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %90

83:                                               ; preds = %80
  %84 = load i32, ptr %18, align 4, !tbaa !5
  %85 = load i32, ptr %16, align 4, !tbaa !5
  %86 = urem i32 %84, %85
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %89

88:                                               ; preds = %83
  store i32 1, ptr %21, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %88, %83
  br label %90

90:                                               ; preds = %89, %80
  %91 = load i32, ptr %19, align 4, !tbaa !5
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  store i32 %91, ptr %92, align 4, !tbaa !5
  %93 = load i32, ptr %17, align 4, !tbaa !5
  %94 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 %93, ptr %94, align 4, !tbaa !5
  %95 = load i32, ptr %18, align 4, !tbaa !5
  %96 = load ptr, ptr %11, align 8, !tbaa !9
  store i32 %95, ptr %96, align 4, !tbaa !5
  %97 = load i32, ptr %16, align 4, !tbaa !5
  %98 = load ptr, ptr %12, align 8, !tbaa !9
  store i32 %97, ptr %98, align 4, !tbaa !5
  %99 = load i32, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  ret i32 %99
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local range(i32 0, 2) i32 @libxsmm_compute_equalized_blocking(i32 noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = tail call i32 @llvm.umax.i32(i32 %0, i32 1)
  %8 = add i32 %7, -1
  %9 = udiv i32 %8, %1
  %10 = add nuw i32 %9, 1
  %11 = urem i32 %7, %10
  %12 = udiv i32 %7, %10
  %13 = add i32 %12, 1
  %spec.select = tail call i32 @llvm.umin.i32(i32 %13, i32 %1)
  %min.iters.check = icmp ult i32 %9, 7
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %6
  %n.vec = and i32 %10, -8
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %11, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert71 = insertelement <4 x i32> poison, i32 %12, i64 0
  %broadcast.splat72 = shufflevector <4 x i32> %broadcast.splatinsert71, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert73 = insertelement <4 x i32> poison, i32 %spec.select, i64 0
  %broadcast.splat74 = shufflevector <4 x i32> %broadcast.splatinsert73, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %22, %vector.body ]
  %vec.phi68 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %23, %vector.body ]
  %vec.phi69 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %18, %vector.body ]
  %vec.phi70 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %19, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %14 = icmp ult <4 x i32> %vec.ind, %broadcast.splat
  %15 = icmp ult <4 x i32> %step.add, %broadcast.splat
  %16 = select <4 x i1> %14, <4 x i32> zeroinitializer, <4 x i32> %broadcast.splat72
  %17 = select <4 x i1> %15, <4 x i32> zeroinitializer, <4 x i32> %broadcast.splat72
  %18 = add <4 x i32> %16, %vec.phi69
  %19 = add <4 x i32> %17, %vec.phi70
  %20 = select <4 x i1> %14, <4 x i32> %broadcast.splat74, <4 x i32> zeroinitializer
  %21 = select <4 x i1> %15, <4 x i32> %broadcast.splat74, <4 x i32> zeroinitializer
  %22 = add <4 x i32> %20, %vec.phi
  %23 = add <4 x i32> %21, %vec.phi68
  %index.next = add nuw i32 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %24 = icmp eq i32 %index.next, %n.vec
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !5

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %23, %22
  %25 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %bin.rdx75 = add <4 x i32> %19, %18
  %26 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx75)
  %cmp.n = icmp eq i32 %10, %n.vec
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %6
  %.03766.ph = phi i32 [ 0, %6 ], [ %n.vec, %middle.block ]
  %.03865.ph = phi i32 [ 0, %6 ], [ %25, %middle.block ]
  %.04064.ph = phi i32 [ 0, %6 ], [ %26, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.03766 = phi i32 [ %30, %scalar.ph ], [ %.03766.ph, %scalar.ph.preheader ]
  %.03865 = phi i32 [ %.139, %scalar.ph ], [ %.03865.ph, %scalar.ph.preheader ]
  %.04064 = phi i32 [ %.141, %scalar.ph ], [ %.04064.ph, %scalar.ph.preheader ]
  %27 = icmp ult i32 %.03766, %11
  %28 = select i1 %27, i32 0, i32 %12
  %.141 = add i32 %28, %.04064
  %29 = select i1 %27, i32 %spec.select, i32 0
  %.139 = add i32 %29, %.03865
  %30 = add nuw i32 %.03766, 1
  %.not63.not = icmp ult i32 %.03766, %9
  br i1 %.not63.not, label %scalar.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %.141.lcssa = phi i32 [ %26, %middle.block ], [ %.141, %scalar.ph ]
  %.139.lcssa = phi i32 [ %25, %middle.block ], [ %.139, %scalar.ph ]
  %31 = icmp eq i32 %11, 0
  br i1 %31, label %.thread, label %33

.thread:                                          ; preds = %.loopexit
  %32 = urem i32 %.141.lcssa, %12
  %.not56 = icmp ne i32 %32, 0
  %spec.select5057 = zext i1 %.not56 to i32
  br label %37

33:                                               ; preds = %.loopexit
  %34 = urem i32 %.139.lcssa, %spec.select
  %.not = icmp ne i32 %34, 0
  %spec.select50 = zext i1 %.not to i32
  %.not48.not = icmp ult i32 %9, %7
  br i1 %.not48.not, label %35, label %37

35:                                               ; preds = %33
  %36 = urem i32 %.141.lcssa, %12
  %.not49 = icmp eq i32 %36, 0
  %spec.select51 = select i1 %.not49, i32 %spec.select50, i32 1
  br label %37

37:                                               ; preds = %.thread, %35, %33
  %.262 = phi i32 [ %.139.lcssa, %33 ], [ %.139.lcssa, %35 ], [ %.141.lcssa, %.thread ]
  %.24261 = phi i32 [ %.141.lcssa, %33 ], [ %.141.lcssa, %35 ], [ 0, %.thread ]
  %.14460 = phi i32 [ %spec.select, %33 ], [ %spec.select, %35 ], [ %12, %.thread ]
  %.04559 = phi i32 [ 0, %33 ], [ %12, %35 ], [ 0, %.thread ]
  %.1 = phi i32 [ %spec.select50, %33 ], [ %spec.select51, %35 ], [ %spec.select5057, %.thread ]
  store i32 %.262, ptr %2, align 4, !tbaa !10
  store i32 %.14460, ptr %3, align 4, !tbaa !10
  store i32 %.24261, ptr %4, align 4, !tbaa !10
  store i32 %.04559, ptr %5, align 4, !tbaa !10
  ret i32 %.1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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 speculatable willreturn memory(none) }

!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, !8, !7}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass