; 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_padm_mod2_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 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 = %44, %2
  %34 = load i32, ptr %5, align 4, !tbaa !18
  %35 = load i32, ptr %12, align 4, !tbaa !18
  %36 = load i32, ptr %10, align 4, !tbaa !18
  %37 = mul nsw i32 %35, %36
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %39, label %47

39:                                               ; preds = %33
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !18
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i16, ptr %40, i64 %42
  store i16 0, ptr %43, align 2, !tbaa !22
  br label %44

44:                                               ; preds = %39
  %45 = load i32, ptr %5, align 4, !tbaa !18
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !18
  br label %33, !llvm.loop !23

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

48:                                               ; preds = %79, %47
  %49 = load i32, ptr %6, align 4, !tbaa !18
  %50 = load i32, ptr %10, align 4, !tbaa !18
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %52, label %82

52:                                               ; preds = %48
  store i32 0, ptr %5, align 4, !tbaa !18
  br label %53

53:                                               ; preds = %75, %52
  %54 = load i32, ptr %5, align 4, !tbaa !18
  %55 = load i32, ptr %9, align 4, !tbaa !18
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %78

57:                                               ; preds = %53
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !18
  %60 = load i32, ptr %11, align 4, !tbaa !18
  %61 = mul nsw i32 %59, %60
  %62 = load i32, ptr %5, align 4, !tbaa !18
  %63 = add nsw i32 %61, %62
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i16, ptr %58, i64 %64
  %66 = load i16, ptr %65, align 2, !tbaa !22
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !18
  %69 = load i32, ptr %12, align 4, !tbaa !18
  %70 = mul nsw i32 %68, %69
  %71 = load i32, ptr %5, align 4, !tbaa !18
  %72 = add nsw i32 %70, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i16, ptr %67, i64 %73
  store i16 %66, ptr %74, align 2, !tbaa !22
  br label %75

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

78:                                               ; preds = %53
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %6, align 4, !tbaa !18
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !18
  br label %48, !llvm.loop !26

82:                                               ; preds = %48
  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 = !{!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_padm_mod2_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 = mul nsw i32 %13, %9
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph.preheader, label %.preheader26

.lr.ph.preheader:                                 ; preds = %2
  %16 = shl nuw i32 %14, 1
  %17 = zext i32 %16 to i64
  tail call void @llvm.memset.p0.i64(ptr align 2 %6, i8 0, i64 %17, i1 false), !tbaa !20
  br label %.preheader26

.preheader26:                                     ; preds = %.lr.ph.preheader, %2
  %18 = icmp sgt i32 %9, 0
  %19 = icmp sgt i32 %7, 0
  %or.cond = select i1 %18, i1 %19, i1 false
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge31

.preheader.us.preheader:                          ; preds = %.preheader26
  %20 = sext i32 %11 to i64
  %21 = sext i32 %13 to i64
  %wide.trip.count39 = zext nneg i32 %9 to i64
  %wide.trip.count = zext nneg i32 %7 to i64
  %22 = add nsw i64 %wide.trip.count39, -1
  %23 = mul nsw i64 %22, %21
  %24 = add i64 %23, %wide.trip.count
  %25 = shl i64 %24, 1
  %scevgep = getelementptr i8, ptr %6, i64 %25
  %26 = mul nsw i64 %22, %20
  %27 = add i64 %26, %wide.trip.count
  %28 = shl i64 %27, 1
  %scevgep43 = getelementptr i8, ptr %4, i64 %28
  %min.iters.check = icmp ult i32 %7, 16
  %bound0 = icmp ult ptr %6, %scevgep43
  %bound1 = icmp ult ptr %4, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  %29 = or i32 %13, %11
  %30 = icmp slt i32 %29, 0
  %31 = or i1 %found.conflict, %30
  %n.vec = and i64 %wide.trip.count, 2147483632
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv36 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next37, %._crit_edge.us ]
  %32 = mul nsw i64 %indvars.iv36, %20
  %33 = mul nsw i64 %indvars.iv36, %21
  %invariant.gep = getelementptr i16, ptr %4, i64 %32
  %invariant.gep41 = getelementptr i16, ptr %6, i64 %33
  %brmerge = select i1 %min.iters.check, i1 true, i1 %31
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %34 = getelementptr i16, ptr %invariant.gep, i64 %index
  %35 = getelementptr i8, ptr %34, i64 16
  %wide.load = load <8 x i16>, ptr %34, align 2, !tbaa !20, !alias.scope !21
  %wide.load45 = load <8 x i16>, ptr %35, align 2, !tbaa !20, !alias.scope !21
  %36 = getelementptr i16, ptr %invariant.gep41, i64 %index
  %37 = getelementptr i8, ptr %36, i64 16
  store <8 x i16> %wide.load, ptr %36, align 2, !tbaa !20, !alias.scope !24, !noalias !21
  store <8 x i16> %wide.load45, ptr %37, align 2, !tbaa !20, !alias.scope !24, !noalias !21
  %index.next = add nuw i64 %index, 16
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !26

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

scalar.ph.preheader:                              ; preds = %.preheader.us, %middle.block
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %gep.prol = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv.prol
  %39 = load i16, ptr %gep.prol, align 2, !tbaa !20
  %gep42.prol = getelementptr i16, ptr %invariant.gep41, i64 %indvars.iv.prol
  store i16 %39, ptr %gep42.prol, align 2, !tbaa !20
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !30

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %40 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %41 = icmp ugt i64 %40, -4
  br i1 %41, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %gep = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv
  %42 = load i16, ptr %gep, align 2, !tbaa !20
  %gep42 = getelementptr i16, ptr %invariant.gep41, i64 %indvars.iv
  store i16 %42, ptr %gep42, align 2, !tbaa !20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %gep.1 = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv.next
  %43 = load i16, ptr %gep.1, align 2, !tbaa !20
  %gep42.1 = getelementptr i16, ptr %invariant.gep41, i64 %indvars.iv.next
  store i16 %43, ptr %gep42.1, align 2, !tbaa !20
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %gep.2 = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv.next.1
  %44 = load i16, ptr %gep.2, align 2, !tbaa !20
  %gep42.2 = getelementptr i16, ptr %invariant.gep41, i64 %indvars.iv.next.1
  store i16 %44, ptr %gep42.2, align 2, !tbaa !20
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %gep.3 = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv.next.2
  %45 = load i16, ptr %gep.3, align 2, !tbaa !20
  %gep42.3 = getelementptr i16, ptr %invariant.gep41, i64 %indvars.iv.next.2
  store i16 %45, ptr %gep42.3, align 2, !tbaa !20
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !32

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count39
  br i1 %exitcond40.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !33

._crit_edge31:                                    ; preds = %._crit_edge.us, %.preheader26
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!25}
!25 = distinct !{!25, !23}
!26 = distinct !{!26, !27, !28, !29}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!"llvm.loop.isvectorized", i32 1}
!29 = !{!"llvm.loop.unroll.runtime.disable"}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.unroll.disable"}
!32 = distinct !{!32, !27, !28}
!33 = distinct !{!33, !27}


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