; LLVM IR from ggml-org/ggml :: src/ggml-cpu (vec)

; 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: alwaysinline mustprogress nounwind uwtable
declare hidden void @_ZL13_mm_storeu_psPfDv4_f(ptr noundef, <4 x float> noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL12_mm_loadu_psPKf(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local double @ggml_vec_soft_max_f32(i32 noundef %0, ptr noundef %1, ptr noundef %2, float noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca <4 x float>, align 16
  %12 = alloca <4 x float>, align 16
  %13 = alloca float, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store float %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store double 0.000000e+00, ptr %10, align 8, !tbaa !13
  br label %14

14:                                               ; preds = %51, %4
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = add nsw i32 %15, 3
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %54

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #5
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds float, ptr %20, i64 %22
  %24 = call noundef <4 x float> @_ZL12_mm_loadu_psPKf(ptr noundef %23)
  %25 = load float, ptr %8, align 4, !tbaa !11
  %26 = call noundef <4 x float> @_ZL11_mm_set1_psf(float noundef %25)
  %27 = call noundef <4 x float> @_ZL10_mm_sub_psDv4_fS_(<4 x float> noundef %24, <4 x float> noundef %26)
  %28 = call noundef <4 x float> @_ZL11ggml_v_expfDv4_f(<4 x float> noundef %27)
  store <4 x float> %28, ptr %11, align 16, !tbaa !15
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds float, ptr %29, i64 %31
  %33 = load <4 x float>, ptr %11, align 16, !tbaa !15
  call void @_ZL13_mm_storeu_psPfDv4_f(ptr noundef %32, <4 x float> noundef %33)
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #5
  %34 = load <4 x float>, ptr %11, align 16, !tbaa !15
  %35 = load <4 x float>, ptr %11, align 16, !tbaa !15
  %36 = shufflevector <4 x float> %34, <4 x float> %35, <4 x i32> <i32 1, i32 0, i32 7, i32 6>
  store <4 x float> %36, ptr %12, align 16, !tbaa !15
  %37 = load <4 x float>, ptr %11, align 16, !tbaa !15
  %38 = load <4 x float>, ptr %12, align 16, !tbaa !15
  %39 = call noundef <4 x float> @_ZL10_mm_add_psDv4_fS_(<4 x float> noundef %37, <4 x float> noundef %38)
  store <4 x float> %39, ptr %11, align 16, !tbaa !15
  %40 = load <4 x float>, ptr %12, align 16, !tbaa !15
  %41 = load <4 x float>, ptr %11, align 16, !tbaa !15
  %42 = call noundef <4 x float> @_ZL13_mm_movehl_psDv4_fS_(<4 x float> noundef %40, <4 x float> noundef %41)
  store <4 x float> %42, ptr %12, align 16, !tbaa !15
  %43 = load <4 x float>, ptr %11, align 16, !tbaa !15
  %44 = load <4 x float>, ptr %12, align 16, !tbaa !15
  %45 = call noundef <4 x float> @_ZL10_mm_add_ssDv4_fS_(<4 x float> noundef %43, <4 x float> noundef %44)
  store <4 x float> %45, ptr %11, align 16, !tbaa !15
  %46 = load <4 x float>, ptr %11, align 16, !tbaa !15
  %47 = call noundef float @_ZL13_mm_cvtss_f32Dv4_f(<4 x float> noundef %46)
  %48 = fpext float %47 to double
  %49 = load double, ptr %10, align 8, !tbaa !13
  %50 = fadd double %49, %48
  store double %50, ptr %10, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  br label %51

51:                                               ; preds = %19
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = add nsw i32 %52, 4
  store i32 %53, ptr %9, align 4, !tbaa !5
  br label %14, !llvm.loop !16

54:                                               ; preds = %14
  br label %55

55:                                               ; preds = %77, %54
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %59, label %80

59:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds float, ptr %60, i64 %62
  %64 = load float, ptr %63, align 4, !tbaa !11
  %65 = load float, ptr %8, align 4, !tbaa !11
  %66 = fsub float %64, %65
  %67 = call float @expf(float noundef %66) #5, !tbaa !5
  store float %67, ptr %13, align 4, !tbaa !11
  %68 = load float, ptr %13, align 4, !tbaa !11
  %69 = fpext float %68 to double
  %70 = load double, ptr %10, align 8, !tbaa !13
  %71 = fadd double %70, %69
  store double %71, ptr %10, align 8, !tbaa !13
  %72 = load float, ptr %13, align 4, !tbaa !11
  %73 = load ptr, ptr %6, align 8, !tbaa !9
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds float, ptr %73, i64 %75
  store float %72, ptr %76, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %77

77:                                               ; preds = %59
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %9, align 4, !tbaa !5
  br label %55, !llvm.loop !18

80:                                               ; preds = %55
  %81 = load double, ptr %10, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret double %81
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef <4 x float> @_ZL11ggml_v_expfDv4_f(<4 x float> noundef) #3

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL10_mm_sub_psDv4_fS_(<4 x float> noundef, <4 x float> noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL11_mm_set1_psf(float noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL10_mm_add_psDv4_fS_(<4 x float> noundef, <4 x float> noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL13_mm_movehl_psDv4_fS_(<4 x float> noundef, <4 x float> noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL10_mm_add_ssDv4_fS_(<4 x float> noundef, <4 x float> noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef float @_ZL13_mm_cvtss_f32Dv4_f(<4 x float> noundef) #1

; Function Attrs: nounwind
declare float @expf(float noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="128" "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 = { mustprogress uwtable "min-legal-vector-width"="128" "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 = { inlinehint mustprogress uwtable "min-legal-vector-width"="128" "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 #4 = { nounwind "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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!7, !7, i64 0}
!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"

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden void @_ZL13_mm_storeu_psPfDv4_f(ptr noundef, <4 x float> noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL12_mm_loadu_psPKf(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local double @ggml_vec_soft_max_f32(i32 noundef %0, ptr noundef %1, ptr noundef %2, float noundef %3) local_unnamed_addr #1 {
  %5 = icmp sgt i32 %0, 3
  br i1 %5, label %.lr.ph, label %.preheader

.preheader.loopexit:                              ; preds = %.lr.ph
  %6 = trunc nuw i64 %indvars.iv.next to i32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %4
  %.030.lcssa = phi double [ 0.000000e+00, %4 ], [ %21, %.preheader.loopexit ]
  %.0.lcssa = phi i32 [ 0, %4 ], [ %6, %.preheader.loopexit ]
  %7 = icmp slt i32 %.0.lcssa, %0
  br i1 %7, label %.lr.ph37.preheader, label %._crit_edge

.lr.ph37.preheader:                               ; preds = %.preheader
  %8 = zext i32 %.0.lcssa to i64
  br label %.lr.ph37

.lr.ph:                                           ; preds = %4, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %4 ]
  %.03032 = phi double [ %21, %.lr.ph ], [ 0.000000e+00, %4 ]
  %9 = getelementptr inbounds float, ptr %2, i64 %indvars.iv
  %10 = tail call noundef <4 x float> @_ZL12_mm_loadu_psPKf(ptr noundef %9)
  %11 = tail call noundef <4 x float> @_ZL11_mm_set1_psf(float noundef %3)
  %12 = tail call noundef <4 x float> @_ZL10_mm_sub_psDv4_fS_(<4 x float> noundef %10, <4 x float> noundef %11)
  %13 = tail call noundef <4 x float> @_ZL11ggml_v_expfDv4_f(<4 x float> noundef %12)
  %14 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  tail call void @_ZL13_mm_storeu_psPfDv4_f(ptr noundef %14, <4 x float> noundef %13)
  %15 = shufflevector <4 x float> %13, <4 x float> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2>
  %16 = tail call noundef <4 x float> @_ZL10_mm_add_psDv4_fS_(<4 x float> noundef %13, <4 x float> noundef %15)
  %17 = tail call noundef <4 x float> @_ZL13_mm_movehl_psDv4_fS_(<4 x float> noundef %15, <4 x float> noundef %16)
  %18 = tail call noundef <4 x float> @_ZL10_mm_add_ssDv4_fS_(<4 x float> noundef %16, <4 x float> noundef %17)
  %19 = tail call noundef float @_ZL13_mm_cvtss_f32Dv4_f(<4 x float> noundef %18)
  %20 = fpext float %19 to double
  %21 = fadd double %.03032, %20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 4
  %22 = trunc i64 %indvars.iv.next to i32
  %23 = or disjoint i32 %22, 3
  %24 = icmp slt i32 %23, %0
  br i1 %24, label %.lr.ph, label %.preheader.loopexit, !llvm.loop !5

.lr.ph37:                                         ; preds = %.lr.ph37.preheader, %.lr.ph37
  %indvars.iv42 = phi i64 [ %8, %.lr.ph37.preheader ], [ %indvars.iv.next43, %.lr.ph37 ]
  %.13135 = phi double [ %.030.lcssa, %.lr.ph37.preheader ], [ %30, %.lr.ph37 ]
  %25 = getelementptr inbounds float, ptr %2, i64 %indvars.iv42
  %26 = load float, ptr %25, align 4, !tbaa !7
  %27 = fsub float %26, %3
  %28 = tail call float @expf(float noundef %27) #4, !tbaa !11
  %29 = fpext float %28 to double
  %30 = fadd double %.13135, %29
  %31 = getelementptr inbounds float, ptr %1, i64 %indvars.iv42
  store float %28, ptr %31, align 4, !tbaa !7
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %32 = trunc nuw i64 %indvars.iv.next43 to i32
  %33 = icmp slt i32 %32, %0
  br i1 %33, label %.lr.ph37, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph37, %.preheader
  %.131.lcssa = phi double [ %.030.lcssa, %.preheader ], [ %30, %.lr.ph37 ]
  ret double %.131.lcssa
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef <4 x float> @_ZL11ggml_v_expfDv4_f(<4 x float> noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL10_mm_sub_psDv4_fS_(<4 x float> noundef, <4 x float> noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL11_mm_set1_psf(float noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL10_mm_add_psDv4_fS_(<4 x float> noundef, <4 x float> noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL13_mm_movehl_psDv4_fS_(<4 x float> noundef, <4 x float> noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <4 x float> @_ZL10_mm_add_ssDv4_fS_(<4 x float> noundef, <4 x float> noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef float @_ZL13_mm_cvtss_f32Dv4_f(<4 x float> noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @expf(float noundef) local_unnamed_addr #3

attributes #0 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="128" "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 = { mustprogress uwtable "min-legal-vector-width"="128" "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 = { inlinehint mustprogress uwtable "min-legal-vector-width"="128" "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 = { mustprogress nofree nounwind willreturn memory(write) "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 #4 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = distinct !{!13, !6}


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