; LLVM IR from T-Troll/alienfx-tools :: alienfx-gui/kiss_fft/kiss_fft.ll (Z14kiss_fft_allociiPvPm)

; 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.kiss_fft_cpx = type { float, float }
%struct.kiss_fft_state = type { i32, i32, ptr, ptr, ptr, ptr }

; 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 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9kf_factoriPi(i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z14kiss_fft_allociiPvPm(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca %struct.kiss_fft_cpx, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store ptr null, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = mul i64 8, %16
  %18 = add i64 40, %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul i64 8, %20
  %22 = add i64 %18, %21
  %23 = add i64 %22, 256
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = mul i64 8, %25
  %27 = add i64 %23, %26
  store i64 %27, ptr %10, align 8, !tbaa !11
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %4
  %31 = load i64, ptr %10, align 8, !tbaa !11
  %32 = call noalias ptr @malloc(i64 noundef %31) #7
  store ptr %32, ptr %9, align 8, !tbaa !9
  br label %43

33:                                               ; preds = %4
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = load i64, ptr %10, align 8, !tbaa !11
  %37 = icmp uge i64 %35, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %33
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %39, ptr %9, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %38, %33
  %41 = load i64, ptr %10, align 8, !tbaa !11
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  store i64 %41, ptr %42, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %40, %30
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %116

46:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.kiss_fft_state, ptr %48, i32 0, i32 0
  store i32 %47, ptr %49, align 8, !tbaa !13
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.kiss_fft_state, ptr %51, i32 0, i32 1
  store i32 %50, ptr %52, align 4, !tbaa !15
  %53 = load ptr, ptr %9, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.kiss_fft_state, ptr %53, i64 1
  %55 = load ptr, ptr %9, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.kiss_fft_state, ptr %55, i32 0, i32 3
  store ptr %54, ptr %56, align 8, !tbaa !16
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.kiss_fft_state, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %59, i64 %61
  %63 = load ptr, ptr %9, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.kiss_fft_state, ptr %63, i32 0, i32 4
  store ptr %62, ptr %64, align 8, !tbaa !17
  %65 = load ptr, ptr %9, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.kiss_fft_state, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !17
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %67, i64 %69
  %71 = load ptr, ptr %9, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.kiss_fft_state, ptr %71, i32 0, i32 5
  store ptr %70, ptr %72, align 8, !tbaa !18
  %73 = load ptr, ptr %9, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.kiss_fft_state, ptr %73, i32 0, i32 5
  %75 = load ptr, ptr %74, align 8, !tbaa !18
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %75, i64 %77
  %79 = load ptr, ptr %9, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.kiss_fft_state, ptr %79, i32 0, i32 2
  store ptr %78, ptr %80, align 8, !tbaa !19
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %108, %46
  %82 = load i32, ptr %11, align 4, !tbaa !5
  %83 = load i32, ptr %5, align 4, !tbaa !5
  %84 = icmp slt i32 %82, %83
  br i1 %84, label %85, label %111

85:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  store double 0x400921FB54442D18, ptr %12, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = sitofp i32 %86 to double
  %88 = fdiv double 0xC01921FB54442D18, %87
  %89 = load i32, ptr %11, align 4, !tbaa !5
  %90 = sitofp i32 %89 to double
  %91 = fmul double %88, %90
  store double %91, ptr %13, align 8, !tbaa !20
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.kiss_fft_state, ptr %92, i32 0, i32 1
  %94 = load i32, ptr %93, align 4, !tbaa !15
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %99

96:                                               ; preds = %85
  %97 = load double, ptr %13, align 8, !tbaa !20
  %98 = fmul double %97, -1.000000e+00
  store double %98, ptr %13, align 8, !tbaa !20
  br label %99

99:                                               ; preds = %96, %85
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %100 = load double, ptr %13, align 8, !tbaa !20
  %101 = call <2 x float> @_ZL7kf_cexpd(double noundef %100)
  store <2 x float> %101, ptr %14, align 4
  %102 = load ptr, ptr %9, align 8, !tbaa !9
  %103 = getelementptr inbounds %struct.kiss_fft_state, ptr %102, i32 0, i32 3
  %104 = load ptr, ptr %103, align 8, !tbaa !16
  %105 = load i32, ptr %11, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %104, i64 %106
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %107, ptr align 4 %14, i64 8, i1 false), !tbaa.struct !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %108

108:                                              ; preds = %99
  %109 = load i32, ptr %11, align 4, !tbaa !5
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %11, align 4, !tbaa !5
  br label %81, !llvm.loop !25

111:                                              ; preds = %81
  %112 = load i32, ptr %5, align 4, !tbaa !5
  %113 = load ptr, ptr %9, align 8, !tbaa !9
  %114 = getelementptr inbounds %struct.kiss_fft_state, ptr %113, i32 0, i32 2
  %115 = load ptr, ptr %114, align 8, !tbaa !19
  call void @_Z9kf_factoriPi(i32 noundef %112, ptr noundef %115)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %116

116:                                              ; preds = %111, %43
  %117 = load ptr, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  ret ptr %117
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden <2 x float> @_ZL7kf_cexpd(double noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { mustprogress uwtable "min-legal-vector-width"="64" "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 allocsize(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 #5 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="64" "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS14kiss_fft_state", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!15 = !{!14, !6, i64 4}
!16 = !{!14, !10, i64 16}
!17 = !{!14, !10, i64 24}
!18 = !{!14, !10, i64 32}
!19 = !{!14, !10, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !7, i64 0}
!22 = !{i64 0, i64 4, !23, i64 4, i64 4, !23}
!23 = !{!24, !24, i64 0}
!24 = !{!"float", !7, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"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"

%struct.kiss_fft_cpx = type { float, float }

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9kf_factoriPi(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z14kiss_fft_allociiPvPm(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = sext i32 %0 to i64
  %6 = shl nsw i64 %5, 3
  %reass.add = shl nsw i64 %5, 4
  %7 = add nsw i64 %reass.add, 296
  %8 = add nsw i64 %7, %6
  %9 = icmp eq ptr %3, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %4
  %11 = tail call noalias ptr @malloc(i64 noundef %8) #4
  br label %14

12:                                               ; preds = %4
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp ult i64 %13, %8
  store i64 %8, ptr %3, align 8, !tbaa !5
  br i1 %.not, label %.thread, label %14

14:                                               ; preds = %12, %10
  %.1 = phi ptr [ %11, %10 ], [ %2, %12 ]
  %.not43 = icmp eq ptr %.1, null
  br i1 %.not43, label %.thread, label %15

15:                                               ; preds = %14
  store i32 %0, ptr %.1, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %.1, i64 4
  store i32 %1, ptr %16, align 4, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %.1, i64 40
  %18 = getelementptr inbounds i8, ptr %.1, i64 16
  store ptr %17, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %17, i64 %5
  %20 = getelementptr inbounds i8, ptr %.1, i64 24
  store ptr %19, ptr %20, align 8, !tbaa !15
  %21 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %19, i64 %5
  %22 = getelementptr inbounds i8, ptr %.1, i64 32
  store ptr %21, ptr %22, align 8, !tbaa !16
  %23 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %21, i64 %5
  %24 = getelementptr inbounds i8, ptr %.1, i64 8
  store ptr %23, ptr %24, align 8, !tbaa !17
  %25 = icmp sgt i32 %0, 0
  br i1 %25, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %15
  %26 = uitofp nneg i32 %0 to double
  %27 = fdiv double 0xC01921FB54442D18, %26
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %28

28:                                               ; preds = %.lr.ph, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %28 ]
  %29 = trunc nuw nsw i64 %indvars.iv to i32
  %30 = uitofp nneg i32 %29 to double
  %31 = fmul double %27, %30
  %32 = load i32, ptr %16, align 4, !tbaa !13
  %.not44 = icmp eq i32 %32, 0
  %33 = fneg double %31
  %.038 = select i1 %.not44, double %31, double %33
  %34 = tail call <2 x float> @_ZL7kf_cexpd(double noundef %.038)
  %35 = load ptr, ptr %18, align 8, !tbaa !14
  %36 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %35, i64 %indvars.iv
  store <2 x float> %34, ptr %36, align 4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %28, !llvm.loop !18

._crit_edge.loopexit:                             ; preds = %28
  %.pre = load ptr, ptr %24, align 8, !tbaa !17
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %15
  %37 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %23, %15 ]
  tail call void @_Z9kf_factoriPi(i32 noundef %0, ptr noundef %37)
  br label %.thread

.thread:                                          ; preds = %12, %._crit_edge, %14
  %.147 = phi ptr [ %.1, %._crit_edge ], [ null, %14 ], [ null, %12 ]
  ret ptr %.147
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden <2 x float> @_ZL7kf_cexpd(double noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 uwtable "min-legal-vector-width"="64" "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind uwtable "min-legal-vector-width"="64" "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 allocsize(0) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS14kiss_fft_state", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !12, i64 16}
!15 = !{!10, !12, i64 24}
!16 = !{!10, !12, i64 32}
!17 = !{!10, !12, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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