; LLVM IR from libxsmm/libxsmm :: samples/utilities/wrap (dgemm)

; 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 @init(i32 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, double noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  store double %5, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %18 = load double, ptr %12, align 8, !tbaa !11
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  %21 = sitofp i32 %20 to double
  %22 = fmul double %18, %21
  store double %22, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !5
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %71, %6
  %24 = load i32, ptr %14, align 4, !tbaa !5
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %74

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %47, %27
  %29 = load i32, ptr %15, align 4, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %50

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %33 = load i32, ptr %14, align 4, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = mul nsw i32 %33, %34
  %36 = load i32, ptr %15, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  store i32 %37, ptr %16, align 4, !tbaa !5
  %38 = load double, ptr %13, align 8, !tbaa !11
  %39 = load i32, ptr %16, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  %41 = sitofp i32 %40 to double
  %42 = fdiv double %38, %41
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = load i32, ptr %16, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  store double %42, ptr %46, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  br label %47

47:                                               ; preds = %32
  %48 = load i32, ptr %15, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %15, align 4, !tbaa !5
  br label %28, !llvm.loop !13

50:                                               ; preds = %28
  br label %51

51:                                               ; preds = %67, %50
  %52 = load i32, ptr %15, align 4, !tbaa !5
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %55, label %70

55:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  %56 = load i32, ptr %14, align 4, !tbaa !5
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = mul nsw i32 %56, %57
  %59 = load i32, ptr %15, align 4, !tbaa !5
  %60 = add nsw i32 %58, %59
  store i32 %60, ptr %17, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = sitofp i32 %61 to double
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  %64 = load i32, ptr %17, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  store double %62, ptr %66, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  br label %67

67:                                               ; preds = %55
  %68 = load i32, ptr %15, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %15, align 4, !tbaa !5
  br label %51, !llvm.loop !15

70:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %14, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %14, align 4, !tbaa !5
  br label %23, !llvm.loop !16

74:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  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 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"double", !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: write) uwtable
define dso_local void @init(i32 noundef %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, double noundef %5) local_unnamed_addr #0 {
  %7 = add nsw i32 %0, 1
  %8 = sitofp i32 %7 to double
  %9 = fmul double %8, %5
  %10 = icmp sgt i32 %3, 0
  br i1 %10, label %.preheader25.lr.ph, label %._crit_edge30

.preheader25.lr.ph:                               ; preds = %6
  %11 = icmp sgt i32 %2, 0
  %12 = sitofp i32 %0 to double
  br i1 %11, label %.preheader25.us.preheader, label %.preheader25.lr.ph.split

.preheader25.us.preheader:                        ; preds = %.preheader25.lr.ph
  %13 = sext i32 %4 to i64
  %wide.trip.count57 = zext nneg i32 %3 to i64
  %wide.trip.count47 = zext nneg i32 %2 to i64
  %14 = icmp slt i32 %2, %4
  %15 = add nuw nsw i64 %wide.trip.count47, 1
  %smax = tail call i64 @llvm.smax.i64(i64 %15, i64 %13)
  %16 = sub nsw i64 %smax, %wide.trip.count47
  %min.iters.check78 = icmp eq i32 %2, 1
  %n.vec81 = and i64 %wide.trip.count47, 2147483646
  %ind.end82 = or i64 %wide.trip.count47, 1
  %broadcast.splatinsert87 = insertelement <2 x double> poison, double %9, i64 0
  %broadcast.splat88 = shufflevector <2 x double> %broadcast.splatinsert87, <2 x double> poison, <2 x i32> zeroinitializer
  %cmp.n90 = icmp eq i64 %n.vec81, %wide.trip.count47
  %min.iters.check65 = icmp ult i64 %16, 4
  %n.vec68 = and i64 %16, -4
  %broadcast.splatinsert72 = insertelement <2 x double> poison, double %12, i64 0
  %broadcast.splat73 = shufflevector <2 x double> %broadcast.splatinsert72, <2 x double> poison, <2 x i32> zeroinitializer
  %cmp.n75 = icmp eq i64 %16, %n.vec68
  br label %.preheader25.us

