; 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_norm_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 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 0
  %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 1
  %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 %6, align 4, !tbaa !18
  %51 = load i32, ptr %12, align 4, !tbaa !18
  %52 = mul nsw i32 %50, %51
  %53 = load i32, ptr %5, align 4, !tbaa !18
  %54 = mul nsw i32 %53, 2
  %55 = load i32, ptr %7, align 4, !tbaa !18
  %56 = add nsw i32 %54, %55
  %57 = add nsw i32 %52, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i16, ptr %49, i64 %58
  %60 = load i16, ptr %59, align 2, !tbaa !22
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !18
  %63 = load i32, ptr %13, align 4, !tbaa !18
  %64 = mul nsw i32 %62, %63
  %65 = mul nsw i32 %64, 2
  %66 = load i32, ptr %6, 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 %61, i64 %71
  store i16 %60, 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 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}


; 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_norm_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 4
  %9 = load i32, ptr %8, align 1, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i32, ptr %10, align 1, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %1, i64 12
  %13 = load i32, ptr %12, align 1, !tbaa !19
  %14 = sdiv i32 %7, 2
  %15 = icmp sgt i32 %7, 1
  %16 = icmp sgt i32 %9, 0
  %or.cond = select i1 %15, i1 %16, i1 false
  br i1 %or.cond, label %.preheader25.us.preheader, label %._crit_edge29

.preheader25.us.preheader:                        ; preds = %2
  %wide.trip.count = zext nneg i32 %9 to i64
  %17 = add nsw i64 %wide.trip.count, -1
  %18 = shl i32 %13, 1
  %scevgep37 = getelementptr i8, ptr %6, i64 2
  %19 = shl i32 %13, 1
  %20 = shl nuw nsw i64 %wide.trip.count, 2
  %scevgep43 = getelementptr i8, ptr %6, i64 %20
  %21 = add nsw i32 %14, -1
  %22 = zext i32 %21 to i64
  %23 = shl nuw nsw i64 %22, 2
  %24 = shl nuw nsw i64 %wide.trip.count, 1
  %25 = getelementptr i8, ptr %4, i64 %23
  %26 = getelementptr i8, ptr %25, i64 %24
  %scevgep45 = getelementptr i8, ptr %26, i64 2
  %min.iters.check = icmp ult i32 %9, 24
  %ident.check = icmp ne i32 %11, 1
  %27 = trunc nsw i64 %17 to i32
  %mul.result = shl i32 %27, 1
  %28 = icmp ugt i64 %17, 4294967295
  %29 = trunc nsw i64 %17 to i32
  %30 = trunc nsw i64 %17 to i32
  %mul.result35 = shl nsw i64 %17, 2
  %mul.result40 = shl nsw i64 %17, 2
  %n.vec = and i64 %wide.trip.count, 2147483644
  %invariant.gep = getelementptr i8, ptr %6, i64 -2
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br label %.preheader25.us

