#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 */
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 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("Coefficients for spectral estimation of spctrl.dat\n\n");
  for (i = 1; i <= 10; i++)
    printf("a[%2d] = %12.6f \n", i, cof[i]);
  printf("\na0 =%12.6f\n", 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   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e2 <main+0x62>
lea    0xe30(%rip),%rdi
call   1030 <nrerror@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jg     1223 <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    11e9 <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    -0xc(%rbp),%rcx
call   1090 <memcof@plt>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     1296 <main+0x116>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde4(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    125c <main+0xdc>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd1(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
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,%r12
lea    0xe38(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11e8 <main+0x58>
lea    0xe2a(%rip),%rdi
call   1040 <nrerror@plt>
mov    $0x4,%ebx
lea    0xe39(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r12,%rbx,1),%rdx
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <fscanf@plt>
add    $0x4,%rbx
cmp    $0xfa4,%rbx
jne    1200 <main+0x70>
mov    %r13,%rdi
call   1050 <fclose@plt>
lea    0xc(%rsp),%rcx
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    $0xa,%edx
mov    %r14,%r8
call   10a0 <memcof@plt>
lea    0xe0a(%rip),%rdi
call   1030 <puts@plt>
movss  0x4(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd5(%rip),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x8(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0xc(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x3,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x10(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x14(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x5,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x18(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x6,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x1c(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x7,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x20(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x24(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0x9,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x28(%r14),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    $0xa,%esi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xce6(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r12,%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 = [53 x i8] c"Coefficients for spectral estimation of spctrl.dat\0A\0A\00"
@.str.5 = [18 x i8] c"a[%2d] = %12.6f \0A\00"
@.str.6 = [13 x i8] c"\0Aa0 =%12.6f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float*
%5 = alloca float*
%6 = alloca i32*
store i32 0, i32* %1
%7 = call float* @vector(i32 1, i32 10)
store float* %7, float** %4
%8 = call float* @vector(i32 1, i32 1000)
store float* %8, float** %5
%9 = 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* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
store i32 1, i32* %2
br label %14
14: ; preds = %24, %13
%15 = load i32, i32* %2
%16 = icmp sle i32 %15, 1000
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32*, i32** %6
%19 = load float*, float** %5
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds float, float* %19, i64 %21
%23 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %22)
br label %24
24: ; preds = %17
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %14
27: ; preds = %14
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load float*, float** %5
%31 = load float*, float** %4
%32 = call i32 @memcof(float* %30, i32 1000, i32 10, float* %3, float* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %34
34: ; preds = %46, %27
%35 = load i32, i32* %2
%36 = icmp sle i32 %35, 10
br i1 %36, label %37, label %49
37: ; preds = %34
%38 = load i32, i32* %2
%39 = load float*, float** %4
%40 = load i32, i32* %2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds float, float* %39, i64 %41
%43 = load float, float* %42
%44 = fpext float %43 to double
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %38, double %44)
br label %46
46: ; preds = %37
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %34
49: ; preds = %34
%50 = load float, float* %3
%51 = fpext float %50 to double
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %51)
%53 = load float*, float** %5
%54 = call i32 @free_vector(float* %53, i32 1, i32 1000)
%55 = load float*, float** %4
%56 = call i32 @free_vector(float* %55, 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.5 = [18 x i8] c"a[%2d] = %12.6f \0A\00"
@.str.6 = [13 x i8] c"\0Aa0 =%12.6f\0A\00"
@str = [52 x i8] c"Coefficients for spectral estimation of spctrl.dat\0A\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 ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%20 = getelementptr inbounds float, float* %3, i64 1
%21 = load float, float* %20
%22 = fpext float %21 to double
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 1, double %22)
%24 = getelementptr inbounds float, float* %3, i64 2
%25 = load float, float* %24
%26 = fpext float %25 to double
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 2, double %26)
%28 = getelementptr inbounds float, float* %3, i64 3
%29 = load float, float* %28
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 3, double %30)
%32 = getelementptr inbounds float, float* %3, i64 4
%33 = load float, float* %32
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 4, double %34)
%36 = getelementptr inbounds float, float* %3, i64 5
%37 = load float, float* %36
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 5, double %38)
%40 = getelementptr inbounds float, float* %3, i64 6
%41 = load float, float* %40
%42 = fpext float %41 to double
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 6, double %42)
%44 = getelementptr inbounds float, float* %3, i64 7
%45 = load float, float* %44
%46 = fpext float %45 to double
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 7, double %46)
%48 = getelementptr inbounds float, float* %3, i64 8
%49 = load float, float* %48
%50 = fpext float %49 to double
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 8, double %50)
%52 = getelementptr inbounds float, float* %3, i64 9
%53 = load float, float* %52
%54 = fpext float %53 to double
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 9, double %54)
%56 = getelementptr inbounds float, float* %3, i64 10
%57 = load float, float* %56
%58 = fpext float %57 to double
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 10, double %58)
%60 = load float, float* %1
%61 = fpext float %60 to double
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), double %61)
%63 = call i32 @free_vector(float* %4, i32 1, i32 1000)
%64 = call i32 @free_vector(float* %3, i32 1, i32 10)
ret i32 0
}