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

; 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_elementwise_store_value(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, ptr noundef %7, i32 noundef %8) #1 {
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca float, align 4
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store i32 %2, ptr %12, align 4, !tbaa !9
  store i32 %3, ptr %13, align 4, !tbaa !9
  store i32 %4, ptr %14, align 4, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !9
  store i32 %6, ptr %16, align 4, !tbaa !9
  store ptr %7, ptr %17, align 8, !tbaa !5
  store i32 %8, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = load float, ptr %25, align 4, !tbaa !11
  store float %26, ptr %19, align 4, !tbaa !11
  %27 = load i32, ptr %16, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %40

29:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %30, ptr %20, align 8, !tbaa !5
  %31 = load float, ptr %19, align 4, !tbaa !11
  %32 = load ptr, ptr %20, align 8, !tbaa !5
  %33 = load i32, ptr %13, align 4, !tbaa !9
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = mul nsw i32 %33, %34
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = add nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds float, ptr %32, i64 %38
  store float %31, ptr %39, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  br label %120

40:                                               ; preds = %9
  %41 = load i32, ptr %16, align 4, !tbaa !9
  %42 = icmp eq i32 %41, 2
  br i1 %42, label %43, label %55

43:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %44, ptr %21, align 8, !tbaa !5
  %45 = load float, ptr %19, align 4, !tbaa !11
  %46 = call zeroext i16 @libxsmm_convert_f32_to_bf16_rne(float noundef %45)
  %47 = load ptr, ptr %21, align 8, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = load i32, ptr %14, align 4, !tbaa !9
  %50 = mul nsw i32 %48, %49
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = add nsw i32 %50, %51
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i16, ptr %47, i64 %53
  store i16 %46, ptr %54, align 2, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  br label %119

55:                                               ; preds = %40
  %56 = load i32, ptr %16, align 4, !tbaa !9
  %57 = icmp eq i32 %56, 3
  br i1 %57, label %58, label %70

58:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %59, ptr %22, align 8, !tbaa !5
  %60 = load float, ptr %19, align 4, !tbaa !11
  %61 = call zeroext i16 @libxsmm_convert_f32_to_f16(float noundef %60)
  %62 = load ptr, ptr %22, align 8, !tbaa !5
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = load i32, ptr %14, align 4, !tbaa !9
  %65 = mul nsw i32 %63, %64
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = add nsw i32 %65, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i16, ptr %62, i64 %68
  store i16 %61, ptr %69, align 2, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  br label %118

70:                                               ; preds = %55
  %71 = load i32, ptr %16, align 4, !tbaa !9
  %72 = icmp eq i32 %71, 4
  br i1 %72, label %73, label %100

73:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %74, ptr %23, align 8, !tbaa !5
  %75 = load i32, ptr %15, align 4, !tbaa !9
  %76 = icmp ugt i32 %75, 0
  br i1 %76, label %77, label %88

77:                                               ; preds = %73
  %78 = load ptr, ptr %23, align 8, !tbaa !5
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = load i32, ptr %14, align 4, !tbaa !9
  %81 = mul nsw i32 %79, %80
  %82 = load i32, ptr %12, align 4, !tbaa !9
  %83 = add nsw i32 %81, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %78, i64 %84
  %86 = load ptr, ptr %17, align 8, !tbaa !5
  %87 = load i32, ptr %18, align 4, !tbaa !9
  call void @libxsmm_stochastic_convert_fp32_bf8(ptr noundef %19, ptr noundef %85, i32 noundef 1, ptr noundef %86, i32 noundef %87)
  br label %99

88:                                               ; preds = %73
  %89 = load float, ptr %19, align 4, !tbaa !11
  %90 = call zeroext i8 @libxsmm_convert_f32_to_bf8_rne(float noundef %89)
  %91 = load ptr, ptr %23, align 8, !tbaa !5
  %92 = load i32, ptr %13, align 4, !tbaa !9
  %93 = load i32, ptr %14, align 4, !tbaa !9
  %94 = mul nsw i32 %92, %93
  %95 = load i32, ptr %12, align 4, !tbaa !9
  %96 = add nsw i32 %94, %95
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i8, ptr %91, i64 %97
  store i8 %90, ptr %98, align 1, !tbaa !15
  br label %99

99:                                               ; preds = %88, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  br label %117

100:                                              ; preds = %70
  %101 = load i32, ptr %16, align 4, !tbaa !9
  %102 = icmp eq i32 %101, 5
  br i1 %102, label %103, label %115

