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

; 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.libxsmm_meltw_unary_param = type { %struct.libxsmm_matrix_op_arg, %struct.libxsmm_matrix_arg, %struct.libxsmm_matrix_arg }
%struct.libxsmm_matrix_op_arg = type { ptr, ptr, ptr, ptr }
%struct.libxsmm_matrix_arg = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.libxsmm_meltw_descriptor = type <{ i32, i32, i32, i32, i32, i32, i8, i8, i8, i16, i16, i8 }>

; 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 void @libxsmm_ref_vnni2_to_vnni2T_16bit(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.libxsmm_meltw_unary_param, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  store ptr %18, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.libxsmm_meltw_unary_param, ptr %19, i32 0, i32 2
  %21 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  store ptr %22, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.libxsmm_meltw_descriptor, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 1, !tbaa !14
  store i32 %25, ptr %11, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.libxsmm_meltw_descriptor, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 1, !tbaa !19
  store i32 %28, ptr %12, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.libxsmm_meltw_descriptor, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 1, !tbaa !20
  store i32 %31, ptr %13, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.libxsmm_meltw_descriptor, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 1, !tbaa !21
  store i32 %34, ptr %14, align 4, !tbaa !18
  store i32 0, ptr %6, align 4, !tbaa !18
  br label %35

35:                                               ; preds = %98, %2
  %36 = load i32, ptr %6, align 4, !tbaa !18
  %37 = load i32, ptr %11, align 4, !tbaa !18
  %38 = sdiv i32 %37, 2
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %40, label %101

40:                                               ; preds = %35
  store i32 0, ptr %5, align 4, !tbaa !18
  br label %41

41:                                               ; preds = %94, %40
  %42 = load i32, ptr %5, align 4, !tbaa !18
  %43 = load i32, ptr %12, align 4, !tbaa !18
  %44 = sdiv i32 %43, 2
  %45 = icmp slt i32 %42, %44
  br i1 %45, label %46, label %97

46:                                               ; preds = %41
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %47

47:                                               ; preds = %90, %46
  %48 = load i32, ptr %7, align 4, !tbaa !18
  %49 = icmp slt i32 %48, 2
  br i1 %49, label %50, label %93

50:                                               ; preds = %47
  store i32 0, ptr %8, align 4, !tbaa !18
  br label %51

51:                                               ; preds = %86, %50
  %52 = load i32, ptr %8, align 4, !tbaa !18
  %53 = icmp slt i32 %52, 2
  br i1 %53, label %54, label %89

54:                                               ; preds = %51
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !18
  %57 = load i32, ptr %13, align 4, !tbaa !18
  %58 = mul nsw i32 %56, %57
  %59 = mul nsw i32 %58, 2
  %60 = load i32, ptr %8, align 4, !tbaa !18
  %61 = add nsw i32 %59, %60
  %62 = load i32, ptr %6, align 4, !tbaa !18
  %63 = mul nsw i32 %62, 2
  %64 = load i32, ptr %7, align 4, !tbaa !18
  %65 = add nsw i32 %63, %64
  %66 = mul nsw i32 %65, 2
  %67 = add nsw i32 %61, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i16, ptr %55, i64 %68
  %70 = load i16, ptr %69, align 2, !tbaa !22
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !18
  %73 = load i32, ptr %14, align 4, !tbaa !18
  %74 = mul nsw i32 %72, %73
  %75 = mul nsw i32 %74, 2
  %76 = load i32, ptr %7, align 4, !tbaa !18
  %77 = add nsw i32 %75, %76
  %78 = load i32, ptr %5, align 4, !tbaa !18
  %79 = mul nsw i32 %78, 2
  %80 = load i32, ptr %8, align 4, !tbaa !18
  %81 = add nsw i32 %79, %80
  %82 = mul nsw i32 %81, 2
  %83 = add nsw i32 %77, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i16, ptr %71, i64 %84
  store i16 %70, ptr %85, align 2, !tbaa !22
  br label %86

86:                                               ; preds = %54
  %87 = load i32, ptr %8, align 4, !tbaa !18
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %8, align 4, !tbaa !18
  br label %51, !llvm.loop !23

89:                                               ; preds = %51
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %7, align 4, !tbaa !18
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %7, align 4, !tbaa !18
  br label %47, !llvm.loop !25

93:                                               ; preds = %47
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %5, align 4, !tbaa !18
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %5, align 4, !tbaa !18
  br label %41, !llvm.loop !26

97:                                               ; preds = %41
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %6, align 4, !tbaa !18
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %6, align 4, !tbaa !18
  br label %35, !llvm.loop !27

101:                                              ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 32}
!10 = !{!"libxsmm_meltw_unary_param", !11, i64 0, !12, i64 32, !12, i64 80}
!11 = !{!"libxsmm_matrix_op_arg", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!12 = !{!"libxsmm_matrix_arg", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!10, !6, i64 80}
!14 = !{!15, !16, i64 0}
!15 = !{!"libxsmm_meltw_descriptor", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12, !16, i64 16, !16, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !17, i64 27, !17, i64 29, !7, i64 31}
!16 = !{!"int", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!16, !16, i64 0}
!19 = !{!15, !16, i64 4}
!20 = !{!15, !16, i64 8}
!21 = !{!15, !16, i64 12}
!22 = !{!17, !17, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}
!26 = distinct !{!26, !24}
!27 = distinct !{!27, !24}


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @libxsmm_ref_vnni2_to_vnni2T_16bit(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 80
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = load i32, ptr %1, align 1, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %1, i64 12
  %9 = load i32, ptr %8, align 1, !tbaa !17
  %10 = sdiv i32 %7, 2
  %factor.op.mul35 = shl i32 %9, 1
  %11 = icmp sgt i32 %7, 1
  br i1 %11, label %.preheader31.lr.ph, label %._crit_edge37

.preheader31.lr.ph:                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load i32, ptr %12, align 1, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %1, i64 4
  %15 = load i32, ptr %14, align 1, !tbaa !19
  %16 = icmp sgt i32 %15, 1
  %17 = shl i32 %13, 1
  br i1 %16, label %.preheader31.us.preheader, label %._crit_edge37

.preheader31.us.preheader:                        ; preds = %.preheader31.lr.ph
  %18 = lshr i32 %15, 1
  %wide.trip.count = zext nneg i32 %18 to i64
  br label %.preheader31.us

.preheader31.us:                                  ; preds = %.preheader31.us.preheader, %._crit_edge.us
  %.02736.us = phi i32 [ %51, %._crit_edge.us ], [ 0, %.preheader31.us.preheader ]
  %factor.op.mul.reass.us = mul i32 %factor.op.mul35, %.02736.us
  %19 = shl i32 %.02736.us, 2
  br label %.preheader30.us

.preheader30.us:                                  ; preds = %.preheader31.us, %.preheader30.us
  %indvars.iv = phi i64 [ 0, %.preheader31.us ], [ %indvars.iv.next, %.preheader30.us ]
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  %21 = mul i32 %17, %20
  %22 = add i32 %21, %19
  %indvars.iv.tr = trunc i64 %indvars.iv to i32
  %23 = shl i32 %indvars.iv.tr, 2
  %24 = add i32 %23, %factor.op.mul.reass.us
  %25 = sext i32 %22 to i64
  %26 = getelementptr inbounds i16, ptr %4, i64 %25
  %27 = load i16, ptr %26, align 2, !tbaa !20
  %28 = sext i32 %24 to i64
  %29 = getelementptr inbounds i16, ptr %6, i64 %28
  store i16 %27, ptr %29, align 2, !tbaa !20
  %30 = or disjoint i32 %22, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i16, ptr %4, i64 %31
  %33 = load i16, ptr %32, align 2, !tbaa !20
  %34 = add i32 %24, 2
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i16, ptr %6, i64 %35
  store i16 %33, ptr %36, align 2, !tbaa !20
  %37 = add i32 %22, 2
  %38 = or disjoint i32 %24, 1
  %39 = sext i32 %37 to i64
  %40 = getelementptr inbounds i16, ptr %4, i64 %39
  %41 = load i16, ptr %40, align 2, !tbaa !20
  %42 = sext i32 %38 to i64
  %43 = getelementptr inbounds i16, ptr %6, i64 %42
  store i16 %41, ptr %43, align 2, !tbaa !20
  %44 = add i32 %22, 3
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i16, ptr %4, i64 %45
  %47 = load i16, ptr %46, align 2, !tbaa !20
  %48 = add i32 %24, 3
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i16, ptr %6, i64 %49
  store i16 %47, ptr %50, align 2, !tbaa !20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %.preheader30.us, !llvm.loop !21

._crit_edge.us:                                   ; preds = %.preheader30.us
  %51 = add nuw nsw i32 %.02736.us, 1
  %exitcond42.not = icmp eq i32 %51, %10
  br i1 %exitcond42.not, label %._crit_edge37, label %.preheader31.us, !llvm.loop !23

._crit_edge37:                                    ; preds = %._crit_edge.us, %.preheader31.lr.ph, %2
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!6, !8, i64 32}
!6 = !{!"libxsmm_meltw_unary_param", !7, i64 0, !11, i64 32, !11, i64 80}
!7 = !{!"libxsmm_matrix_op_arg", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"libxsmm_matrix_arg", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40}
!12 = !{!6, !8, i64 80}
!13 = !{!14, !15, i64 0}
!14 = !{!"libxsmm_meltw_descriptor", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20, !9, i64 24, !9, i64 25, !9, i64 26, !16, i64 27, !16, i64 29, !9, i64 31}
!15 = !{!"int", !9, i64 0}
!16 = !{!"short", !9, i64 0}
!17 = !{!14, !15, i64 12}
!18 = !{!14, !15, i64 8}
!19 = !{!14, !15, i64 4}
!20 = !{!16, !16, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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