#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 EXIT_FAILURE;
int EXIT_SUCCESS;
float *calloc(size_t, size_t);
int /*<<< orphan*/ esprit_r(float *, int *, int *, int *, float const *,
                            float *, float *);
double fabsf(float);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(float *);
float *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ signoise_r(float const *, float const *, float const *,
                              int *, float *);
int /*<<< orphan*/ stderr;
int main(void) {
  printf("C Esprit\n");
  int Ns = 1024;
  int Ntone = 2;
  int M = Ns / 2;
  const float fs = 48000.;
  const float snr = 60.;
  const float f0 = (float)12345.6;
  float *x;
  x = malloc((size_t)Ns * sizeof(float));
  signoise_r(&fs, &f0, &snr, &Ns, &x[0]);
  float *tones = calloc((size_t)Ntone, (size_t)Ntone * sizeof(float));
  float *sigma = calloc((size_t)Ntone, (size_t)Ntone * sizeof(float));
  esprit_r(&x[0], &Ns, &Ntone, &M, &fs, &tones[0], &sigma[0]);
  free(x);
  printf("estimated tone freq [Hz]: ");
  for (int i = 0; i < Ntone; i++)
    printf("%f ", tones[i]);
  printf("\nwith sigma:               ");
  for (int i = 0; i < Ntone; i++)
    printf("%f ", sigma[i]);
  printf("\n");
  if (fabsf(tones[0] - f0) > 0.0001 * f0) {
    fprintf(stderr, "E: failed to meet tolerance\n");
    free(tones);
    free(sigma);
    return EXIT_FAILURE;
  } else {
    printf("OK\n");
    free(tones);
    free(sigma);
    return EXIT_SUCCESS;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x400,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
movss  0xe47(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe36(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xe25(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movslq -0x8(%rbp),%rdi
shl    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%r8
lea    -0x14(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x8(%rbp),%rcx
call   10a0 <signoise_r@plt>
movslq -0xc(%rbp),%rdi
movslq -0xc(%rbp),%rsi
shl    $0x2,%rsi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0xc(%rbp),%rdi
movslq -0xc(%rbp),%rsi
shl    $0x2,%rsi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
mov    %rax,(%rsp)
call   1090 <esprit_r@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12b0 <main+0x130>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xda2(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1277 <main+0xf7>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12fe <main+0x17e>
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd54(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12c5 <main+0x145>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
movss  (%rax),%xmm0
movss  0xce4(%rip),%xmm1
subss  %xmm1,%xmm0
call   1040 <fabsf@plt>
movsd  0xce3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    136f <main+0x1ef>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xd16(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139b <main+0x21b>
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xeb4(%rip),%rdi
call   1060 <puts@plt>
movl   $0x400,0x1c(%rsp)
movl   $0x2,0x8(%rsp)
movl   $0x200,0x18(%rsp)
movl   $0x473b8000,0x14(%rsp)
47
movl   $0x42700000,0x10(%rsp)
42
movl   $0x4640e666,0xc(%rsp)
46
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
lea    0x14(%rsp),%r12
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x1c(%rsp),%rbx
mov    %r12,%rdi
mov    %rbx,%rcx
mov    %rax,%r8
call   10c0 <signoise_r@plt>
mov    $0x2,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r13
mov    $0x2,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r14
mov    %rax,(%rsp)
lea    0x8(%rsp),%rdx
lea    0x18(%rsp),%rcx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%r8
mov    %r13,%r9
call   10b0 <esprit_r@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xda6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    12b3 <main+0x113>
xor    %ebx,%ebx
lea    0xdaa(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  0x0(%r13,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1290 <main+0xf0>
lea    0xd75(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1302 <main+0x162>
xor    %ebx,%ebx
lea    0xd5a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  (%r14,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     12e0 <main+0x140>
mov    $0xa,%edi
call   1040 <putchar@plt>
movss  0x0(%r13),%xmm0
addss  0xce6(%rip),%xmm0
call   1050 <fabsf@plt>
ucomisd 0xce1(%rip),%xmm0
jbe    1347 <main+0x1a7>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2c93(%rip),%rbx
jmp    135a <main+0x1ba>
lea    0xd23(%rip),%rdi
call   1060 <puts@plt>
mov    0x2c76(%rip),%rbx
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rbx),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"C Esprit\0A\00"
@.str.1 = [27 x i8] c"estimated tone freq [Hz]: \00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [28 x i8] c"\0Awith sigma: \00"
@.str.4 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.5 = [29 x i8] c"E: failed to meet tolerance\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [4 x i8] c"OK\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float*
%9 = alloca float*
%10 = alloca float*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1024, i32* %2
store i32 2, i32* %3
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 2
store i32 %15, i32* %4
store float 4.800000e+04, float* %5
store float 6.000000e+01, float* %6
store float 0x40C81CCCC0000000, float* %7
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 4
%19 = call float* @malloc(i64 %18)
store float* %19, float** %8
%20 = load float*, float** %8
%21 = getelementptr inbounds float, float* %20, i64 0
%22 = call i32 @signoise_r(float* %5, float* %7, float* %6, i32* %2, float* %21)
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = call float* @calloc(i64 %24, i64 %27)
store float* %28, float** %9
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 4
%34 = call float* @calloc(i64 %30, i64 %33)
store float* %34, float** %10
%35 = load float*, float** %8
%36 = getelementptr inbounds float, float* %35, i64 0
%37 = load float*, float** %9
%38 = getelementptr inbounds float, float* %37, i64 0
%39 = load float*, float** %10
%40 = getelementptr inbounds float, float* %39, i64 0
%41 = call i32 @esprit_r(float* %36, i32* %2, i32* %3, i32* %4, float* %5, float* %38, float* %40)
%42 = load float*, float** %8
%43 = call i32 @free(float* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %11
br label %45
45: ; preds = %57, %0
%46 = load i32, i32* %11
%47 = load i32, i32* %3
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %60
49: ; preds = %45
%50 = load float*, float** %9
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds float, float* %50, i64 %52
%54 = load float, float* %53
%55 = fpext float %54 to double
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %55)
br label %57
57: ; preds = %49
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
br label %45
60: ; preds = %45
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %12
br label %62
62: ; preds = %74, %60
%63 = load i32, i32* %12
%64 = load i32, i32* %3
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %77
66: ; preds = %62
%67 = load float*, float** %10
%68 = load i32, i32* %12
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds float, float* %67, i64 %69
%71 = load float, float* %70
%72 = fpext float %71 to double
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %72)
br label %74
74: ; preds = %66
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
br label %62
77: ; preds = %62
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%79 = load float*, float** %9
%80 = getelementptr inbounds float, float* %79, i64 0
%81 = load float, float* %80
%82 = fsub float %81, 0x40C81CCCC0000000
%83 = call double @fabsf(float %82)
%84 = fcmp ogt double %83, 0x3FF3C0C1F212D773
br i1 %84, label %85, label %93
85: ; preds = %77
%86 = load i32, i32* @stderr
%87 = call i32 @fprintf(i32 %86, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%88 = load float*, float** %9
%89 = call i32 @free(float* %88)
%90 = load float*, float** %10
%91 = call i32 @free(float* %90)
%92 = load i32, i32* @EXIT_FAILURE
store i32 %92, i32* %1
br label %100
93: ; preds = %77
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%95 = load float*, float** %9
%96 = call i32 @free(float* %95)
%97 = load float*, float** %10
%98 = call i32 @free(float* %97)
%99 = load i32, i32* @EXIT_SUCCESS
store i32 %99, i32* %1
br label %100
100: ; preds = %93, %85
%101 = load i32, i32* %1
ret i32 %101
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"estimated tone freq [Hz]: \00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [28 x i8] c"\0Awith sigma: \00"
@stderr = global i32 0
@.str.5 = [29 x i8] c"E: failed to meet tolerance\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [9 x i8] c"C Esprit\00"
@str.7 = [3 x i8] c"OK\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%8 = bitcast i32* %1 to i8*
store i32 1024, i32* %1
%9 = bitcast i32* %2 to i8*
store i32 2, i32* %2
%10 = bitcast i32* %3 to i8*
store i32 512, i32* %3
%11 = bitcast float* %4 to i8*
store float 4.800000e+04, float* %4
%12 = bitcast float* %5 to i8*
store float 6.000000e+01, float* %5
%13 = bitcast float* %6 to i8*
store float 0x40C81CCCC0000000, float* %6
%14 = tail call float* @malloc(i64 4096)
%15 = call i32 @signoise_r(float* %4, float* %6, float* %5, i32* %1, float* %14)
%16 = call float* @calloc(i64 2, i64 8)
%17 = call float* @calloc(i64 2, i64 8)
%18 = call i32 @esprit_r(float* %14, i32* %1, i32* %2, i32* %3, float* %4, float* %16, float* %17)
%19 = call i32 @free(float* %14)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* %2
%22 = icmp sgt i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %27, %0
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 0
br i1 %26, label %43, label %37
27: ; preds = %0, %27
%28 = phi i64 [ %33, %27 ], [ 0, %0 ]
%29 = getelementptr inbounds float, float* %16, i64 %28
%30 = load float, float* %29
%31 = fpext float %30 to double
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %31)
%33 = add nuw nsw i64 %28, 1
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %27, label %23
37: ; preds = %43, %23
%38 = call i32 @putchar(i32 10)
%39 = load float, float* %16
%40 = fadd float %39, 0xC0C81CCCC0000000
%41 = call double @fabsf(float %40)
%42 = fcmp ogt double %41, 0x3FF3C0C1F212D773
br i1 %42, label %53, label %56
43: ; preds = %23, %43
%44 = phi i64 [ %49, %43 ], [ 0, %23 ]
%45 = getelementptr inbounds float, float* %17, i64 %44
%46 = load float, float* %45
%47 = fpext float %46 to double
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %47)
%49 = add nuw nsw i64 %44, 1
%50 = load i32, i32* %2
%51 = sext i32 %50 to i64
%52 = icmp slt i64 %49, %51
br i1 %52, label %43, label %37
53: ; preds = %37
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %58
56: ; preds = %37
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
%59 = phi i32* [ @EXIT_FAILURE, %53 ], [ @EXIT_SUCCESS, %56 ]
%60 = call i32 @free(float* %16)
%61 = call i32 @free(float* %17)
%62 = load i32, i32* %59
ret i32 %62
}