#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 */

/* Variables and functions */
int AFMT_S16_LE;
int AFMT_U8;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SNDCTL_DSP_SETFMT;
int /*<<< orphan*/ SNDCTL_DSP_SPEED;
int /*<<< orphan*/ SNDCTL_DSP_STEREO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ftruncate(int, int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int RecWavDesc(char *sFilename, int hAudio, unsigned dSeconds,
               unsigned short dChannels, unsigned ldSamplesPerSec,
               unsigned short dBitsPerSample, unsigned dOptions) {
  int hFilename = 0;
  int dRequest;
  char cBuffer[8192];
  unsigned dBytesPerSec, dBytesPerSample = 0;
  unsigned dBufferWrites;
  unsigned dTotalSampleBytes;
  unsigned dTotalWavSize;
  unsigned i;
  unsigned short dFormatTag = 0x0001;
  unsigned short dBlockAlign;
  if (dFormatTag != 0x0001) {
    return -1;
  }
  if (dFormatTag == 0x0001) {
    switch (dBitsPerSample) {
    case 8:
      dRequest = AFMT_U8;
      ioctl(hAudio, SNDCTL_DSP_SETFMT, &dRequest);
      if (dRequest != AFMT_U8) {
        close(hFilename);
        return -1;
      }
      break;
    case 16:
      dRequest = AFMT_S16_LE;
      ioctl(hAudio, SNDCTL_DSP_SETFMT, &dRequest);
      if (dRequest != AFMT_S16_LE) {
        close(hFilename);
        return -1;
      }
      break;
    default:
      close(hFilename);
      return -1;
      break;
    }
  } else {
    close(hFilename);
    return -1;
  }
  if (dChannels > 0 && dChannels < 3) {
    dRequest = dChannels - 1;
    ioctl(hAudio, SNDCTL_DSP_STEREO, &dRequest);
    if (dRequest != dChannels - 1) {
      close(hFilename);
      return -1;
    }
  } else {
    close(hFilename);
    return -1;
  }
  dRequest = (int)ldSamplesPerSec;
  ioctl(hAudio, SNDCTL_DSP_SPEED, &dRequest);
  if ((dOptions & 0x40000000) != 0) {
    return 0;
  }
  if (dBitsPerSample <= 8) {
    dBytesPerSample = 1;
  }
  if (dBitsPerSample > 8 && dBitsPerSample <= 16) {
    dBytesPerSample = 2;
  }
  if (dBitsPerSample > 16) {
    dBytesPerSample = 3;
  }
  dBlockAlign = dBytesPerSample * dChannels;
  dBytesPerSec = ldSamplesPerSec * dBytesPerSample * dChannels;
  dTotalSampleBytes = dBytesPerSec * dSeconds;
  dBufferWrites = dTotalSampleBytes / 8192 + 1;
  dTotalSampleBytes = dBufferWrites * 8192;
  dTotalWavSize = dTotalSampleBytes + 36;
  hFilename = open(sFilename, O_WRONLY | O_CREAT, 0644);
  if (hFilename < 0) {
    perror("open");
    return -1;
  }
  strcpy(cBuffer, "RIFF");
  write(hFilename, cBuffer, 4);
  cBuffer[0] = dTotalWavSize & 0x000000FF;
  cBuffer[1] = (dTotalWavSize & 0x0000FF00) >> 8;
  cBuffer[2] = (dTotalWavSize & 0x00FF0000) >> 16;
  cBuffer[3] = (dTotalWavSize & 0xFF000000) >> 24;
  write(hFilename, cBuffer, 4);
  strcpy(cBuffer, "WAVE");
  write(hFilename, cBuffer, 4);
  strcpy(cBuffer, "fmt ");
  write(hFilename, cBuffer, 4);
  cBuffer[0] = 0x10;
  cBuffer[1] = 0;
  cBuffer[2] = 0;
  cBuffer[3] = 0;
  write(hFilename, cBuffer, 4);
  cBuffer[0] = dFormatTag & 0x00FF;
  cBuffer[1] = (dFormatTag & 0xFF00) >> 8;
  write(hFilename, cBuffer, 2);
  cBuffer[0] = dChannels & 0x00FF;
  cBuffer[1] = (dChannels & 0xFF00) >> 8;
  write(hFilename, cBuffer, 2);
  cBuffer[0] = ldSamplesPerSec & 0x000000FF;
  cBuffer[1] = (ldSamplesPerSec & 0x0000FF00) >> 8;
  cBuffer[2] = (ldSamplesPerSec & 0x00FF0000) >> 16;
  cBuffer[3] = (ldSamplesPerSec & 0xFF000000) >> 24;
  write(hFilename, cBuffer, 4);
  cBuffer[0] = dBytesPerSec & 0x000000FF;
  cBuffer[1] = (dBytesPerSec & 0x0000FF00) >> 8;
  cBuffer[2] = (dBytesPerSec & 0x00FF0000) >> 16;
  cBuffer[3] = (dBytesPerSec & 0xFF000000) >> 24;
  write(hFilename, cBuffer, 4);
  cBuffer[0] = dBlockAlign & 0x00FF;
  cBuffer[1] = (dBlockAlign & 0xFF00) >> 8;
  write(hFilename, cBuffer, 2);
  cBuffer[0] = dBitsPerSample & 0x00FF;
  cBuffer[1] = (dBitsPerSample & 0xFF00) >> 8;
  write(hFilename, cBuffer, 2);
  strcpy(cBuffer, "data");
  write(hFilename, cBuffer, 4);
  cBuffer[0] = dTotalSampleBytes & 0x000000FF;
  cBuffer[1] = (dTotalSampleBytes & 0x0000FF00) >> 8;
  cBuffer[2] = (dTotalSampleBytes & 0x00FF0000) >> 16;
  cBuffer[3] = (dTotalSampleBytes & 0xFF000000) >> 24;
  write(hFilename, cBuffer, 4);
  for (i = 0; i < dBufferWrites; i++) {
    read(hAudio, cBuffer, 8192);
    write(hFilename, cBuffer, 8192);
  }
  ftruncate(hFilename, lseek(hFilename, 0, SEEK_CUR));
  close(hFilename);
  return 0;
}


x86 assembly (clang, -O0):
<RecWavDesc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
mov    %r9w,%ax
mov    0x10(%rbp),%r9d
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %cx,-0x1a(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %ax,-0x22(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2038(%rbp)
movw   $0x1,-0x204a(%rbp)
movzwl -0x204a(%rbp),%eax
cmp    $0x1,%eax
je     11ef <RecWavDesc+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
movzwl -0x204a(%rbp),%eax
cmp    $0x1,%eax
jne    12dc <RecWavDesc+0x14c>
movzwl -0x22(%rbp),%eax
mov    %eax,-0x2050(%rbp)
sub    $0x8,%eax
je     122b <RecWavDesc+0x9b>
jmp    1217 <RecWavDesc+0x87>
mov    -0x2050(%rbp),%eax
sub    $0x10,%eax
je     1277 <RecWavDesc+0xe7>
jmp    12c3 <RecWavDesc+0x133>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1070 <ioctl@plt>
mov    -0x2c(%rbp),%eax
mov    0x2d4a(%rip),%rcx
cmp    (%rcx),%eax
je     1272 <RecWavDesc+0xe2>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
jmp    12d7 <RecWavDesc+0x147>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d2b(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1070 <ioctl@plt>
mov    -0x2c(%rbp),%eax
mov    0x2d26(%rip),%rcx
cmp    (%rcx),%eax
je     12be <RecWavDesc+0x12e>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
jmp    12d7 <RecWavDesc+0x147>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
jmp    12f0 <RecWavDesc+0x160>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
movzwl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jle    1354 <RecWavDesc+0x1c4>
movzwl -0x1a(%rbp),%eax
cmp    $0x3,%eax
jge    1354 <RecWavDesc+0x1c4>
movzwl -0x1a(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cc2(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1070 <ioctl@plt>
mov    -0x2c(%rbp),%eax
movzwl -0x1a(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     134f <RecWavDesc+0x1bf>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
jmp    1368 <RecWavDesc+0x1d8>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c48(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1070 <ioctl@plt>
mov    0x10(%rbp),%eax
and    $0x40000000,%eax
cmp    $0x0,%eax
je     13a0 <RecWavDesc+0x210>
movl   $0x0,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
movzwl -0x22(%rbp),%eax
cmp    $0x8,%eax
jg     13b7 <RecWavDesc+0x227>
movl   $0x1,-0x2038(%rbp)
movzwl -0x22(%rbp),%eax
cmp    $0x8,%eax
jle    13db <RecWavDesc+0x24b>
movzwl -0x22(%rbp),%eax
cmp    $0x10,%eax
jg     13db <RecWavDesc+0x24b>
movl   $0x2,-0x2038(%rbp)
movzwl -0x22(%rbp),%eax
cmp    $0x10,%eax
jle    13f2 <RecWavDesc+0x262>
movl   $0x3,-0x2038(%rbp)
mov    -0x2038(%rbp),%eax
movzwl -0x1a(%rbp),%ecx
imul   %ecx,%eax
mov    %ax,-0x204c(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x2038(%rbp),%eax
movzwl -0x1a(%rbp),%ecx
imul   %ecx,%eax
mov    %eax,-0x2034(%rbp)
mov    -0x2034(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x2040(%rbp)
mov    -0x2040(%rbp),%eax
shr    $0xd,%eax
add    $0x1,%eax
mov    %eax,-0x203c(%rbp)
mov    -0x203c(%rbp),%eax
shl    $0xd,%eax
mov    %eax,-0x2040(%rbp)
mov    -0x2040(%rbp),%eax
add    $0x24,%eax
mov    %eax,-0x2044(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2b40(%rip),%rax
mov    (%rax),%esi
mov    0x2b87(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10a0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    14a2 <RecWavDesc+0x312>
lea    0xb6f(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1856 <RecWavDesc+0x6c6>
lea    -0x2030(%rbp),%rdi
lea    0xb55(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x2044(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2030(%rbp)
mov    -0x2044(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x202f(%rbp)
mov    -0x2044(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x202e(%rbp)
mov    -0x2044(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x202d(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
lea    -0x2030(%rbp),%rdi
lea    0xad2(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
lea    -0x2030(%rbp),%rdi
lea    0xab0(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movb   $0x10,-0x2030(%rbp)
movb   $0x0,-0x202f(%rbp)
movb   $0x0,-0x202e(%rbp)
movb   $0x0,-0x202d(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movzwl -0x204a(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2030(%rbp)
movzwl -0x204a(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x202f(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movzwl -0x1a(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2030(%rbp)
movzwl -0x1a(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x202f(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2030(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x202f(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x202e(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x202d(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x2034(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2030(%rbp)
mov    -0x2034(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x202f(%rbp)
mov    -0x2034(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x202e(%rbp)
mov    -0x2034(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x202d(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movzwl -0x204c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2030(%rbp)
movzwl -0x204c(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x202f(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movzwl -0x22(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2030(%rbp)
movzwl -0x22(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x202f(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
lea    -0x2030(%rbp),%rdi
lea    0x8c8(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x2040(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2030(%rbp)
mov    -0x2040(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x202f(%rbp)
mov    -0x2040(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x202e(%rbp)
mov    -0x2040(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x202d(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movl   $0x0,-0x2048(%rbp)
mov    -0x2048(%rbp),%eax
cmp    -0x203c(%rbp),%eax
jae    181e <RecWavDesc+0x68e>
mov    -0x14(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x2000,%edx
call   1090 <read@plt>
mov    -0x28(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x2000,%edx
call   1040 <write@plt>
mov    -0x2048(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2048(%rbp)
jmp    17d0 <RecWavDesc+0x640>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2054(%rbp)
mov    -0x28(%rbp),%edi
mov    0x27a7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x2054(%rbp),%edi
mov    %eax,%esi
call   1050 <ftruncate@plt>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RecWavDesc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2038,%rsp
mov    %r9d,%r15d
mov    %r8d,%r12d
mov    %ecx,%r13d
mov    %edx,%ebx
mov    %esi,%r14d
cmp    $0x10,%r15w
je     11cf <RecWavDesc+0x3f>
cmp    $0x8,%r15w
jne    14df <RecWavDesc+0x34f>
mov    %rdi,0x8(%rsp)
mov    0x2dd3(%rip),%rbp
jmp    11db <RecWavDesc+0x4b>
mov    %rdi,0x8(%rsp)
mov    0x2ded(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %r14d,%edi
call   1070 <ioctl@plt>
mov    0x4(%rsp),%eax
cmp    0x0(%rbp),%eax
jne    14df <RecWavDesc+0x34f>
lea    -0x1(%r13),%eax
cmp    $0x1,%ax
ja     14df <RecWavDesc+0x34f>
mov    %r13,0x20(%rsp)
movzwl %r13w,%r13d
lea    -0x1(%r13),%ebp
mov    %ebp,0x4(%rsp)
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %r14d,%edi
call   1070 <ioctl@plt>
cmp    %ebp,0x4(%rsp)
jne    14df <RecWavDesc+0x34f>
mov    0x2070(%rsp),%ebp
mov    %r12d,0x14(%rsp)
mov    %r12d,0x4(%rsp)
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %r14d,%edi
call   1070 <ioctl@plt>
xor    %r12d,%r12d
test   $0x40000000,%ebp
jne    14ec <RecWavDesc+0x35c>
mov    %r13,%rbp
xor    %eax,%eax
mov    %r15d,%ecx
sub    $0x9,%cx
setb   %al
cmp    $0x8,%cx
mov    $0x2,%r12d
cmovae %eax,%r12d
mov    0x2d0a(%rip),%rax
mov    0x2d53(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x8(%rsp),%rdi
mov    $0x1a4,%edx
call   10a0 <open@plt>
test   %eax,%eax
js     1501 <RecWavDesc+0x371>
mov    %eax,%r13d
imul   0x14(%rsp),%ebp
imul   %r12d,%ebp
mov    %rbp,0x28(%rsp)
imul   %ebp,%ebx
lea    0x2000(%rbx),%eax
mov    %eax,0x8(%rsp)
shr    $0xd,%ebx
mov    0x20(%rsp),%rax
imul   %r12d,%eax
mov    %eax,0x18(%rsp)
lea    0xd10(%rip),%rsi
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movb   $0x24,0x30(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,%r12d
shr    $0x8,%r12d
and    $0xe0,%r12b
mov    %r12b,0x31(%rsp)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %ecx,0x1c(%rsp)
mov    %cl,0x32(%rsp)
shr    $0x18,%eax
mov    %eax,0x8(%rsp)
mov    %al,0x33(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
lea    0xcb0(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
lea    0xc96(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movl   $0x10,0x30(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movw   $0x1,0x30(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    0x20(%rsp),%rax
mov    %al,0x30(%rsp)
movb   $0x0,0x31(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    0x14(%rsp),%eax
mov    %eax,0x30(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    0x28(%rsp),%rax
mov    %eax,0x30(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    0x18(%rsp),%eax
mov    %al,0x30(%rsp)
movb   $0x0,0x31(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %r15w,0x30(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
lea    0xbcb(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
movb   $0x0,0x30(%rsp)
mov    %r12b,0x31(%rsp)
mov    0x1c(%rsp),%eax
mov    %al,0x32(%rsp)
mov    0x8(%rsp),%eax
mov    %al,0x33(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
add    $0x1,%ebx
xchg   %ax,%ax
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x2000,%edx
call   1090 <read@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x2000,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebx
jne    1490 <RecWavDesc+0x300>
mov    0x2b1c(%rip),%rax
mov    (%rax),%edx
xor    %r12d,%r12d
mov    %r13d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %r13d,%edi
mov    %eax,%esi
call   1050 <ftruncate@plt>
mov    %r13d,%edi
call   1080 <close@plt>
jmp    14ec <RecWavDesc+0x35c>
xor    %edi,%edi
call   1080 <close@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x2038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xaf8(%rip),%rdi
call   10b0 <perror@plt>
jmp    14e6 <RecWavDesc+0x356>

LLVM IR (-O0):
@AFMT_U8 = global i32 0
@SNDCTL_DSP_SETFMT = global i32 0
@AFMT_S16_LE = global i32 0
@SNDCTL_DSP_STEREO = global i32 0
@SNDCTL_DSP_SPEED = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [5 x i8] c"RIFF\00"
@.str.2 = [5 x i8] c"WAVE\00"
@.str.3 = [5 x i8] c"fmt \00"
@.str.4 = [5 x i8] c"data\00"
@SEEK_CUR = global i32 0
define i32 @RecWavDesc(i8* %0, i32 %1, i32 %2, i16 zeroext %3, i32 %4, i16 zeroext %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i16
%13 = alloca i32
%14 = alloca i16
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [8192 x i8]
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i16
%26 = alloca i16
store i8* %0, i8** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i16 %3, i16* %12
store i32 %4, i32* %13
store i16 %5, i16* %14
store i32 %6, i32* %15
store i32 0, i32* %16
store i32 0, i32* %20
store i16 1, i16* %25
%27 = load i16, i16* %25
%28 = zext i16 %27 to i32
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %7
store i32 -1, i32* %8
br label %349
31: ; preds = %7
%32 = load i16, i16* %25
%33 = zext i16 %32 to i32
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %66
35: ; preds = %31
%36 = load i16, i16* %14
%37 = zext i16 %36 to i32
switch i32 %37, label %62 [
i32 8, label %38
i32 16, label %50
]
38: ; preds = %35
%39 = load i32, i32* @AFMT_U8
store i32 %39, i32* %17
%40 = load i32, i32* %10
%41 = load i32, i32* @SNDCTL_DSP_SETFMT
%42 = call i32 @ioctl(i32 %40, i32 %41, i32* %17)
%43 = load i32, i32* %17
%44 = load i32, i32* @AFMT_U8
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %38
%47 = load i32, i32* %16
%48 = call i32 @close(i32 %47)
store i32 -1, i32* %8
br label %349
49: ; preds = %38
br label %65
50: ; preds = %35
%51 = load i32, i32* @AFMT_S16_LE
store i32 %51, i32* %17
%52 = load i32, i32* %10
%53 = load i32, i32* @SNDCTL_DSP_SETFMT
%54 = call i32 @ioctl(i32 %52, i32 %53, i32* %17)
%55 = load i32, i32* %17
%56 = load i32, i32* @AFMT_S16_LE
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = load i32, i32* %16
%60 = call i32 @close(i32 %59)
store i32 -1, i32* %8
br label %349
61: ; preds = %50
br label %65
62: ; preds = %35
%63 = load i32, i32* %16
%64 = call i32 @close(i32 %63)
store i32 -1, i32* %8
br label %349
65: ; preds = %61, %49
br label %69
66: ; preds = %31
%67 = load i32, i32* %16
%68 = call i32 @close(i32 %67)
store i32 -1, i32* %8
br label %349
69: ; preds = %65
%70 = load i16, i16* %12
%71 = zext i16 %70 to i32
%72 = icmp sgt i32 %71, 0
br i1 %72, label %73, label %93
73: ; preds = %69
%74 = load i16, i16* %12
%75 = zext i16 %74 to i32
%76 = icmp slt i32 %75, 3
br i1 %76, label %77, label %93
77: ; preds = %73
%78 = load i16, i16* %12
%79 = zext i16 %78 to i32
%80 = sub nsw i32 %79, 1
store i32 %80, i32* %17
%81 = load i32, i32* %10
%82 = load i32, i32* @SNDCTL_DSP_STEREO
%83 = call i32 @ioctl(i32 %81, i32 %82, i32* %17)
%84 = load i32, i32* %17
%85 = load i16, i16* %12
%86 = zext i16 %85 to i32
%87 = sub nsw i32 %86, 1
%88 = icmp ne i32 %84, %87
br i1 %88, label %89, label %92
89: ; preds = %77
%90 = load i32, i32* %16
%91 = call i32 @close(i32 %90)
store i32 -1, i32* %8
br label %349
92: ; preds = %77
br label %96
93: ; preds = %73, %69
%94 = load i32, i32* %16
%95 = call i32 @close(i32 %94)
store i32 -1, i32* %8
br label %349
96: ; preds = %92
%97 = load i32, i32* %13
store i32 %97, i32* %17
%98 = load i32, i32* %10
%99 = load i32, i32* @SNDCTL_DSP_SPEED
%100 = call i32 @ioctl(i32 %98, i32 %99, i32* %17)
%101 = load i32, i32* %15
%102 = and i32 %101, 1073741824
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %105
104: ; preds = %96
store i32 0, i32* %8
br label %349
105: ; preds = %96
%106 = load i16, i16* %14
%107 = zext i16 %106 to i32
%108 = icmp sle i32 %107, 8
br i1 %108, label %109, label %110
109: ; preds = %105
store i32 1, i32* %20
br label %110
110: ; preds = %109, %105
%111 = load i16, i16* %14
%112 = zext i16 %111 to i32
%113 = icmp sgt i32 %112, 8
br i1 %113, label %114, label %119
114: ; preds = %110
%115 = load i16, i16* %14
%116 = zext i16 %115 to i32
%117 = icmp sle i32 %116, 16
br i1 %117, label %118, label %119
118: ; preds = %114
store i32 2, i32* %20
br label %119
119: ; preds = %118, %114, %110
%120 = load i16, i16* %14
%121 = zext i16 %120 to i32
%122 = icmp sgt i32 %121, 16
br i1 %122, label %123, label %124
123: ; preds = %119
store i32 3, i32* %20
br label %124
124: ; preds = %123, %119
%125 = load i32, i32* %20
%126 = load i16, i16* %12
%127 = zext i16 %126 to i32
%128 = mul i32 %125, %127
%129 = trunc i32 %128 to i16
store i16 %129, i16* %26
%130 = load i32, i32* %13
%131 = load i32, i32* %20
%132 = mul i32 %130, %131
%133 = load i16, i16* %12
%134 = zext i16 %133 to i32
%135 = mul i32 %132, %134
store i32 %135, i32* %19
%136 = load i32, i32* %19
%137 = load i32, i32* %11
%138 = mul i32 %136, %137
store i32 %138, i32* %22
%139 = load i32, i32* %22
%140 = udiv i32 %139, 8192
%141 = add i32 %140, 1
store i32 %141, i32* %21
%142 = load i32, i32* %21
%143 = mul i32 %142, 8192
store i32 %143, i32* %22
%144 = load i32, i32* %22
%145 = add i32 %144, 36
store i32 %145, i32* %23
%146 = load i8*, i8** %9
%147 = load i32, i32* @O_WRONLY
%148 = load i32, i32* @O_CREAT
%149 = or i32 %147, %148
%150 = call i32 @open(i8* %146, i32 %149, i32 420)
store i32 %150, i32* %16
%151 = load i32, i32* %16
%152 = icmp slt i32 %151, 0
br i1 %152, label %153, label %155
153: ; preds = %124
%154 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %8
br label %349
155: ; preds = %124
%156 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%157 = call i32 @strcpy(i8* %156, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%158 = load i32, i32* %16
%159 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%160 = call i32 @write(i32 %158, i8* %159, i32 4)
%161 = load i32, i32* %23
%162 = and i32 %161, 255
%163 = trunc i32 %162 to i8
%164 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 %163, i8* %164
%165 = load i32, i32* %23
%166 = and i32 %165, 65280
%167 = lshr i32 %166, 8
%168 = trunc i32 %167 to i8
%169 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 %168, i8* %169
%170 = load i32, i32* %23
%171 = and i32 %170, 16711680
%172 = lshr i32 %171, 16
%173 = trunc i32 %172 to i8
%174 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 2
store i8 %173, i8* %174
%175 = load i32, i32* %23
%176 = and i32 %175, -16777216
%177 = lshr i32 %176, 24
%178 = trunc i32 %177 to i8
%179 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 3
store i8 %178, i8* %179
%180 = load i32, i32* %16
%181 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%182 = call i32 @write(i32 %180, i8* %181, i32 4)
%183 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%184 = call i32 @strcpy(i8* %183, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%185 = load i32, i32* %16
%186 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%187 = call i32 @write(i32 %185, i8* %186, i32 4)
%188 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%189 = call i32 @strcpy(i8* %188, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%190 = load i32, i32* %16
%191 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%192 = call i32 @write(i32 %190, i8* %191, i32 4)
%193 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 16, i8* %193
%194 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 0, i8* %194
%195 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 2
store i8 0, i8* %195
%196 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 3
store i8 0, i8* %196
%197 = load i32, i32* %16
%198 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%199 = call i32 @write(i32 %197, i8* %198, i32 4)
%200 = load i16, i16* %25
%201 = zext i16 %200 to i32
%202 = and i32 %201, 255
%203 = trunc i32 %202 to i8
%204 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 %203, i8* %204
%205 = load i16, i16* %25
%206 = zext i16 %205 to i32
%207 = and i32 %206, 65280
%208 = ashr i32 %207, 8
%209 = trunc i32 %208 to i8
%210 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 %209, i8* %210
%211 = load i32, i32* %16
%212 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%213 = call i32 @write(i32 %211, i8* %212, i32 2)
%214 = load i16, i16* %12
%215 = zext i16 %214 to i32
%216 = and i32 %215, 255
%217 = trunc i32 %216 to i8
%218 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 %217, i8* %218
%219 = load i16, i16* %12
%220 = zext i16 %219 to i32
%221 = and i32 %220, 65280
%222 = ashr i32 %221, 8
%223 = trunc i32 %222 to i8
%224 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 %223, i8* %224
%225 = load i32, i32* %16
%226 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%227 = call i32 @write(i32 %225, i8* %226, i32 2)
%228 = load i32, i32* %13
%229 = and i32 %228, 255
%230 = trunc i32 %229 to i8
%231 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 %230, i8* %231
%232 = load i32, i32* %13
%233 = and i32 %232, 65280
%234 = lshr i32 %233, 8
%235 = trunc i32 %234 to i8
%236 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 %235, i8* %236
%237 = load i32, i32* %13
%238 = and i32 %237, 16711680
%239 = lshr i32 %238, 16
%240 = trunc i32 %239 to i8
%241 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 2
store i8 %240, i8* %241
%242 = load i32, i32* %13
%243 = and i32 %242, -16777216
%244 = lshr i32 %243, 24
%245 = trunc i32 %244 to i8
%246 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 3
store i8 %245, i8* %246
%247 = load i32, i32* %16
%248 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%249 = call i32 @write(i32 %247, i8* %248, i32 4)
%250 = load i32, i32* %19
%251 = and i32 %250, 255
%252 = trunc i32 %251 to i8
%253 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 %252, i8* %253
%254 = load i32, i32* %19
%255 = and i32 %254, 65280
%256 = lshr i32 %255, 8
%257 = trunc i32 %256 to i8
%258 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 %257, i8* %258
%259 = load i32, i32* %19
%260 = and i32 %259, 16711680
%261 = lshr i32 %260, 16
%262 = trunc i32 %261 to i8
%263 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 2
store i8 %262, i8* %263
%264 = load i32, i32* %19
%265 = and i32 %264, -16777216
%266 = lshr i32 %265, 24
%267 = trunc i32 %266 to i8
%268 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 3
store i8 %267, i8* %268
%269 = load i32, i32* %16
%270 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%271 = call i32 @write(i32 %269, i8* %270, i32 4)
%272 = load i16, i16* %26
%273 = zext i16 %272 to i32
%274 = and i32 %273, 255
%275 = trunc i32 %274 to i8
%276 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 %275, i8* %276
%277 = load i16, i16* %26
%278 = zext i16 %277 to i32
%279 = and i32 %278, 65280
%280 = ashr i32 %279, 8
%281 = trunc i32 %280 to i8
%282 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 %281, i8* %282
%283 = load i32, i32* %16
%284 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%285 = call i32 @write(i32 %283, i8* %284, i32 2)
%286 = load i16, i16* %14
%287 = zext i16 %286 to i32
%288 = and i32 %287, 255
%289 = trunc i32 %288 to i8
%290 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 %289, i8* %290
%291 = load i16, i16* %14
%292 = zext i16 %291 to i32
%293 = and i32 %292, 65280
%294 = ashr i32 %293, 8
%295 = trunc i32 %294 to i8
%296 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 %295, i8* %296
%297 = load i32, i32* %16
%298 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%299 = call i32 @write(i32 %297, i8* %298, i32 2)
%300 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%301 = call i32 @strcpy(i8* %300, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%302 = load i32, i32* %16
%303 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%304 = call i32 @write(i32 %302, i8* %303, i32 4)
%305 = load i32, i32* %22
%306 = and i32 %305, 255
%307 = trunc i32 %306 to i8
%308 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
store i8 %307, i8* %308
%309 = load i32, i32* %22
%310 = and i32 %309, 65280
%311 = lshr i32 %310, 8
%312 = trunc i32 %311 to i8
%313 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 1
store i8 %312, i8* %313
%314 = load i32, i32* %22
%315 = and i32 %314, 16711680
%316 = lshr i32 %315, 16
%317 = trunc i32 %316 to i8
%318 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 2
store i8 %317, i8* %318
%319 = load i32, i32* %22
%320 = and i32 %319, -16777216
%321 = lshr i32 %320, 24
%322 = trunc i32 %321 to i8
%323 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 3
store i8 %322, i8* %323
%324 = load i32, i32* %16
%325 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%326 = call i32 @write(i32 %324, i8* %325, i32 4)
store i32 0, i32* %24
br label %327
327: ; preds = %338, %155
%328 = load i32, i32* %24
%329 = load i32, i32* %21
%330 = icmp ult i32 %328, %329
br i1 %330, label %331, label %341
331: ; preds = %327
%332 = load i32, i32* %10
%333 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%334 = call i32 @read(i32 %332, i8* %333, i32 8192)
%335 = load i32, i32* %16
%336 = getelementptr inbounds [8192 x i8], [8192 x i8]* %18, i64 0, i64 0
%337 = call i32 @write(i32 %335, i8* %336, i32 8192)
br label %338
338: ; preds = %331
%339 = load i32, i32* %24
%340 = add i32 %339, 1
store i32 %340, i32* %24
br label %327
341: ; preds = %327
%342 = load i32, i32* %16
%343 = load i32, i32* %16
%344 = load i32, i32* @SEEK_CUR
%345 = call i32 @lseek(i32 %343, i32 0, i32 %344)
%346 = call i32 @ftruncate(i32 %342, i32 %345)
%347 = load i32, i32* %16
%348 = call i32 @close(i32 %347)
store i32 0, i32* %8
br label %349
349: ; preds = %341, %153, %104, %93, %89, %66, %62, %58, %46, %30
%350 = load i32, i32* %8
ret i32 %350
}

LLVM IR (-O2):
@AFMT_U8 = global i32 0
@SNDCTL_DSP_SETFMT = global i32 0
@AFMT_S16_LE = global i32 0
@SNDCTL_DSP_STEREO = global i32 0
@SNDCTL_DSP_SPEED = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [5 x i8] c"RIFF\00"
@.str.2 = [5 x i8] c"WAVE\00"
@.str.3 = [5 x i8] c"fmt \00"
@.str.4 = [5 x i8] c"data\00"
@SEEK_CUR = global i32 0
define i32 @RecWavDesc(i8* nocapture %0, i32 %1, i32 %2, i16 zeroext %3, i32 %4, i16 zeroext %5, i32 %6) {
%8 = alloca i32
%9 = alloca [8192 x i8]
%10 = bitcast i32* %8 to i8*
%11 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
switch i16 %5, label %30 [
i16 8, label %12
i16 16, label %21
]
12: ; preds = %7
%13 = load i32, i32* @AFMT_U8
store i32 %13, i32* %8
%14 = load i32, i32* @SNDCTL_DSP_SETFMT
%15 = call i32 @ioctl(i32 %1, i32 %14, i32* %8)
%16 = load i32, i32* %8
%17 = load i32, i32* @AFMT_U8
%18 = icmp eq i32 %16, %17
br i1 %18, label %32, label %19
19: ; preds = %12
%20 = call i32 @close(i32 0)
br label %129
21: ; preds = %7
%22 = load i32, i32* @AFMT_S16_LE
store i32 %22, i32* %8
%23 = load i32, i32* @SNDCTL_DSP_SETFMT
%24 = call i32 @ioctl(i32 %1, i32 %23, i32* %8)
%25 = load i32, i32* %8
%26 = load i32, i32* @AFMT_S16_LE
%27 = icmp eq i32 %25, %26
br i1 %27, label %32, label %28
28: ; preds = %21
%29 = call i32 @close(i32 0)
br label %129
30: ; preds = %7
%31 = tail call i32 @close(i32 0)
br label %129
32: ; preds = %12, %21
%33 = zext i16 %3 to i32
%34 = add i16 %3, -1
%35 = icmp ult i16 %34, 2
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = add nsw i32 %33, -1
store i32 %37, i32* %8
%38 = load i32, i32* @SNDCTL_DSP_STEREO
%39 = call i32 @ioctl(i32 %1, i32 %38, i32* %8)
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, %37
br i1 %41, label %46, label %42
42: ; preds = %36
%43 = call i32 @close(i32 0)
br label %129
44: ; preds = %32
%45 = call i32 @close(i32 0)
br label %129
46: ; preds = %36
store i32 %4, i32* %8
%47 = load i32, i32* @SNDCTL_DSP_SPEED
%48 = call i32 @ioctl(i32 %1, i32 %47, i32* %8)
%49 = and i32 %6, 1073741824
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %129
51: ; preds = %46
%52 = icmp ult i16 %5, 9
%53 = zext i1 %52 to i32
%54 = add nsw i16 %5, -9
%55 = icmp ult i16 %54, 8
%56 = select i1 %55, i32 2, i32 %53
%57 = mul i32 %33, %4
%58 = mul i32 %57, %56
%59 = mul i32 %58, %2
%60 = add i32 %59, 8192
%61 = load i32, i32* @O_WRONLY
%62 = load i32, i32* @O_CREAT
%63 = or i32 %62, %61
%64 = call i32 @open(i8* %0, i32 %63, i32 420)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %51
%67 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %129
68: ; preds = %51
%69 = lshr i32 %59, 13
%70 = trunc i32 %56 to i16
%71 = mul nuw nsw i16 %70, %3
%72 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%73 = call i32 @write(i32 %64, i8* %11, i32 4)
store i8 36, i8* %11
%74 = lshr i32 %60, 8
%75 = trunc i32 %74 to i8
%76 = and i8 %75, -32
%77 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 1
store i8 %76, i8* %77
%78 = lshr i32 %60, 16
%79 = trunc i32 %78 to i8
%80 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 2
store i8 %79, i8* %80
%81 = lshr i32 %60, 24
%82 = trunc i32 %81 to i8
%83 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 3
store i8 %82, i8* %83
%84 = call i32 @write(i32 %64, i8* %11, i32 4)
%85 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%86 = call i32 @write(i32 %64, i8* %11, i32 4)
%87 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%88 = call i32 @write(i32 %64, i8* %11, i32 4)
store i8 16, i8* %11
store i8 0, i8* %77
store i8 0, i8* %80
store i8 0, i8* %83
%89 = call i32 @write(i32 %64, i8* %11, i32 4)
store i8 1, i8* %11
store i8 0, i8* %77
%90 = call i32 @write(i32 %64, i8* %11, i32 2)
%91 = trunc i16 %3 to i8
store i8 %91, i8* %11
store i8 0, i8* %77
%92 = call i32 @write(i32 %64, i8* %11, i32 2)
%93 = trunc i32 %4 to i8
store i8 %93, i8* %11
%94 = lshr i32 %4, 8
%95 = trunc i32 %94 to i8
store i8 %95, i8* %77
%96 = lshr i32 %4, 16
%97 = trunc i32 %96 to i8
store i8 %97, i8* %80
%98 = lshr i32 %4, 24
%99 = trunc i32 %98 to i8
store i8 %99, i8* %83
%100 = call i32 @write(i32 %64, i8* %11, i32 4)
%101 = trunc i32 %58 to i8
store i8 %101, i8* %11
%102 = lshr i32 %58, 8
%103 = trunc i32 %102 to i8
store i8 %103, i8* %77
%104 = lshr i32 %58, 16
%105 = trunc i32 %104 to i8
store i8 %105, i8* %80
%106 = lshr i32 %58, 24
%107 = trunc i32 %106 to i8
store i8 %107, i8* %83
%108 = call i32 @write(i32 %64, i8* %11, i32 4)
%109 = trunc i16 %71 to i8
store i8 %109, i8* %11
store i8 0, i8* %77
%110 = call i32 @write(i32 %64, i8* %11, i32 2)
%111 = trunc i16 %5 to i8
store i8 %111, i8* %11
%112 = lshr i16 %5, 8
%113 = trunc i16 %112 to i8
store i8 %113, i8* %77
%114 = call i32 @write(i32 %64, i8* %11, i32 2)
%115 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%116 = call i32 @write(i32 %64, i8* %11, i32 4)
store i8 0, i8* %11
store i8 %76, i8* %77
store i8 %79, i8* %80
store i8 %82, i8* %83
%117 = call i32 @write(i32 %64, i8* %11, i32 4)
br label %118
118: ; preds = %68, %118
%119 = phi i32 [ 0, %68 ], [ %122, %118 ]
%120 = call i32 @read(i32 %1, i8* %11, i32 8192)
%121 = call i32 @write(i32 %64, i8* %11, i32 8192)
%122 = add nuw nsw i32 %119, 1
%123 = icmp eq i32 %119, %69
br i1 %123, label %124, label %118
124: ; preds = %118
%125 = load i32, i32* @SEEK_CUR
%126 = call i32 @lseek(i32 %64, i32 0, i32 %125)
%127 = call i32 @ftruncate(i32 %64, i32 %126)
%128 = call i32 @close(i32 %64)
br label %129
129: ; preds = %46, %124, %66, %44, %42, %30, %28, %19
%130 = phi i32 [ -1, %30 ], [ -1, %28 ], [ -1, %42 ], [ -1, %66 ], [ 0, %124 ], [ -1, %44 ], [ -1, %19 ], [ 0, %46 ]
ret i32 %130
}