; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/CMSIS/DSP/Source/StatisticsFunctions (arm_logsumexp_f32)

; 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: nounwind uwtable
define dso_local float @arm_logsumexp_f32(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %11, ptr %8, align 4, !tbaa !9
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds float, ptr %12, i32 1
  store ptr %13, ptr %7, align 8, !tbaa !5
  %14 = load float, ptr %12, align 4, !tbaa !11
  store float %14, ptr %5, align 4, !tbaa !11
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = add i32 %15, -1
  store i32 %16, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %29, %2
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp ugt i32 %18, 0
  br i1 %19, label %20, label %32

20:                                               ; preds = %17
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds float, ptr %21, i32 1
  store ptr %22, ptr %7, align 8, !tbaa !5
  %23 = load float, ptr %21, align 4, !tbaa !11
  store float %23, ptr %6, align 4, !tbaa !11
  %24 = load float, ptr %6, align 4, !tbaa !11
  %25 = load float, ptr %5, align 4, !tbaa !11
  %26 = fcmp ogt float %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %20
  %28 = load float, ptr %6, align 4, !tbaa !11
  store float %28, ptr %5, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %27, %20
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = add i32 %30, -1
  store i32 %31, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !13

32:                                               ; preds = %17
  %33 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %33, ptr %8, align 4, !tbaa !9
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %34, ptr %7, align 8, !tbaa !5
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %38, %32
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = icmp ugt i32 %36, 0
  br i1 %37, label %38, label %50

38:                                               ; preds = %35
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds float, ptr %39, i32 1
  store ptr %40, ptr %7, align 8, !tbaa !5
  %41 = load float, ptr %39, align 4, !tbaa !11
  store float %41, ptr %6, align 4, !tbaa !11
  %42 = load float, ptr %6, align 4, !tbaa !11
  %43 = load float, ptr %5, align 4, !tbaa !11
  %44 = fsub float %42, %43
  %45 = call float @expf(float noundef %44) #3, !tbaa !9
  %46 = load float, ptr %9, align 4, !tbaa !11
  %47 = fadd float %46, %45
  store float %47, ptr %9, align 4, !tbaa !11
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = add i32 %48, -1
  store i32 %49, ptr %8, align 4, !tbaa !9
  br label %35, !llvm.loop !15

50:                                               ; preds = %35
  %51 = load float, ptr %5, align 4, !tbaa !11
  %52 = load float, ptr %9, align 4, !tbaa !11
  %53 = call float @logf(float noundef %52) #3
  %54 = fadd float %51, %53
  store float %54, ptr %9, align 4, !tbaa !11
  %55 = load float, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret float %55
}

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

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

; Function Attrs: nounwind
declare float @logf(float noundef) #2

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

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


