; LLVM IR from libxsmm/libxsmm :: samples/deeplearning/vnni_pack (vnni_pack)

; 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 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @libxsmm_nonconst_int(i32 noundef) #1

; 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 @pack_tpp_normtovnni(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, ptr noundef %7) #2 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca %struct.libxsmm_meltw_unary_param, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !9
  store i32 %3, ptr %12, align 4, !tbaa !9
  store i32 %4, ptr %13, align 4, !tbaa !9
  store i32 %5, ptr %14, align 4, !tbaa !9
  store i32 %6, ptr %15, align 4, !tbaa !9
  store ptr %7, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = load i32, ptr %14, align 4, !tbaa !9
  %26 = sdiv i32 %24, %25
  store i32 %26, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = sdiv i32 %27, %28
  store i32 %29, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = call i32 @libxsmm_nonconst_int(i32 noundef %30)
  %32 = zext i32 %31 to i64
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = call i32 @libxsmm_nonconst_int(i32 noundef %33)
  %35 = zext i32 %34 to i64
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %36, ptr %21, align 8, !tbaa !5
  %37 = load i32, ptr %18, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = load i32, ptr %13, align 4, !tbaa !9
  %40 = load i32, ptr %15, align 4, !tbaa !9
  %41 = sdiv i32 %39, %40
  %42 = zext i32 %41 to i64
  %43 = load i32, ptr %14, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = call i32 @libxsmm_nonconst_int(i32 noundef %45)
  %47 = zext i32 %46 to i64
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  %48 = load i32, ptr %18, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = load i32, ptr %13, align 4, !tbaa !9
  %51 = load i32, ptr %15, align 4, !tbaa !9
  %52 = sdiv i32 %50, %51
  %53 = zext i32 %52 to i64
  %54 = load i32, ptr %14, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = load i32, ptr %15, align 4, !tbaa !9
  %57 = call i32 @libxsmm_nonconst_int(i32 noundef %56)
  %58 = zext i32 %57 to i64
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %59, ptr %22, align 8, !tbaa !5
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %153, %8
  %61 = load i32, ptr %20, align 4, !tbaa !9
  %62 = load i32, ptr %18, align 4, !tbaa !9
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %64, label %156

64:                                               ; preds = %60
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %149, %64
  %66 = load i32, ptr %19, align 4, !tbaa !9
  %67 = load i32, ptr %17, align 4, !tbaa !9
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %69, label %152

69:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 128, ptr %23) #3
  %70 = load ptr, ptr %21, align 8, !tbaa !5
  %71 = load i32, ptr %12, align 4, !tbaa !9
  %72 = mul nsw i32 0, %71
  %73 = sext i32 %72 to i64
  %74 = mul nsw i64 %73, %32
  %75 = getelementptr inbounds i16, ptr %70, i64 %74
  %76 = load i32, ptr %20, align 4, !tbaa !9
  %77 = load i32, ptr %13, align 4, !tbaa !9
  %78 = mul nsw i32 %76, %77
  %79 = sext i32 %78 to i64
  %80 = mul nsw i64 %79, %32
  %81 = getelementptr inbounds i16, ptr %75, i64 %80
  %82 = load i32, ptr %19, align 4, !tbaa !9
  %83 = load i32, ptr %14, align 4, !tbaa !9
  %84 = mul nsw i32 %82, %83
  %85 = call i32 @libxsmm_nonconst_int(i32 noundef %84)
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i16, ptr %81, i64 %86
  %88 = getelementptr inbounds %struct.libxsmm_meltw_unary_param, ptr %23, i32 0, i32 1
  %89 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %88, i32 0, i32 0
  store ptr %87, ptr %89, align 8, !tbaa !11
  %90 = load ptr, ptr %22, align 8, !tbaa !5
  %91 = load i32, ptr %18, align 4, !tbaa !9
  %92 = mul nsw i32 0, %91
  %93 = sext i32 %92 to i64
  %94 = mul nuw i64 %38, %42
  %95 = mul nuw i64 %94, %44
  %96 = mul nuw i64 %95, %47
  %97 = mul nsw i64 %93, %96
  %98 = getelementptr inbounds i16, ptr %90, i64 %97
  %99 = load i32, ptr %13, align 4, !tbaa !9
  %100 = load i32, ptr %15, align 4, !tbaa !9
  %101 = sdiv i32 %99, %100
  %102 = mul nsw i32 0, %101
  %103 = sext i32 %102 to i64
  %104 = mul nuw i64 %38, %42
  %105 = mul nuw i64 %104, %44
  %106 = mul nuw i64 %105, %47
  %107 = mul nsw i64 %103, %106
  %108 = getelementptr inbounds i16, ptr %98, i64 %107
  %109 = load i32, ptr %14, align 4, !tbaa !9
  %110 = mul nsw i32 0, %109
  %111 = sext i32 %110 to i64
  %112 = mul nuw i64 %38, %42
  %113 = mul nuw i64 %112, %44
  %114 = mul nuw i64 %113, %47
  %115 = mul nsw i64 %111, %114
  %116 = getelementptr inbounds i16, ptr %108, i64 %115
  %117 = load i32, ptr %15, align 4, !tbaa !9
  %118 = mul nsw i32 0, %117
  %119 = sext i32 %118 to i64
  %120 = mul nuw i64 %38, %42
  %121 = mul nuw i64 %120, %44
  %122 = mul nuw i64 %121, %47
  %123 = mul nsw i64 %119, %122
  %124 = getelementptr inbounds i16, ptr %116, i64 %123
  %125 = load i32, ptr %19, align 4, !tbaa !9
  %126 = sext i32 %125 to i64
  %127 = mul nuw i64 %38, %42
  %128 = mul nuw i64 %127, %44
  %129 = mul nuw i64 %128, %47
  %130 = mul nsw i64 %126, %129
  %131 = getelementptr inbounds i16, ptr %124, i64 %130
  %132 = load i32, ptr %20, align 4, !tbaa !9
  %133 = sext i32 %132 to i64
  %134 = mul nuw i64 %42, %44
  %135 = mul nuw i64 %134, %47
  %136 = mul nsw i64 %133, %135
  %137 = getelementptr inbounds i16, ptr %131, i64 %136
  %138 = mul nuw i64 %44, %47
  %139 = mul nsw i64 0, %138
  %140 = getelementptr inbounds i16, ptr %137, i64 %139
  %141 = mul nsw i64 0, %47
  %142 = getelementptr inbounds i16, ptr %140, i64 %141
  %143 = call i32 @libxsmm_nonconst_int(i32 noundef 0)
  %144 = sext i32 %143 to i64
  %145 = getelementptr inbounds i16, ptr %142, i64 %144
  %146 = getelementptr inbounds %struct.libxsmm_meltw_unary_param, ptr %23, i32 0, i32 2
  %147 = getelementptr inbounds %struct.libxsmm_matrix_arg, ptr %146, i32 0, i32 0
  store ptr %145, ptr %147, align 8, !tbaa !15
  %148 = load ptr, ptr %16, align 8, !tbaa !5
  call void %148(ptr noundef %23)
  call void @llvm.lifetime.end.p0(i64 128, ptr %23) #3
  br label %149

