; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/CMSIS/DSP/Source/SupportFunctions (arm_bitonic_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_bitonic_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 i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  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 2, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.arm_sort_instance_f32, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr %11, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %17, %18
  br i1 %19, label %20, label %27

20:                                               ; preds = %4
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = mul i64 %24, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %21, ptr align 4 %22, i64 %25, i1 false)
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %26, ptr %12, align 8, !tbaa !5
  br label %29

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

29:                                               ; preds = %27, %20
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = sub i32 %31, 1
  %33 = and i32 %30, %32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %70

35:                                               ; preds = %29
  store i16 2, ptr %9, align 2, !tbaa !14
  br label %36

36:                                               ; preds = %64, %35
  %37 = load i16, ptr %9, align 2, !tbaa !14
  %38 = zext i16 %37 to i32
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = icmp ule i32 %38, %39
  br i1 %40, label %41, label %69

41:                                               ; preds = %36
  store i16 0, ptr %10, align 2, !tbaa !14
  br label %42

42:                                               ; preds = %56, %41
  %43 = load i16, ptr %10, align 2, !tbaa !14
  %44 = zext i16 %43 to i32
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = icmp ult i32 %44, %45
  br i1 %46, label %47, label %63

47:                                               ; preds = %42
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load i16, ptr %10, align 2, !tbaa !14
  %50 = zext i16 %49 to i32
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds float, ptr %48, i64 %51
  %53 = load i16, ptr %9, align 2, !tbaa !14
  %54 = zext i16 %53 to i32
  %55 = load i8, ptr %11, align 1, !tbaa !13
  call void @arm_bitonic_sort_core_f32(ptr noundef %52, i32 noundef %54, i8 noundef zeroext %55)
  br label %56

56:                                               ; preds = %47
  %57 = load i16, ptr %10, align 2, !tbaa !14
  %58 = zext i16 %57 to i32
  %59 = load i16, ptr %9, align 2, !tbaa !14
  %60 = zext i16 %59 to i32
  %61 = add nsw i32 %58, %60
  %62 = trunc i32 %61 to i16
  store i16 %62, ptr %10, align 2, !tbaa !14
  br label %42, !llvm.loop !16

63:                                               ; preds = %42
  br label %64

64:                                               ; preds = %63
  %65 = load i16, ptr %9, align 2, !tbaa !14
  %66 = zext i16 %65 to i32
  %67 = mul nsw i32 %66, 2
  %68 = trunc i32 %67 to i16
  store i16 %68, ptr %9, align 2, !tbaa !14
  br label %36, !llvm.loop !18

69:                                               ; preds = %36
  br label %70

70:                                               ; preds = %69, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 2, 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_bitonic_sort_core_f32(ptr 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 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !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: nounwind uwtable
define dso_local void @arm_bitonic_sort_f32(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = trunc i32 %6 to i8
  %.not = icmp eq ptr %1, %2
  br i1 %.not, label %11, label %8

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

11:                                               ; preds = %4, %8
  %.0 = phi ptr [ %2, %8 ], [ %1, %4 ]
  %12 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %3)
  %13 = icmp ugt i32 %12, 1
  %.not2729 = icmp ult i32 %3, 2
  %or.cond = or i1 %13, %.not2729
  br i1 %or.cond, label %.loopexit, label %.preheader.us

.preheader.us:                                    ; preds = %11, %._crit_edge.us
  %14 = phi i32 [ %23, %._crit_edge.us ], [ 2, %11 ]
  br label %15

15:                                               ; preds = %.preheader.us, %15
  %16 = phi i32 [ 0, %.preheader.us ], [ %20, %15 ]
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds float, ptr %.0, i64 %17
  tail call void @arm_bitonic_sort_core_f32(ptr noundef %18, i32 noundef %14, i8 noundef zeroext %7)
  %19 = add nuw nsw i32 %16, %14
  %20 = and i32 %19, 65535
  %21 = icmp ult i32 %20, %3
  br i1 %21, label %15, label %._crit_edge.us, !llvm.loop !10

._crit_edge.us:                                   ; preds = %15
  %22 = shl nuw nsw i32 %14, 1
  %23 = and i32 %22, 65532
  %.not27.us = icmp ugt i32 %23, %3
  br i1 %.not27.us, label %.loopexit, label %.preheader.us, !llvm.loop !12

.loopexit:                                        ; preds = %._crit_edge.us, %11
  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_bitonic_sort_core_f32(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #2

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) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = distinct !{!12, !11}


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