; LLVM IR from Smorodov/Multitarget-tracker :: src/Detector/darknet/src (cpu_gemm)

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

31:                                               ; preds = %85, %13
  %32 = load i32, ptr %27, align 4, !tbaa !5
  %33 = load i32, ptr %16, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %88

35:                                               ; preds = %31
  store i32 0, ptr %29, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %81, %35
  %37 = load i32, ptr %29, align 4, !tbaa !5
  %38 = load i32, ptr %18, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %84

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #3
  %41 = load float, ptr %19, align 4, !tbaa !9
  %42 = load ptr, ptr %20, align 8, !tbaa !11
  %43 = load i32, ptr %27, align 4, !tbaa !5
  %44 = load i32, ptr %21, align 4, !tbaa !5
  %45 = mul nsw i32 %43, %44
  %46 = load i32, ptr %29, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %42, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !9
  %51 = fmul float %41, %50
  store float %51, ptr %30, align 4, !tbaa !9
  store i32 0, ptr %28, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %77, %40
  %53 = load i32, ptr %28, align 4, !tbaa !5
  %54 = load i32, ptr %17, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %80

56:                                               ; preds = %52
  %57 = load float, ptr %30, align 4, !tbaa !9
  %58 = load ptr, ptr %22, align 8, !tbaa !11
  %59 = load i32, ptr %29, align 4, !tbaa !5
  %60 = load i32, ptr %23, align 4, !tbaa !5
  %61 = mul nsw i32 %59, %60
  %62 = load i32, ptr %28, align 4, !tbaa !5
  %63 = add nsw i32 %61, %62
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds float, ptr %58, i64 %64
  %66 = load float, ptr %65, align 4, !tbaa !9
  %67 = load ptr, ptr %25, align 8, !tbaa !11
  %68 = load i32, ptr %27, align 4, !tbaa !5
  %69 = load i32, ptr %26, align 4, !tbaa !5
  %70 = mul nsw i32 %68, %69
  %71 = load i32, ptr %28, align 4, !tbaa !5
  %72 = add nsw i32 %70, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds float, ptr %67, i64 %73
  %75 = load float, ptr %74, align 4, !tbaa !9
  %76 = call float @llvm.fmuladd.f32(float %57, float %66, float %75)
  store float %76, ptr %74, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %56
  %78 = load i32, ptr %28, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %28, align 4, !tbaa !5
  br label %52, !llvm.loop !13

80:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #3
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %29, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %29, align 4, !tbaa !5
  br label %36, !llvm.loop !15

84:                                               ; preds = %36
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %27, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %27, align 4, !tbaa !5
  br label %31, !llvm.loop !16

88:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %29) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #3
  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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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: readwrite) uwtable
define dso_local void @cpu_gemm_nn(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, float noundef %5, ptr nocapture noundef readonly %6, i32 noundef %7, ptr nocapture noundef readonly %8, i32 noundef %9, float noundef %10, ptr nocapture noundef %11, i32 noundef %12) local_unnamed_addr #0 {
  %14 = icmp sgt i32 %2, 0
  %15 = icmp sgt i32 %4, 0
  %or.cond = and i1 %14, %15
  %16 = icmp sgt i32 %3, 0
  %or.cond49 = and i1 %or.cond, %16
  br i1 %or.cond49, label %.preheader.us.us.preheader, label %._crit_edge

.preheader.us.us.preheader:                       ; preds = %13
  %17 = sext i32 %9 to i64
  %18 = sext i32 %7 to i64
  %19 = sext i32 %12 to i64
  %wide.trip.count43 = zext nneg i32 %2 to i64
  %wide.trip.count38 = zext nneg i32 %4 to i64
  %wide.trip.count = zext nneg i32 %3 to i64
  %20 = shl nsw i64 %19, 2
  %21 = shl nuw nsw i64 %wide.trip.count, 2
  %22 = add nuw nsw i64 %wide.trip.count38, 4611686018427387903
  %23 = mul i64 %22, %17
  %24 = add i64 %23, %wide.trip.count
  %25 = shl i64 %24, 2
  %scevgep51 = getelementptr i8, ptr %8, i64 %25
  %26 = getelementptr i8, ptr %11, i64 %21
  %min.iters.check = icmp ult i32 %3, 8
  %stride.check = icmp slt i32 %9, 0
  %n.vec = and i64 %wide.trip.count, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %27 = add nsw i64 %wide.trip.count, -1
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %.preheader.us.us.preheader, %._crit_edge27.split.us.us.us
  %indvars.iv40 = phi i64 [ 0, %.preheader.us.us.preheader ], [ %indvars.iv.next41, %._crit_edge27.split.us.us.us ]
  %28 = mul i64 %20, %indvars.iv40
  %scevgep = getelementptr i8, ptr %11, i64 %28
  %scevgep50 = getelementptr i8, ptr %26, i64 %28
  %29 = mul nsw i64 %indvars.iv40, %18
  %30 = mul nsw i64 %indvars.iv40, %19
  %invariant.gep47 = getelementptr float, ptr %6, i64 %29
  %invariant.gep45 = getelementptr float, ptr %11, i64 %30
  %bound0 = icmp ult ptr %scevgep, %scevgep51
  %bound1 = icmp ugt ptr %scevgep50, %8
  %found.conflict = and i1 %bound0, %bound1
  %31 = or i1 %found.conflict, %stride.check
  br label %.lr.ph.us.us.us

