#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 Read16(unsigned char *);
int Read32(unsigned char *);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ Write32(unsigned char *, int);
int abs(short);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *malloc(long);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int wavtrim(char *filename, int maxsilence, char *errstring, int errsize) {
  FILE *pFile;
  long lFileSize, lGot;
  unsigned char *pBuf;
  int bps;
  int sps;
  int datapos;
  int datalen;
  unsigned char *databuf;
  int skip_head, skip_tail, pad_head, pad_tail;
  int i;
  int max_silence = maxsilence;
  signed char sample8;
  short sample16;
  pFile = fopen(filename, "rb");
  if (pFile == NULL) {
    snprintf(errstring, errsize, "Error opening file %s for reading\n",
             filename);
    return -1;
  }
  fseek(pFile, 0, SEEK_END);
  lFileSize = ftell(pFile);
  fseek(pFile, 0, SEEK_SET);
  pBuf = malloc(lFileSize);
  if (pBuf == NULL) {
    snprintf(errstring, errsize,
             "Out of memory to allocate %ld bytes for file.\n", lFileSize);
    fclose(pFile);
    return -1;
  }
  lGot = fread(pBuf, 1, lFileSize, pFile);
  fclose(pFile);
  if (lGot != lFileSize) {
    snprintf(errstring, errsize,
             "File read error, got only %ld bytes out of %ld.\n", lGot,
             lFileSize);
    free(pBuf);
    return -1;
  }
  bps = Read16(pBuf + 32);
  datapos = 28 + Read16(pBuf + 16);
  databuf = &pBuf[datapos];
  if (Read32(pBuf) != 0x46464952 || Read32(pBuf + 8) != 0x45564157 ||
      Read32(pBuf + 12) != 0x20746d66 ||
      Read32(pBuf + datapos - 8) != 0x61746164) {
    snprintf(errstring, errsize, "No valid input WAV file?\n");
    free(pBuf);
    return -1;
  }
  datalen = Read32(pBuf + datapos - 4);
  skip_head = skip_tail = 0;
  sps = Read32(pBuf + 24);
  pad_head = sps * 10 / 1000;
  pad_tail = sps * 10 / 1000;
  if (bps == 1) {
    max_silence >>= 8;
    for (i = 0; i < datalen; i++) {
      sample8 = databuf[i] - 0x80;
      if (abs(sample8) > max_silence)
        break;
    }
    skip_head = i;
    skip_head = (skip_head > pad_head) ? skip_head - pad_head : 0;
    for (i = datalen - 1; i > skip_head; i--) {
      sample8 = databuf[i] - 0x80;
      if (abs(sample8) > max_silence)
        break;
    }
    skip_tail = datalen - 1 - i;
    skip_tail = (skip_tail > pad_tail) ? skip_tail - pad_tail : 0;
  } else if (bps == 2) {
    for (i = 0; i < datalen; i += 2) {
      sample16 = (*(databuf + i + 1) << 8) | *(databuf + i);
      if (abs(sample16) > max_silence)
        break;
    }
    skip_head = i;
    skip_head = (skip_head > 2 * pad_head) ? skip_head - 2 * pad_head : 0;
    for (i = datalen - 2; i > skip_head; i -= 2) {
      sample16 = (*(databuf + i + 1) << 8) | *(databuf + i);
      if (abs(sample16) > max_silence)
        break;
    }
    skip_tail = datalen - 2 - i;
    skip_tail = (skip_tail > 2 * pad_tail) ? skip_tail - 2 * pad_tail : 0;
  }
  Write32(pBuf + 4, Read32(pBuf + 4) - skip_head - skip_tail);
  Write32(pBuf + datapos - 4, datalen - skip_head - skip_tail);
  pFile = fopen(filename, "wb");
  if (pFile == NULL) {
    snprintf(errstring, errsize, "Error opening file %s for writing\n",
             filename);
    free(pBuf);
    return -1;
  }
  if ((int)fwrite(pBuf, 1, datapos, pFile) != datapos) {
    snprintf(errstring, errsize, "Error writing file %s header\n", filename);
    fclose(pFile);
    free(pBuf);
    return -1;
  }
  if ((int)fwrite(pBuf + datapos + skip_head, 1,
                  datalen - skip_head - skip_tail,
                  pFile) != datalen - skip_head - skip_tail) {
    snprintf(errstring, errsize, "Error writing file %s data\n", filename);
    fclose(pFile);
    free(pBuf);
    return -1;
  }
  fclose(pFile);
  free(pBuf);
  return 0;
}


