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

/* Variables and functions */
int EX_USAGE;
double atof(char *);
float fabsf(float);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fread(float *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(float *);
int getopt(int, char **, char *);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char const *, double);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
float *realloc(float *, size_t);
double scan_for_bpm(float *, size_t, double, double, int, int,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usage(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  float *nrg = NULL;
  size_t len = 0, buf = 0;
  off_t n = 0;
  double bpm, min = 84.0, max = 146.0, v = 0.0;
  const char *format = "%0.3f";
  FILE *fdiff = NULL, *fnrg = NULL;
  for (;;) {
    int c;
    c = getopt(argc, argv, "vf:g:e:m:x:h");
    if (c == -1)
      break;
    switch (c) {
    case 'f':
      format = optarg;
      break;
    case 'g':
      fdiff = fopen(optarg, "w");
      if (fdiff == NULL) {
        perror(optarg);
        return -1;
      }
      break;
    case 'e':
      fnrg = fopen(optarg, "w");
      if (fnrg == NULL) {
        perror(optarg);
        return -1;
      }
      break;
    case 'm':
      min = atof(optarg);
      break;
    case 'x':
      max = atof(optarg);
      break;
    case 'h':
      usage(stdout);
      return 0;
    default:
      return EX_USAGE;
    }
  }
  argv += optind;
  argc -= optind;
  if (argc > 0) {
    fprintf(stderr, "%s: Too many arguments\n", "bpm");
    return EX_USAGE;
  }
  for (;;) {
    float z;
    if (fread(&z, sizeof z, 1, stdin) != 1)
      break;
    z = fabsf(z);
    if (z > v) {
      v += (z - v) / 8;
    } else {
      v -= (v - z) / 512;
    }
    n++;
    if (n != 128)
      continue;
    n = 0;
    if (len == buf) {
      size_t n;
      n = buf + 4096;
      nrg = realloc(nrg, n * sizeof(*nrg));
      if (nrg == NULL) {
        perror("realloc");
        return -1;
      }
      buf = n;
    }
    if (fnrg != NULL) {
      fprintf(fnrg, "%lf\t%lf\n", (double)len * 128 / 44100, v);
    }
    nrg[len++] = v;
  }
  bpm = scan_for_bpm(nrg, len, min, max, 1024, 1024, fdiff);
  printf(format, bpm);
  putc('\n', stdout);
  free(nrg);
  if (fdiff != NULL) {
    if (fclose(fdiff) != 0)
      perror("fclose");
  }
  if (fnrg != NULL) {
    if (fclose(fnrg) != 0)
      perror("fclose");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movsd  0xdf8(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xde3(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
lea    0xe7f(%rip),%rax
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe63(%rip),%rdx
call   10f0 <getopt@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0xffffffff,-0x6c(%rbp)
jne    126a <main+0x9a>
jmp    1392 <main+0x1c2>
mov    -0x6c(%rbp),%eax
add    $0xffffff9b,%eax
mov    %eax,%ecx
mov    %rcx,-0x80(%rbp)
sub    $0x13,%eax
ja     137c <main+0x1ac>
mov    -0x80(%rbp),%rax
lea    0xdd6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d5e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    138d <main+0x1bd>
mov    0x2d4b(%rip),%rax
mov    (%rax),%rdi
lea    0xe0c(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    12e6 <main+0x116>
mov    0x2d26(%rip),%rax
mov    (%rax),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    165e <main+0x48e>
jmp    138d <main+0x1bd>
mov    0x2d06(%rip),%rax
mov    (%rax),%rdi
lea    0xdc7(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    132b <main+0x15b>
mov    0x2ce1(%rip),%rax
mov    (%rax),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    165e <main+0x48e>
jmp    138d <main+0x1bd>
mov    0x2cc1(%rip),%rax
mov    (%rax),%rdi
call   1060 <atof@plt>
movsd  %xmm0,-0x40(%rbp)
jmp    138d <main+0x1bd>
mov    0x2ca8(%rip),%rax
mov    (%rax),%rdi
call   1060 <atof@plt>
movsd  %xmm0,-0x48(%rbp)
jmp    138d <main+0x1bd>
mov    0x2c4f(%rip),%rax
mov    (%rax),%edi
call   10c0 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    165e <main+0x48e>
mov    0x2c55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    165e <main+0x48e>
jmp    1245 <main+0x75>
mov    0x2c37(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    13f6 <main+0x226>
mov    0x2bf3(%rip),%rax
movslq (%rax),%rdi
lea    0xcee(%rip),%rsi
lea    0xcff(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2bec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    165e <main+0x48e>
jmp    13fb <main+0x22b>
mov    0x2bde(%rip),%rax
mov    (%rax),%ecx
lea    -0x70(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
cmp    $0x1,%eax
je     1425 <main+0x255>
jmp    15a8 <main+0x3d8>
movss  -0x70(%rbp),%xmm0
movaps 0xbff(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x70(%rbp)
movss  -0x70(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    1477 <main+0x2a7>
movss  -0x70(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  0xbb4(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    14a3 <main+0x2d3>
movsd  -0x50(%rbp),%xmm1
movss  -0x70(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  %xmm0,%xmm1
movsd  0xb7f(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x80,-0x2c(%rbp)
je     14be <main+0x2ee>
jmp    13fb <main+0x22b>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1521 <main+0x351>
mov    -0x28(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x78(%rbp),%rsi
shl    $0x2,%rsi
call   10b0 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1519 <main+0x349>
lea    0xbd9(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    165e <main+0x48e>
mov    -0x78(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1582 <main+0x3b2>
mov    -0x68(%rbp),%rdi
movaps 0xb09(%rip),%xmm1
movq   -0x20(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xb08(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xac9(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xab5(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x50(%rbp),%xmm1
lea    0xb6e(%rip),%rsi
mov    $0x2,%al
call   10a0 <fprintf@plt>
movsd  -0x50(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
movss  %xmm0,(%rax,%rcx,4)
jmp    13fb <main+0x22b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
mov    -0x60(%rbp),%r8
mov    $0x400,%ecx
mov    %ecx,%edx
call   1030 <scan_for_bpm@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x58(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
call   1080 <printf@plt>
mov    0x29d4(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0x0,-0x60(%rbp)
je     1628 <main+0x458>
mov    -0x60(%rbp),%rdi
call   1070 <fclose@plt>
cmp    $0x0,%rax
je     1623 <main+0x453>
lea    0xad4(%rip),%rdi
call   10e0 <perror@plt>
jmp    1628 <main+0x458>
cmpq   $0x0,-0x68(%rbp)
je     1657 <main+0x487>
mov    -0x68(%rbp),%rdi
call   1070 <fclose@plt>
cmp    $0x0,%rax
je     1652 <main+0x482>
lea    0xaa5(%rip),%rdi
call   10e0 <perror@plt>
jmp    1657 <main+0x487>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xec2(%rip),%rax
mov    %rax,0x28(%rsp)
movsd  0xe09(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0xe03(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
mov    %rax,0x30(%rsp)
lea    0xe99(%rip),%r13
mov    0x2dd8(%rip),%r14
lea    0xe98(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   10f0 <getopt@plt>
cmp    $0x65,%eax
jne    125a <main+0x8a>
mov    (%r14),%rdi
mov    %r15,%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1230 <main+0x60>
jmp    151a <main+0x34a>
lea    -0x66(%rax),%ecx
cmp    $0x12,%ecx
ja     12bc <main+0xec>
lea    0xdf7(%rip),%rdx
movslq (%rdx,%rcx,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    (%r14),%rax
mov    %rax,0x28(%rsp)
jmp    1230 <main+0x60>
mov    (%r14),%rdi
mov    %r15,%rsi
call   10d0 <fopen@plt>
mov    %rax,%rcx
mov    %rax,0x30(%rsp)
test   %rax,%rax
jne    1230 <main+0x60>
jmp    151a <main+0x34a>
mov    (%r14),%rdi
call   1060 <atof@plt>
movsd  %xmm0,0x18(%rsp)
jmp    1230 <main+0x60>
mov    (%r14),%rdi
call   1060 <atof@plt>
movsd  %xmm0,0x20(%rsp)
jmp    1230 <main+0x60>
cmp    $0xffffffff,%eax
jne    12ed <main+0x11d>
mov    0x2d08(%rip),%rax
sub    (%rax),%ebp
test   %ebp,%ebp
jle    1319 <main+0x149>
mov    0x2ceb(%rip),%rax
movslq (%rax),%rdi
lea    0xde2(%rip),%rsi
lea    0xdf3(%rip),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%ebp
jmp    1308 <main+0x138>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   10c0 <usage@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc0(%rip),%rax
mov    (%rax),%ecx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
xor    %ebp,%ebp
mov    $0x0,%r12d
mov    $0x0,%r13d
cmp    $0x1,%eax
jne    148d <main+0x2bd>
xorpd  %xmm1,%xmm1
lea    0xc(%rsp),%r14
xor    %r15d,%r15d
xor    %r13d,%r13d
xor    %r12d,%r12d
jmp    13ad <main+0x1dd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,(%r12,%r13,4)
add    $0x1,%r13
xor    %ebp,%ebp
mov    0x2c56(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
cmp    $0x1,%eax
movsd  0x10(%rsp),%xmm1
jne    148d <main+0x2bd>
movss  0xc(%rsp),%xmm0
andps  0xc76(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
cvtss2sd %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    13e0 <main+0x210>
subsd  %xmm1,%xmm0
mulsd  0xc42(%rip),%xmm0
addsd  %xmm0,%xmm1
jmp    13f4 <main+0x224>
nopl   0x0(%rax)
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
mulsd  0xc20(%rip),%xmm2
addsd  %xmm2,%xmm1
add    $0x1,%ebp
cmp    $0x80,%ebp
movsd  %xmm1,0x10(%rsp)
jne    1383 <main+0x1b3>
cmp    %r15,%r13
jne    1437 <main+0x267>
lea    0x4000(,%r15,4),%rsi
mov    %r12,%rdi
call   10b0 <realloc@plt>
test   %rax,%rax
je     153a <main+0x36a>
mov    %rax,%r12
add    $0x1000,%r15
movsd  0x10(%rsp),%xmm1
test   %rbx,%rbx
je     1370 <main+0x1a0>
movq   %r13,%xmm2
punpckldq 0xbf3(%rip),%xmm2
subpd  0xbfb(%rip),%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
addsd  %xmm2,%xmm0
mulsd  0xbb7(%rip),%xmm0
divsd  0xbb7(%rip),%xmm0
mov    %rbx,%rdi
lea    0xc6a(%rip),%rsi
mov    $0x2,%al
call   10a0 <fprintf@plt>
movsd  0x10(%rsp),%xmm1
jmp    1370 <main+0x1a0>
mov    %r12,%rdi
mov    %r13,%rsi
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    $0x400,%edx
mov    $0x400,%ecx
mov    0x30(%rsp),%rbp
mov    %rbp,%r8
call   1030 <scan_for_bpm@plt>
mov    0x28(%rsp),%rdi
call   1080 <printf@plt>
mov    0x2af1(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    %r12,%rdi
call   1040 <free@plt>
test   %rbp,%rbp
je     14ed <main+0x31d>
mov    %rbp,%rdi
call   1070 <fclose@plt>
test   %rax,%rax
jne    152c <main+0x35c>
xor    %ebp,%ebp
test   %rbx,%rbx
je     1308 <main+0x138>
mov    %rbx,%rdi
call   1070 <fclose@plt>
test   %rax,%rax
je     1308 <main+0x138>
lea    0xbde(%rip),%rdi
call   10e0 <perror@plt>
jmp    1308 <main+0x138>
mov    (%r14),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1308 <main+0x138>
lea    0xbbb(%rip),%rdi
call   10e0 <perror@plt>
jmp    14ed <main+0x31d>
lea    0xb9c(%rip),%rdi
jmp    151d <main+0x34d>

LLVM IR (-O0):
@.str = [6 x i8] c"%0.3f\00"
@.str.1 = [13 x i8] c"vf:g:e:m:x:h\00"
@optarg = global i8* null
@.str.2 = [2 x i8] c"w\00"
@stdout = global i32 0
@EX_USAGE = global i32 0
@optind = global i64 0
@stderr = global i32 0
@.str.3 = [24 x i8] c"%s: Too many arguments\0A\00"
@.str.4 = [4 x i8] c"bpm\00"
@stdin = global i32 0
@.str.5 = [8 x i8] c"realloc\00"
@.str.6 = [9 x i8] c"%lf\09%lf\0A\00"
@.str.7 = [7 x i8] c"fclose\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i8*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32
%18 = alloca float
%19 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store float* null, float** %6
store i64 0, i64* %7
store i64 0, i64* %8
store i32 0, i32* %9
store double 8.400000e+01, double* %11
store double 1.460000e+02, double* %12
store double 0.000000e+00, double* %13
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %14
store i32* null, i32** %15
store i32* null, i32** %16
br label %20
20: ; preds = %60, %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 %23, i32* %17
%24 = load i32, i32* %17
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %20
br label %61
27: ; preds = %20
%28 = load i32, i32* %17
switch i32 %28, label %58 [
i32 102, label %29
i32 103, label %31
i32 101, label %40
i32 109, label %49
i32 120, label %52
i32 104, label %55
]
29: ; preds = %27
%30 = load i8*, i8** @optarg
store i8* %30, i8** %14
br label %60
31: ; preds = %27
%32 = load i8*, i8** @optarg
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %15
%34 = load i32*, i32** %15
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i8*, i8** @optarg
%38 = call i32 @perror(i8* %37)
store i32 -1, i32* %3
br label %182
39: ; preds = %31
br label %60
40: ; preds = %27
%41 = load i8*, i8** @optarg
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %42, i32** %16
%43 = load i32*, i32** %16
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** @optarg
%47 = call i32 @perror(i8* %46)
store i32 -1, i32* %3
br label %182
48: ; preds = %40
br label %60
49: ; preds = %27
%50 = load i8*, i8** @optarg
%51 = call double @atof(i8* %50)
store double %51, double* %11
br label %60
52: ; preds = %27
%53 = load i8*, i8** @optarg
%54 = call double @atof(i8* %53)
store double %54, double* %12
br label %60
55: ; preds = %27
%56 = load i32, i32* @stdout
%57 = call i32 @usage(i32 %56)
store i32 0, i32* %3
br label %182
58: ; preds = %27
%59 = load i32, i32* @EX_USAGE
store i32 %59, i32* %3
br label %182
60: ; preds = %52, %49, %48, %39, %29
br label %20
61: ; preds = %26
%62 = load i64, i64* @optind
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 %62
store i8** %64, i8*** %5
%65 = load i64, i64* @optind
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = sub nsw i64 %67, %65
%69 = trunc i64 %68 to i32
store i32 %69, i32* %4
%70 = load i32, i32* %4
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %61
%73 = load i32, i32* @stderr
%74 = sext i32 %73 to i64
%75 = inttoptr i64 %74 to i32*
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32, i32* @EX_USAGE
store i32 %77, i32* %3
br label %182
78: ; preds = %61
br label %79
79: ; preds = %141, %112, %78
%80 = load i32, i32* @stdin
%81 = call i32 @fread(float* %18, i32 4, i32 1, i32 %80)
%82 = icmp ne i32 %81, 1
br i1 %82, label %83, label %84
83: ; preds = %79
br label %148
84: ; preds = %79
%85 = load float, float* %18
%86 = call float @llvm.fabs.f32(float %85)
store float %86, float* %18
%87 = load float, float* %18
%88 = fpext float %87 to double
%89 = load double, double* %13
%90 = fcmp ogt double %88, %89
br i1 %90, label %91, label %99
91: ; preds = %84
%92 = load float, float* %18
%93 = fpext float %92 to double
%94 = load double, double* %13
%95 = fsub double %93, %94
%96 = fdiv double %95, 8.000000e+00
%97 = load double, double* %13
%98 = fadd double %97, %96
store double %98, double* %13
br label %107
99: ; preds = %84
%100 = load double, double* %13
%101 = load float, float* %18
%102 = fpext float %101 to double
%103 = fsub double %100, %102
%104 = fdiv double %103, 5.120000e+02
%105 = load double, double* %13
%106 = fsub double %105, %104
store double %106, double* %13
br label %107
107: ; preds = %99, %91
%108 = load i32, i32* %9
%109 = add nsw i32 %108, 1
store i32 %109, i32* %9
%110 = load i32, i32* %9
%111 = icmp ne i32 %110, 128
br i1 %111, label %112, label %113
112: ; preds = %107
br label %79
113: ; preds = %107
store i32 0, i32* %9
%114 = load i64, i64* %7
%115 = load i64, i64* %8
%116 = icmp eq i64 %114, %115
br i1 %116, label %117, label %130
117: ; preds = %113
%118 = load i64, i64* %8
%119 = add i64 %118, 4096
store i64 %119, i64* %19
%120 = load float*, float** %6
%121 = load i64, i64* %19
%122 = mul i64 %121, 4
%123 = call float* @realloc(float* %120, i64 %122)
store float* %123, float** %6
%124 = load float*, float** %6
%125 = icmp eq float* %124, null
br i1 %125, label %126, label %128
126: ; preds = %117
%127 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %182
128: ; preds = %117
%129 = load i64, i64* %19
store i64 %129, i64* %8
br label %130
130: ; preds = %128, %113
%131 = load i32*, i32** %16
%132 = icmp ne i32* %131, null
br i1 %132, label %133, label %141
133: ; preds = %130
%134 = load i32*, i32** %16
%135 = load i64, i64* %7
%136 = uitofp i64 %135 to double
%137 = fmul double %136, 1.280000e+02
%138 = fdiv double %137, 4.410000e+04
%139 = load double, double* %13
%140 = call i32 (i32*, i8*, ...) @fprintf(i32* %134, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), double %138, double %139)
br label %141
141: ; preds = %133, %130
%142 = load double, double* %13
%143 = fptrunc double %142 to float
%144 = load float*, float** %6
%145 = load i64, i64* %7
%146 = add i64 %145, 1
store i64 %146, i64* %7
%147 = getelementptr inbounds float, float* %144, i64 %145
store float %143, float* %147
br label %79
148: ; preds = %83
%149 = load float*, float** %6
%150 = load i64, i64* %7
%151 = load double, double* %11
%152 = load double, double* %12
%153 = load i32*, i32** %15
%154 = call double @scan_for_bpm(float* %149, i64 %150, double %151, double %152, i32 1024, i32 1024, i32* %153)
store double %154, double* %10
%155 = load i8*, i8** %14
%156 = load double, double* %10
%157 = call i32 @printf(i8* %155, double %156)
%158 = load i32, i32* @stdout
%159 = call i32 @putc(i8 signext 10, i32 %158)
%160 = load float*, float** %6
%161 = call i32 @free(float* %160)
%162 = load i32*, i32** %15
%163 = icmp ne i32* %162, null
br i1 %163, label %164, label %171
164: ; preds = %148
%165 = load i32*, i32** %15
%166 = call i64 @fclose(i32* %165)
%167 = icmp ne i64 %166, 0
br i1 %167, label %168, label %170
168: ; preds = %164
%169 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %170
170: ; preds = %168, %164
br label %171
171: ; preds = %170, %148
%172 = load i32*, i32** %16
%173 = icmp ne i32* %172, null
br i1 %173, label %174, label %181
174: ; preds = %171
%175 = load i32*, i32** %16
%176 = call i64 @fclose(i32* %175)
%177 = icmp ne i64 %176, 0
br i1 %177, label %178, label %180
178: ; preds = %174
%179 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %180
180: ; preds = %178, %174
br label %181
181: ; preds = %180, %171
store i32 0, i32* %3
br label %182
182: ; preds = %181, %126, %72, %58, %55, %45, %36
%183 = load i32, i32* %3
ret i32 %183
}

LLVM IR (-O2):
@.str = [6 x i8] c"%0.3f\00"
@.str.1 = [13 x i8] c"vf:g:e:m:x:h\00"
@optarg = global i8* null
@.str.2 = [2 x i8] c"w\00"
@stdout = global i32 0
@EX_USAGE = global i32 0
@optind = global i64 0
@stderr = global i32 0
@.str.3 = [24 x i8] c"%s: Too many arguments\0A\00"
@.str.4 = [4 x i8] c"bpm\00"
@stdin = global i32 0
@.str.5 = [8 x i8] c"realloc\00"
@.str.6 = [9 x i8] c"%lf\09%lf\0A\00"
@.str.7 = [7 x i8] c"fclose\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca float
br label %4
4: ; preds = %41, %2
%5 = phi double [ %43, %41 ], [ 8.400000e+01, %2 ]
%6 = phi double [ %11, %41 ], [ 1.460000e+02, %2 ]
%7 = phi i8* [ %16, %41 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %2 ]
%8 = phi i32* [ %20, %41 ], [ null, %2 ]
%9 = phi i32* [ %23, %41 ], [ null, %2 ]
br label %10
10: ; preds = %4, %44
%11 = phi double [ %6, %4 ], [ %46, %44 ]
%12 = phi i8* [ %7, %4 ], [ %16, %44 ]
%13 = phi i32* [ %8, %4 ], [ %20, %44 ]
%14 = phi i32* [ %9, %4 ], [ %23, %44 ]
br label %15
15: ; preds = %10, %25
%16 = phi i8* [ %12, %10 ], [ %26, %25 ]
%17 = phi i32* [ %13, %10 ], [ %20, %25 ]
%18 = phi i32* [ %14, %10 ], [ %23, %25 ]
br label %19
19: ; preds = %15, %27
%20 = phi i32* [ %17, %15 ], [ %29, %27 ]
%21 = phi i32* [ %18, %15 ], [ %23, %27 ]
br label %22
22: ; preds = %19, %34
%23 = phi i32* [ %36, %34 ], [ %21, %19 ]
%24 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
switch i32 %24, label %50 [
i32 -1, label %52
i32 102, label %25
i32 103, label %27
i32 101, label %34
i32 109, label %41
i32 120, label %44
i32 104, label %47
]
25: ; preds = %22
%26 = load i8*, i8** @optarg
br label %15
27: ; preds = %22
%28 = load i8*, i8** @optarg
%29 = tail call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %19
31: ; preds = %27
%32 = load i8*, i8** @optarg
%33 = tail call i32 @perror(i8* %32)
br label %142
34: ; preds = %22
%35 = load i8*, i8** @optarg
%36 = tail call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %22
38: ; preds = %34
%39 = load i8*, i8** @optarg
%40 = tail call i32 @perror(i8* %39)
br label %142
41: ; preds = %22
%42 = load i8*, i8** @optarg
%43 = tail call double @atof(i8* %42)
br label %4
44: ; preds = %22
%45 = load i8*, i8** @optarg
%46 = tail call double @atof(i8* %45)
br label %10
47: ; preds = %22
%48 = load i32, i32* @stdout
%49 = tail call i32 @usage(i32 %48)
br label %142
50: ; preds = %22
%51 = load i32, i32* @EX_USAGE
br label %142
52: ; preds = %22
%53 = load i64, i64* @optind
%54 = trunc i64 %53 to i32
%55 = sub i32 %0, %54
%56 = icmp sgt i32 %55, 0
br i1 %56, label %64, label %57
57: ; preds = %52
%58 = bitcast float* %3 to i8*
%59 = load i32, i32* @stdin
%60 = call i32 @fread(float* %3, i32 4, i32 1, i32 %59)
%61 = icmp eq i32 %60, 1
br i1 %61, label %62, label %121
62: ; preds = %57
%63 = icmp eq i32* %23, null
br label %70
64: ; preds = %52
%65 = load i32, i32* @stderr
%66 = sext i32 %65 to i64
%67 = inttoptr i64 %66 to i32*
%68 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%69 = load i32, i32* @EX_USAGE
br label %142
70: ; preds = %62, %113
%71 = phi double [ 0.000000e+00, %62 ], [ %89, %113 ]
%72 = phi i32 [ 0, %62 ], [ %117, %113 ]
%73 = phi i64 [ 0, %62 ], [ %116, %113 ]
%74 = phi i64 [ 0, %62 ], [ %115, %113 ]
%75 = phi float* [ null, %62 ], [ %114, %113 ]
%76 = load float, float* %3
%77 = call float @llvm.fabs.f32(float %76)
store float %77, float* %3
%78 = fpext float %77 to double
%79 = fcmp olt double %71, %78
br i1 %79, label %80, label %84
80: ; preds = %70
%81 = fsub double %78, %71
%82 = fmul double %81, 1.250000e-01
%83 = fadd double %71, %82
br label %88
84: ; preds = %70
%85 = fsub double %71, %78
%86 = fmul double %85, 0x3F60000000000000
%87 = fsub double %71, %86
br label %88
88: ; preds = %84, %80
%89 = phi double [ %83, %80 ], [ %87, %84 ]
%90 = add nsw i32 %72, 1
%91 = icmp eq i32 %90, 128
br i1 %91, label %92, label %113
92: ; preds = %88
%93 = icmp eq i64 %74, %73
br i1 %93, label %94, label %101
94: ; preds = %92
%95 = add i64 %73, 4096
%96 = shl i64 %95, 2
%97 = call float* @realloc(float* %75, i64 %96)
%98 = icmp eq float* %97, null
br i1 %98, label %99, label %101
99: ; preds = %94
%100 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %142
101: ; preds = %94, %92
%102 = phi float* [ %75, %92 ], [ %97, %94 ]
%103 = phi i64 [ %73, %92 ], [ %95, %94 ]
br i1 %63, label %109, label %104
104: ; preds = %101
%105 = uitofp i64 %74 to double
%106 = fmul double %105, 1.280000e+02
%107 = fdiv double %106, 4.410000e+04
%108 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), double %107, double %89)
br label %109
109: ; preds = %104, %101
%110 = fptrunc double %89 to float
%111 = add i64 %74, 1
%112 = getelementptr inbounds float, float* %102, i64 %74
store float %110, float* %112
br label %113
113: ; preds = %88, %109
%114 = phi float* [ %102, %109 ], [ %75, %88 ]
%115 = phi i64 [ %111, %109 ], [ %74, %88 ]
%116 = phi i64 [ %103, %109 ], [ %73, %88 ]
%117 = phi i32 [ 0, %109 ], [ %90, %88 ]
%118 = load i32, i32* @stdin
%119 = call i32 @fread(float* %3, i32 4, i32 1, i32 %118)
%120 = icmp eq i32 %119, 1
br i1 %120, label %70, label %121
121: ; preds = %113, %57
%122 = phi float* [ null, %57 ], [ %114, %113 ]
%123 = phi i64 [ 0, %57 ], [ %115, %113 ]
%124 = call double @scan_for_bpm(float* %122, i64 %123, double %5, double %11, i32 1024, i32 1024, i32* %20)
%125 = call i32 @printf(i8* %16, double %124)
%126 = load i32, i32* @stdout
%127 = call i32 @putc(i8 signext 10, i32 %126)
%128 = call i32 @free(float* %122)
%129 = icmp eq i32* %20, null
br i1 %129, label %135, label %130
130: ; preds = %121
%131 = call i64 @fclose(i32* %20)
%132 = icmp eq i64 %131, 0
br i1 %132, label %135, label %133
133: ; preds = %130
%134 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %135
135: ; preds = %130, %133, %121
%136 = icmp eq i32* %23, null
br i1 %136, label %142, label %137
137: ; preds = %135
%138 = call i64 @fclose(i32* %23)
%139 = icmp eq i64 %138, 0
br i1 %139, label %142, label %140
140: ; preds = %137
%141 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %142
142: ; preds = %31, %38, %47, %50, %99, %135, %140, %137, %64
%143 = phi i32 [ %69, %64 ], [ 0, %137 ], [ 0, %140 ], [ 0, %135 ], [ -1, %99 ], [ -1, %31 ], [ -1, %38 ], [ 0, %47 ], [ %51, %50 ]
ret i32 %143
}