.preheader25.us:                                  ; preds = %.preheader25.us.preheader, %._crit_edge.us
  %indvars.iv54 = phi i64 [ 0, %.preheader25.us.preheader ], [ %indvars.iv.next55, %._crit_edge.us ]
  %17 = mul nsw i64 %indvars.iv54, %13
  br i1 %min.iters.check78, label %scalar.ph77.preheader, label %vector.body85

scalar.ph77.preheader:                            ; preds = %middle.block76, %.preheader25.us
  %indvars.iv49.ph = phi i64 [ 1, %.preheader25.us ], [ %ind.end82, %middle.block76 ]
  %indvars.iv44.ph = phi i64 [ 0, %.preheader25.us ], [ %n.vec81, %middle.block76 ]
  br label %scalar.ph77

vector.body85:                                    ; preds = %.preheader25.us, %vector.body85
  %index86 = phi i64 [ %index.next89, %vector.body85 ], [ 0, %.preheader25.us ]
  %18 = or disjoint i64 %index86, 1
  %19 = add nsw i64 %index86, %17
  %20 = add nsw i64 %18, %17
  %21 = insertelement <2 x i64> poison, i64 %19, i64 0
  %22 = insertelement <2 x i64> %21, i64 %20, i64 1
  %23 = trunc <2 x i64> %22 to <2 x i32>
  %24 = add <2 x i32> %23, <i32 1, i32 1>
  %25 = sitofp <2 x i32> %24 to <2 x double>
  %26 = fdiv <2 x double> %broadcast.splat88, %25
  %27 = getelementptr inbounds double, ptr %1, i64 %19
  store <2 x double> %26, ptr %27, align 8, !tbaa !5
  %index.next89 = add nuw i64 %index86, 2
  %28 = icmp eq i64 %index.next89, %n.vec81
  br i1 %28, label %middle.block76, label %vector.body85, !llvm.loop !9

middle.block76:                                   ; preds = %vector.body85
  br i1 %cmp.n90, label %..preheader_crit_edge.us, label %scalar.ph77.preheader

._crit_edge.us:                                   ; preds = %scalar.ph64, %middle.block63, %..preheader_crit_edge.us
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %exitcond58.not = icmp eq i64 %indvars.iv.next55, %wide.trip.count57
  br i1 %exitcond58.not, label %._crit_edge30, label %.preheader25.us, !llvm.loop !13

scalar.ph64:                                      ; preds = %scalar.ph64.preheader, %scalar.ph64
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %scalar.ph64 ], [ %indvars.iv51.ph, %scalar.ph64.preheader ]
  %gep61 = getelementptr double, ptr %invariant.gep60, i64 %indvars.iv51
  store double %12, ptr %gep61, align 8, !tbaa !5
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %29 = icmp slt i64 %indvars.iv.next52, %13
  br i1 %29, label %scalar.ph64, label %._crit_edge.us, !llvm.loop !14

scalar.ph77:                                      ; preds = %scalar.ph77.preheader, %scalar.ph77
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %scalar.ph77 ], [ %indvars.iv49.ph, %scalar.ph77.preheader ]
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %scalar.ph77 ], [ %indvars.iv44.ph, %scalar.ph77.preheader ]
  %30 = add nsw i64 %indvars.iv44, %17
  %31 = trunc i64 %30 to i32
  %32 = add i32 %31, 1
  %33 = sitofp i32 %32 to double
  %34 = fdiv double %9, %33
  %35 = getelementptr inbounds double, ptr %1, i64 %30
  store double %34, ptr %35, align 8, !tbaa !5
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count47
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  br i1 %exitcond48.not, label %..preheader_crit_edge.us, label %scalar.ph77, !llvm.loop !15

..preheader_crit_edge.us:                         ; preds = %scalar.ph77, %middle.block76
  %indvars.iv49.lcssa = phi i64 [ %n.vec81, %middle.block76 ], [ %indvars.iv49, %scalar.ph77 ]
  br i1 %14, label %.lr.ph28.us, label %._crit_edge.us

