#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 */
float *calloc(int, int);
int fabs(float);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *, float *);
int /*<<< orphan*/ printf(char *, ...);
float sqrt(float);
int /*<<< orphan*/ stderr;
float *readBandsFromFile(char *fileName, int octn, float *limits) {
  int i;
  float octaveinflimit;
  float octavesuplimit;
  float centraloct;
  float co;
  float *calib = calloc(sizeof(float), octn);
  FILE *fin = fopen(fileName, "r");
  if (fin == NULL) {
    fprintf(stderr, "Could not open input file (%s)!\n", fileName);
    return NULL;
  }
  char c;
  do {
    c = fgetc(fin);
  } while (c != '\n');
  for (i = 0; i < octn; ++i) {
    octaveinflimit = limits[i];
    octavesuplimit = limits[i + 1];
    centraloct = sqrt(octavesuplimit * octaveinflimit);
    fscanf(fin, "%f%f", &co, &calib[i]);
    printf("%f   %f\n", co, calib[i]);
    if (1 == 0) {
      fprintf(stderr, "Input file does not seem to have enough bands\n");
      fclose(fin);
      return NULL;
    } else if (fabs(co - centraloct) > 1) {
      fprintf(stderr, "Incompatible input file.\n");
      fclose(fin);
      return NULL;
    }
  }
  fclose(fin);
  printf("File %s read.\n", fileName);
  return calib;
}