.lr.ph.us.us.us:                                  ; preds = %._crit_edge.us.us.us, %.preheader.us.us
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %._crit_edge.us.us.us ], [ 0, %.preheader.us.us ]
  %gep48 = getelementptr float, ptr %invariant.gep47, i64 %indvars.iv35
  %32 = load float, ptr %gep48, align 4, !tbaa !5
  %33 = fmul float %32, %5
  %34 = mul nsw i64 %indvars.iv35, %17
  %invariant.gep = getelementptr float, ptr %8, i64 %34
  %brmerge = select i1 %min.iters.check, i1 true, i1 %31
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us.us.us
  %broadcast.splatinsert = insertelement <4 x float> poison, float %33, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %35 = getelementptr float, ptr %invariant.gep, i64 %index
  %36 = getelementptr i8, ptr %35, i64 16
  %wide.load = load <4 x float>, ptr %35, align 4, !tbaa !5, !alias.scope !9
  %wide.load52 = load <4 x float>, ptr %36, align 4, !tbaa !5, !alias.scope !9
  %37 = getelementptr float, ptr %invariant.gep45, i64 %index
  %38 = getelementptr i8, ptr %37, i64 16
  %wide.load53 = load <4 x float>, ptr %37, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load54 = load <4 x float>, ptr %38, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %39 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat, <4 x float> %wide.load, <4 x float> %wide.load53)
  %40 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat, <4 x float> %wide.load52, <4 x float> %wide.load54)
  store <4 x float> %39, ptr %37, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x float> %40, ptr %38, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 8
  %41 = icmp eq i64 %index.next, %n.vec
  br i1 %41, label %middle.block, label %vector.body, !llvm.loop !14

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

scalar.ph.preheader:                              ; preds = %.lr.ph.us.us.us, %middle.block
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.us.us.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %gep.prol = getelementptr float, ptr %invariant.gep, i64 %indvars.iv.ph
  %42 = load float, ptr %gep.prol, align 4, !tbaa !5
  %gep46.prol = getelementptr float, ptr %invariant.gep45, i64 %indvars.iv.ph
  %43 = load float, ptr %gep46.prol, align 4, !tbaa !5
  %44 = tail call float @llvm.fmuladd.f32(float %33, float %42, float %43)
  store float %44, ptr %gep46.prol, align 4, !tbaa !5
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %45 = icmp eq i64 %indvars.iv.ph, %27
  br i1 %45, label %._crit_edge.us.us.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  %46 = load float, ptr %gep, align 4, !tbaa !5
  %gep46 = getelementptr float, ptr %invariant.gep45, i64 %indvars.iv
  %47 = load float, ptr %gep46, align 4, !tbaa !5
  %48 = tail call float @llvm.fmuladd.f32(float %33, float %46, float %47)
  store float %48, ptr %gep46, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %gep.1 = getelementptr float, ptr %invariant.gep, i64 %indvars.iv.next
  %49 = load float, ptr %gep.1, align 4, !tbaa !5
  %gep46.1 = getelementptr float, ptr %invariant.gep45, i64 %indvars.iv.next
  %50 = load float, ptr %gep46.1, align 4, !tbaa !5
  %51 = tail call float @llvm.fmuladd.f32(float %33, float %49, float %50)
  store float %51, ptr %gep46.1, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %._crit_edge.us.us.us, label %scalar.ph, !llvm.loop !18

._crit_edge.us.us.us:                             ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge27.split.us.us.us, label %.lr.ph.us.us.us, !llvm.loop !19

._crit_edge27.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond44.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count43
  br i1 %exitcond44.not, label %._crit_edge, label %.preheader.us.us, !llvm.loop !20

._crit_edge:                                      ; preds = %._crit_edge27.split.us.us.us, %13
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #2

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 speculatable willreturn memory(none) }
attributes #2 = { 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 = !{!6, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}
!19 = distinct !{!19, !15}
!20 = distinct !{!20, !15}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass