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

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

39:                                               ; preds = %34
  store i32 0, ptr %6, align 4, !tbaa !18
  br label %40

40:                                               ; preds = %77, %39
  %41 = load i32, ptr %6, align 4, !tbaa !18
  %42 = load i32, ptr %11, align 4, !tbaa !18
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %44, label %80

44:                                               ; preds = %40
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %45

45:                                               ; preds = %73, %44
  %46 = load i32, ptr %7, align 4, !tbaa !18
  %47 = icmp slt i32 %46, 2
  br i1 %47, label %48, label %76

48:                                               ; preds = %45
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !18
  %51 = load i32, ptr %12, align 4, !tbaa !18
  %52 = mul nsw i32 %50, %51
  %53 = mul nsw i32 %52, 2
  %54 = load i32, ptr %6, align 4, !tbaa !18
  %55 = mul nsw i32 %54, 2
  %56 = load i32, ptr %7, align 4, !tbaa !18
  %57 = add nsw i32 %55, %56
  %58 = add nsw i32 %53, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i16, ptr %49, i64 %59
  %61 = load i16, ptr %60, align 2, !tbaa !22
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !18
  %64 = load i32, ptr %13, align 4, !tbaa !18
  %65 = mul nsw i32 %63, %64
  %66 = load i32, ptr %5, align 4, !tbaa !18
  %67 = mul nsw i32 %66, 2
  %68 = add nsw i32 %65, %67
  %69 = load i32, ptr %7, align 4, !tbaa !18
  %70 = add nsw i32 %68, %69
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i16, ptr %62, i64 %71
  store i16 %61, ptr %72, align 2, !tbaa !22
  br label %73

73:                                               ; preds = %48
  %74 = load i32, ptr %7, align 4, !tbaa !18
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !18
  br label %45, !llvm.loop !23

76:                                               ; preds = %45
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %6, align 4, !tbaa !18
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %6, align 4, !tbaa !18
  br label %40, !llvm.loop !25

80:                                               ; preds = %40
  br label %81

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

84:                                               ; preds = %34
  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 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, 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 4}
!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 0}
!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}


; 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_vnni2T_to_norm_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 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = load i32, ptr %7, align 1, !tbaa !13
  %9 = load i32, ptr %1, align 1, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i32, ptr %10, align 1, !tbaa !18
  %factor.op.mul28 = shl i32 %11, 1
  %12 = icmp sgt i32 %8, 1
  %13 = icmp sgt i32 %9, 0
  %or.cond = select i1 %12, i1 %13, i1 false
  br i1 %or.cond, label %.preheader25.us.preheader, label %._crit_edge30

.preheader25.us.preheader:                        ; preds = %2
  %14 = lshr i32 %8, 1
  %15 = getelementptr inbounds i8, ptr %1, i64 12
  %16 = load i32, ptr %15, align 1, !tbaa !19
  %17 = sext i32 %16 to i64
  %wide.trip.count37 = zext nneg i32 %14 to i64
  %wide.trip.count = zext nneg i32 %9 to i64
  %invariant.gep = getelementptr i8, ptr %6, i64 2
  br label %.preheader25.us

.preheader25.us:                                  ; preds = %.preheader25.us.preheader, %._crit_edge.us
  %indvars.iv34 = phi i64 [ 0, %.preheader25.us.preheader ], [ %indvars.iv.next35, %._crit_edge.us ]
  %18 = trunc nuw nsw i64 %indvars.iv34 to i32
  %factor.op.mul.reass.us = mul i32 %factor.op.mul28, %18
  %19 = shl nuw nsw i64 %indvars.iv34, 1
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader25.us, %.preheader.us
  %indvars.iv = phi i64 [ 0, %.preheader25.us ], [ %indvars.iv.next, %.preheader.us ]
  %indvars.iv.tr = trunc i64 %indvars.iv to i32
  %20 = shl i32 %indvars.iv.tr, 1
  %21 = add i32 %20, %factor.op.mul.reass.us
  %22 = mul nsw i64 %indvars.iv, %17
  %23 = add nsw i64 %22, %19
  %24 = sext i32 %21 to i64
  %25 = getelementptr inbounds i16, ptr %4, i64 %24
  %26 = load i16, ptr %25, align 2, !tbaa !20
  %27 = getelementptr inbounds i16, ptr %6, i64 %23
  store i16 %26, ptr %27, align 2, !tbaa !20
  %28 = or disjoint i32 %21, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i16, ptr %4, i64 %29
  %31 = load i16, ptr %30, align 2, !tbaa !20
  %gep = getelementptr i16, ptr %invariant.gep, i64 %23
  store i16 %31, ptr %gep, 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 %.preheader.us, !llvm.loop !21

._crit_edge.us:                                   ; preds = %.preheader.us
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge30, label %.preheader25.us, !llvm.loop !23

._crit_edge30:                                    ; preds = %._crit_edge.us, %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 4}
!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 0}
!18 = !{!14, !15, i64 8}
!19 = !{!14, !15, i64 12}
!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