#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 long atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
double nextSample(int /*<<< orphan*/ *, int, short);
int /*<<< orphan*/ printf(char *, ...);
char round(double);
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  char prefix[4];
  char fileFormat[4];
  char ckID[4];
  unsigned long nChunkSize;
  short wFormatTag;
  short nChannels;
  unsigned long nSamplesPerSecond;
  unsigned long nBytesPerSecond;
  unsigned long nOutputSamplesPerSecond;
  short nBlockAlign;
  short nBitsPerSample;
  int i, j;
  if (argc < 3) {
    printf("Usage: wav2raw sourceWavFile destRawFile <outRate>\n");
    printf("Output rate is given in Hand should be <= to the input sample "
           "sample.\n");
    printf("Success returns errorlevel 0. Error return greater than zero.\n");
    printf("\n");
    printf("Ex: wav2raw input.wav output.raw 11025\n");
    exit(1);
  }
  if ((infile = fopen(argv[1], "rb")) == NULL) {
    printf("The source file %s was not opened\n", argv[1]);
    exit(2);
  }
  if (argc > 3)
    nOutputSamplesPerSecond = atoi(argv[3]);
  else
    nOutputSamplesPerSecond = 0;
  fscanf(infile, "%4s", prefix);
  fscanf(infile, "%4c", &nChunkSize);
  fscanf(infile, "%4c", fileFormat);
  fscanf(infile, "%4c", ckID);
  fscanf(infile, "%4c", &nChunkSize);
  fscanf(infile, "%2c", &wFormatTag);
  fscanf(infile, "%2c", &nChannels);
  fscanf(infile, "%4c", &nSamplesPerSecond);
  fscanf(infile, "%4c", &nBytesPerSecond);
  fscanf(infile, "%2c", &nBlockAlign);
  fscanf(infile, "%2c", &nBitsPerSample);
  for (i = 0; i < nChunkSize - 0x10; i++)
    fscanf(infile, "%1c", &j);
  fscanf(infile, "%4c", ckID);
  fscanf(infile, "%4c", &nChunkSize);
  if (nOutputSamplesPerSecond == 0)
    nOutputSamplesPerSecond = nSamplesPerSecond;
  if (nSamplesPerSecond < nOutputSamplesPerSecond) {
    printf("Output rate (%ld) cannot be above input rate (%ld)\n",
           nOutputSamplesPerSecond, nSamplesPerSecond);
    printf("Use lower output rate value or higher input rate file\n");
    exit(4);
  }
  if ((outfile = fopen(argv[2], "w")) == NULL) {
    printf("The output file %s was not opened\n", argv[2]);
    exit(3);
  }
  int nBytesPerSample = nBitsPerSample / 8;
  int size = nChunkSize / (nChannels * nBytesPerSample);
  double offset;
  double step;
  double value;
  double lastSample;
  step = nSamplesPerSecond;
  step /= nOutputSamplesPerSecond;
  value = 0;
  lastSample = 0;
  for (offset = 0; offset < size; offset += step) {
    char byte;
    double sample = 0;
    if (value < 0)
      sample += lastSample * -value;
    value += step;
    while (value > 0) {
      lastSample = nextSample(infile, nBytesPerSample, nChannels);
      if (value >= 1)
        sample += lastSample;
      else
        sample += lastSample * value;
      value--;
    }
    sample /= step;
    byte = round(sample);
    fwrite(&byte, 1, 1, outfile);
  }
  fclose(infile);
  fclose(outfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1203 <main+0x73>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xef8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf00(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1245 <main+0xb5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jle    1265 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x58(%rbp)
jmp    126d <main+0xdd>
movq   $0x0,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rdx
lea    0xebc(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xeae(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rdx
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rdx
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe6c(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe5a(%rip),%rsi
lea    -0x3a(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe44(%rip),%rsi
lea    -0x3c(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe2a(%rip),%rsi
lea    -0x48(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe14(%rip),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe02(%rip),%rsi
lea    -0x5a(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdec(%rip),%rsi
lea    -0x5c(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
movl   $0x0,-0x60(%rbp)
movslq -0x60(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    $0x10,%rcx
cmp    %rcx,%rax
jae    139f <main+0x20f>
mov    -0x18(%rbp),%rdi
lea    0xdbe(%rip),%rsi
lea    -0x64(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1366 <main+0x1d6>
mov    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rdx
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xd7c(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
cmpq   $0x0,-0x58(%rbp)
jne    13de <main+0x24e>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x58(%rbp),%rax
jae    141a <main+0x28a>
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    145c <main+0x2cc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
movswl -0x5c(%rbp),%eax
mov    %eax,%ecx
add    $0x7,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
sar    $0x3,%eax
mov    %eax,-0x68(%rbp)
mov    -0x38(%rbp),%rax
movswl -0x3c(%rbp),%ecx
mov    -0x68(%rbp),%edx
imul   %edx,%ecx
movslq %ecx,%rcx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x6c(%rbp)
movq   -0x48(%rbp),%xmm1
movaps 0xb6b(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xb6f(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm3
unpckhpd %xmm1,%xmm1
addsd  %xmm3,%xmm1
movsd  %xmm1,-0x80(%rbp)
movq   -0x58(%rbp),%xmm1
punpckldq %xmm2,%xmm1
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm1
cvtsi2sdl -0x6c(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    167d <main+0x4ed>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
xorps  %xmm0,%xmm0
ucomisd -0x88(%rbp),%xmm0
ff
jbe    1568 <main+0x3d8>
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x88(%rbp),%xmm1
ff
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
movsd  -0xa0(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
addsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1626 <main+0x496>
mov    -0x18(%rbp),%rdi
mov    -0x68(%rbp),%esi
movswl -0x3c(%rbp),%edx
call   1030 <nextSample@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  0xa66(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     15e1 <main+0x451>
movsd  -0x90(%rbp),%xmm0
ff
addsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0xa0(%rbp)
ff
jmp    1609 <main+0x479>
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x88(%rbp),%xmm2
ff
movsd  -0xa0(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  0xa17(%rip),%xmm0
addsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x88(%rbp)
ff
jmp    157d <main+0x3ed>
movsd  -0x80(%rbp),%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0xa0(%rbp),%xmm0
ff
call   1080 <round@plt>
mov    %al,-0x91(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x91(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10b0 <fwrite@plt>
movsd  -0x80(%rbp),%xmm0
addsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    14f9 <main+0x369>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
cmp    $0x2,%edi
jle    1562 <main+0x3b2>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     15a6 <main+0x3f6>
mov    %rax,%rbx
cmp    $0x4,%ebp
jb     11fb <main+0x4b>
mov    0x18(%r15),%rdi
call   10c0 <atoi@plt>
mov    %rax,%r14
jmp    11fe <main+0x4e>
xor    %r14d,%r14d
lea    0xe51(%rip),%rsi
lea    0x5c(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0xe3f(%rip),%rbp
lea    0x8(%rsp),%r12
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0x58(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0x14(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0xdf3(%rip),%r12
lea    0x12(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0x18(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0x70(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0x6(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
cmpq   $0x10,0x8(%rsp)
je     1312 <main+0x162>
lea    0xd7c(%rip),%r12
lea    0x54(%rsp),%r13
xor    %ebp,%ebp
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1080 <fscanf@plt>
add    $0x1,%rbp
mov    0x8(%rsp),%rax
add    $0xfffffffffffffff0,%rax
cmp    %rbp,%rax
ja     12f0 <main+0x140>
lea    0xd41(%rip),%rbp
lea    0x14(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <fscanf@plt>
test   %r14,%r14
mov    0x18(%rsp),%rdx
cmove  %rdx,%r14
cmp    %r14,%rdx
jb     15c2 <main+0x412>
mov    0x10(%r15),%rdi
lea    0xd3d(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     15e9 <main+0x439>
mov    %rax,%r12
movzwl 0x6(%rsp),%eax
lea    0x7(%rax),%ecx
test   %ax,%ax
cmovns %eax,%ecx
movswl %cx,%ebp
sar    $0x3,%ebp
mov    0x8(%rsp),%rax
movswq 0x4(%rsp),%rdx
movslq %ebp,%rcx
imul   %rdx,%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     13ae <main+0x1fe>
xor    %edx,%edx
div    %rcx
test   %eax,%eax
jg     13ba <main+0x20a>
jmp    1541 <main+0x391>
xor    %edx,%edx
div    %ecx
test   %eax,%eax
jle    1541 <main+0x391>
movsd  0x18(%rsp),%xmm0
movapd 0xc38(%rip),%xmm1
unpcklps %xmm1,%xmm0
movapd 0xc3d(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
movq   %r14,%xmm0
punpckldq %xmm1,%xmm0
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x40(%rsp)
xorpd  %xmm2,%xmm2
xorpd  %xmm4,%xmm4
xorpd  %xmm6,%xmm6
xorpd  %xmm1,%xmm1
movapd %xmm3,0x60(%rsp)
jmp    1484 <main+0x2d4>
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm5,0x30(%rsp)
movsd  %xmm4,0x20(%rsp)
divsd  %xmm3,%xmm6
movapd %xmm6,%xmm0
call   10b0 <round@plt>
movsbl %al,%edi
mov    %r12,%rsi
call   1090 <fputc@plt>
movapd 0x60(%rsp),%xmm3
movsd  0x48(%rsp),%xmm1
addsd  %xmm3,%xmm1
movsd  0x40(%rsp),%xmm0
ucomisd %xmm1,%xmm0
movapd 0x30(%rsp),%xmm6
xorpd  %xmm2,%xmm2
movsd  0x20(%rsp),%xmm4
jbe    1541 <main+0x391>
movsd  %xmm1,0x48(%rsp)
movapd %xmm4,%xmm0
mulsd  %xmm6,%xmm0
xorpd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm3,%xmm5
addsd  %xmm6,%xmm5
cmpltsd %xmm2,%xmm6
andpd  %xmm1,%xmm6
ucomisd %xmm2,%xmm5
jbe    1430 <main+0x280>
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm6,0x20(%rsp)
movapd %xmm5,0x30(%rsp)
movswl 0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <nextSample@plt>
movapd 0x30(%rsp),%xmm5
movapd %xmm0,%xmm3
mulsd  %xmm5,%xmm3
movapd 0x20(%rsp),%xmm1
addsd  %xmm1,%xmm3
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm4
movsd  0xb1d(%rip),%xmm6
cmpnlesd %xmm5,%xmm6
movapd %xmm6,%xmm2
andnpd %xmm1,%xmm2
andpd  %xmm3,%xmm6
orpd   %xmm2,%xmm6
xorpd  %xmm2,%xmm2
addsd  0xb04(%rip),%xmm5
ucomisd %xmm2,%xmm5
ja     14c0 <main+0x310>
movapd %xmm5,0x30(%rsp)
movsd  %xmm0,0x20(%rsp)
movapd 0x60(%rsp),%xmm3
jmp    143c <main+0x28c>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb8c(%rip),%rdi
call   1040 <puts@plt>
lea    0xbb3(%rip),%rdi
call   1040 <puts@plt>
lea    0xbed(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xc15(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x8(%r15),%rsi
lea    0xa82(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
lea    0xa9d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xae5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x4,%edi
call   10d0 <exit@plt>
mov    0x10(%r15),%rsi
lea    0xaa8(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"Usage: wav2raw sourceWavFile destRawFile <outRate>\0A\00"
@.str.1 = [71 x i8] c"Output rate is given in Hand should be <= to the input sample sample.\0A\00"
@.str.2 = [63 x i8] c"Success returns errorlevel 0. Error return greater than zero.\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [40 x i8] c"Ex: wav2raw input.wav output.raw 11025\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [35 x i8] c"The source file %s was not opened\0A\00"
@.str.7 = [4 x i8] c"%4s\00"
@.str.8 = [4 x i8] c"%4c\00"
@.str.9 = [4 x i8] c"%2c\00"
@.str.10 = [4 x i8] c"%1c\00"
@.str.11 = [52 x i8] c"Output rate (%ld) cannot be above input rate (%ld)\0A\00"
@.str.12 = [55 x i8] c"Use lower output rate value or higher input rate file\0A\00"
@.str.13 = [2 x i8] c"w\00"
@.str.14 = [35 x i8] c"The output file %s was not opened\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [4 x i8]
%9 = alloca [4 x i8]
%10 = alloca [4 x i8]
%11 = alloca i64
%12 = alloca i16
%13 = alloca i16
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i16
%18 = alloca i16
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca i8
%28 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %38
31: ; preds = %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %2
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %42, i32** %6
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %50
44: ; preds = %38
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %47)
%49 = call i32 @exit(i32 2)
unreachable
50: ; preds = %38
%51 = load i32, i32* %4
%52 = icmp sgt i32 %51, 3
br i1 %52, label %53, label %58
53: ; preds = %50
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = call i64 @atoi(i8* %56)
store i64 %57, i64* %16
br label %59
58: ; preds = %50
store i64 0, i64* %16
br label %59
59: ; preds = %58, %53
%60 = load i32*, i32** %6
%61 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%62 = call i32 (i32*, i8*, ...) @fscanf(i32* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %61)
%63 = load i32*, i32** %6
%64 = call i32 (i32*, i8*, ...) @fscanf(i32* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %11)
%65 = load i32*, i32** %6
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%67 = call i32 (i32*, i8*, ...) @fscanf(i32* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %66)
%68 = load i32*, i32** %6
%69 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%70 = call i32 (i32*, i8*, ...) @fscanf(i32* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %69)
%71 = load i32*, i32** %6
%72 = call i32 (i32*, i8*, ...) @fscanf(i32* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %11)
%73 = load i32*, i32** %6
%74 = call i32 (i32*, i8*, ...) @fscanf(i32* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i16* %12)
%75 = load i32*, i32** %6
%76 = call i32 (i32*, i8*, ...) @fscanf(i32* %75, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i16* %13)
%77 = load i32*, i32** %6
%78 = call i32 (i32*, i8*, ...) @fscanf(i32* %77, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %14)
%79 = load i32*, i32** %6
%80 = call i32 (i32*, i8*, ...) @fscanf(i32* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %15)
%81 = load i32*, i32** %6
%82 = call i32 (i32*, i8*, ...) @fscanf(i32* %81, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i16* %17)
%83 = load i32*, i32** %6
%84 = call i32 (i32*, i8*, ...) @fscanf(i32* %83, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i16* %18)
store i32 0, i32* %19
br label %85
85: ; preds = %94, %59
%86 = load i32, i32* %19
%87 = sext i32 %86 to i64
%88 = load i64, i64* %11
%89 = sub i64 %88, 16
%90 = icmp ult i64 %87, %89
br i1 %90, label %91, label %97
91: ; preds = %85
%92 = load i32*, i32** %6
%93 = call i32 (i32*, i8*, ...) @fscanf(i32* %92, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32* %20)
br label %94
94: ; preds = %91
%95 = load i32, i32* %19
%96 = add nsw i32 %95, 1
store i32 %96, i32* %19
br label %85
97: ; preds = %85
%98 = load i32*, i32** %6
%99 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%100 = call i32 (i32*, i8*, ...) @fscanf(i32* %98, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %99)
%101 = load i32*, i32** %6
%102 = call i32 (i32*, i8*, ...) @fscanf(i32* %101, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %11)
%103 = load i64, i64* %16
%104 = icmp eq i64 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %97
%106 = load i64, i64* %14
store i64 %106, i64* %16
br label %107
107: ; preds = %105, %97
%108 = load i64, i64* %14
%109 = load i64, i64* %16
%110 = icmp ult i64 %108, %109
br i1 %110, label %111, label %117
111: ; preds = %107
%112 = load i64, i64* %16
%113 = load i64, i64* %14
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0), i64 %112, i64 %113)
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.12, i64 0, i64 0))
%116 = call i32 @exit(i32 4)
unreachable
117: ; preds = %107
%118 = load i8**, i8*** %5
%119 = getelementptr inbounds i8*, i8** %118, i64 2
%120 = load i8*, i8** %119
%121 = call i32* @fopen(i8* %120, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
store i32* %121, i32** %7
%122 = icmp eq i32* %121, null
br i1 %122, label %123, label %129
123: ; preds = %117
%124 = load i8**, i8*** %5
%125 = getelementptr inbounds i8*, i8** %124, i64 2
%126 = load i8*, i8** %125
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %126)
%128 = call i32 @exit(i32 3)
unreachable
129: ; preds = %117
%130 = load i16, i16* %18
%131 = sext i16 %130 to i32
%132 = sdiv i32 %131, 8
store i32 %132, i32* %21
%133 = load i64, i64* %11
%134 = load i16, i16* %13
%135 = sext i16 %134 to i32
%136 = load i32, i32* %21
%137 = mul nsw i32 %135, %136
%138 = sext i32 %137 to i64
%139 = udiv i64 %133, %138
%140 = trunc i64 %139 to i32
store i32 %140, i32* %22
%141 = load i64, i64* %14
%142 = uitofp i64 %141 to double
store double %142, double* %24
%143 = load i64, i64* %16
%144 = uitofp i64 %143 to double
%145 = load double, double* %24
%146 = fdiv double %145, %144
store double %146, double* %24
store double 0.000000e+00, double* %25
store double 0.000000e+00, double* %26
store double 0.000000e+00, double* %23
br label %147
147: ; preds = %195, %129
%148 = load double, double* %23
%149 = load i32, i32* %22
%150 = sitofp i32 %149 to double
%151 = fcmp olt double %148, %150
br i1 %151, label %152, label %199
152: ; preds = %147
store double 0.000000e+00, double* %28
%153 = load double, double* %25
%154 = fcmp olt double %153, 0.000000e+00
br i1 %154, label %155, label %161
155: ; preds = %152
%156 = load double, double* %26
%157 = load double, double* %25
%158 = fneg double %157
%159 = load double, double* %28
%160 = call double @llvm.fmuladd.f64(double %156, double %158, double %159)
store double %160, double* %28
br label %161
161: ; preds = %155, %152
%162 = load double, double* %24
%163 = load double, double* %25
%164 = fadd double %163, %162
store double %164, double* %25
br label %165
165: ; preds = %184, %161
%166 = load double, double* %25
%167 = fcmp ogt double %166, 0.000000e+00
br i1 %167, label %168, label %187
168: ; preds = %165
%169 = load i32*, i32** %6
%170 = load i32, i32* %21
%171 = load i16, i16* %13
%172 = call double @nextSample(i32* %169, i32 %170, i16 signext %171)
store double %172, double* %26
%173 = load double, double* %25
%174 = fcmp oge double %173, 1.000000e+00
br i1 %174, label %175, label %179
175: ; preds = %168
%176 = load double, double* %26
%177 = load double, double* %28
%178 = fadd double %177, %176
store double %178, double* %28
br label %184
179: ; preds = %168
%180 = load double, double* %26
%181 = load double, double* %25
%182 = load double, double* %28
%183 = call double @llvm.fmuladd.f64(double %180, double %181, double %182)
store double %183, double* %28
br label %184
184: ; preds = %179, %175
%185 = load double, double* %25
%186 = fadd double %185, -1.000000e+00
store double %186, double* %25
br label %165
187: ; preds = %165
%188 = load double, double* %24
%189 = load double, double* %28
%190 = fdiv double %189, %188
store double %190, double* %28
%191 = load double, double* %28
%192 = call signext i8 @round(double %191)
store i8 %192, i8* %27
%193 = load i32*, i32** %7
%194 = call i32 @fwrite(i8* %27, i32 1, i32 1, i32* %193)
br label %195
195: ; preds = %187
%196 = load double, double* %24
%197 = load double, double* %23
%198 = fadd double %197, %196
store double %198, double* %23
br label %147
199: ; preds = %147
%200 = load i32*, i32** %6
%201 = call i32 @fclose(i32* %200)
%202 = load i32*, i32** %7
%203 = call i32 @fclose(i32* %202)
ret i32 0
}

LLVM IR (-O2):
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [35 x i8] c"The source file %s was not opened\0A\00"
@.str.7 = [4 x i8] c"%4s\00"
@.str.8 = [4 x i8] c"%4c\00"
@.str.9 = [4 x i8] c"%2c\00"
@.str.10 = [4 x i8] c"%1c\00"
@.str.11 = [52 x i8] c"Output rate (%ld) cannot be above input rate (%ld)\0A\00"
@.str.13 = [2 x i8] c"w\00"
@.str.14 = [35 x i8] c"The output file %s was not opened\0A\00"
@str = [54 x i8] c"Use lower output rate value or higher input rate file\00"
@str.15 = [51 x i8] c"Usage: wav2raw sourceWavFile destRawFile <outRate>\00"
@str.16 = [70 x i8] c"Output rate is given in Hand should be <= to the input sample sample.\00"
@str.17 = [62 x i8] c"Success returns errorlevel 0. Error return greater than zero.\00"
@str.18 = [39 x i8] c"Ex: wav2raw input.wav output.raw 11025\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = alloca [4 x i8]
%5 = alloca [4 x i8]
%6 = alloca i64
%7 = alloca i16
%8 = alloca i16
%9 = alloca i64
%10 = alloca i64
%11 = alloca i16
%12 = alloca i16
%13 = alloca i32
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%17 = bitcast i64* %6 to i8*
%18 = bitcast i16* %7 to i8*
%19 = bitcast i16* %8 to i8*
%20 = bitcast i64* %9 to i8*
%21 = bitcast i64* %10 to i8*
%22 = bitcast i16* %11 to i8*
%23 = bitcast i16* %12 to i8*
%24 = bitcast i32* %13 to i8*
%25 = icmp slt i32 %0, 3
br i1 %25, label %26, label %33
26: ; preds = %2
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.15, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.16, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.17, i64 0, i64 0))
%30 = tail call i32 @putchar(i32 10)
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.18, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %2
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = tail call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i8*, i8** %34
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%41 = tail call i32 @exit(i32 2)
unreachable
42: ; preds = %33
%43 = icmp ugt i32 %0, 3
br i1 %43, label %44, label %48
44: ; preds = %42
%45 = getelementptr inbounds i8*, i8** %1, i64 3
%46 = load i8*, i8** %45
%47 = tail call i64 @atoi(i8* %46)
br label %48
48: ; preds = %42, %44
%49 = phi i64 [ %47, %44 ], [ 0, %42 ]
%50 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %14)
%51 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %6)
%52 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %15)
%53 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %16)
%54 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %6)
%55 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i16* %7)
%56 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i16* %8)
%57 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %9)
%58 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %10)
%59 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i16* %11)
%60 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i16* %12)
%61 = load i64, i64* %6
%62 = icmp eq i64 %61, 16
br i1 %62, label %70, label %63
63: ; preds = %48, %63
%64 = phi i64 [ %66, %63 ], [ 0, %48 ]
%65 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32* %13)
%66 = add nuw i64 %64, 1
%67 = load i64, i64* %6
%68 = add i64 %67, -16
%69 = icmp ugt i64 %68, %66
br i1 %69, label %63, label %70
70: ; preds = %63, %48
%71 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %16)
%72 = call i32 (i32*, i8*, ...) @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %6)
%73 = icmp eq i64 %49, 0
%74 = load i64, i64* %9
%75 = select i1 %73, i64 %74, i64 %49
%76 = icmp ult i64 %74, %75
br i1 %76, label %77, label %81
77: ; preds = %70
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0), i64 %75, i64 %74)
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
%80 = call i32 @exit(i32 4)
unreachable
81: ; preds = %70
%82 = getelementptr inbounds i8*, i8** %1, i64 2
%83 = load i8*, i8** %82
%84 = call i32* @fopen(i8* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %90
86: ; preds = %81
%87 = load i8*, i8** %82
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %87)
%89 = call i32 @exit(i32 3)
unreachable
90: ; preds = %81
%91 = load i16, i16* %12
%92 = sdiv i16 %91, 8
%93 = sext i16 %92 to i32
%94 = load i64, i64* %6
%95 = load i16, i16* %8
%96 = sext i16 %95 to i32
%97 = mul nsw i32 %96, %93
%98 = sext i32 %97 to i64
%99 = udiv i64 %94, %98
%100 = trunc i64 %99 to i32
%101 = load i64, i64* %9
%102 = uitofp i64 %101 to double
%103 = uitofp i64 %75 to double
%104 = fdiv double %102, %103
%105 = sitofp i32 %100 to double
%106 = icmp sgt i32 %100, 0
br i1 %106, label %107, label %138
107: ; preds = %90, %128
%108 = phi double [ %130, %128 ], [ 0.000000e+00, %90 ]
%109 = phi double [ %129, %128 ], [ 0.000000e+00, %90 ]
%110 = phi double [ %136, %128 ], [ 0.000000e+00, %90 ]
%111 = fcmp olt double %109, 0.000000e+00
%112 = fneg double %109
%113 = call double @llvm.fmuladd.f64(double %108, double %112, double 0.000000e+00)
%114 = select i1 %111, double %113, double 0.000000e+00
%115 = fadd double %104, %109
%116 = fcmp ogt double %115, 0.000000e+00
br i1 %116, label %117, label %128
117: ; preds = %107, %117
%118 = phi double [ %125, %117 ], [ %114, %107 ]
%119 = phi double [ %126, %117 ], [ %115, %107 ]
%120 = load i16, i16* %8
%121 = call double @nextSample(i32* %36, i32 %93, i16 signext %120)
%122 = fcmp ult double %119, 1.000000e+00
%123 = fadd double %118, %121
%124 = call double @llvm.fmuladd.f64(double %121, double %119, double %118)
%125 = select i1 %122, double %124, double %123
%126 = fadd double %119, -1.000000e+00
%127 = fcmp ogt double %126, 0.000000e+00
br i1 %127, label %117, label %128
128: ; preds = %117, %107
%129 = phi double [ %115, %107 ], [ %126, %117 ]
%130 = phi double [ %108, %107 ], [ %121, %117 ]
%131 = phi double [ %114, %107 ], [ %125, %117 ]
%132 = fdiv double %131, %104
%133 = call signext i8 @round(double %132)
%134 = sext i8 %133 to i32
%135 = call i32 @fputc(i32 %134, i32* %84)
%136 = fadd double %104, %110
%137 = fcmp olt double %136, %105
br i1 %137, label %107, label %138
138: ; preds = %128, %90
%139 = call i32 @fclose(i32* %36)
%140 = call i32 @fclose(i32* %84)
ret i32 0
}