149:                                              ; preds = %69
  %150 = load i32, ptr %19, align 4, !tbaa !9
  %151 = add nsw i32 %150, 1
  store i32 %151, ptr %19, align 4, !tbaa !9
  br label %65, !llvm.loop !16

152:                                              ; preds = %65
  br label %153

153:                                              ; preds = %152
  %154 = load i32, ptr %20, align 4, !tbaa !9
  %155 = add nsw i32 %154, 1
  store i32 %155, ptr %20, align 4, !tbaa !9
  br label %60, !llvm.loop !18

156:                                              ; preds = %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 #3 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"libxsmm_meltw_unary_param", !13, i64 0, !14, i64 32, !14, i64 80}
!13 = !{!"libxsmm_matrix_op_arg", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"libxsmm_matrix_arg", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!12, !6, i64 80}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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"

%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 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @libxsmm_nonconst_int(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 @pack_tpp_normtovnni(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, ptr nocapture noundef readonly %7) local_unnamed_addr #2 {
  %9 = alloca %struct.libxsmm_meltw_unary_param, align 8
  %10 = sdiv i32 %3, %5
  %11 = sdiv i32 %2, %4
  %12 = tail call i32 @libxsmm_nonconst_int(i32 noundef %3)
  %13 = zext i32 %12 to i64
  %14 = tail call i32 @libxsmm_nonconst_int(i32 noundef %3)
  %15 = tail call i32 @libxsmm_nonconst_int(i32 noundef %6)
  %16 = tail call i32 @libxsmm_nonconst_int(i32 noundef %6)
  %17 = icmp sgt i32 %11, 0
  br i1 %17, label %.preheader.lr.ph, label %._crit_edge45

.preheader.lr.ph:                                 ; preds = %8
  %18 = sdiv i32 %4, %6
  %19 = zext i32 %18 to i64
  %20 = zext i32 %5 to i64
  %factor.op.mul43 = mul nuw i64 %19, %20
  %21 = zext i32 %15 to i64
  %factor.op.mul42 = mul nuw i64 %19, %21
  %factor.op.mul = mul i64 %factor.op.mul42, %20
  %22 = zext nneg i32 %11 to i64
  %factor.op.mul.reass.reass = mul i64 %factor.op.mul, %22
  %factor.op.mul40.reass = mul i64 %factor.op.mul43, %21
  %23 = icmp sgt i32 %10, 0
  %24 = getelementptr inbounds i8, ptr %9, i64 32
  %25 = getelementptr inbounds i8, ptr %9, i64 80
  br i1 %23, label %.preheader.us.preheader, label %._crit_edge45

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %26 = sext i32 %4 to i64
  %factor.op.mul53 = mul nsw i64 %26, %13
  %wide.trip.count = zext nneg i32 %10 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv48 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next49, %._crit_edge.us ]
  %.reass = mul i64 %indvars.iv48, %factor.op.mul53
  %27 = getelementptr inbounds i16, ptr %0, i64 %.reass
  %28 = mul nsw i64 %factor.op.mul40.reass, %indvars.iv48
  %invariant.gep.us = getelementptr i16, ptr %1, i64 %28
  br label %29

29:                                               ; preds = %.preheader.us, %29
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %29 ]
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %9) #3
  %30 = trunc i64 %indvars.iv to i32
  %31 = mul i32 %30, %5
  %32 = call i32 @libxsmm_nonconst_int(i32 noundef %31)
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i16, ptr %27, i64 %33
  store ptr %34, ptr %24, align 8, !tbaa !5
  %35 = mul nsw i64 %factor.op.mul.reass.reass, %indvars.iv
  %gep.us = getelementptr i16, ptr %invariant.gep.us, i64 %35
  %36 = call i32 @libxsmm_nonconst_int(i32 noundef 0)
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i16, ptr %gep.us, i64 %37
  store ptr %38, ptr %25, align 8, !tbaa !12
  call void %7(ptr noundef nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %9) #3
  %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 %29, !llvm.loop !13

._crit_edge.us:                                   ; preds = %29
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next49, %22
  br i1 %exitcond52.not, label %._crit_edge45, label %.preheader.us, !llvm.loop !15

._crit_edge45:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %8
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 #3 = { 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, !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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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