#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 /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(unsigned short *, int, int, int /*<<< orphan*/ *);
int ioctl(int, int, int *);
int /*<<< orphan*/ memset(unsigned short *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned short *, int);
int /*<<< orphan*/ write_wav_header(int /*<<< orphan*/ *, int *,
                                    unsigned short *, int *, unsigned short *);
int main(int ac, char *av[]) {
  unsigned short chan, bits;
  int remaining_bytes, bytes_read;
  int frequency, channels, bytes;
  int bytes_to_read, total_bytes;
  unsigned short buf[(1024 * 32)];
  int val, res, input_dev;
  int bytes_written;
  FILE *fd_file;
  int fd_audio;
  int format;
  printf("Hi... \n");
  if (ac != 6) {
    printf("Records an audio file from /dev/sound/dsp1 (uncompressed data)\n");
    printf("Usage: %s <soundfile.wav> <input_dev> <bytes> <frequency> "
           "<channels>\n",
           av[0]);
    printf("soundfile.wav    : wav file to be created\n\n");
    printf("input_dev options: 1 (handset, J4, for mono/stereo recording)\n");
    printf("                   2 (headset, J3, for mono recording)\n");
    printf("		   3 (line in, J7, for mono recording)\n\n");
    printf("bytes            : Amount of bytes to record\n\n");
    printf("frequency options: 8000\n");
    printf("                   16000\n\n");
    printf("channels options : 1 (mono)\n");
    printf("                   2 (stereo, ONLY WORKS for input_dev = 1)\n\n");
    return 0;
  }
  input_dev = atoi(av[2]);
  bytes = atoi(av[3]);
  frequency = atoi(av[4]);
  channels = atoi(av[5]);
  if ((fd_audio = open("/dev/sound/dsp", O_RDONLY)) < 0) {
    printf("Error opening /dev/sound/dsp");
    return 1;
  }
  if ((fd_file = fopen(av[1], "w+")) <= 0) {
    printf("Error when creating the sample file");
    goto error1;
  }
  if ((channels != 2) && (channels != 1)) {
    printf("channels error: %d\n", channels);
    goto error2;
  }
  if ((channels == 2) && (input_dev != 1)) {
    printf("Stereo recording not supported for this device, 		"
           "		using mono instead\n");
    channels = 1;
  }
  printf("frequency = %d, bytes = %d, input_dev = %d\n", frequency, bytes,
         input_dev);
  if ((frequency != 16000) && (frequency != 8000)) {
    printf("frequency error: %d\n", frequency);
    goto error2;
  }
  format = 0x00000010;
  res = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 5)),
              &format);
  if (res < 0) {
    printf("Sound format set error\n");
    goto error2;
  }
  res = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 2)),
              &frequency);
  if (res < 0) {
    printf("SOUND_PCM_WRITE_RATE error\n");
    goto error2;
  }
  res = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('P' << 8) | 6)),
              &channels);
  if (res < 0) {
    printf("SOUND_PCM_WRITE_CHANNELS error\n");
    goto error2;
  }
  switch (input_dev) {
  case 1:
    val = (1 << 20);
    break;
  case 2:
    val = (1 << 7);
    break;
  case 3:
    val = (1 << 6);
    break;
  default:
    printf("Unknown input src, using the default one\n");
    val = (1 << 7);
  }
  res = ioctl(fd_audio,
              ((int)((0x40000000 | 0x20000000) |
                     ((sizeof(int) & 0x1fff) << 16) | ('M' << 8) | 0xff)),
              &val);
  if (res < 0) {
    printf("SOUND_MIXER_WRITE_RECSRC error\n");
    goto error2;
  }
  memset(buf, 0, (1024 * 32));
  fwrite(buf, 44, 1, fd_file);
  bytes_to_read = remaining_bytes = bytes;
  while (remaining_bytes > 0) {
    if (bytes_to_read > (1024 * 32)) {
      bytes_to_read = (1024 * 32);
    }
    bytes_read = read(fd_audio, buf, bytes_to_read);
    if (bytes_read < 0) {
      printf("Error reading audio data \n");
      break;
    }
    printf("%d bytes read from the device\n", bytes_read);
    remaining_bytes -= bytes_read;
    bytes_to_read = remaining_bytes;
    total_bytes += bytes_read;
    bytes_written = fwrite(buf, 1, bytes_read, fd_file);
    if (bytes_written < 0) {
      perror("/dev/audio\n");
    }
  }
  printf(" total bytes read: (%d)", total_bytes);
  bits = 16;
  chan = channels;
  write_wav_header(fd_file, &total_bytes, &chan, &frequency, &bits);
  printf("Closing the device\n");
  return 0;
error2:
  printf("Unsuccessful operation (2)\n");
  fclose(fd_file);
error1:
  printf("Unsuccessful operation (1)\n");
  close(fd_audio);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10060,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x6,-0x8(%rbp)
je     129e <main+0xde>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    16fa <main+0x53a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x1003c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
lea    0xf37(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x1004c(%rbp)
cmp    $0x0,%eax
jge    131f <main+0x15f>
lea    0xf0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16fa <main+0x53a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf09(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10048(%rbp)
cmp    $0x0,%rax
ja     1357 <main+0x197>
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    16da <main+0x51a>
cmpl   $0x2,-0x24(%rbp)
je     1381 <main+0x1c1>
cmpl   $0x1,-0x24(%rbp)
je     1381 <main+0x1c1>
mov    -0x24(%rbp),%esi
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    16c0 <main+0x500>
cmpl   $0x2,-0x24(%rbp)
jne    13ad <main+0x1ed>
cmpl   $0x1,-0x1003c(%rbp)
je     13ad <main+0x1ed>
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x1003c(%rbp),%ecx
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x3e80,-0x20(%rbp)
je     13f7 <main+0x237>
cmpl   $0x1f40,-0x20(%rbp)
je     13f7 <main+0x237>
mov    -0x20(%rbp),%esi
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    16c0 <main+0x500>
movl   $0x10,-0x10050(%rbp)
mov    -0x1004c(%rbp),%edi
mov    $0x60045005,%esi
lea    -0x10050(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x10038(%rbp)
cmpl   $0x0,-0x10038(%rbp)
jge    143e <main+0x27e>
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    16c0 <main+0x500>
mov    -0x1004c(%rbp),%edi
mov    $0x60045002,%esi
lea    -0x20(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x10038(%rbp)
cmpl   $0x0,-0x10038(%rbp)
jge    1478 <main+0x2b8>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    16c0 <main+0x500>
mov    -0x1004c(%rbp),%edi
mov    $0x60045006,%esi
lea    -0x24(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x10038(%rbp)
cmpl   $0x0,-0x10038(%rbp)
jge    14b2 <main+0x2f2>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    16c0 <main+0x500>
mov    -0x1003c(%rbp),%eax
mov    %eax,-0x10054(%rbp)
sub    $0x1,%eax
je     14f4 <main+0x334>
jmp    14cc <main+0x30c>
mov    -0x10054(%rbp),%eax
sub    $0x2,%eax
je     1503 <main+0x343>
jmp    14e0 <main+0x320>
mov    -0x10054(%rbp),%eax
sub    $0x3,%eax
je     1512 <main+0x352>
jmp    1521 <main+0x361>
movl   $0x100000,-0x10034(%rbp)
jmp    1539 <main+0x379>
movl   $0x80,-0x10034(%rbp)
jmp    1539 <main+0x379>
movl   $0x40,-0x10034(%rbp)
jmp    1539 <main+0x379>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x80,-0x10034(%rbp)
mov    -0x1004c(%rbp),%edi
mov    $0x60044dff,%esi
lea    -0x10034(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x10038(%rbp)
cmpl   $0x0,-0x10038(%rbp)
jge    1576 <main+0x3b6>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    16c0 <main+0x500>
lea    -0x10030(%rbp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1050 <memset@plt>
lea    -0x10030(%rbp),%rdi
mov    -0x10048(%rbp),%rcx
mov    $0x2c,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    166c <main+0x4ac>
cmpl   $0x8000,-0x2c(%rbp)
jle    15cd <main+0x40d>
movl   $0x8000,-0x2c(%rbp)
mov    -0x1004c(%rbp),%edi
lea    -0x10030(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1602 <main+0x442>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    166c <main+0x4ac>
mov    -0x1c(%rbp),%esi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    -0x10030(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10048(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    %eax,-0x10040(%rbp)
cmpl   $0x0,-0x10040(%rbp)
jge    1667 <main+0x4a7>
lea    0xd71(%rip),%rdi
call   10c0 <perror@plt>
jmp    15af <main+0x3ef>
mov    -0x30(%rbp),%esi
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movw   $0x10,-0x14(%rbp)
mov    -0x24(%rbp),%eax
mov    %ax,-0x12(%rbp)
mov    -0x10048(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x12(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1090 <write_wav_header@plt>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    16fa <main+0x53a>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10048(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1004c(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10028,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xf35(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x6,%ebx
jne    128a <main+0xba>
mov    0x10(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r13d
mov    0x20(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebx
mov    %eax,0x14(%rsp)
mov    0x28(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r14d
mov    %eax,0xc(%rsp)
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
lea    0xe12(%rip),%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     131b <main+0x14b>
mov    %eax,%r12d
mov    0x8(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     132e <main+0x15e>
mov    %rax,%rbp
lea    -0x3(%r14),%eax
cmp    $0xfffffffd,%eax
ja     1341 <main+0x171>
lea    0xe08(%rip),%rdi
mov    %r14d,%esi
jmp    13f6 <main+0x226>
lea    0xfdb(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%rsi
lea    0xd5f(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xffa(%rip),%rdi
call   1030 <puts@plt>
lea    0x1019(%rip),%rdi
call   1030 <puts@plt>
lea    0x104b(%rip),%rdi
call   1030 <puts@plt>
lea    0x1076(%rip),%rdi
call   1030 <puts@plt>
lea    0x1094(%rip),%rdi
call   1030 <puts@plt>
lea    0x10b6(%rip),%rdi
call   1030 <puts@plt>
lea    0x10c2(%rip),%rdi
call   1030 <puts@plt>
lea    0x10d0(%rip),%rdi
call   1030 <puts@plt>
lea    0x10e0(%rip),%rdi
call   1030 <puts@plt>
jmp    1532 <main+0x362>
lea    0xd24(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    152d <main+0x35d>
lea    0xd31(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1519 <main+0x349>
cmp    $0x2,%r14d
jne    1361 <main+0x191>
cmp    $0x1,%r15d
je     1361 <main+0x191>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,0xc(%rsp)
lea    0xd36(%rip),%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x1f40,%ebx
je     1387 <main+0x1b7>
cmp    $0x3e80,%ebx
jne    13ed <main+0x21d>
movl   $0x10,0x18(%rsp)
lea    0x18(%rsp),%rdx
mov    %r12d,%edi
mov    $0x60045005,%esi
call   1070 <ioctl@plt>
test   %eax,%eax
js     1402 <main+0x232>
lea    0x14(%rsp),%rdx
mov    %r12d,%edi
mov    $0x60045002,%esi
call   1070 <ioctl@plt>
test   %eax,%eax
js     140e <main+0x23e>
lea    0xc(%rsp),%rdx
mov    %r12d,%edi
mov    $0x60045006,%esi
call   1070 <ioctl@plt>
test   %eax,%eax
js     141a <main+0x24a>
cmp    $0x3,%r15d
je     1426 <main+0x256>
cmp    $0x2,%r15d
je     143c <main+0x26c>
cmp    $0x1,%r15d
jne    1430 <main+0x260>
movl   $0x100000,0x8(%rsp)
jmp    1444 <main+0x274>
lea    0xcd6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1505 <main+0x335>
lea    0xe05(%rip),%rdi
jmp    1500 <main+0x330>
lea    0xdde(%rip),%rdi
jmp    1500 <main+0x330>
lea    0xdb3(%rip),%rdi
jmp    1500 <main+0x330>
movl   $0x40,0x8(%rsp)
jmp    1444 <main+0x274>
lea    0xd74(%rip),%rdi
call   1030 <puts@plt>
movl   $0x80,0x8(%rsp)
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
mov    $0x60044dff,%esi
call   1070 <ioctl@plt>
test   %eax,%eax
js     14f9 <main+0x329>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10f0 <fwrite@plt>
cmp    $0x8000,%r13d
mov    $0x8000,%edx
cmovb  %r13d,%edx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1090 <read@plt>
test   %eax,%eax
js     1546 <main+0x376>
mov    %eax,%r14d
lea    0xc2b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
sub    %r14d,%r13d
add    %r14d,%r15d
mov    %r15d,0x1c(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbp,%rcx
call   10f0 <fwrite@plt>
test   %eax,%eax
js     14e6 <main+0x316>
test   %r13d,%r13d
jg     1487 <main+0x2b7>
jmp    1552 <main+0x382>
lea    0xc11(%rip),%rdi
call   10d0 <perror@plt>
test   %r13d,%r13d
jg     1487 <main+0x2b7>
jmp    1552 <main+0x382>
lea    0xc56(%rip),%rdi
call   1030 <puts@plt>
lea    0xc69(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xc70(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,%edi
call   1080 <close@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbef(%rip),%rdi
call   1030 <puts@plt>
lea    0xbb1(%rip),%rdi
xor    %ebx,%ebx
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movw   $0x10,0x10(%rsp)
movzwl 0xc(%rsp),%eax
mov    %ax,0x12(%rsp)
lea    0x1c(%rsp),%rsi
lea    0x12(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rbp,%rdi
call   10a0 <write_wav_header@plt>
lea    0xb90(%rip),%rdi
jmp    1311 <main+0x141>

LLVM IR (-O0):
@.str = [8 x i8] c"Hi... \0A\00"
@.str.1 = [64 x i8] c"Records an audio file from /dev/sound/dsp1 (uncompressed data)\0A\00"
@.str.2 = [70 x i8] c"Usage: %s <soundfile.wav> <input_dev> <bytes> <frequency> <channels>\0A\00"
@.str.3 = [44 x i8] c"soundfile.wav : wav file to be created\0A\0A\00"
@.str.4 = [63 x i8] c"input_dev options: 1 (handset, J4, for mono/stereo recording)\0A\00"
@.str.5 = [56 x i8] c" 2 (headset, J3, for mono recording)\0A\00"
@.str.6 = [43 x i8] c"\09\09 3 (line in, J7, for mono recording)\0A\0A\00"
@.str.7 = [47 x i8] c"bytes : Amount of bytes to record\0A\0A\00"
@.str.8 = [25 x i8] c"frequency options: 8000\0A\00"
@.str.9 = [27 x i8] c" 16000\0A\0A\00"
@.str.10 = [29 x i8] c"channels options : 1 (mono)\0A\00"
@.str.11 = [62 x i8] c" 2 (stereo, ONLY WORKS for input_dev = 1)\0A\0A\00"
@.str.12 = [15 x i8] c"/dev/sound/dsp\00"
@O_RDONLY = global i32 0
@.str.13 = [29 x i8] c"Error opening /dev/sound/dsp\00"
@.str.14 = [3 x i8] c"w+\00"
@.str.15 = [36 x i8] c"Error when creating the sample file\00"
@.str.16 = [20 x i8] c"channels error: %d\0A\00"
@.str.17 = [72 x i8] c"Stereo recording not supported for this device, \09\09\09\09using mono instead\0A\00"
@.str.18 = [44 x i8] c"frequency = %d, bytes = %d, input_dev = %d\0A\00"
@.str.19 = [21 x i8] c"frequency error: %d\0A\00"
@.str.20 = [24 x i8] c"Sound format set error\0A\00"
@.str.21 = [28 x i8] c"SOUND_PCM_WRITE_RATE error\0A\00"
@.str.22 = [32 x i8] c"SOUND_PCM_WRITE_CHANNELS error\0A\00"
@.str.23 = [42 x i8] c"Unknown input src, using the default one\0A\00"
@.str.24 = [32 x i8] c"SOUND_MIXER_WRITE_RECSRC error\0A\00"
@.str.25 = [27 x i8] c"Error reading audio data \0A\00"
@.str.26 = [31 x i8] c"%d bytes read from the device\0A\00"
@.str.27 = [12 x i8] c"/dev/audio\0A\00"
@.str.28 = [24 x i8] c" total bytes read: (%d)\00"
@.str.29 = [20 x i8] c"Closing the device\0A\00"
@.str.30 = [28 x i8] c"Unsuccessful operation (2)\0A\00"
@.str.31 = [28 x i8] c"Unsuccessful operation (1)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i16
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [32768 x i16]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32*
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 6
br i1 %25, label %26, label %41
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %3
br label %194
41: ; preds = %2
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
store i32 %45, i32* %18
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = call i32 @atoi(i8* %48)
store i32 %49, i32* %12
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 4
%52 = load i8*, i8** %51
%53 = call i32 @atoi(i8* %52)
store i32 %53, i32* %10
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 5
%56 = load i8*, i8** %55
%57 = call i32 @atoi(i8* %56)
store i32 %57, i32* %11
%58 = load i32, i32* @O_RDONLY
%59 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %58)
store i32 %59, i32* %21
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %41
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %3
br label %194
63: ; preds = %41
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i32* @fopen(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
store i32* %67, i32** %20
%68 = icmp ule i32* %67, null
br i1 %68, label %69, label %71
69: ; preds = %63
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.15, i64 0, i64 0))
br label %190
71: ; preds = %63
%72 = load i32, i32* %11
%73 = icmp ne i32 %72, 2
br i1 %73, label %74, label %80
74: ; preds = %71
%75 = load i32, i32* %11
%76 = icmp ne i32 %75, 1
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32, i32* %11
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0), i32 %78)
br label %186
80: ; preds = %74, %71
%81 = load i32, i32* %11
%82 = icmp eq i32 %81, 2
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = load i32, i32* %18
%85 = icmp ne i32 %84, 1
br i1 %85, label %86, label %88
86: ; preds = %83
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.17, i64 0, i64 0))
store i32 1, i32* %11
br label %88
88: ; preds = %86, %83, %80
%89 = load i32, i32* %10
%90 = load i32, i32* %12
%91 = load i32, i32* %18
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.18, i64 0, i64 0), i32 %89, i32 %90, i32 %91)
%93 = load i32, i32* %10
%94 = icmp ne i32 %93, 16000
br i1 %94, label %95, label %101
95: ; preds = %88
%96 = load i32, i32* %10
%97 = icmp ne i32 %96, 8000
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i32, i32* %10
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.19, i64 0, i64 0), i32 %99)
br label %186
101: ; preds = %95, %88
store i32 16, i32* %22
%102 = load i32, i32* %21
%103 = call i32 @ioctl(i32 %102, i32 1610895365, i32* %22)
store i32 %103, i32* %17
%104 = load i32, i32* %17
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %101
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.20, i64 0, i64 0))
br label %186
108: ; preds = %101
%109 = load i32, i32* %21
%110 = call i32 @ioctl(i32 %109, i32 1610895362, i32* %10)
store i32 %110, i32* %17
%111 = load i32, i32* %17
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %108
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.21, i64 0, i64 0))
br label %186
115: ; preds = %108
%116 = load i32, i32* %21
%117 = call i32 @ioctl(i32 %116, i32 1610895366, i32* %11)
store i32 %117, i32* %17
%118 = load i32, i32* %17
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %115
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.22, i64 0, i64 0))
br label %186
122: ; preds = %115
%123 = load i32, i32* %18
switch i32 %123, label %127 [
i32 1, label %124
i32 2, label %125
i32 3, label %126
]
124: ; preds = %122
store i32 1048576, i32* %16
br label %129
125: ; preds = %122
store i32 128, i32* %16
br label %129
126: ; preds = %122
store i32 64, i32* %16
br label %129
127: ; preds = %122
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.23, i64 0, i64 0))
store i32 128, i32* %16
br label %129
129: ; preds = %127, %126, %125, %124
%130 = load i32, i32* %21
%131 = call i32 @ioctl(i32 %130, i32 1610894847, i32* %16)
store i32 %131, i32* %17
%132 = load i32, i32* %17
%133 = icmp slt i32 %132, 0
br i1 %133, label %134, label %136
134: ; preds = %129
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.24, i64 0, i64 0))
br label %186
136: ; preds = %129
%137 = getelementptr inbounds [32768 x i16], [32768 x i16]* %15, i64 0, i64 0
%138 = call i32 @memset(i16* %137, i32 0, i32 32768)
%139 = getelementptr inbounds [32768 x i16], [32768 x i16]* %15, i64 0, i64 0
%140 = load i32*, i32** %20
%141 = call i32 @fwrite(i16* %139, i32 44, i32 1, i32* %140)
%142 = load i32, i32* %12
store i32 %142, i32* %8
store i32 %142, i32* %13
br label %143
143: ; preds = %177, %136
%144 = load i32, i32* %8
%145 = icmp sgt i32 %144, 0
br i1 %145, label %146, label %178
146: ; preds = %143
%147 = load i32, i32* %13
%148 = icmp sgt i32 %147, 32768
br i1 %148, label %149, label %150
149: ; preds = %146
store i32 32768, i32* %13
br label %150
150: ; preds = %149, %146
%151 = load i32, i32* %21
%152 = getelementptr inbounds [32768 x i16], [32768 x i16]* %15, i64 0, i64 0
%153 = load i32, i32* %13
%154 = call i32 @read(i32 %151, i16* %152, i32 %153)
store i32 %154, i32* %9
%155 = load i32, i32* %9
%156 = icmp slt i32 %155, 0
br i1 %156, label %157, label %159
157: ; preds = %150
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.25, i64 0, i64 0))
br label %178
159: ; preds = %150
%160 = load i32, i32* %9
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.26, i64 0, i64 0), i32 %160)
%162 = load i32, i32* %9
%163 = load i32, i32* %8
%164 = sub nsw i32 %163, %162
store i32 %164, i32* %8
%165 = load i32, i32* %8
store i32 %165, i32* %13
%166 = load i32, i32* %9
%167 = load i32, i32* %14
%168 = add nsw i32 %167, %166
store i32 %168, i32* %14
%169 = getelementptr inbounds [32768 x i16], [32768 x i16]* %15, i64 0, i64 0
%170 = load i32, i32* %9
%171 = load i32*, i32** %20
%172 = call i32 @fwrite(i16* %169, i32 1, i32 %170, i32* %171)
store i32 %172, i32* %19
%173 = load i32, i32* %19
%174 = icmp slt i32 %173, 0
br i1 %174, label %175, label %177
175: ; preds = %159
%176 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.27, i64 0, i64 0))
br label %177
177: ; preds = %175, %159
br label %143
178: ; preds = %157, %143
%179 = load i32, i32* %14
%180 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.28, i64 0, i64 0), i32 %179)
store i16 16, i16* %7
%181 = load i32, i32* %11
%182 = trunc i32 %181 to i16
store i16 %182, i16* %6
%183 = load i32*, i32** %20
%184 = call i32 @write_wav_header(i32* %183, i32* %14, i16* %6, i32* %10, i16* %7)
%185 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.29, i64 0, i64 0))
store i32 0, i32* %3
br label %194
186: ; preds = %134, %120, %113, %106, %98, %77
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.30, i64 0, i64 0))
%188 = load i32*, i32** %20
%189 = call i32 @fclose(i32* %188)
br label %190
190: ; preds = %186, %69
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.31, i64 0, i64 0))
%192 = load i32, i32* %21
%193 = call i32 @close(i32 %192)
store i32 1, i32* %3
br label %194
194: ; preds = %190, %178, %61, %26
%195 = load i32, i32* %3
ret i32 %195
}

LLVM IR (-O2):
@.str.2 = [70 x i8] c"Usage: %s <soundfile.wav> <input_dev> <bytes> <frequency> <channels>\0A\00"
@.str.12 = [15 x i8] c"/dev/sound/dsp\00"
@O_RDONLY = global i32 0
@.str.13 = [29 x i8] c"Error opening /dev/sound/dsp\00"
@.str.14 = [3 x i8] c"w+\00"
@.str.15 = [36 x i8] c"Error when creating the sample file\00"
@.str.16 = [20 x i8] c"channels error: %d\0A\00"
@.str.18 = [44 x i8] c"frequency = %d, bytes = %d, input_dev = %d\0A\00"
@.str.19 = [21 x i8] c"frequency error: %d\0A\00"
@.str.26 = [31 x i8] c"%d bytes read from the device\0A\00"
@.str.27 = [12 x i8] c"/dev/audio\0A\00"
@.str.28 = [24 x i8] c" total bytes read: (%d)\00"
@str = [7 x i8] c"Hi... \00"
@str.32 = [19 x i8] c"Closing the device\00"
@str.33 = [26 x i8] c"Error reading audio data \00"
@str.34 = [31 x i8] c"SOUND_MIXER_WRITE_RECSRC error\00"
@str.35 = [27 x i8] c"Unsuccessful operation (2)\00"
@str.36 = [27 x i8] c"Unsuccessful operation (1)\00"
@str.37 = [41 x i8] c"Unknown input src, using the default one\00"
@str.38 = [31 x i8] c"SOUND_PCM_WRITE_CHANNELS error\00"
@str.39 = [27 x i8] c"SOUND_PCM_WRITE_RATE error\00"
@str.40 = [23 x i8] c"Sound format set error\00"
@str.41 = [71 x i8] c"Stereo recording not supported for this device, \09\09\09\09using mono instead\00"
@str.42 = [63 x i8] c"Records an audio file from /dev/sound/dsp1 (uncompressed data)\00"
@str.43 = [43 x i8] c"soundfile.wav : wav file to be created\0A\00"
@str.44 = [62 x i8] c"input_dev options: 1 (handset, J4, for mono/stereo recording)\00"
@str.45 = [55 x i8] c" 2 (headset, J3, for mono recording)\00"
@str.46 = [42 x i8] c"\09\09 3 (line in, J7, for mono recording)\0A\00"
@str.47 = [46 x i8] c"bytes : Amount of bytes to record\0A\00"
@str.48 = [24 x i8] c"frequency options: 8000\00"
@str.49 = [26 x i8] c" 16000\0A\00"
@str.50 = [28 x i8] c"channels options : 1 (mono)\00"
@str.51 = [61 x i8] c" 2 (stereo, ONLY WORKS for input_dev = 1)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca i16
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [32768 x i16]
%9 = alloca i32
%10 = alloca i32
%11 = bitcast i16* %3 to i8*
%12 = bitcast i16* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = bitcast i32* %7 to i8*
%16 = bitcast [32768 x i16]* %8 to i8*
%17 = bitcast i32* %9 to i8*
%18 = bitcast i32* %10 to i8*
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%20 = icmp eq i32 %0, 6
br i1 %20, label %34, label %21
21: ; preds = %2
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.42, i64 0, i64 0))
%23 = load i8*, i8** %1
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.43, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.44, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.45, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.46, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.47, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.48, i64 0, i64 0))
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.49, i64 0, i64 0))
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.50, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.51, i64 0, i64 0))
br label %137
34: ; preds = %2
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = tail call i32 @atoi(i8* %36)
%38 = getelementptr inbounds i8*, i8** %1, i64 3
%39 = load i8*, i8** %38
%40 = tail call i32 @atoi(i8* %39)
%41 = getelementptr inbounds i8*, i8** %1, i64 4
%42 = load i8*, i8** %41
%43 = tail call i32 @atoi(i8* %42)
store i32 %43, i32* %5
%44 = getelementptr inbounds i8*, i8** %1, i64 5
%45 = load i8*, i8** %44
%46 = tail call i32 @atoi(i8* %45)
store i32 %46, i32* %6
%47 = load i32, i32* @O_RDONLY
%48 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %47)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %34
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
br label %137
52: ; preds = %34
%53 = getelementptr inbounds i8*, i8** %1, i64 1
%54 = load i8*, i8** %53
%55 = tail call i32* @fopen(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.15, i64 0, i64 0))
br label %134
59: ; preds = %52
%60 = add i32 %46, -3
%61 = icmp ult i32 %60, -2
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0), i32 %46)
br label %131
64: ; preds = %59
%65 = icmp eq i32 %46, 2
%66 = icmp ne i32 %37, 1
%67 = select i1 %65, i1 %66, i1 false
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.41, i64 0, i64 0))
store i32 1, i32* %6
br label %70
70: ; preds = %68, %64
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.18, i64 0, i64 0), i32 %43, i32 %40, i32 %37)
switch i32 %43, label %72 [
i32 16000, label %74
i32 8000, label %74
]
72: ; preds = %70
%73 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.19, i64 0, i64 0), i32 %43)
br label %131
74: ; preds = %70, %70
store i32 16, i32* %10
%75 = call i32 @ioctl(i32 %48, i32 1610895365, i32* %10)
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.40, i64 0, i64 0))
br label %131
79: ; preds = %74
%80 = call i32 @ioctl(i32 %48, i32 1610895362, i32* %5)
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.39, i64 0, i64 0))
br label %131
84: ; preds = %79
%85 = call i32 @ioctl(i32 %48, i32 1610895366, i32* %6)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.38, i64 0, i64 0))
br label %131
89: ; preds = %84
switch i32 %37, label %93 [
i32 1, label %90
i32 2, label %91
i32 3, label %92
]
90: ; preds = %89
store i32 1048576, i32* %9
br label %95
91: ; preds = %89
store i32 128, i32* %9
br label %95
92: ; preds = %89
store i32 64, i32* %9
br label %95
93: ; preds = %89
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.37, i64 0, i64 0))
store i32 128, i32* %9
br label %95
95: ; preds = %93, %92, %91, %90
%96 = call i32 @ioctl(i32 %48, i32 1610894847, i32* %9)
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.34, i64 0, i64 0))
br label %131
100: ; preds = %95
%101 = getelementptr inbounds [32768 x i16], [32768 x i16]* %8, i64 0, i64 0
%102 = call i32 @memset(i16* %101, i32 0, i32 32768)
%103 = call i32 @fwrite(i16* %101, i32 44, i32 1, i32* %55)
%104 = icmp sgt i32 %40, 0
br label %105
105: ; preds = %100, %122
%106 = phi i32 [ %117, %122 ], [ undef, %100 ]
%107 = phi i32 [ %116, %122 ], [ %40, %100 ]
%108 = icmp ult i32 %107, 32768
%109 = select i1 %108, i32 %107, i32 32768
%110 = call i32 @read(i32 %48, i16* %101, i32 %109)
%111 = icmp slt i32 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %105
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.33, i64 0, i64 0))
br label %124
114: ; preds = %105
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.26, i64 0, i64 0), i32 %110)
%116 = sub nsw i32 %107, %110
%117 = add nsw i32 %106, %110
store i32 %117, i32* %7
%118 = call i32 @fwrite(i16* %101, i32 1, i32 %110, i32* %55)
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %114
%121 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.27, i64 0, i64 0))
br label %122
122: ; preds = %120, %114
%123 = icmp sgt i32 %116, 0
br i1 %123, label %105, label %124
124: ; preds = %122, %112
%125 = phi i32 [ %106, %112 ], [ %117, %122 ]
%126 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.28, i64 0, i64 0), i32 %125)
store i16 16, i16* %4
%127 = load i32, i32* %6
%128 = trunc i32 %127 to i16
store i16 %128, i16* %3
%129 = call i32 @write_wav_header(i32* %55, i32* %7, i16* %3, i32* %5, i16* %4)
%130 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.32, i64 0, i64 0))
br label %137
131: ; preds = %98, %87, %82, %77, %72, %62
%132 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.35, i64 0, i64 0))
%133 = call i32 @fclose(i32* %55)
br label %134
134: ; preds = %131, %57
%135 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.36, i64 0, i64 0))
%136 = call i32 @close(i32 %48)
br label %137
137: ; preds = %134, %124, %50, %21
%138 = phi i32 [ 0, %21 ], [ 1, %50 ], [ 1, %134 ], [ 0, %124 ]
ret i32 %138
}