#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
float sqrt(float);
int /*<<< orphan*/ stderr;
void writeBandsOnFile(char *fileName, int octn, float *limits,
                      float *calcvalues) {
  int i;
  float octaveinflimit;
  float octavesuplimit;
  float centraloct;
  FILE *fout = fopen(fileName, "w");
  if (fout == NULL) {
    fprintf(stderr, "Could not open output file (%s)!\n", fileName);
    return;
  }
  fprintf(fout,
          "# 1/3 octave analysis. Center band in Hz, PSD in dB/YREF*Hz\n");
  for (i = 0; i < octn; ++i) {
    octaveinflimit = limits[i];
    octavesuplimit = limits[i + 1];
    centraloct = sqrt(octavesuplimit * octaveinflimit);
    fprintf(fout, " %f  %f \n", centraloct, calcvalues[i]);
  }
  fclose(fout);
  printf("File %s written.\n", fileName);
}


x86 assembly (clang, -O0):
<writeBandsOnFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11a7 <writeBandsOnFile+0x57>
mov    0x2e53(%rip),%rax
movslq (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    125c <writeBandsOnFile+0x10c>
mov    -0x38(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1243 <writeBandsOnFile+0xf3>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x18(%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   1070 <sqrt@plt>
movss  %xmm0,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
movss  -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe33(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c0 <writeBandsOnFile+0x70>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeBandsOnFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe86(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1232 <writeBandsOnFile+0xd2>
mov    %rax,%r12
mov    %rbp,(%rsp)
lea    0xe8e(%rip),%rdi
mov    $0x3c,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
test   %r14d,%r14d
jle    120c <writeBandsOnFile+0xac>
mov    %r14d,%ebp
xor    %r14d,%r14d
jmp    11ec <writeBandsOnFile+0x8c>
nopl   0x0(%rax)
call   1070 <sqrt@plt>
cvtss2sd %xmm0,%xmm0
movss  (%r15,%r14,4),%xmm1
cvtss2sd %xmm1,%xmm1
mov    %r12,%rdi
lea    0xe88(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    %r13,%r14
cmp    %r13,%rbp
je     120c <writeBandsOnFile+0xac>
movss  (%rbx,%r14,4),%xmm0
lea    0x1(%r14),%r13
mulss  0x4(%rbx,%r14,4),%xmm0
ucomiss 0xdfc(%rip),%xmm0
jb     11c0 <writeBandsOnFile+0x60>
sqrtss %xmm0,%xmm0
jmp    11c5 <writeBandsOnFile+0x65>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xe54(%rip),%rdi
mov    (%rsp),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
mov    0x2da7(%rip),%rax
movslq (%rax),%rdi
lea    0xdc3(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Could not open output file (%s)!\0A\00"
@.str.2 = [61 x i8] c"# 1/3 octave analysis. Center band in Hz, PSD in dB/YREF*Hz\0A\00"
@.str.3 = [10 x i8] c" %f %f \0A\00"
@.str.4 = [18 x i8] c"File %s written.\0A\00"
define void @writeBandsOnFile(i8* %0, i32 %1, float* %2, float* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca float*
%8 = alloca float*
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store float* %2, float** %7
store float* %3, float** %8
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %13
%16 = load i32*, i32** %13
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i32*
%22 = load i8*, i8** %5
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %65
24: ; preds = %4
%25 = load i32*, i32** %13
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %27
27: ; preds = %57, %24
%28 = load i32, i32* %9
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %60
31: ; preds = %27
%32 = load float*, float** %7
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float, float* %32, i64 %34
%36 = load float, float* %35
store float %36, float* %10
%37 = load float*, float** %7
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %37, i64 %40
%42 = load float, float* %41
store float %42, float* %11
%43 = load float, float* %11
%44 = load float, float* %10
%45 = fmul float %43, %44
%46 = call float @sqrt(float %45)
store float %46, float* %12
%47 = load i32*, i32** %13
%48 = load float, float* %12
%49 = fpext float %48 to double
%50 = load float*, float** %8
%51 = load i32, i32* %9
%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 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %49, double %55)
br label %57
57: ; preds = %31
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %27
60: ; preds = %27
%61 = load i32*, i32** %13
%62 = call i32 @fclose(i32* %61)
%63 = load i8*, i8** %5
%64 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %60, %18
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Could not open output file (%s)!\0A\00"
@.str.2 = [61 x i8] c"# 1/3 octave analysis. Center band in Hz, PSD in dB/YREF*Hz\0A\00"
@.str.3 = [10 x i8] c" %f %f \0A\00"
@.str.4 = [18 x i8] c"File %s written.\0A\00"
define void @writeBandsOnFile(i8* %0, i32 %1, float* nocapture %2, float* nocapture %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i32*
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %35
12: ; preds = %4
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i64 60, i64 1, i32* %5)
%14 = icmp sgt i32 %1, 0
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = zext i32 %1 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %21, %17 ]
%19 = getelementptr inbounds float, float* %2, i64 %18
%20 = load float, float* %19
%21 = add nuw nsw i64 %18, 1
%22 = getelementptr inbounds float, float* %2, i64 %21
%23 = load float, float* %22
%24 = fmul float %20, %23
%25 = tail call float @sqrt(float %24)
%26 = fpext float %25 to double
%27 = getelementptr inbounds float, float* %3, i64 %18
%28 = load float, float* %27
%29 = fpext float %28 to double
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %26, double %29)
%31 = icmp eq i64 %21, %16
br i1 %31, label %32, label %17
32: ; preds = %17, %12
%33 = tail call i32 @fclose(i32* %5)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %35
35: ; preds = %32, %7
ret void
}