x86 assembly (clang, -O0):
<wavtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1233 <wavtrim+0x63>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0xde3(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1828 <wavtrim+0x658>
mov    -0x30(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2d79(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12ae <wavtrim+0xde>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x38(%rbp),%rcx
lea    0xd94(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1828 <wavtrim+0x658>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     1311 <wavtrim+0x141>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xd60(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1828 <wavtrim+0x658>
mov    -0x48(%rbp),%rdi
add    $0x20,%rdi
call   10c0 <Read16@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x10,%rdi
call   10c0 <Read16@plt>
add    $0x1c,%eax
mov    %eax,-0x54(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
call   10d0 <Read32@plt>
cmp    $0x46464952,%eax
jne    13a6 <wavtrim+0x1d6>
mov    -0x48(%rbp),%rdi
add    $0x8,%rdi
call   10d0 <Read32@plt>
cmp    $0x45564157,%eax
jne    13a6 <wavtrim+0x1d6>
mov    -0x48(%rbp),%rdi
add    $0xc,%rdi
call   10d0 <Read32@plt>
cmp    $0x20746d66,%eax
jne    13a6 <wavtrim+0x1d6>
mov    -0x48(%rbp),%rdi
movslq -0x54(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffff8,%rdi
call   10d0 <Read32@plt>
cmp    $0x61746164,%eax
je     13d0 <wavtrim+0x200>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    0xcd2(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1828 <wavtrim+0x658>
mov    -0x48(%rbp),%rdi
movslq -0x54(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
call   10d0 <Read32@plt>
mov    %eax,-0x58(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x18,%rdi
call   10d0 <Read32@plt>
mov    %eax,-0x50(%rbp)
imul   $0xa,-0x50(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x6c(%rbp)
imul   $0xa,-0x50(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x70(%rbp)
cmpl   $0x1,-0x4c(%rbp)
jne    1554 <wavtrim+0x384>
mov    -0x78(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x78(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    148a <wavtrim+0x2ba>
mov    -0x60(%rbp),%rax
movslq -0x74(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sub    $0x80,%eax
mov    %al,-0x79(%rbp)
movsbl -0x79(%rbp),%eax
movswl %ax,%edi
call   1050 <abs@plt>
cmp    -0x78(%rbp),%eax
jle    1477 <wavtrim+0x2a7>
jmp    148a <wavtrim+0x2ba>
jmp    147c <wavtrim+0x2ac>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    143d <wavtrim+0x26d>
mov    -0x74(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jle    14aa <wavtrim+0x2da>
mov    -0x64(%rbp),%eax
sub    -0x6c(%rbp),%eax
mov    %eax,-0x80(%rbp)
jmp    14b4 <wavtrim+0x2e4>
xor    %eax,%eax
mov    %eax,-0x80(%rbp)
jmp    14b4 <wavtrim+0x2e4>
mov    -0x80(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x64(%rbp),%eax
jle    1510 <wavtrim+0x340>
mov    -0x60(%rbp),%rax
movslq -0x74(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sub    $0x80,%eax
mov    %al,-0x79(%rbp)
movsbl -0x79(%rbp),%eax
movswl %ax,%edi
call   1050 <abs@plt>
cmp    -0x78(%rbp),%eax
jle    14fd <wavtrim+0x32d>
jmp    1510 <wavtrim+0x340>
jmp    1502 <wavtrim+0x332>
mov    -0x74(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
jmp    14c3 <wavtrim+0x2f3>
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
sub    -0x74(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x70(%rbp),%eax
jle    1539 <wavtrim+0x369>
mov    -0x68(%rbp),%eax
sub    -0x70(%rbp),%eax
mov    %eax,-0x84(%rbp)
jmp    1546 <wavtrim+0x376>
xor    %eax,%eax
mov    %eax,-0x84(%rbp)
jmp    1546 <wavtrim+0x376>
mov    -0x84(%rbp),%eax
mov    %eax,-0x68(%rbp)
jmp    16af <wavtrim+0x4df>
cmpl   $0x2,-0x4c(%rbp)
jne    16aa <wavtrim+0x4da>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    15bd <wavtrim+0x3ed>
mov    -0x60(%rbp),%rax
movslq -0x74(%rbp),%rcx
movzbl 0x1(%rax,%rcx,1),%eax
shl    $0x8,%eax
mov    -0x60(%rbp),%rcx
movslq -0x74(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
or     %ecx,%eax
mov    %ax,-0x7c(%rbp)
movswl -0x7c(%rbp),%edi
call   1050 <abs@plt>
cmp    -0x78(%rbp),%eax
jle    15aa <wavtrim+0x3da>
jmp    15bd <wavtrim+0x3ed>
jmp    15af <wavtrim+0x3df>
mov    -0x74(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x74(%rbp)
jmp    1565 <wavtrim+0x395>
mov    -0x74(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x6c(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    15ea <wavtrim+0x41a>
mov    -0x64(%rbp),%eax
mov    -0x6c(%rbp),%ecx
shl    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x88(%rbp)
jmp    15f7 <wavtrim+0x427>
xor    %eax,%eax
mov    %eax,-0x88(%rbp)
jmp    15f7 <wavtrim+0x427>
mov    -0x88(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x58(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x64(%rbp),%eax
jle    1661 <wavtrim+0x491>
mov    -0x60(%rbp),%rax
movslq -0x74(%rbp),%rcx
movzbl 0x1(%rax,%rcx,1),%eax
shl    $0x8,%eax
mov    -0x60(%rbp),%rcx
movslq -0x74(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
or     %ecx,%eax
mov    %ax,-0x7c(%rbp)
movswl -0x7c(%rbp),%edi
call   1050 <abs@plt>
cmp    -0x78(%rbp),%eax
jle    164e <wavtrim+0x47e>
jmp    1661 <wavtrim+0x491>
jmp    1653 <wavtrim+0x483>
mov    -0x74(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x74(%rbp)
jmp    1609 <wavtrim+0x439>
mov    -0x58(%rbp),%eax
sub    $0x2,%eax
sub    -0x74(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
mov    -0x70(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    1694 <wavtrim+0x4c4>
mov    -0x68(%rbp),%eax
mov    -0x70(%rbp),%ecx
shl    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x8c(%rbp)
jmp    16a1 <wavtrim+0x4d1>
xor    %eax,%eax
mov    %eax,-0x8c(%rbp)
jmp    16a1 <wavtrim+0x4d1>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x68(%rbp)
jmp    16af <wavtrim+0x4df>
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x98(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x4,%rdi
call   10d0 <Read32@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%esi
sub    -0x64(%rbp),%esi
sub    -0x68(%rbp),%esi
call   1080 <Write32@plt>
mov    -0x48(%rbp),%rdi
movslq -0x54(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
mov    -0x58(%rbp),%esi
sub    -0x64(%rbp),%esi
sub    -0x68(%rbp),%esi
call   1080 <Write32@plt>
mov    -0x10(%rbp),%rdi
lea    0x999(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1749 <wavtrim+0x579>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0x976(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1828 <wavtrim+0x658>
mov    -0x48(%rbp),%rdi
mov    -0x54(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
cmp    -0x54(%rbp),%eax
je     179e <wavtrim+0x5ce>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0x94d(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1828 <wavtrim+0x658>
mov    -0x48(%rbp),%rdi
movslq -0x54(%rbp),%rax
add    %rax,%rdi
movslq -0x64(%rbp),%rax
add    %rax,%rdi
mov    -0x58(%rbp),%edx
sub    -0x64(%rbp),%edx
sub    -0x68(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    -0x58(%rbp),%ecx
sub    -0x64(%rbp),%ecx
sub    -0x68(%rbp),%ecx
cmp    %ecx,%eax
je     180f <wavtrim+0x63f>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0x8fa(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1828 <wavtrim+0x658>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wavtrim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %ecx,%r14d
mov    %rdx,%r13
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xe0f(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13ff <wavtrim+0x22f>
mov    %rax,%rbp
mov    %rbx,0x38(%rsp)
mov    %r15d,%ebx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbp,%rdi
call   1090 <ftell@plt>
mov    %rax,%r12
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r12,%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1418 <wavtrim+0x248>
mov    %rax,%r15
mov    %r13,0x20(%rsp)
mov    %r14d,0x4(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1060 <fclose@plt>
cmp    %r12,%r14
jne    1439 <wavtrim+0x269>
lea    0x20(%r15),%rdi
call   10c0 <Read16@plt>
mov    %eax,%r12d
lea    0x10(%r15),%rdi
call   10c0 <Read16@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   10d0 <Read32@plt>
cmp    $0x46464952,%eax
jne    1458 <wavtrim+0x288>
lea    0x8(%r15),%rdi
call   10d0 <Read32@plt>
cmp    $0x45564157,%eax
jne    1458 <wavtrim+0x288>
lea    0xc(%r15),%rdi
call   10d0 <Read32@plt>
cmp    $0x20746d66,%eax
jne    1458 <wavtrim+0x288>
movslq %ebp,%r14
lea    (%r15,%r14,1),%rbp
add    $0x1c,%rbp
lea    -0x8(%rbp),%rdi
call   10d0 <Read32@plt>
cmp    $0x61746164,%eax
jne    1458 <wavtrim+0x288>
add    $0x1c,%r14
mov    %rbp,0x28(%rsp)
lea    -0x4(%rbp),%rdi
mov    %rdi,0x40(%rsp)
call   10d0 <Read32@plt>
mov    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0x18(%r15),%rdi
call   10d0 <Read32@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x25,%rcx
add    %eax,%ecx
cmp    $0x1,%r12d
mov    %r14,0x30(%rsp)
je     148b <wavtrim+0x2bb>
xor    %r13d,%r13d
mov    $0x0,%r14d
cmp    $0x2,%r12d
mov    0x8(%rsp),%r12
jne    153a <wavtrim+0x36a>
xor    %eax,%eax
mov    $0x0,%ebp
test   %r12d,%r12d
jle    1395 <wavtrim+0x1c5>
mov    %ebx,%r12d
mov    %rcx,%r13
mov    0x30(%rsp),%rax
lea    (%rax,%r15,1),%r14
add    $0x1,%r14
xor    %ebp,%ebp
movswl -0x1(%r14,%rbp,1),%edi
call   1050 <abs@plt>
cmp    %r12d,%eax
jg     1390 <wavtrim+0x1c0>
add    $0x2,%rbp
cmp    %ebp,0x8(%rsp)
jg     1376 <wavtrim+0x1a6>
xor    %eax,%eax
mov    %r13,%rcx
add    %ecx,%ecx
sub    %ecx,%ebp
cmovg  %ebp,%eax
mov    0x8(%rsp),%r12
lea    -0x2(%r12),%r14d
mov    %r14d,%ebp
cmp    %eax,%r14d
jle    13f4 <wavtrim+0x224>
mov    %rcx,0x10(%rsp)
movslq %r14d,%rbp
mov    %eax,%r13d
mov    %eax,%eax
mov    %rax,0x18(%rsp)
mov    0x30(%rsp),%rax
lea    (%rax,%r15,1),%r12
add    $0x1,%r12
movswl -0x1(%r12,%rbp,1),%edi
call   1050 <abs@plt>
cmp    %ebx,%eax
jg     13e7 <wavtrim+0x217>
add    $0xfffffffffffffffe,%rbp
cmp    0x18(%rsp),%rbp
jg     13cd <wavtrim+0x1fd>
mov    0x8(%rsp),%r12
mov    %r13d,%eax
mov    0x10(%rsp),%rcx
sub    %ebp,%r14d
mov    %eax,%r13d
jmp    1531 <wavtrim+0x361>
lea    0xbfd(%rip),%rdx
mov    %r13,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
jmp    1477 <wavtrim+0x2a7>
lea    0xc07(%rip),%rdx
mov    %r13,%rdi
mov    %r14d,%esi
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
jmp    1477 <wavtrim+0x2a7>
lea    0xc15(%rip),%rdx
mov    0x20(%rsp),%rdi
mov    0x4(%rsp),%esi
mov    %r14,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1070 <snprintf@plt>
jmp    146f <wavtrim+0x29f>
lea    0xc27(%rip),%rdx
mov    0x20(%rsp),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
sar    $0x8,%ebx
xor    %r13d,%r13d
mov    $0x0,%ebp
mov    0x8(%rsp),%r12
test   %r12d,%r12d
mov    %rcx,0x10(%rsp)
jle    14d2 <wavtrim+0x302>
xor    %ebp,%ebp
mov    0x28(%rsp),%r13
movsbl 0x0(%r13,%rbp,1),%edi
xor    $0xffffff80,%edi
call   1050 <abs@plt>
cmp    %ebx,%eax
jg     14ca <wavtrim+0x2fa>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    14ac <wavtrim+0x2dc>
mov    %r12d,%ebp
xor    %r13d,%r13d
mov    0x10(%rsp),%rcx
sub    %ecx,%ebp
cmovg  %ebp,%r13d
lea    -0x1(%r12),%r14d
mov    %r14d,%ebp
cmp    %r13d,%r14d
jle    152e <wavtrim+0x35e>
movslq %r14d,%rbp
mov    %r13d,0x18(%rsp)
mov    %r13d,%r12d
mov    0x28(%rsp),%r13
movsbl 0x0(%r13,%rbp,1),%edi
xor    $0xffffff80,%edi
call   1050 <abs@plt>
cmp    %ebx,%eax
jg     151f <wavtrim+0x34f>
add    $0xffffffffffffffff,%rbp
cmp    %r12,%rbp
jg     14f5 <wavtrim+0x325>
mov    0x18(%rsp),%r13d
mov    %r13d,%ebp
mov    0x8(%rsp),%r12
jmp    1529 <wavtrim+0x359>
mov    0x8(%rsp),%r12
mov    0x18(%rsp),%r13d
mov    0x10(%rsp),%rcx
sub    %ebp,%r14d
xor    %eax,%eax
sub    %ecx,%r14d
cmovle %eax,%r14d
mov    %r15,%rbp
add    $0x4,%rbp
mov    %rbp,%rdi
call   10d0 <Read32@plt>
mov    %r13d,0x18(%rsp)
add    %r13d,%r14d
sub    %r14d,%eax
mov    %rbp,%rdi
mov    %eax,%esi
call   1080 <Write32@plt>
sub    %r14d,%r12d
mov    0x40(%rsp),%rdi
mov    %r12,%rbp
mov    %r12d,%esi
call   1080 <Write32@plt>
lea    0xb28(%rip),%rsi
mov    0x38(%rsp),%rbx
mov    %rbx,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     15ea <wavtrim+0x41a>
mov    %rax,%r12
mov    %r15,%rdi
mov    $0x1,%esi
mov    0x30(%rsp),%rbx
mov    %ebx,%edx
mov    %rax,%rcx
call   10f0 <fwrite@plt>
cmp    %eax,%ebx
jne    1609 <wavtrim+0x439>
mov    0x18(%rsp),%eax
mov    0x28(%rsp),%rdi
add    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rbx
mov    %ebx,%edx
mov    %r12,%rcx
call   10f0 <fwrite@plt>
cmp    %eax,%ebx
mov    0x4(%rsp),%esi
mov    0x20(%rsp),%rdi
jne    161b <wavtrim+0x44b>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    147c <wavtrim+0x2ac>
lea    0xab2(%rip),%rdx
mov    0x20(%rsp),%rdi
mov    0x4(%rsp),%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
jmp    146f <wavtrim+0x29f>
lea    0xab6(%rip),%rdx
mov    0x20(%rsp),%rdi
mov    0x4(%rsp),%esi
jmp    1622 <wavtrim+0x452>
lea    0xac2(%rip),%rdx
mov    0x38(%rsp),%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
jmp    146f <wavtrim+0x29f>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [35 x i8] c"Error opening file %s for reading\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [47 x i8] c"Out of memory to allocate %ld bytes for file.\0A\00"
@.str.3 = [49 x i8] c"File read error, got only %ld bytes out of %ld.\0A\00"
@.str.4 = [26 x i8] c"No valid input WAV file?\0A\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [35 x i8] c"Error opening file %s for writing\0A\00"
@.str.7 = [30 x i8] c"Error writing file %s header\0A\00"
@.str.8 = [28 x i8] c"Error writing file %s data\0A\00"
define i32 @wavtrim(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i8
%26 = alloca i16
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%27 = load i32, i32* %7
store i32 %27, i32* %24
%28 = load i8*, i8** %6
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %10
%30 = load i32*, i32** %10
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %37
32: ; preds = %4
%33 = load i8*, i8** %8
%34 = load i32, i32* %9
%35 = load i8*, i8** %6
%36 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %33, i32 %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %35)
store i32 -1, i32* %5
br label %394
37: ; preds = %4
%38 = load i32*, i32** %10
%39 = load i32, i32* @SEEK_END
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i32*, i32** %10
%42 = call i64 @ftell(i32* %41)
store i64 %42, i64* %11
%43 = load i32*, i32** %10
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @fseek(i32* %43, i32 0, i32 %44)
%46 = load i64, i64* %11
%47 = call i8* @malloc(i64 %46)
store i8* %47, i8** %13
%48 = load i8*, i8** %13
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %57
50: ; preds = %37
%51 = load i8*, i8** %8
%52 = load i32, i32* %9
%53 = load i64, i64* %11
%54 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %51, i32 %52, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i64 %53)
%55 = load i32*, i32** %10
%56 = call i32 @fclose(i32* %55)
store i32 -1, i32* %5
br label %394
57: ; preds = %37
%58 = load i8*, i8** %13
%59 = load i64, i64* %11
%60 = load i32*, i32** %10
%61 = call i64 @fread(i8* %58, i32 1, i64 %59, i32* %60)
store i64 %61, i64* %12
%62 = load i32*, i32** %10
%63 = call i32 @fclose(i32* %62)
%64 = load i64, i64* %12
%65 = load i64, i64* %11
%66 = icmp ne i64 %64, %65
br i1 %66, label %67, label %75
67: ; preds = %57
%68 = load i8*, i8** %8
%69 = load i32, i32* %9
%70 = load i64, i64* %12
%71 = load i64, i64* %11
%72 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %68, i32 %69, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i64 %70, i64 %71)
%73 = load i8*, i8** %13
%74 = call i32 @free(i8* %73)
store i32 -1, i32* %5
br label %394
75: ; preds = %57
%76 = load i8*, i8** %13
%77 = getelementptr inbounds i8, i8* %76, i64 32
%78 = call i32 @Read16(i8* %77)
store i32 %78, i32* %14
%79 = load i8*, i8** %13
%80 = getelementptr inbounds i8, i8* %79, i64 16
%81 = call i32 @Read16(i8* %80)
%82 = add nsw i32 28, %81
store i32 %82, i32* %16
%83 = load i8*, i8** %13
%84 = load i32, i32* %16
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
store i8* %86, i8** %18
%87 = load i8*, i8** %13
%88 = call i32 @Read32(i8* %87)
%89 = icmp ne i32 %88, 1179011410
br i1 %89, label %108, label %90
90: ; preds = %75
%91 = load i8*, i8** %13
%92 = getelementptr inbounds i8, i8* %91, i64 8
%93 = call i32 @Read32(i8* %92)
%94 = icmp ne i32 %93, 1163280727
br i1 %94, label %108, label %95
95: ; preds = %90
%96 = load i8*, i8** %13
%97 = getelementptr inbounds i8, i8* %96, i64 12
%98 = call i32 @Read32(i8* %97)
%99 = icmp ne i32 %98, 544501094
br i1 %99, label %108, label %100
100: ; preds = %95
%101 = load i8*, i8** %13
%102 = load i32, i32* %16
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %101, i64 %103
%105 = getelementptr inbounds i8, i8* %104, i64 -8
%106 = call i32 @Read32(i8* %105)
%107 = icmp ne i32 %106, 1635017060
br i1 %107, label %108, label %114
108: ; preds = %100, %95, %90, %75
%109 = load i8*, i8** %8
%110 = load i32, i32* %9
%111 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %109, i32 %110, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%112 = load i8*, i8** %13
%113 = call i32 @free(i8* %112)
store i32 -1, i32* %5
br label %394
114: ; preds = %100
%115 = load i8*, i8** %13
%116 = load i32, i32* %16
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds i8, i8* %115, i64 %117
%119 = getelementptr inbounds i8, i8* %118, i64 -4
%120 = call i32 @Read32(i8* %119)
store i32 %120, i32* %17
store i32 0, i32* %20
store i32 0, i32* %19
%121 = load i8*, i8** %13
%122 = getelementptr inbounds i8, i8* %121, i64 24
%123 = call i32 @Read32(i8* %122)
store i32 %123, i32* %15
%124 = load i32, i32* %15
%125 = mul nsw i32 %124, 10
%126 = sdiv i32 %125, 1000
store i32 %126, i32* %21
%127 = load i32, i32* %15
%128 = mul nsw i32 %127, 10
%129 = sdiv i32 %128, 1000
store i32 %129, i32* %22
%130 = load i32, i32* %14
%131 = icmp eq i32 %130, 1
br i1 %131, label %132, label %210
132: ; preds = %114
%133 = load i32, i32* %24
%134 = ashr i32 %133, 8
store i32 %134, i32* %24
store i32 0, i32* %23
br label %135
135: ; preds = %155, %132
%136 = load i32, i32* %23
%137 = load i32, i32* %17
%138 = icmp slt i32 %136, %137
br i1 %138, label %139, label %158
139: ; preds = %135
%140 = load i8*, i8** %18
%141 = load i32, i32* %23
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i8, i8* %140, i64 %142
%144 = load i8, i8* %143
%145 = zext i8 %144 to i32
%146 = sub nsw i32 %145, 128
%147 = trunc i32 %146 to i8
store i8 %147, i8* %25
%148 = load i8, i8* %25
%149 = sext i8 %148 to i16
%150 = call i32 @abs(i16 signext %149)
%151 = load i32, i32* %24
%152 = icmp sgt i32 %150, %151
br i1 %152, label %153, label %154
153: ; preds = %139
br label %158
154: ; preds = %139
br label %155
155: ; preds = %154
%156 = load i32, i32* %23
%157 = add nsw i32 %156, 1
store i32 %157, i32* %23
br label %135
158: ; preds = %153, %135
%159 = load i32, i32* %23
store i32 %159, i32* %19
%160 = load i32, i32* %19
%161 = load i32, i32* %21
%162 = icmp sgt i32 %160, %161
br i1 %162, label %163, label %167
163: ; preds = %158
%164 = load i32, i32* %19
%165 = load i32, i32* %21
%166 = sub nsw i32 %164, %165
br label %168
167: ; preds = %158
br label %168
168: ; preds = %167, %163
%169 = phi i32 [ %166, %163 ], [ 0, %167 ]
store i32 %169, i32* %19
%170 = load i32, i32* %17
%171 = sub nsw i32 %170, 1
store i32 %171, i32* %23
br label %172
172: ; preds = %192, %168
%173 = load i32, i32* %23
%174 = load i32, i32* %19
%175 = icmp sgt i32 %173, %174
br i1 %175, label %176, label %195
176: ; preds = %172
%177 = load i8*, i8** %18
%178 = load i32, i32* %23
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i8, i8* %177, i64 %179
%181 = load i8, i8* %180
%182 = zext i8 %181 to i32
%183 = sub nsw i32 %182, 128
%184 = trunc i32 %183 to i8
store i8 %184, i8* %25
%185 = load i8, i8* %25
%186 = sext i8 %185 to i16
%187 = call i32 @abs(i16 signext %186)
%188 = load i32, i32* %24
%189 = icmp sgt i32 %187, %188
br i1 %189, label %190, label %191
190: ; preds = %176
br label %195
191: ; preds = %176
br label %192
192: ; preds = %191
%193 = load i32, i32* %23
%194 = add nsw i32 %193, -1
store i32 %194, i32* %23
br label %172
195: ; preds = %190, %172
%196 = load i32, i32* %17
%197 = sub nsw i32 %196, 1
%198 = load i32, i32* %23
%199 = sub nsw i32 %197, %198
store i32 %199, i32* %20
%200 = load i32, i32* %20
%201 = load i32, i32* %22
%202 = icmp sgt i32 %200, %201
br i1 %202, label %203, label %207
203: ; preds = %195
%204 = load i32, i32* %20
%205 = load i32, i32* %22
%206 = sub nsw i32 %204, %205
br label %208
207: ; preds = %195
br label %208
208: ; preds = %207, %203
%209 = phi i32 [ %206, %203 ], [ 0, %207 ]
store i32 %209, i32* %20
br label %308
210: ; preds = %114
%211 = load i32, i32* %14
%212 = icmp eq i32 %211, 2
br i1 %212, label %213, label %307
213: ; preds = %210
store i32 0, i32* %23
br label %214
214: ; preds = %241, %213
%215 = load i32, i32* %23
%216 = load i32, i32* %17
%217 = icmp slt i32 %215, %216
br i1 %217, label %218, label %244
218: ; preds = %214
%219 = load i8*, i8** %18
%220 = load i32, i32* %23
%221 = sext i32 %220 to i64
%222 = getelementptr inbounds i8, i8* %219, i64 %221
%223 = getelementptr inbounds i8, i8* %222, i64 1
%224 = load i8, i8* %223
%225 = zext i8 %224 to i32
%226 = shl i32 %225, 8
%227 = load i8*, i8** %18
%228 = load i32, i32* %23
%229 = sext i32 %228 to i64
%230 = getelementptr inbounds i8, i8* %227, i64 %229
%231 = load i8, i8* %230
%232 = zext i8 %231 to i32
%233 = or i32 %226, %232
%234 = trunc i32 %233 to i16
store i16 %234, i16* %26
%235 = load i16, i16* %26
%236 = call i32 @abs(i16 signext %235)
%237 = load i32, i32* %24
%238 = icmp sgt i32 %236, %237
br i1 %238, label %239, label %240
239: ; preds = %218
br label %244
240: ; preds = %218
br label %241
241: ; preds = %240
%242 = load i32, i32* %23
%243 = add nsw i32 %242, 2
store i32 %243, i32* %23
br label %214
244: ; preds = %239, %214
%245 = load i32, i32* %23
store i32 %245, i32* %19
%246 = load i32, i32* %19
%247 = load i32, i32* %21
%248 = mul nsw i32 2, %247
%249 = icmp sgt i32 %246, %248
br i1 %249, label %250, label %255
250: ; preds = %244
%251 = load i32, i32* %19
%252 = load i32, i32* %21
%253 = mul nsw i32 2, %252
%254 = sub nsw i32 %251, %253
br label %256
255: ; preds = %244
br label %256
256: ; preds = %255, %250
%257 = phi i32 [ %254, %250 ], [ 0, %255 ]
store i32 %257, i32* %19
%258 = load i32, i32* %17
%259 = sub nsw i32 %258, 2
store i32 %259, i32* %23
br label %260
260: ; preds = %287, %256
%261 = load i32, i32* %23
%262 = load i32, i32* %19
%263 = icmp sgt i32 %261, %262
br i1 %263, label %264, label %290
264: ; preds = %260
%265 = load i8*, i8** %18
%266 = load i32, i32* %23
%267 = sext i32 %266 to i64
%268 = getelementptr inbounds i8, i8* %265, i64 %267
%269 = getelementptr inbounds i8, i8* %268, i64 1
%270 = load i8, i8* %269
%271 = zext i8 %270 to i32
%272 = shl i32 %271, 8
%273 = load i8*, i8** %18
%274 = load i32, i32* %23
%275 = sext i32 %274 to i64
%276 = getelementptr inbounds i8, i8* %273, i64 %275
%277 = load i8, i8* %276
%278 = zext i8 %277 to i32
%279 = or i32 %272, %278
%280 = trunc i32 %279 to i16
store i16 %280, i16* %26
%281 = load i16, i16* %26
%282 = call i32 @abs(i16 signext %281)
%283 = load i32, i32* %24
%284 = icmp sgt i32 %282, %283
br i1 %284, label %285, label %286
285: ; preds = %264
br label %290
286: ; preds = %264
br label %287
287: ; preds = %286
%288 = load i32, i32* %23
%289 = sub nsw i32 %288, 2
store i32 %289, i32* %23
br label %260
290: ; preds = %285, %260
%291 = load i32, i32* %17
%292 = sub nsw i32 %291, 2
%293 = load i32, i32* %23
%294 = sub nsw i32 %292, %293
store i32 %294, i32* %20
%295 = load i32, i32* %20
%296 = load i32, i32* %22
%297 = mul nsw i32 2, %296
%298 = icmp sgt i32 %295, %297
br i1 %298, label %299, label %304
299: ; preds = %290
%300 = load i32, i32* %20
%301 = load i32, i32* %22
%302 = mul nsw i32 2, %301
%303 = sub nsw i32 %300, %302
br label %305
304: ; preds = %290
br label %305
305: ; preds = %304, %299
%306 = phi i32 [ %303, %299 ], [ 0, %304 ]
store i32 %306, i32* %20
br label %307
307: ; preds = %305, %210
br label %308
308: ; preds = %307, %208
%309 = load i8*, i8** %13
%310 = getelementptr inbounds i8, i8* %309, i64 4
%311 = load i8*, i8** %13
%312 = getelementptr inbounds i8, i8* %311, i64 4
%313 = call i32 @Read32(i8* %312)
%314 = load i32, i32* %19
%315 = sub nsw i32 %313, %314
%316 = load i32, i32* %20
%317 = sub nsw i32 %315, %316
%318 = call i32 @Write32(i8* %310, i32 %317)
%319 = load i8*, i8** %13
%320 = load i32, i32* %16
%321 = sext i32 %320 to i64
%322 = getelementptr inbounds i8, i8* %319, i64 %321
%323 = getelementptr inbounds i8, i8* %322, i64 -4
%324 = load i32, i32* %17
%325 = load i32, i32* %19
%326 = sub nsw i32 %324, %325
%327 = load i32, i32* %20
%328 = sub nsw i32 %326, %327
%329 = call i32 @Write32(i8* %323, i32 %328)
%330 = load i8*, i8** %6
%331 = call i32* @fopen(i8* %330, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %331, i32** %10
%332 = load i32*, i32** %10
%333 = icmp eq i32* %332, null
br i1 %333, label %334, label %341
334: ; preds = %308
%335 = load i8*, i8** %8
%336 = load i32, i32* %9
%337 = load i8*, i8** %6
%338 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %335, i32 %336, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %337)
%339 = load i8*, i8** %13
%340 = call i32 @free(i8* %339)
store i32 -1, i32* %5
br label %394
341: ; preds = %308
%342 = load i8*, i8** %13
%343 = load i32, i32* %16
%344 = load i32*, i32** %10
%345 = call i64 @fwrite(i8* %342, i32 1, i32 %343, i32* %344)
%346 = trunc i64 %345 to i32
%347 = load i32, i32* %16
%348 = icmp ne i32 %346, %347
br i1 %348, label %349, label %358
349: ; preds = %341
%350 = load i8*, i8** %8
%351 = load i32, i32* %9
%352 = load i8*, i8** %6
%353 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %350, i32 %351, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %352)
%354 = load i32*, i32** %10
%355 = call i32 @fclose(i32* %354)
%356 = load i8*, i8** %13
%357 = call i32 @free(i8* %356)
store i32 -1, i32* %5
br label %394
358: ; preds = %341
%359 = load i8*, i8** %13
%360 = load i32, i32* %16
%361 = sext i32 %360 to i64
%362 = getelementptr inbounds i8, i8* %359, i64 %361
%363 = load i32, i32* %19
%364 = sext i32 %363 to i64
%365 = getelementptr inbounds i8, i8* %362, i64 %364
%366 = load i32, i32* %17
%367 = load i32, i32* %19
%368 = sub nsw i32 %366, %367
%369 = load i32, i32* %20
%370 = sub nsw i32 %368, %369
%371 = load i32*, i32** %10
%372 = call i64 @fwrite(i8* %365, i32 1, i32 %370, i32* %371)
%373 = trunc i64 %372 to i32
%374 = load i32, i32* %17
%375 = load i32, i32* %19
%376 = sub nsw i32 %374, %375
%377 = load i32, i32* %20
%378 = sub nsw i32 %376, %377
%379 = icmp ne i32 %373, %378
br i1 %379, label %380, label %389
380: ; preds = %358
%381 = load i8*, i8** %8
%382 = load i32, i32* %9
%383 = load i8*, i8** %6
%384 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %381, i32 %382, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %383)
%385 = load i32*, i32** %10
%386 = call i32 @fclose(i32* %385)
%387 = load i8*, i8** %13
%388 = call i32 @free(i8* %387)
store i32 -1, i32* %5
br label %394
389: ; preds = %358
%390 = load i32*, i32** %10
%391 = call i32 @fclose(i32* %390)
%392 = load i8*, i8** %13
%393 = call i32 @free(i8* %392)
store i32 0, i32* %5
br label %394
394: ; preds = %389, %380, %349, %334, %108, %67, %50, %32
%395 = load i32, i32* %5
ret i32 %395
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [35 x i8] c"Error opening file %s for reading\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [47 x i8] c"Out of memory to allocate %ld bytes for file.\0A\00"
@.str.3 = [49 x i8] c"File read error, got only %ld bytes out of %ld.\0A\00"
@.str.4 = [26 x i8] c"No valid input WAV file?\0A\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [35 x i8] c"Error opening file %s for writing\0A\00"
@.str.7 = [30 x i8] c"Error writing file %s header\0A\00"
@.str.8 = [28 x i8] c"Error writing file %s data\0A\00"
define i32 @wavtrim(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %197
9: ; preds = %4
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %5, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %5)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %5, i32 0, i32 %13)
%15 = tail call i8* @malloc(i64 %12)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i64 %12)
%19 = tail call i32 @fclose(i32* %5)
br label %197
20: ; preds = %9
%21 = tail call i64 @fread(i8* %15, i32 1, i64 %12, i32* %5)
%22 = tail call i32 @fclose(i32* %5)
%23 = icmp eq i64 %21, %12
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i64 %21, i64 %12)
%26 = tail call i32 @free(i8* %15)
br label %197
27: ; preds = %20
%28 = getelementptr inbounds i8, i8* %15, i64 32
%29 = tail call i32 @Read16(i8* %28)
%30 = getelementptr inbounds i8, i8* %15, i64 16
%31 = tail call i32 @Read16(i8* %30)
%32 = add nsw i32 %31, 28
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %15, i64 %33
%35 = tail call i32 @Read32(i8* %15)
%36 = icmp eq i32 %35, 1179011410
br i1 %36, label %37, label %49
37: ; preds = %27
%38 = getelementptr inbounds i8, i8* %15, i64 8
%39 = tail call i32 @Read32(i8* %38)
%40 = icmp eq i32 %39, 1163280727
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = getelementptr inbounds i8, i8* %15, i64 12
%43 = tail call i32 @Read32(i8* %42)
%44 = icmp eq i32 %43, 544501094
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = getelementptr inbounds i8, i8* %34, i64 -8
%47 = tail call i32 @Read32(i8* %46)
%48 = icmp eq i32 %47, 1635017060
br i1 %48, label %52, label %49
49: ; preds = %45, %41, %37, %27
%50 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%51 = tail call i32 @free(i8* %15)
br label %197
52: ; preds = %45
%53 = getelementptr inbounds i8, i8* %34, i64 -4
%54 = tail call i32 @Read32(i8* %53)
%55 = getelementptr inbounds i8, i8* %15, i64 24
%56 = tail call i32 @Read32(i8* %55)
%57 = sdiv i32 %56, 100
switch i32 %29, label %161 [
i32 1, label %60
i32 2, label %58
]
58: ; preds = %52
%59 = icmp sgt i32 %54, 0
br i1 %59, label %107, label %126
60: ; preds = %52
%61 = ashr i32 %1, 8
%62 = icmp sgt i32 %54, 0
br i1 %62, label %63, label %78
63: ; preds = %60
%64 = zext i32 %54 to i64
br label %65
65: ; preds = %63, %73
%66 = phi i64 [ 0, %63 ], [ %74, %73 ]
%67 = getelementptr inbounds i8, i8* %34, i64 %66
%68 = load i8, i8* %67
%69 = xor i8 %68, -128
%70 = sext i8 %69 to i16
%71 = tail call i32 @abs(i16 signext %70)
%72 = icmp sgt i32 %71, %61
br i1 %72, label %76, label %73
73: ; preds = %65
%74 = add nuw nsw i64 %66, 1
%75 = icmp eq i64 %74, %64
br i1 %75, label %78, label %65
76: ; preds = %65
%77 = trunc i64 %66 to i32
br label %78
78: ; preds = %73, %76, %60
%79 = phi i32 [ 0, %60 ], [ %77, %76 ], [ %54, %73 ]
%80 = icmp sgt i32 %79, %57
%81 = sub nsw i32 %79, %57
%82 = select i1 %80, i32 %81, i32 0
%83 = add i32 %54, -1
%84 = icmp sgt i32 %83, %82
br i1 %84, label %85, label %101
85: ; preds = %78
%86 = sext i32 %83 to i64
%87 = zext i32 %82 to i64
br label %88
88: ; preds = %85, %96
%89 = phi i64 [ %86, %85 ], [ %97, %96 ]
%90 = getelementptr inbounds i8, i8* %34, i64 %89
%91 = load i8, i8* %90
%92 = xor i8 %91, -128
%93 = sext i8 %92 to i16
%94 = tail call i32 @abs(i16 signext %93)
%95 = icmp sgt i32 %94, %61
br i1 %95, label %99, label %96
96: ; preds = %88
%97 = add nsw i64 %89, -1
%98 = icmp sgt i64 %97, %87
br i1 %98, label %88, label %101
99: ; preds = %88
%100 = trunc i64 %89 to i32
br label %101
101: ; preds = %96, %99, %78
%102 = phi i32 [ %83, %78 ], [ %100, %99 ], [ %82, %96 ]
%103 = sub nsw i32 %83, %102
%104 = icmp sgt i32 %103, %57
%105 = sub nsw i32 %103, %57
%106 = select i1 %104, i32 %105, i32 0
br label %161
107: ; preds = %58, %119
%108 = phi i64 [ %120, %119 ], [ 0, %58 ]
%109 = getelementptr inbounds i8, i8* %34, i64 %108
%110 = getelementptr inbounds i8, i8* %109, i64 1
%111 = load i8, i8* %110
%112 = zext i8 %111 to i16
%113 = shl nuw i16 %112, 8
%114 = load i8, i8* %109
%115 = zext i8 %114 to i16
%116 = or i16 %113, %115
%117 = tail call i32 @abs(i16 signext %116)
%118 = icmp sgt i32 %117, %1
br i1 %118, label %123, label %119
119: ; preds = %107
%120 = add nuw i64 %108, 2
%121 = trunc i64 %120 to i32
%122 = icmp sgt i32 %54, %121
br i1 %122, label %107, label %123
123: ; preds = %119, %107
%124 = phi i64 [ %108, %107 ], [ %120, %119 ]
%125 = trunc i64 %124 to i32
br label %126
126: ; preds = %123, %58
%127 = phi i32 [ 0, %58 ], [ %125, %123 ]
%128 = shl nsw i32 %57, 1
%129 = icmp sgt i32 %127, %128
%130 = sub nsw i32 %127, %128
%131 = select i1 %129, i32 %130, i32 0
%132 = add i32 %54, -2
%133 = icmp sgt i32 %132, %131
br i1 %133, label %134, label %155
134: ; preds = %126
%135 = sext i32 %132 to i64
%136 = zext i32 %131 to i64
br label %137
137: ; preds = %134, %149
%138 = phi i64 [ %135, %134 ], [ %150, %149 ]
%139 = getelementptr inbounds i8, i8* %34, i64 %138
%140 = getelementptr inbounds i8, i8* %139, i64 1
%141 = load i8, i8* %140
%142 = zext i8 %141 to i16
%143 = shl nuw i16 %142, 8
%144 = load i8, i8* %139
%145 = zext i8 %144 to i16
%146 = or i16 %143, %145
%147 = tail call i32 @abs(i16 signext %146)
%148 = icmp sgt i32 %147, %1
br i1 %148, label %152, label %149
149: ; preds = %137
%150 = add i64 %138, -2
%151 = icmp sgt i64 %150, %136
br i1 %151, label %137, label %152
152: ; preds = %137, %149
%153 = phi i64 [ %150, %149 ], [ %138, %137 ]
%154 = trunc i64 %153 to i32
br label %155
155: ; preds = %152, %126
%156 = phi i32 [ %132, %126 ], [ %154, %152 ]
%157 = sub nsw i32 %132, %156
%158 = icmp sgt i32 %157, %128
%159 = sub nsw i32 %157, %128
%160 = select i1 %158, i32 %159, i32 0
br label %161
161: ; preds = %52, %155, %101
%162 = phi i32 [ %82, %101 ], [ %131, %155 ], [ 0, %52 ]
%163 = phi i32 [ %106, %101 ], [ %160, %155 ], [ 0, %52 ]
%164 = getelementptr inbounds i8, i8* %15, i64 4
%165 = tail call i32 @Read32(i8* %164)
%166 = add nuw i32 %163, %162
%167 = sub i32 %165, %166
%168 = tail call i32 @Write32(i8* %164, i32 %167)
%169 = sub i32 %54, %166
%170 = tail call i32 @Write32(i8* %53, i32 %169)
%171 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%172 = icmp eq i32* %171, null
br i1 %172, label %173, label %176
173: ; preds = %161
%174 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%175 = tail call i32 @free(i8* %15)
br label %197
176: ; preds = %161
%177 = tail call i64 @fwrite(i8* %15, i32 1, i32 %32, i32* %171)
%178 = trunc i64 %177 to i32
%179 = icmp eq i32 %32, %178
br i1 %179, label %184, label %180
180: ; preds = %176
%181 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%182 = tail call i32 @fclose(i32* %171)
%183 = tail call i32 @free(i8* %15)
br label %197
184: ; preds = %176
%185 = zext i32 %162 to i64
%186 = getelementptr inbounds i8, i8* %34, i64 %185
%187 = tail call i64 @fwrite(i8* %186, i32 1, i32 %169, i32* %171)
%188 = trunc i64 %187 to i32
%189 = icmp eq i32 %169, %188
br i1 %189, label %194, label %190
190: ; preds = %184
%191 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %0)
%192 = tail call i32 @fclose(i32* %171)
%193 = tail call i32 @free(i8* %15)
br label %197
194: ; preds = %184
%195 = tail call i32 @fclose(i32* %171)
%196 = tail call i32 @free(i8* %15)
br label %197
197: ; preds = %194, %190, %180, %173, %49, %24, %17, %7
%198 = phi i32 [ -1, %7 ], [ -1, %17 ], [ -1, %24 ], [ -1, %49 ], [ -1, %173 ], [ -1, %180 ], [ -1, %190 ], [ 0, %194 ]
ret i32 %198
}