.preheader25.us:                                  ; preds = %.preheader25.us.preheader, %._crit_edge.us
  %.028.us = phi i32 [ %87, %._crit_edge.us ], [ 0, %.preheader25.us.preheader ]
  %31 = mul i32 %19, %.028.us
  %32 = sext i32 %31 to i64
  %33 = shl nsw i64 %32, 1
  %scevgep42 = getelementptr i8, ptr %6, i64 %33
  %scevgep44 = getelementptr i8, ptr %scevgep43, i64 %33
  %34 = shl nuw nsw i32 %.028.us, 1
  %35 = mul nsw i32 %.028.us, %13
  br i1 %min.iters.check, label %.preheader.us.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.preheader25.us
  %36 = mul i32 %18, %.028.us
  %37 = sext i32 %36 to i64
  %38 = shl nsw i64 %37, 1
  %scevgep38 = getelementptr i8, ptr %scevgep37, i64 %38
  %scevgep = getelementptr i8, ptr %6, i64 %38
  %39 = shl nuw i32 %.028.us, 1
  %40 = or disjoint i32 %39, 1
  %41 = add i32 %36, %mul.result
  %42 = icmp slt i32 %41, %36
  %43 = or i1 %42, %28
  %44 = add i32 %39, %29
  %45 = icmp slt i32 %44, %39
  %46 = add i32 %40, %30
  %47 = icmp sle i32 %46, %39
  %48 = getelementptr i8, ptr %scevgep, i64 %mul.result35
  %49 = icmp ult ptr %48, %scevgep
  %50 = getelementptr i8, ptr %scevgep38, i64 %mul.result40
  %51 = icmp ult ptr %50, %scevgep38
  %52 = or i1 %ident.check, %43
  %53 = or i1 %45, %52
  %54 = or i1 %47, %53
  %55 = or i1 %49, %54
  %56 = or i1 %51, %55
  br i1 %56, label %.preheader.us.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %bound0 = icmp ult ptr %scevgep42, %scevgep45
  %bound1 = icmp ult ptr %4, %scevgep44
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.preheader.us.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %57 = trunc i64 %index to i32
  %58 = trunc i64 %index to i32
  %59 = add i32 %34, %57
  %60 = add i32 %35, %58
  %61 = shl i32 %60, 1
  %62 = sext i32 %59 to i64
  %63 = getelementptr inbounds i16, ptr %4, i64 %62
  %wide.load = load <4 x i16>, ptr %63, align 2, !tbaa !20, !alias.scope !21
  %64 = or disjoint i32 %59, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i16, ptr %4, i64 %65
  %wide.load46 = load <4 x i16>, ptr %66, align 2, !tbaa !20, !alias.scope !21
  %67 = or disjoint i32 %61, 1
  %68 = sext i32 %67 to i64
  %gep = getelementptr i16, ptr %invariant.gep, i64 %68
  %interleaved.vec = shufflevector <4 x i16> %wide.load, <4 x i16> %wide.load46, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>
  store <8 x i16> %interleaved.vec, ptr %gep, align 2, !tbaa !20
  %index.next = add nuw i64 %index, 4
  %69 = icmp eq i64 %index.next, %n.vec
  br i1 %69, label %middle.block, label %vector.body, !llvm.loop !24

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

.preheader.us.preheader:                          ; preds = %middle.block, %vector.memcheck, %vector.scevcheck, %.preheader25.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %vector.scevcheck ], [ 0, %.preheader25.us ], [ %n.vec, %middle.block ]
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %.preheader.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader.us ], [ %indvars.iv.ph, %.preheader.us.preheader ]
  %70 = trunc i64 %indvars.iv to i32
  %71 = mul i32 %11, %70
  %72 = add i32 %71, %34
  %73 = trunc nuw nsw i64 %indvars.iv to i32
  %74 = add i32 %35, %73
  %75 = shl i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = sext i32 %72 to i64
  %78 = getelementptr inbounds i16, ptr %4, i64 %77
  %79 = load i16, ptr %78, align 2, !tbaa !20
  %80 = getelementptr inbounds i16, ptr %6, i64 %76
  store i16 %79, ptr %80, align 2, !tbaa !20
  %81 = add i32 %72, 1
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i16, ptr %4, i64 %82
  %84 = load i16, ptr %83, align 2, !tbaa !20
  %85 = or disjoint i64 %76, 1
  %86 = getelementptr inbounds i16, ptr %6, i64 %85
  store i16 %84, ptr %86, 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 !28

._crit_edge.us:                                   ; preds = %.preheader.us, %middle.block
  %87 = add nuw nsw i32 %.028.us, 1
  %exitcond33.not = icmp eq i32 %87, %14
  br i1 %exitcond33.not, label %._crit_edge29, label %.preheader25.us, !llvm.loop !29

._crit_edge29:                                    ; 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 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 4}
!18 = !{!14, !15, i64 8}
!19 = !{!14, !15, i64 12}
!20 = !{!16, !16, i64 0}
!21 = !{!22}
!22 = distinct !{!22, !23}
!23 = distinct !{!23, !"LVerDomain"}
!24 = distinct !{!24, !25, !26, !27}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!"llvm.loop.isvectorized", i32 1}
!27 = !{!"llvm.loop.unroll.runtime.disable"}
!28 = distinct !{!28, !25, !26}
!29 = distinct !{!29, !25}


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