x86 assembly (clang, -O0):
<readBandsFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%esi
mov    $0x4,%edi
call   1070 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11fb <readBandsFromFile+0x6b>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    132f <readBandsFromFile+0x19f>
jmp    1200 <readBandsFromFile+0x70>
mov    -0x48(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x49(%rbp)
movsbl -0x49(%rbp),%eax
cmp    $0xa,%eax
jne    1200 <readBandsFromFile+0x70>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    130c <readBandsFromFile+0x17c>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
call   10b0 <sqrt@plt>
movss  %xmm0,-0x30(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rcx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
lea    0xda0(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <fscanf@plt>
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x40(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd7b(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movss  -0x34(%rbp),%xmm0
subss  -0x30(%rbp),%xmm0
call   1080 <fabs@plt>
cmp    $0x1,%eax
jle    12f9 <readBandsFromFile+0x169>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    132f <readBandsFromFile+0x19f>
jmp    12fe <readBandsFromFile+0x16e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1220 <readBandsFromFile+0x90>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rsi
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBandsFromFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %esi,%r13d
mov    %rdi,%rbp
mov    $0x4,%edi
call   1070 <calloc@plt>
mov    %rax,%r15
lea    0xe49(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128c <readBandsFromFile+0xfc>
mov    %rax,%rbx
mov    %rbp,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    $0xa,%al
jne    11e0 <readBandsFromFile+0x50>
xor    %r14d,%r14d
test   %r13d,%r13d
cmovle %r14d,%r13d
shl    $0x2,%r13
lea    0xe2b(%rip),%rbp
jmp    126b <readBandsFromFile+0xdb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   10b0 <sqrt@plt>
movss  %xmm0,0x8(%rsp)
lea    (%r15,%r14,1),%rcx
mov    %rbx,%rdi
lea    0xdfe(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <fscanf@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%r15,%r14,1),%xmm1
cvtss2sd %xmm1,%xmm1
mov    %rbp,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm0
subss  0x8(%rsp),%xmm0
call   1080 <fabs@plt>
add    $0x4,%r14
cmp    $0x2,%eax
jge    12ab <readBandsFromFile+0x11b>
cmp    %r14,%r13
je     12cf <readBandsFromFile+0x13f>
movss  (%r12,%r14,1),%xmm0
mulss  0x4(%r12,%r14,1),%xmm0
ucomiss 0xd7c(%rip),%xmm0
jb     1210 <readBandsFromFile+0x80>
sqrtss %xmm0,%xmm0
jmp    1215 <readBandsFromFile+0x85>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
xor    %r15d,%r15d
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12ea <readBandsFromFile+0x15a>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
xor    %r15d,%r15d
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    12ea <readBandsFromFile+0x15a>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd71(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Could not open input file (%s)!\0A\00"
@.str.2 = [5 x i8] c"%f%f\00"
@.str.3 = [9 x i8] c"%f %f\0A\00"
@.str.4 = [26 x i8] c"Incompatible input file.\0A\00"
@.str.5 = [15 x i8] c"File %s read.\0A\00"
define float* @readBandsFromFile(i8* %0, i32 %1, float* %2) {
%4 = alloca float*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca float*
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float*
%14 = alloca i32*
%15 = alloca i8
store i8* %0, i8** %5
store i32 %1, i32* %6
store float* %2, float** %7
%16 = load i32, i32* %6
%17 = call float* @calloc(i32 4, i32 %16)
store float* %17, float** %13
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %14
%20 = load i32*, i32** %14
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %5
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store float* null, float** %4
br label %90
26: ; preds = %3
br label %27
27: ; preds = %30, %26
%28 = load i32*, i32** %14
%29 = call signext i8 @fgetc(i32* %28)
store i8 %29, i8* %15
br label %30
30: ; preds = %27
%31 = load i8, i8* %15
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br i1 %33, label %27, label %34
34: ; preds = %30
store i32 0, i32* %8
br label %35
35: ; preds = %81, %34
%36 = load i32, i32* %8
%37 = load i32, i32* %6
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %84
39: ; preds = %35
%40 = load float*, float** %7
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds float, float* %40, i64 %42
%44 = load float, float* %43
store float %44, float* %9
%45 = load float*, float** %7
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds float, float* %45, i64 %48
%50 = load float, float* %49
store float %50, float* %10
%51 = load float, float* %10
%52 = load float, float* %9
%53 = fmul float %51, %52
%54 = call float @sqrt(float %53)
store float %54, float* %11
%55 = load i32*, i32** %14
%56 = load float*, float** %13
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds float, float* %56, i64 %58
%60 = call i32 @fscanf(i32* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), float* %12, float* %59)
%61 = load float, float* %12
%62 = fpext float %61 to double
%63 = load float*, float** %13
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds float, float* %63, i64 %65
%67 = load float, float* %66
%68 = fpext float %67 to double
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %62, double %68)
%70 = load float, float* %12
%71 = load float, float* %11
%72 = fsub float %70, %71
%73 = call i32 @fabs(float %72)
%74 = icmp sgt i32 %73, 1
br i1 %74, label %75, label %80
75: ; preds = %39
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32*, i32** %14
%79 = call i32 @fclose(i32* %78)
store float* null, float** %4
br label %90
80: ; preds = %39
br label %81
81: ; preds = %80
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %35
84: ; preds = %35
%85 = load i32*, i32** %14
%86 = call i32 @fclose(i32* %85)
%87 = load i8*, i8** %5
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %87)
%89 = load float*, float** %13
store float* %89, float** %4
br label %90
90: ; preds = %84, %75, %22
%91 = load float*, float** %4
ret float* %91
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Could not open input file (%s)!\0A\00"
@.str.2 = [5 x i8] c"%f%f\00"
@.str.3 = [9 x i8] c"%f %f\0A\00"
@.str.4 = [26 x i8] c"Incompatible input file.\0A\00"
@.str.5 = [15 x i8] c"File %s read.\0A\00"
define float* @readBandsFromFile(i8* %0, i32 %1, float* nocapture %2) {
%4 = alloca float
%5 = bitcast float* %4 to i8*
%6 = tail call float* @calloc(i32 4, i32 %1)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %47
12: ; preds = %3, %12
%13 = tail call signext i8 @fgetc(i32* %7)
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %12
15: ; preds = %12
%16 = call i32 @llvm.smax.i32(i32 %1, i32 0)
%17 = zext i32 %16 to i64
br label %18
18: ; preds = %15, %21
%19 = phi i64 [ 0, %15 ], [ %24, %21 ]
%20 = icmp eq i64 %19, %17
br i1 %20, label %44, label %21
21: ; preds = %18
%22 = getelementptr inbounds float, float* %2, i64 %19
%23 = load float, float* %22
%24 = add nuw nsw i64 %19, 1
%25 = getelementptr inbounds float, float* %2, i64 %24
%26 = load float, float* %25
%27 = fmul float %23, %26
%28 = call float @sqrt(float %27)
%29 = getelementptr inbounds float, float* %6, i64 %19
%30 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), float* %4, float* %29)
%31 = load float, float* %4
%32 = fpext float %31 to double
%33 = load float, float* %29
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double %32, double %34)
%36 = load float, float* %4
%37 = fsub float %36, %28
%38 = call i32 @fabs(float %37)
%39 = icmp sgt i32 %38, 1
br i1 %39, label %40, label %18
40: ; preds = %21
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @fclose(i32* %7)
br label %47
44: ; preds = %18
%45 = call i32 @fclose(i32* %7)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %47
47: ; preds = %40, %44, %9
%48 = phi float* [ null, %9 ], [ null, %40 ], [ %6, %44 ]
ret float* %48
}