.lr.ph28.us:                                      ; preds = %..preheader_crit_edge.us
  %invariant.gep60 = getelementptr double, ptr %1, i64 %17
  br i1 %min.iters.check65, label %scalar.ph64.preheader, label %vector.ph66

scalar.ph64.preheader:                            ; preds = %middle.block63, %.lr.ph28.us
  %indvars.iv51.ph = phi i64 [ %indvars.iv49.lcssa, %.lr.ph28.us ], [ %ind.end, %middle.block63 ]
  br label %scalar.ph64

vector.ph66:                                      ; preds = %.lr.ph28.us
  %ind.end = add i64 %indvars.iv49.lcssa, %n.vec68
  %36 = getelementptr double, ptr %invariant.gep60, i64 %indvars.iv49.lcssa
  br label %vector.body70

vector.body70:                                    ; preds = %vector.body70, %vector.ph66
  %index71 = phi i64 [ 0, %vector.ph66 ], [ %index.next74, %vector.body70 ]
  %37 = getelementptr double, ptr %36, i64 %index71
  %38 = getelementptr i8, ptr %37, i64 16
  store <2 x double> %broadcast.splat73, ptr %37, align 8, !tbaa !5
  store <2 x double> %broadcast.splat73, ptr %38, align 8, !tbaa !5
  %index.next74 = add nuw i64 %index71, 4
  %39 = icmp eq i64 %index.next74, %n.vec68
  br i1 %39, label %middle.block63, label %vector.body70, !llvm.loop !16

middle.block63:                                   ; preds = %vector.body70
  br i1 %cmp.n75, label %._crit_edge.us, label %scalar.ph64.preheader

.preheader25.lr.ph.split:                         ; preds = %.preheader25.lr.ph
  %40 = icmp sgt i32 %4, 0
  br i1 %40, label %.preheader25.us31.preheader, label %._crit_edge30

.preheader25.us31.preheader:                      ; preds = %.preheader25.lr.ph.split
  %41 = zext nneg i32 %4 to i64
  %wide.trip.count42 = zext nneg i32 %3 to i64
  %min.iters.check = icmp ult i32 %4, 4
  %n.vec = and i64 %41, 2147483644
  %broadcast.splatinsert = insertelement <2 x double> poison, double %12, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %cmp.n = icmp eq i64 %n.vec, %41
  br label %.preheader25.us31

.preheader25.us31:                                ; preds = %.preheader25.us31.preheader, %._crit_edge.us35
  %indvars.iv39 = phi i64 [ 0, %.preheader25.us31.preheader ], [ %indvars.iv.next40, %._crit_edge.us35 ]
  %42 = mul nuw nsw i64 %indvars.iv39, %41
  %invariant.gep = getelementptr inbounds double, ptr %1, i64 %42
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader25.us31, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader25.us31 ]
  %43 = getelementptr inbounds double, ptr %invariant.gep, i64 %index
  %44 = getelementptr inbounds i8, ptr %43, i64 16
  store <2 x double> %broadcast.splat, ptr %43, align 8, !tbaa !5
  store <2 x double> %broadcast.splat, ptr %44, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %45 = icmp eq i64 %index.next, %n.vec
  br i1 %45, label %middle.block, label %vector.body, !llvm.loop !17

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

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader25.us31
  %indvars.iv.ph = phi i64 [ 0, %.preheader25.us31 ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv
  store double %12, ptr %gep, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %41
  br i1 %exitcond.not, label %._crit_edge.us35, label %scalar.ph, !llvm.loop !18

._crit_edge.us35:                                 ; preds = %scalar.ph, %middle.block
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count42
  br i1 %exitcond43.not, label %._crit_edge30, label %.preheader25.us31, !llvm.loop !13

._crit_edge30:                                    ; preds = %._crit_edge.us35, %._crit_edge.us, %.preheader25.lr.ph.split, %6
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #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 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10, !12, !11}
!16 = distinct !{!16, !10, !11, !12}
!17 = distinct !{!17, !10, !11, !12}
!18 = distinct !{!18, !10, !12, !11}


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