#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 */
unsigned int detectPeaks(float *, unsigned int const);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  const unsigned int MAG1 = 2597;
  const unsigned int MAG2 = 8381;
  float mag1[MAG1];
  float mag2[MAG2];
  float num;
  FILE *data_in;
  data_in = fopen("ConstRate_X.txt", "r");
  unsigned int i;
  unsigned int peaksDetected = 0;
  for (i = 0; i < MAG1; i++) {
    fscanf(data_in, "%f", &num);
    mag1[i] = num;
  }
  fclose(data_in);
  data_in = fopen("SweepRate_X.txt", "r");
  for (i = 0; i < MAG2; i++) {
    fscanf(data_in, "%f", &num);
    mag2[i] = num;
  }
  fclose(data_in);
  printf("Test Case 1: ConstRate_X.txt\n");
  peaksDetected = detectPeaks(mag1, MAG1);
  printf("\tPeaks Detected: %d\n", peaksDetected);
  printf("Test Case 2: SweepRate_X.txt\n");
  peaksDetected = detectPeaks(mag2, MAG2);
  printf("\tPeaks Detected: %d\n", peaksDetected);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xabd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa25,-0x8(%rbp)
movl   $0x20bd,-0xc(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
lea    0xe82(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xa25,-0x2c(%rbp)
jae    11dc <main+0x8c>
mov    -0x28(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <fscanf@plt>
movss  -0x1c(%rbp),%xmm0
mov    -0x2c(%rbp),%eax
movss  %xmm0,-0x28d0(%rbp,%rax,4)
ff ff
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119c <main+0x4c>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe29(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x20bd,-0x2c(%rbp)
jae    1243 <main+0xf3>
mov    -0x28(%rbp),%rdi
lea    0xdf7(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <fscanf@plt>
movss  -0x1c(%rbp),%xmm0
mov    -0x2c(%rbp),%eax
movss  %xmm0,-0xabd0(%rbp,%rax,4)
ff ff
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1203 <main+0xb3>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x28d0(%rbp),%rdi
mov    $0xa25,%esi
call   1070 <detectPeaks@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xabd0(%rbp),%rdi
mov    $0x20bd,%esi
call   1070 <detectPeaks@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xabd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xaba8,%rsp
lea    0xeb2(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xe75(%rip),%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fscanf@plt>
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xa25,%rbx
jne    11a0 <main+0x40>
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0xe6e(%rip),%rdi
lea    0xe23(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xe14(%rip),%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fscanf@plt>
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x28b0(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x20bd,%rbx
jne    1200 <main+0xa0>
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0xde1(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
mov    $0xa25,%esi
call   1080 <detectPeaks@plt>
lea    0xdb1(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd0(%rip),%rdi
call   1030 <puts@plt>
lea    0x28b0(%rsp),%rdi
mov    $0x20bd,%esi
call   1080 <detectPeaks@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xaba8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"ConstRate_X.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [16 x i8] c"SweepRate_X.txt\00"
@.str.4 = [30 x i8] c"Test Case 1: ConstRate_X.txt\0A\00"
@.str.5 = [21 x i8] c"\09Peaks Detected: %d\0A\00"
@.str.6 = [30 x i8] c"Test Case 2: SweepRate_X.txt\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca float
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 2597, i32* %2
store i32 8381, i32* %3
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca float, i64 2597
%11 = alloca float, i64 8381
%12 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %13
13: ; preds = %23, %0
%14 = load i32, i32* %7
%15 = icmp ult i32 %14, 2597
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32*, i32** %6
%18 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %5)
%19 = load float, float* %5
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds float, float* %10, i64 %21
store float %19, float* %22
br label %23
23: ; preds = %16
%24 = load i32, i32* %7
%25 = add i32 %24, 1
store i32 %25, i32* %7
br label %13
26: ; preds = %13
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
%29 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %6
store i32 0, i32* %7
br label %30
30: ; preds = %40, %26
%31 = load i32, i32* %7
%32 = icmp ult i32 %31, 8381
br i1 %32, label %33, label %43
33: ; preds = %30
%34 = load i32*, i32** %6
%35 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %5)
%36 = load float, float* %5
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds float, float* %11, i64 %38
store float %36, float* %39
br label %40
40: ; preds = %33
%41 = load i32, i32* %7
%42 = add i32 %41, 1
store i32 %42, i32* %7
br label %30
43: ; preds = %30
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @detectPeaks(float* %10, i32 2597)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%51 = call i32 @detectPeaks(float* %11, i32 8381)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %52)
store i32 0, i32* %1
%54 = load i8*, i8** %4
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [16 x i8] c"ConstRate_X.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [16 x i8] c"SweepRate_X.txt\00"
@.str.5 = [21 x i8] c"\09Peaks Detected: %d\0A\00"
@str = [29 x i8] c"Test Case 1: ConstRate_X.txt\00"
@str.7 = [29 x i8] c"Test Case 2: SweepRate_X.txt\00"
define i32 @main() {
%1 = alloca float
%2 = alloca [2597 x float]
%3 = alloca [8381 x float]
%4 = bitcast float* %1 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 0, %0 ], [ %11, %6 ]
%8 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %1)
%9 = load float, float* %1
%10 = getelementptr inbounds [2597 x float], [2597 x float]* %2, i64 0, i64 %7
store float %9, float* %10
%11 = add nuw nsw i64 %7, 1
%12 = icmp eq i64 %11, 2597
br i1 %12, label %13, label %6
13: ; preds = %6
%14 = call i32 @fclose(i32* %5)
%15 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %13, %16
%17 = phi i64 [ 0, %13 ], [ %21, %16 ]
%18 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %1)
%19 = load float, float* %1
%20 = getelementptr inbounds [8381 x float], [8381 x float]* %3, i64 0, i64 %17
store float %19, float* %20
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, 8381
br i1 %22, label %23, label %16
23: ; preds = %16
%24 = getelementptr inbounds [2597 x float], [2597 x float]* %2, i64 0, i64 0
%25 = getelementptr inbounds [8381 x float], [8381 x float]* %3, i64 0, i64 0
%26 = call i32 @fclose(i32* %15)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%28 = call i32 @detectPeaks(float* %24, i32 2597)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
%31 = call i32 @detectPeaks(float* %25, i32 8381)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %31)
ret i32 0
}