#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*/ FFT(double *, double *, int, double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ twiddle(int, double *);
int main(int argc, char *argv[]) {
  int n, i;
  printf("Enter the size of the discrete points of signal\n");
  scanf("%d", &n);
  printf("Enter the real parts for each of the %d elements\n", n);
  double *real = (double *)malloc(n * sizeof(double));
  double *imag = (double *)malloc(n * sizeof(double));
  double *w = (double *)malloc(n * sizeof(double));
  for (i = 0; i < n; i++) {
    scanf("%lf", &real[i]);
  }
  printf("Enter the imaginary parts for each of the %d elements\n", n);
  for (i = 0; i < n; i++) {
    scanf("%lf", &imag[i]);
  }
  twiddle(n, w);
  FFT(real, imag, n, w);
  printf("The transformed signal is:\n");
  for (i = 0; i < n; i++) {
    printf("%.lf+%.2lfj, ", real[i], imag[i]);
  }
  printf("\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x14(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    120e <main+0xbe>
mov    -0x20(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d7 <main+0x87>
mov    -0x14(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125d <main+0x10d>
mov    -0x28(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1226 <main+0xd6>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1060 <twiddle@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1070 <FFT@plt>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12d4 <main+0x184>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xdfe(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1292 <main+0x142>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
lea    0xe72(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    120f <main+0x9f>
lea    0xe4d(%rip),%r13
mov    %r14,%rbx
xor    %ebp,%ebp
nopl   (%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rsi
add    $0x8,%rbx
cmp    %rsi,%rbp
jl     11f0 <main+0x80>
lea    0xe23(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    125f <main+0xef>
lea    0xe09(%rip),%r13
mov    %r12,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rdi
add    $0x8,%rbx
cmp    %rdi,%rbp
jl     1240 <main+0xd0>
mov    %r15,%rsi
call   1080 <twiddle@plt>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rcx
call   1090 <FFT@plt>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x4(%rsp)
jle    12c4 <main+0x154>
xor    %ebx,%ebx
lea    0xddb(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%r14,%rbx,8),%xmm0
movsd  (%r12,%rbx,8),%xmm1
mov    %r15,%rdi
mov    $0x2,%al
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     12a0 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Enter the size of the discrete points of signal\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [50 x i8] c"Enter the real parts for each of the %d elements\0A\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [55 x i8] c"Enter the imaginary parts for each of the %d elements\0A\00"
@.str.5 = [28 x i8] c"The transformed signal is:\0A\00"
@.str.6 = [14 x i8] c"%.lf+%.2lfj, \00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%13 = load i32, i32* %6
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 8
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to double*
store double* %20, double** %8
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to double*
store double* %26, double** %9
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 8
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to double*
store double* %32, double** %10
store i32 0, i32* %7
br label %33
33: ; preds = %43, %2
%34 = load i32, i32* %7
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = load double*, double** %8
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %41)
br label %43
43: ; preds = %37
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %33
46: ; preds = %33
%47 = load i32, i32* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 %47)
store i32 0, i32* %7
br label %49
49: ; preds = %59, %46
%50 = load i32, i32* %7
%51 = load i32, i32* %6
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %62
53: ; preds = %49
%54 = load double*, double** %9
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %57)
br label %59
59: ; preds = %53
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
br label %49
62: ; preds = %49
%63 = load i32, i32* %6
%64 = load double*, double** %10
%65 = call i32 @twiddle(i32 %63, double* %64)
%66 = load double*, double** %8
%67 = load double*, double** %9
%68 = load i32, i32* %6
%69 = load double*, double** %10
%70 = call i32 @FFT(double* %66, double* %67, i32 %68, double* %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %7
br label %72
72: ; preds = %88, %62
%73 = load i32, i32* %7
%74 = load i32, i32* %6
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %91
76: ; preds = %72
%77 = load double*, double** %8
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %77, i64 %79
%81 = load double, double* %80
%82 = load double*, double** %9
%83 = load i32, i32* %7
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
%86 = load double, double* %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), double %81, double %86)
br label %88
88: ; preds = %76
%89 = load i32, i32* %7
%90 = add nsw i32 %89, 1
store i32 %90, i32* %7
br label %72
91: ; preds = %72
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [50 x i8] c"Enter the real parts for each of the %d elements\0A\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [55 x i8] c"Enter the imaginary parts for each of the %d elements\0A\00"
@.str.6 = [14 x i8] c"%.lf+%.2lfj, \00"
@str = [48 x i8] c"Enter the size of the discrete points of signal\00"
@str.8 = [27 x i8] c"The transformed signal is:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %3
%10 = shl i32 %9, 3
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to double*
%13 = load i32, i32* %3
%14 = shl i32 %13, 3
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to double*
%17 = load i32, i32* %3
%18 = shl i32 %17, 3
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to double*
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %2, %23
%24 = phi i64 [ %27, %23 ], [ 0, %2 ]
%25 = getelementptr inbounds double, double* %12, i64 %24
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %25)
%27 = add nuw nsw i64 %24, 1
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %23, label %31
31: ; preds = %23, %2
%32 = phi i32 [ %21, %2 ], [ %28, %23 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %3
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %31, %36
%37 = phi i64 [ %40, %36 ], [ 0, %31 ]
%38 = getelementptr inbounds double, double* %16, i64 %37
%39 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %38)
%40 = add nuw nsw i64 %37, 1
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = icmp slt i64 %40, %42
br i1 %43, label %36, label %44
44: ; preds = %36, %31
%45 = phi i32 [ %34, %31 ], [ %41, %36 ]
%46 = call i32 @twiddle(i32 %45, double* %20)
%47 = load i32, i32* %3
%48 = call i32 @FFT(double* %12, double* %16, i32 %47, double* %20)
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.8, i64 0, i64 0))
%50 = load i32, i32* %3
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %63
52: ; preds = %44, %52
%53 = phi i64 [ %59, %52 ], [ 0, %44 ]
%54 = getelementptr inbounds double, double* %12, i64 %53
%55 = load double, double* %54
%56 = getelementptr inbounds double, double* %16, i64 %53
%57 = load double, double* %56
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), double %55, double %57)
%59 = add nuw nsw i64 %53, 1
%60 = load i32, i32* %3
%61 = sext i32 %60 to i64
%62 = icmp slt i64 %59, %61
br i1 %62, label %52, label %63
63: ; preds = %52, %44
%64 = call i32 @putchar(i32 10)
ret i32 0
}