#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double evlmem(float, float *, int, float);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free_vector(float *, int, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ memcof(float *, int, int, float *, float *);
int /*<<< orphan*/ nrerror(char *);
int /*<<< orphan*/ printf(char *, ...);
float *vector(int, int);
int main(void) {
  int i;
  float fdt, pm, *cof, *data;
  FILE *fp;
  cof = vector(1, 10);
  data = vector(1, 1000);
  if ((fp = fopen("spctrl.dat", "r")) == NULL)
    nrerror("Data file spctrl.dat not found\n");
  for (i = 1; i <= 1000; i++)
    fscanf(fp, "%f", &data[i]);
  fclose(fp);
  memcof(data, 1000, 10, &pm, cof);
  printf("Power spectum estimate of data in spctrl.dat\n");
  printf("     f*delta      power\n");
  for (fdt = 0.0; fdt <= 0.5; fdt += 0.5 / 16)
    printf("%12.6f %12.6f\n", fdt, evlmem(fdt, cof, 10, pm));
  free_vector(data, 1, 1000);
  free_vector(cof, 1, 10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0xa,%esi
call   1080 <vector@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
mov    $0x3e8,%esi
call   1080 <vector@plt>
mov    %rax,-0x20(%rbp)
lea    0xe44(%rip),%rdi
lea    0xe48(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11f2 <main+0x62>
lea    0xe30(%rip),%rdi
call   1030 <nrerror@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jg     1233 <main+0xa3>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe1d(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f9 <main+0x69>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%r8
mov    $0x3e8,%esi
mov    $0xa,%edx
lea    -0x10(%rbp),%rcx
call   10a0 <memcof@plt>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd74(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     12f5 <main+0x165>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movss  -0xc(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
movss  -0x10(%rbp),%xmm1
mov    $0xa,%esi
call   1090 <evlmem@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
lea    0xdbc(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd25(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    127b <main+0xeb>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x3e8,%edx
call   1060 <free_vector@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1060 <free_vector@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
mov    $0xa,%esi
call   1090 <vector@plt>
mov    %rax,%r14
mov    $0x1,%edi
mov    $0x3e8,%esi
call   1090 <vector@plt>
mov    %rax,%r15
lea    0xe84(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11f8 <main+0x58>
lea    0xe15(%rip),%rdi
call   1040 <nrerror@plt>
mov    $0x4,%ebx
lea    0xe24(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%rbx,1),%rdx
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <fscanf@plt>
add    $0x4,%rbx
cmp    $0xfa4,%rbx
jne    1210 <main+0x70>
mov    %r13,%rdi
call   1050 <fclose@plt>
lea    0x4(%rsp),%rcx
mov    %r15,%rdi
mov    $0x3e8,%esi
mov    $0xa,%edx
mov    %r14,%r8
call   10b0 <memcof@plt>
lea    0xde5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
lea    0xdbb(%rip),%rbx
movss  %xmm0,(%rsp)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movss  0x4(%rsp),%xmm1
movss  (%rsp),%xmm0
mov    %r14,%rdi
mov    $0xa,%esi
call   10a0 <evlmem@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1060 <printf@plt>
movss  (%rsp),%xmm0
addss  0xd49(%rip),%xmm0
movss  0xd45(%rip),%xmm1
ucomiss %xmm0,%xmm1
jae    1270 <main+0xd0>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x3e8,%edx
call   1070 <free_vector@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1070 <free_vector@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"spctrl.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"Data file spctrl.dat not found\0A\00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [46 x i8] c"Power spectum estimate of data in spctrl.dat\0A\00"
@.str.5 = [25 x i8] c" f*delta power\0A\00"
@.str.6 = [15 x i8] c"%12.6f %12.6f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float*
%6 = alloca float*
%7 = alloca i32*
store i32 0, i32* %1
%8 = call float* @vector(i32 1, i32 10)
store float* %8, float** %5
%9 = call float* @vector(i32 1, i32 1000)
store float* %9, float** %6
%10 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
store i32 1, i32* %2
br label %15
15: ; preds = %25, %14
%16 = load i32, i32* %2
%17 = icmp sle i32 %16, 1000
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32*, i32** %7
%20 = load float*, float** %6
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds float, float* %20, i64 %22
%24 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %23)
br label %25
25: ; preds = %18
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %15
28: ; preds = %15
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
%31 = load float*, float** %6
%32 = load float*, float** %5
%33 = call i32 @memcof(float* %31, i32 1000, i32 10, float* %4, float* %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
store float 0.000000e+00, float* %3
br label %36
36: ; preds = %48, %28
%37 = load float, float* %3
%38 = fpext float %37 to double
%39 = fcmp ole double %38, 5.000000e-01
br i1 %39, label %40, label %53
40: ; preds = %36
%41 = load float, float* %3
%42 = fpext float %41 to double
%43 = load float, float* %3
%44 = load float*, float** %5
%45 = load float, float* %4
%46 = call double @evlmem(float %43, float* %44, i32 10, float %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), double %42, double %46)
br label %48
48: ; preds = %40
%49 = load float, float* %3
%50 = fpext float %49 to double
%51 = fadd double %50, 3.125000e-02
%52 = fptrunc double %51 to float
store float %52, float* %3
br label %36
53: ; preds = %36
%54 = load float*, float** %6
%55 = call i32 @free_vector(float* %54, i32 1, i32 1000)
%56 = load float*, float** %5
%57 = call i32 @free_vector(float* %56, i32 1, i32 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"spctrl.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"Data file spctrl.dat not found\0A\00"
@.str.3 = [3 x i8] c"%f\00"
@.str.6 = [15 x i8] c"%12.6f %12.6f\0A\00"
@str = [45 x i8] c"Power spectum estimate of data in spctrl.dat\00"
@str.7 = [24 x i8] c" f*delta power\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call float* @vector(i32 1, i32 10)
%4 = tail call float* @vector(i32 1, i32 1000)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
br label %10
10: ; preds = %9, %10
%11 = phi i64 [ %14, %10 ], [ 1, %9 ]
%12 = getelementptr inbounds float, float* %4, i64 %11
%13 = tail call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %12)
%14 = add nuw nsw i64 %11, 1
%15 = icmp eq i64 %14, 1001
br i1 %15, label %16, label %10
16: ; preds = %10
%17 = tail call i32 @fclose(i32* %5)
%18 = call i32 @memcof(float* %4, i32 1000, i32 10, float* %1, float* %3)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0))
br label %21
21: ; preds = %16, %21
%22 = phi float [ 0.000000e+00, %16 ], [ %27, %21 ]
%23 = fpext float %22 to double
%24 = load float, float* %1
%25 = call double @evlmem(float %22, float* %3, i32 10, float %24)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), double %23, double %25)
%27 = fadd float %22, 3.125000e-02
%28 = fcmp ugt float %27, 5.000000e-01
br i1 %28, label %29, label %21
29: ; preds = %21
%30 = call i32 @free_vector(float* %4, i32 1, i32 1000)
%31 = call i32 @free_vector(float* %3, i32 1, i32 10)
ret i32 0
}