void fft_forward(int n, float *buf, float *trigcache, int *splitcache) {
  int flag = 0;
  if (!trigcache || !splitcache) {
    trigcache = calloc(3 * n, sizeof(float));
    splitcache = calloc(32, sizeof(int));
    fdrffti(n, trigcache, splitcache);
    flag = 1;
  }
  fdrfftf(n, buf, trigcache, splitcache);
  if (flag) {
    free(trigcache);
    free(splitcache);
  }
}


x86 assembly (clang, -O0):
<fft_forward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1174 <fft_forward+0x34>
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <fft_forward+0x75>
imul   $0x3,-0x4(%rbp),%eax
movslq %eax,%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x20,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1060 <fdrffti@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <fdrfftf@plt>
cmpl   $0x0,-0x24(%rbp)
je     11e7 <fft_forward+0xa7>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fft_forward>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
test   %rdx,%rdx
je     116e <fft_forward+0x2e>
test   %rcx,%rcx
je     116e <fft_forward+0x2e>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <fdrfftf@plt>
lea    (%rbx,%rbx,2),%eax
movslq %eax,%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
mov    $0x20,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fdrffti@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <fdrfftf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @fft_forward(i32 %0, float* %1, float* %2, i32* %3) {
%5 = alloca i32
%6 = alloca float*
%7 = alloca float*
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store float* %1, float** %6
store float* %2, float** %7
store i32* %3, i32** %8
store i32 0, i32* %9
%10 = load float*, float** %7
%11 = icmp ne float* %10, null
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i32*, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %27, label %15
15: ; preds = %12, %4
%16 = load i32, i32* %5
%17 = mul nsw i32 3, %16
%18 = sext i32 %17 to i64
%19 = call i8* @calloc(i64 %18, i64 4)
%20 = bitcast i8* %19 to float*
store float* %20, float** %7
%21 = call i8* @calloc(i64 32, i64 4)
%22 = bitcast i8* %21 to i32*
store i32* %22, i32** %8
%23 = load i32, i32* %5
%24 = load float*, float** %7
%25 = load i32*, i32** %8
%26 = call i32 (i32, float*, i32*, ...) bitcast (i32 (...)* @fdrffti to i32 (i32, float*, i32*, ...)*)(i32 %23, float* %24, i32* %25)
store i32 1, i32* %9
br label %27
27: ; preds = %15, %12
%28 = load i32, i32* %5
%29 = load float*, float** %6
%30 = load float*, float** %7
%31 = load i32*, i32** %8
%32 = call i32 (i32, float*, float*, i32*, ...) bitcast (i32 (...)* @fdrfftf to i32 (i32, float*, float*, i32*, ...)*)(i32 %28, float* %29, float* %30, i32* %31)
%33 = load i32, i32* %9
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %27
%36 = load float*, float** %7
%37 = bitcast float* %36 to i8*
%38 = load i32*, i32** %8
%39 = bitcast i32* %38 to i8*
br label %40
40: ; preds = %35, %27
ret void
}

LLVM IR (-O2):
define void @fft_forward(i32 %0, float* %1, float* %2, i32* %3) {
%5 = icmp ne float* %2, null
%6 = icmp ne i32* %3, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 (i32, float*, float*, i32*, ...) bitcast (i32 (...)* @fdrfftf to i32 (i32, float*, float*, i32*, ...)*)(i32 %0, float* %1, float* %2, i32* %3)
br label %19
10: ; preds = %4
%11 = mul nsw i32 %0, 3
%12 = sext i32 %11 to i64
%13 = tail call i8* @calloc(i64 %12, i64 4)
%14 = bitcast i8* %13 to float*
%15 = tail call dereferenceable_or_null(128) i8* @calloc(i64 32, i64 4)
%16 = bitcast i8* %15 to i32*
%17 = tail call i32 (i32, float*, i32*, ...) bitcast (i32 (...)* @fdrffti to i32 (i32, float*, i32*, ...)*)(i32 %0, float* %14, i32* %16)
%18 = tail call i32 (i32, float*, float*, i32*, ...) bitcast (i32 (...)* @fdrfftf to i32 (i32, float*, float*, i32*, ...)*)(i32 %0, float* %1, float* %14, i32* %16)
tail call void @free(i8* %13)
tail call void @free(i8* %15)
br label %19
19: ; preds = %8, %10
ret void
}