; 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_norm_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 = %70, %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 %73

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

38:                                               ; preds = %66, %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 %69

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 = load i32, ptr %12, align 4, !tbaa !18
  %61 = mul nsw i32 %59, %60
  %62 = load i32, ptr %6, align 4, !tbaa !18
  %63 = add nsw i32 %61, %62
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %58, i64 %64
  store i8 %57, ptr %65, align 1, !tbaa !22
  br label %66

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

69:                                               ; preds = %38
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %5, align 4, !tbaa !18
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %5, align 4, !tbaa !18
  br label %33, !llvm.loop !25

73:                                               ; 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_norm_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 = icmp sgt i32 %9, 0
  %13 = icmp sgt i32 %7, 0
  %or.cond = select i1 %12, i1 %13, i1 false
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge23

.preheader.us.preheader:                          ; preds = %2
  %14 = getelementptr inbounds i8, ptr %1, i64 12
  %15 = load i32, ptr %14, align 1, !tbaa !19
  %16 = sext i32 %15 to i64
  %wide.trip.count29 = zext nneg i32 %9 to i64
  %wide.trip.count = zext nneg i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %17 = 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
  %indvars.iv26 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next27, %._crit_edge.us ]
  %18 = trunc nuw nsw i64 %indvars.iv26 to i32
  %19 = lshr i32 %18, 2
  %20 = mul nsw i32 %19, %11
  %21 = and i32 %18, 3
  %22 = mul nsw i64 %indvars.iv26, %16
  %invariant.gep = getelementptr i8, ptr %6, i64 %22
  br i1 %17, 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 %20, %23
  %25 = shl i32 %24, 2
  %26 = or disjoint i32 %25, %21
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %4, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !20
  %gep = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv
  store i8 %29, ptr %gep, align 1, !tbaa !20
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %30 = trunc nuw nsw i64 %indvars.iv.next to i32
  %31 = add i32 %20, %30
  %32 = shl i32 %31, 2
  %33 = or disjoint i32 %32, %21
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %4, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !20
  %gep.1 = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv.next
  store i8 %36, ptr %gep.1, 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
  %37 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %38 = add i32 %20, %37
  %39 = shl i32 %38, 2
  %40 = or disjoint i32 %39, %21
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %4, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !20
  %gep.epil = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv.unr
  store i8 %43, ptr %gep.epil, align 1, !tbaa !20
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond30.not = icmp eq i64 %indvars.iv.next27, %wide.trip.count29
  br i1 %exitcond30.not, label %._crit_edge23, label %.preheader.us, !llvm.loop !23

._crit_edge23:                                    ; 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