; 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 nounwind memory(readwrite, inaccessiblemem: write) uwtable
define dso_local float @arm_logsumexp_f32(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load float, ptr %0, align 4, !tbaa !5
  %.02027 = add i32 %1, -1
  %.not28 = icmp eq i32 %.02027, 0
  br i1 %.not28, label %.lr.ph36.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %4 = add i32 %1, -2
  %xtraiter = and i32 %.02027, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.02031.prol = phi i32 [ %.020.prol, %.lr.ph.prol ], [ %.02027, %.lr.ph.preheader ]
  %.pn30.prol = phi ptr [ %.021.prol, %.lr.ph.prol ], [ %0, %.lr.ph.preheader ]
  %.02329.prol = phi float [ %.124.prol, %.lr.ph.prol ], [ %3, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %.021.prol = getelementptr inbounds i8, ptr %.pn30.prol, i64 4
  %5 = load float, ptr %.021.prol, align 4, !tbaa !5
  %6 = fcmp ogt float %5, %.02329.prol
  %.124.prol = select i1 %6, float %5, float %.02329.prol
  %.020.prol = add i32 %.02031.prol, -1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !9

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.124.lcssa.unr = phi float [ poison, %.lr.ph.preheader ], [ %.124.prol, %.lr.ph.prol ]
  %.02031.unr = phi i32 [ %.02027, %.lr.ph.preheader ], [ %.020.prol, %.lr.ph.prol ]
  %.pn30.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %.021.prol, %.lr.ph.prol ]
  %.02329.unr = phi float [ %3, %.lr.ph.preheader ], [ %.124.prol, %.lr.ph.prol ]
  %7 = icmp ult i32 %4, 3
  br i1 %7, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %.lr.ph.prol.loopexit
  %.124.lcssa = phi float [ %.124.lcssa.unr, %.lr.ph.prol.loopexit ], [ %.124.3, %.lr.ph ]
  %.not2632 = icmp eq i32 %1, 0
  br i1 %.not2632, label %._crit_edge, label %.lr.ph36.preheader

.lr.ph36.preheader:                               ; preds = %2, %.preheader
  %.023.lcssa40 = phi float [ %.124.lcssa, %.preheader ], [ %3, %2 ]
  br label %.lr.ph36

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.02031 = phi i32 [ %.020.3, %.lr.ph ], [ %.02031.unr, %.lr.ph.prol.loopexit ]
  %.pn30 = phi ptr [ %.021.3, %.lr.ph ], [ %.pn30.unr, %.lr.ph.prol.loopexit ]
  %.02329 = phi float [ %.124.3, %.lr.ph ], [ %.02329.unr, %.lr.ph.prol.loopexit ]
  %.021 = getelementptr inbounds i8, ptr %.pn30, i64 4
  %8 = load float, ptr %.021, align 4, !tbaa !5
  %9 = fcmp ogt float %8, %.02329
  %.124 = select i1 %9, float %8, float %.02329
  %.021.1 = getelementptr inbounds i8, ptr %.pn30, i64 8
  %10 = load float, ptr %.021.1, align 4, !tbaa !5
  %11 = fcmp ogt float %10, %.124
  %.124.1 = select i1 %11, float %10, float %.124
  %.021.2 = getelementptr inbounds i8, ptr %.pn30, i64 12
  %12 = load float, ptr %.021.2, align 4, !tbaa !5
  %13 = fcmp ogt float %12, %.124.1
  %.124.2 = select i1 %13, float %12, float %.124.1
  %.021.3 = getelementptr inbounds i8, ptr %.pn30, i64 16
  %14 = load float, ptr %.021.3, align 4, !tbaa !5
  %15 = fcmp ogt float %14, %.124.2
  %.124.3 = select i1 %15, float %14, float %.124.2
  %.020.3 = add i32 %.02031, -4
  %.not.3 = icmp eq i32 %.020.3, 0
  br i1 %.not.3, label %.preheader, label %.lr.ph, !llvm.loop !11

.lr.ph36:                                         ; preds = %.lr.ph36.preheader, %.lr.ph36
  %.035 = phi float [ %20, %.lr.ph36 ], [ 0.000000e+00, %.lr.ph36.preheader ]
  %.134 = phi i32 [ %21, %.lr.ph36 ], [ %1, %.lr.ph36.preheader ]
  %.12233 = phi ptr [ %16, %.lr.ph36 ], [ %0, %.lr.ph36.preheader ]
  %16 = getelementptr inbounds i8, ptr %.12233, i64 4
  %17 = load float, ptr %.12233, align 4, !tbaa !5
  %18 = fsub float %17, %.023.lcssa40
  %19 = tail call float @expf(float noundef %18) #2, !tbaa !13
  %20 = fadd float %.035, %19
  %21 = add i32 %.134, -1
  %.not26 = icmp eq i32 %21, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph36, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph36, %.preheader
  %.023.lcssa41 = phi float [ %.124.lcssa, %.preheader ], [ %.023.lcssa40, %.lr.ph36 ]
  %.0.lcssa = phi float [ 0.000000e+00, %.preheader ], [ %20, %.lr.ph36 ]
  %22 = tail call float @logf(float noundef %.0.lcssa) #2
  %23 = fadd float %.023.lcssa41, %22
  ret float %23
}

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

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

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: write) 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 = { 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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !12}


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