; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/CMSIS/DSP/Source/SupportFunctions (arm_heap_sort_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"

%struct.arm_sort_instance_f32 = type { i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @arm_heap_sort_f32(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca float, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp ne ptr %12, %13
  br i1 %14, label %15, label %22

15:                                               ; preds = %4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = mul i64 %19, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %17, i64 %20, i1 false)
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %21, ptr %9, align 8, !tbaa !5
  br label %24

22:                                               ; preds = %4
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %23, ptr %9, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %22, %15
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = udiv i32 %25, 2
  %27 = sub i32 %26, 1
  store i32 %27, ptr %10, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %39, %24
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = icmp sge i32 %29, 0
  br i1 %30, label %31, label %42

31:                                               ; preds = %28
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.arm_sort_instance_f32, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = trunc i32 %37 to i8
  call void @arm_heapify(ptr noundef %32, i32 noundef %33, i32 noundef %34, i8 noundef zeroext %38)
  br label %39

39:                                               ; preds = %31
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr %10, align 4, !tbaa !9
  br label %28, !llvm.loop !13

42:                                               ; preds = %28
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sub i32 %43, 1
  store i32 %44, ptr %10, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %70, %42
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = icmp sge i32 %46, 0
  br i1 %47, label %48, label %73

48:                                               ; preds = %45
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds float, ptr %49, i64 %51
  %53 = load float, ptr %52, align 4, !tbaa !15
  store float %53, ptr %11, align 4, !tbaa !15
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds float, ptr %54, i64 0
  %56 = load float, ptr %55, align 4, !tbaa !15
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds float, ptr %57, i64 %59
  store float %56, ptr %60, align 4, !tbaa !15
  %61 = load float, ptr %11, align 4, !tbaa !15
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds float, ptr %62, i64 0
  store float %61, ptr %63, align 4, !tbaa !15
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.arm_sort_instance_f32, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !11
  %69 = trunc i32 %68 to i8
  call void @arm_heapify(ptr noundef %64, i32 noundef %65, i32 noundef 0, i8 noundef zeroext %69)
  br label %70

70:                                               ; preds = %48
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = add nsw i32 %71, -1
  store i32 %72, ptr %10, align 4, !tbaa !9
  br label %45, !llvm.loop !17

73:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden void @arm_heapify(ptr noundef, i32 noundef, i32 noundef, i8 noundef zeroext) #0

; 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 4}
!12 = !{!"", !10, i64 0, !10, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = distinct !{!17, !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: nounwind uwtable
define dso_local void @arm_heap_sort_f32(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, %2
  br i1 %.not, label %8, label %5

5:                                                ; preds = %4
  %6 = zext i32 %3 to i64
  %7 = shl nuw nsw i64 %6, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %1, i64 %7, i1 false)
  br label %8

8:                                                ; preds = %4, %5
  %.0 = phi ptr [ %2, %5 ], [ %1, %4 ]
  %.not34 = icmp ult i32 %3, 2
  br i1 %.not34, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %9 = lshr i32 %3, 1
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  br label %14

.preheader:                                       ; preds = %14, %8
  %.131 = add i32 %3, -1
  %11 = icmp sgt i32 %.131, -1
  br i1 %11, label %.lr.ph33, label %._crit_edge

.lr.ph33:                                         ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = zext nneg i32 %.131 to i64
  br label %18

14:                                               ; preds = %.lr.ph, %14
  %.026.in30 = phi i32 [ %9, %.lr.ph ], [ %.026, %14 ]
  %.026 = add nsw i32 %.026.in30, -1
  %15 = load i32, ptr %10, align 4, !tbaa !5
  %16 = trunc i32 %15 to i8
  tail call void @arm_heapify(ptr noundef %.0, i32 noundef %3, i32 noundef %.026, i8 noundef zeroext %16)
  %17 = icmp ugt i32 %.026.in30, 1
  br i1 %17, label %14, label %.preheader, !llvm.loop !10

18:                                               ; preds = %.lr.ph33, %18
  %indvars.iv = phi i64 [ %13, %.lr.ph33 ], [ %indvars.iv.next, %18 ]
  %19 = getelementptr inbounds float, ptr %.0, i64 %indvars.iv
  %20 = load float, ptr %19, align 4, !tbaa !12
  %21 = load float, ptr %.0, align 4, !tbaa !12
  store float %21, ptr %19, align 4, !tbaa !12
  store float %20, ptr %.0, align 4, !tbaa !12
  %22 = load i32, ptr %12, align 4, !tbaa !5
  %23 = trunc i32 %22 to i8
  %24 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @arm_heapify(ptr noundef nonnull %.0, i32 noundef %24, i32 noundef 0, i8 noundef zeroext %23)
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not36 = icmp eq i64 %indvars.iv, 0
  br i1 %.not36, label %._crit_edge, label %18, !llvm.loop !14

._crit_edge:                                      ; preds = %18, %.preheader
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @arm_heapify(ptr noundef, i32 noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = distinct !{!14, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass