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

33:                                               ; preds = %76, %2
  %34 = load i32, ptr %5, align 4, !tbaa !18
  %35 = load i32, ptr %10, align 4, !tbaa !18
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %37, label %79

37:                                               ; preds = %33
  store i32 0, ptr %6, align 4, !tbaa !18
  br label %38

38:                                               ; preds = %72, %37
  %39 = load i32, ptr %6, align 4, !tbaa !18
  %40 = load i32, ptr %9, align 4, !tbaa !18
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %75

42:                                               ; preds = %38
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !18
  %45 = sdiv i32 %44, 4
  %46 = load i32, ptr %11, align 4, !tbaa !18
  %47 = mul nsw i32 %45, %46
  %48 = mul nsw i32 %47, 4
  %49 = load i32, ptr %6, align 4, !tbaa !18
  %50 = mul nsw i32 %49, 4
  %51 = add nsw i32 %48, %50
  %52 = load i32, ptr %5, align 4, !tbaa !18
  %53 = srem i32 %52, 4
  %54 = add nsw i32 %51, %53
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %43, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !22
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !18
  %60 = sdiv i32 %59, 2
  %61 = load i32, ptr %12, align 4, !tbaa !18
  %62 = mul nsw i32 %60, %61
  %63 = mul nsw i32 %62, 2
  %64 = load i32, ptr %6, align 4, !tbaa !18
  %65 = mul nsw i32 %64, 2
  %66 = add nsw i32 %63, %65
  %67 = load i32, ptr %5, align 4, !tbaa !18
  %68 = srem i32 %67, 2
  %69 = add nsw i32 %66, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %58, i64 %70
  store i8 %57, ptr %71, align 1, !tbaa !22
  br label %72

72:                                               ; preds = %42
  %73 = load i32, ptr %6, align 4, !tbaa !18
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %6, align 4, !tbaa !18
  br label %38, !llvm.loop !23

75:                                               ; preds = %38
  br label %76

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

79:                                               ; preds = %33
  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 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, 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 = !{!7, !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !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_vnni4_to_vnni2_08bit(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 = icmp sgt i32 %9, 0
  %15 = icmp sgt i32 %7, 0
  %or.cond = select i1 %14, i1 %15, i1 false
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge24

.preheader.us.preheader:                          ; preds = %2
  %wide.trip.count = zext nneg i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %16 = icmp eq i32 %7, 1
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.023.us = phi i32 [ %60, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %17 = lshr i32 %.023.us, 2
  %18 = mul nsw i32 %17, %11
  %19 = and i32 %.023.us, 3
  %20 = lshr i32 %.023.us, 1
  %21 = mul nsw i32 %20, %13
  %22 = and i32 %.023.us, 1
  br i1 %16, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %23 = trunc nuw nsw i64 %indvars.iv to i32
  %24 = add i32 %18, %23
  %25 = shl i32 %24, 2
  %26 = or disjoint i32 %25, %19
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %4, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !20
  %30 = add i32 %21, %23
  %31 = shl i32 %30, 1
  %32 = or disjoint i32 %31, %22
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %6, i64 %33
  store i8 %29, ptr %34, align 1, !tbaa !20
  %35 = trunc i64 %indvars.iv to i32
  %36 = or disjoint i32 %35, 1
  %37 = add i32 %18, %36
  %38 = shl i32 %37, 2
  %39 = or disjoint i32 %38, %19
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %4, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !20
  %43 = add i32 %21, %36
  %44 = shl i32 %43, 1
  %45 = or disjoint i32 %44, %22
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %6, i64 %46
  store i8 %42, ptr %47, align 1, !tbaa !20
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !21

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %48 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %49 = add i32 %18, %48
  %50 = shl i32 %49, 2
  %51 = or disjoint i32 %50, %19
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %4, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !20
  %55 = add i32 %21, %48
  %56 = shl i32 %55, 1
  %57 = or disjoint i32 %56, %22
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %6, i64 %58
  store i8 %54, ptr %59, align 1, !tbaa !20
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %60 = add nuw nsw i32 %.023.us, 1
  %exitcond27.not = icmp eq i32 %60, %9
  br i1 %exitcond27.not, label %._crit_edge24, label %.preheader.us, !llvm.loop !23

._crit_edge24:                                    ; 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 = !{!9, !9, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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