#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ FFTInterp(double *, double *, double *, double *, int, int,
                             double *, int);
int /*<<< orphan*/ memcpy(double *, double *, int);
int /*<<< orphan*/ transpose(double *, int);
void grid_fourier(double *realgrid, double *imaggrid, double *rmatrix,
                  double *imatrix, int size, double *workspace) {
  double *rout, *iout, *scratchpad;
  int i;
  rout = workspace;
  iout = rout + size;
  scratchpad = iout + size;
  if (1) {
    for (i = 0; i < size; i++) {
      FFTInterp(realgrid + (i * size), imaggrid + (i * size),
                rmatrix + (i * size), imatrix + (i * size), size, size,
                scratchpad, 1);
    }
  } else {
    for (i = 0; i < size; i++) {
      FFTInterp(realgrid + (i * size), imaggrid + (i * size), rout, iout, size,
                size, scratchpad, 1);
      memcpy(rmatrix + (i * size), rout, sizeof(double) * size);
      memcpy(imatrix + (i * size), iout, sizeof(double) * size);
    }
  }
  transpose(rmatrix, size);
  transpose(imatrix, size);
}


x86 assembly (clang, -O0):
<grid_fourier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11fc <grid_fourier+0xdc>
mov    -0x8(%rbp),%rdi
mov    -0x4c(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x4c(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x4c(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rcx
mov    -0x4c(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x24(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    -0x48(%rbp),%rax
mov    %rax,(%rsp)
movl   $0x1,0x8(%rsp)
call   1040 <FFTInterp@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1175 <grid_fourier+0x55>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <transpose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <transpose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_fourier>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %r8d,0xc(%rsp)
test   %r8d,%r8d
jle    11a5 <grid_fourier+0x85>
mov    %rsi,%r13
mov    %rdi,%rbp
mov    0xc(%rsp),%ecx
movslq %ecx,%r14
lea    (%r9,%r14,8),%rax
lea    (%rax,%r14,8),%rax
mov    %rax,0x20(%rsp)
mov    %ecx,%r12d
shl    $0x3,%r14
mov    0x18(%rsp),%rbx
mov    0x10(%rsp),%r15
nopl   (%rax)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    0xc(%rsp),%r8d
mov    %r8d,%r9d
push   $0x1
push   0x28(%rsp)
call   1040 <FFTInterp@plt>
add    $0x10,%rsp
add    %r14,%rbp
add    %r14,%r13
add    %r14,%r15
add    %r14,%rbx
add    $0xffffffffffffffff,%r12
jne    1170 <grid_fourier+0x50>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%ebx
mov    %ebx,%esi
call   1030 <transpose@plt>
mov    0x18(%rsp),%rdi
mov    %ebx,%esi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <transpose@plt>

LLVM IR (-O0):
define void @grid_fourier(double* %0, double* %1, double* %2, double* %3, i32 %4, double* %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store double* %3, double** %10
store i32 %4, i32* %11
store double* %5, double** %12
%17 = load double*, double** %12
store double* %17, double** %13
%18 = load double*, double** %13
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
store double* %21, double** %14
%22 = load double*, double** %14
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double* %25, double** %15
store i32 0, i32* %16
br label %26
26: ; preds = %59, %6
%27 = load i32, i32* %16
%28 = load i32, i32* %11
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %62
30: ; preds = %26
%31 = load double*, double** %7
%32 = load i32, i32* %16
%33 = load i32, i32* %11
%34 = mul nsw i32 %32, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %31, i64 %35
%37 = load double*, double** %8
%38 = load i32, i32* %16
%39 = load i32, i32* %11
%40 = mul nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %37, i64 %41
%43 = load double*, double** %9
%44 = load i32, i32* %16
%45 = load i32, i32* %11
%46 = mul nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %43, i64 %47
%49 = load double*, double** %10
%50 = load i32, i32* %16
%51 = load i32, i32* %11
%52 = mul nsw i32 %50, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %49, i64 %53
%55 = load i32, i32* %11
%56 = load i32, i32* %11
%57 = load double*, double** %15
%58 = call i32 @FFTInterp(double* %36, double* %42, double* %48, double* %54, i32 %55, i32 %56, double* %57, i32 1)
br label %59
59: ; preds = %30
%60 = load i32, i32* %16
%61 = add nsw i32 %60, 1
store i32 %61, i32* %16
br label %26
62: ; preds = %26
%63 = load double*, double** %9
%64 = load i32, i32* %11
%65 = call i32 @transpose(double* %63, i32 %64)
%66 = load double*, double** %10
%67 = load i32, i32* %11
%68 = call i32 @transpose(double* %66, i32 %67)
ret void
}

LLVM IR (-O2):
define void @grid_fourier(double* %0, double* %1, double* %2, double* %3, i32 %4, double* %5) {
%7 = sext i32 %4 to i64
%8 = getelementptr inbounds double, double* %5, i64 %7
%9 = getelementptr inbounds double, double* %8, i64 %7
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %23
11: ; preds = %6
%12 = zext i32 %4 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %21, %13 ]
%15 = mul nsw i64 %14, %7
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = getelementptr inbounds double, double* %1, i64 %15
%18 = getelementptr inbounds double, double* %2, i64 %15
%19 = getelementptr inbounds double, double* %3, i64 %15
%20 = tail call i32 @FFTInterp(double* %16, double* %17, double* %18, double* %19, i32 %4, i32 %4, double* %9, i32 1)
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, %12
br i1 %22, label %23, label %13
23: ; preds = %13, %6
%24 = tail call i32 @transpose(double* %2, i32 %4)
%25 = tail call i32 @transpose(double* %3, i32 %4)
ret void
}