103:                                              ; preds = %100
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #3
  %104 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %104, ptr %24, align 8, !tbaa !5
  %105 = load float, ptr %19, align 4, !tbaa !11
  %106 = call zeroext i8 @libxsmm_convert_f32_to_hf8_rne(float noundef %105)
  %107 = load ptr, ptr %24, align 8, !tbaa !5
  %108 = load i32, ptr %13, align 4, !tbaa !9
  %109 = load i32, ptr %14, align 4, !tbaa !9
  %110 = mul nsw i32 %108, %109
  %111 = load i32, ptr %12, align 4, !tbaa !9
  %112 = add nsw i32 %110, %111
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds i8, ptr %107, i64 %113
  store i8 %106, ptr %114, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #3
  br label %116

115:                                              ; preds = %100
  br label %116

116:                                              ; preds = %115, %103
  br label %117

117:                                              ; preds = %116, %99
  br label %118

118:                                              ; preds = %117, %58
  br label %119

119:                                              ; preds = %118, %43
  br label %120

120:                                              ; preds = %119, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  ret void
}

declare zeroext i16 @libxsmm_convert_f32_to_bf16_rne(float noundef) #2

declare zeroext i16 @libxsmm_convert_f32_to_f16(float noundef) #2

declare void @libxsmm_stochastic_convert_fp32_bf8(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) #2

declare zeroext i8 @libxsmm_convert_f32_to_bf8_rne(float noundef) #2

declare zeroext i8 @libxsmm_convert_f32_to_hf8_rne(float noundef) #2

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 = { "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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!7, !7, i64 0}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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 @libxsmm_elementwise_store_value(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, ptr noundef %7, i32 noundef %8) local_unnamed_addr #1 {
  %10 = alloca float, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #3
  %11 = load float, ptr %1, align 4, !tbaa !5
  store float %11, ptr %10, align 4, !tbaa !5
  switch i32 %6, label %47 [
    i32 1, label %12
    i32 2, label %17
    i32 3, label %23
    i32 4, label %29
    i32 5, label %41
  ]

12:                                               ; preds = %9
  %13 = mul nsw i32 %4, %3
  %14 = add nsw i32 %13, %2
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds float, ptr %0, i64 %15
  store float %11, ptr %16, align 4, !tbaa !5
  br label %47

17:                                               ; preds = %9
  %18 = tail call zeroext i16 @libxsmm_convert_f32_to_bf16_rne(float noundef %11) #3
  %19 = mul nsw i32 %4, %3
  %20 = add nsw i32 %19, %2
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i16, ptr %0, i64 %21
  store i16 %18, ptr %22, align 2, !tbaa !9
  br label %47

23:                                               ; preds = %9
  %24 = tail call zeroext i16 @libxsmm_convert_f32_to_f16(float noundef %11) #3
  %25 = mul nsw i32 %4, %3
  %26 = add nsw i32 %25, %2
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i16, ptr %0, i64 %27
  store i16 %24, ptr %28, align 2, !tbaa !9
  br label %47

29:                                               ; preds = %9
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %35, label %30

30:                                               ; preds = %29
  %31 = mul nsw i32 %4, %3
  %32 = add nsw i32 %31, %2
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %0, i64 %33
  call void @libxsmm_stochastic_convert_fp32_bf8(ptr noundef nonnull %10, ptr noundef %34, i32 noundef 1, ptr noundef %7, i32 noundef %8) #3
  br label %47

35:                                               ; preds = %29
  %36 = tail call zeroext i8 @libxsmm_convert_f32_to_bf8_rne(float noundef %11) #3
  %37 = mul nsw i32 %4, %3
  %38 = add nsw i32 %37, %2
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %0, i64 %39
  store i8 %36, ptr %40, align 1, !tbaa !11
  br label %47

41:                                               ; preds = %9
  %42 = tail call zeroext i8 @libxsmm_convert_f32_to_hf8_rne(float noundef %11) #3
  %43 = mul nsw i32 %4, %3
  %44 = add nsw i32 %43, %2
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %0, i64 %45
  store i8 %42, ptr %46, align 1, !tbaa !11
  br label %47

47:                                               ; preds = %9, %30, %35, %17, %41, %23, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #3
  ret void
}

declare zeroext i16 @libxsmm_convert_f32_to_bf16_rne(float noundef) local_unnamed_addr #2

declare zeroext i16 @libxsmm_convert_f32_to_f16(float noundef) local_unnamed_addr #2

declare void @libxsmm_stochastic_convert_fp32_bf8(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare zeroext i8 @libxsmm_convert_f32_to_bf8_rne(float noundef) local_unnamed_addr #2

declare zeroext i8 @libxsmm_convert_f32_to_hf8_rne(float noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass