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

; 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 void @arm_bitreversal_64(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %11

11:                                               ; preds = %16, %3
  %12 = load i64, ptr %9, align 8, !tbaa !11
  %13 = load i16, ptr %5, align 2, !tbaa !9
  %14 = zext i16 %13 to i64
  %15 = icmp ult i64 %12, %14
  br i1 %15, label %16, label %68

16:                                               ; preds = %11
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i64, ptr %9, align 8, !tbaa !11
  %19 = getelementptr inbounds i16, ptr %17, i64 %18
  %20 = load i16, ptr %19, align 2, !tbaa !9
  %21 = zext i16 %20 to i32
  %22 = ashr i32 %21, 2
  %23 = sext i32 %22 to i64
  store i64 %23, ptr %7, align 8, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i64, ptr %9, align 8, !tbaa !11
  %26 = add i64 %25, 1
  %27 = getelementptr inbounds i16, ptr %24, i64 %26
  %28 = load i16, ptr %27, align 2, !tbaa !9
  %29 = zext i16 %28 to i32
  %30 = ashr i32 %29, 2
  %31 = sext i32 %30 to i64
  store i64 %31, ptr %8, align 8, !tbaa !11
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i64, ptr %7, align 8, !tbaa !11
  %34 = getelementptr inbounds i64, ptr %32, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !11
  store i64 %35, ptr %10, align 8, !tbaa !11
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i64, ptr %8, align 8, !tbaa !11
  %38 = getelementptr inbounds i64, ptr %36, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !11
  %42 = getelementptr inbounds i64, ptr %40, i64 %41
  store i64 %39, ptr %42, align 8, !tbaa !11
  %43 = load i64, ptr %10, align 8, !tbaa !11
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i64, ptr %8, align 8, !tbaa !11
  %46 = getelementptr inbounds i64, ptr %44, i64 %45
  store i64 %43, ptr %46, align 8, !tbaa !11
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !11
  %49 = add i64 %48, 1
  %50 = getelementptr inbounds i64, ptr %47, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !11
  store i64 %51, ptr %10, align 8, !tbaa !11
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i64, ptr %8, align 8, !tbaa !11
  %54 = add i64 %53, 1
  %55 = getelementptr inbounds i64, ptr %52, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !11
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load i64, ptr %7, align 8, !tbaa !11
  %59 = add i64 %58, 1
  %60 = getelementptr inbounds i64, ptr %57, i64 %59
  store i64 %56, ptr %60, align 8, !tbaa !11
  %61 = load i64, ptr %10, align 8, !tbaa !11
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load i64, ptr %8, align 8, !tbaa !11
  %64 = add i64 %63, 1
  %65 = getelementptr inbounds i64, ptr %62, i64 %64
  store i64 %61, ptr %65, align 8, !tbaa !11
  %66 = load i64, ptr %9, align 8, !tbaa !11
  %67 = add i64 %66, 2
  store i64 %67, ptr %9, align 8, !tbaa !11
  br label %11, !llvm.loop !13

68:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  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 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 }

!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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @arm_bitreversal_64(ptr nocapture noundef %0, i16 noundef zeroext %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = zext i16 %1 to i64
  %.not = icmp eq i16 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.024 = phi i64 [ %22, %.lr.ph ], [ 0, %3 ]
  %5 = getelementptr inbounds i16, ptr %2, i64 %.024
  %6 = load i16, ptr %5, align 2, !tbaa !5
  %7 = lshr i16 %6, 2
  %8 = zext nneg i16 %7 to i64
  %9 = or disjoint i64 %.024, 1
  %10 = getelementptr inbounds i16, ptr %2, i64 %9
  %11 = load i16, ptr %10, align 2, !tbaa !5
  %12 = lshr i16 %11, 2
  %13 = zext nneg i16 %12 to i64
  %14 = getelementptr inbounds i64, ptr %0, i64 %8
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds i64, ptr %0, i64 %13
  %17 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %17, ptr %14, align 8, !tbaa !9
  store i64 %15, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %14, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %16, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !9
  store i64 %21, ptr %18, align 8, !tbaa !9
  store i64 %19, ptr %20, align 8, !tbaa !9
  %22 = add nuw nsw i64 %.024, 2
  %23 = icmp ult i64 %22, %4
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

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


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