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

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int get_channel_count(int /*<<< orphan*/ *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_ID(int /*<<< orphan*/ *, int *);
int read_ckDataSize(int /*<<< orphan*/ *);
scalar_t__ strcmp(int *, char *);
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  int channelcount;
  uint8_t *inbuf, *outbuf;
  uint8_t tmp, ckID[5], tmparr[256];
  uint64_t i, j, k, n;
  uint64_t frm8size, chunksize, curpos, dsddatasize, inbufsize;
  if (argc != 3) {
    printf("Usage: %s input.dff output.pcm\n", argv[0]);
    exit(1);
  }
  infile = fopen(argv[1], "rb");
  if (infile == NULL) {
    printf("cannot open input\n");
    exit(1);
  }
  outfile = fopen(argv[2], "wb");
  if (outfile == NULL) {
    printf("cannot open output\n");
    exit(1);
  }
  read_ID(infile, ckID);
  if (strcmp(ckID, "FRM8")) {
    printf("not a valid DSDIFF file");
    exit(1);
  }
  frm8size = read_ckDataSize(infile);
  read_ID(infile, ckID);
  if (strcmp(ckID, "DSD ")) {
    printf("not a valid DSDIFF file");
    exit(1);
  }
  n = ftell(infile);
  while (n < 16 + frm8size) {
    read_ID(infile, ckID);
    chunksize = read_ckDataSize(infile);
    if (strcmp(ckID, "PROP") == 0) {
      printf("PROP chunk\n");
      read_ID(infile, ckID);
      if (strcmp(ckID, "SND ")) {
        printf("PROP chunk is not of type SND , skipping");
        fseek(infile, chunksize - 4, SEEK_CUR);
      }
      channelcount = get_channel_count(infile, chunksize - 4);
    } else if (strcmp(ckID, "DSD ") == 0) {
      printf("DSD  chunk\n");
      dsddatasize = chunksize;
      goto processdsddata;
    } else {
      fseek(infile, chunksize, SEEK_CUR);
    }
    n = ftell(infile);
  }
  printf("FAIL: no DSD data!!\n");
  exit(1);
processdsddata:
  inbufsize = channelcount * (44100 * 16) / 8;
  inbuf = malloc(inbufsize);
  outbuf = malloc(channelcount * (44100 * 16));
  while (dsddatasize > 0) {
    n = fread(inbuf, 1, (dsddatasize < inbufsize ? dsddatasize : inbufsize),
              infile);
    dsddatasize -= n;
    for (i = 0; i < n / channelcount; i++) {
      for (j = 0; j < channelcount; j++) {
        tmp = inbuf[i * channelcount + j];
        for (k = 0; k < 8; k++) {
          outbuf[i * channelcount * 8 + j + k * channelcount] =
              (tmp & 0x80) | 0x40;
          tmp = tmp << 1;
        }
      }
    }
    fwrite(outbuf, 1, n * 8, outfile);
  }
  fclose(infile);
  fclose(outfile);
  printf("DONE!\n");
  printf("When you load the pcm file, set channels = %d and sample format = "
         "8bit unsigned/signed (doesn't matter for this program's output)\n",
         channelcount);
  printf("Set sample rate to %d if possible. If not, set it to anything you "
         "like and take this into account when reading timestamps and spectral "
         "displays\n",
         44100 * 64);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1212 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdff(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124d <main+0x7d>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdda(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1288 <main+0xb8>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   10b0 <read_ID@plt>
lea    -0x50(%rbp),%rdi
lea    0xdad(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12c7 <main+0xf7>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <read_ckDataSize@plt>
mov    %eax,-0x464(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   10b0 <read_ID@plt>
lea    -0x50(%rbp),%rdi
lea    0xd7c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1315 <main+0x145>
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x460(%rbp)
mov    -0x460(%rbp),%eax
mov    -0x464(%rbp),%ecx
add    $0x10,%ecx
cmp    %ecx,%eax
jge    1453 <main+0x283>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   10b0 <read_ID@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <read_ckDataSize@plt>
mov    %eax,-0x468(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xd0d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    13e9 <main+0x219>
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   10b0 <read_ID@plt>
lea    -0x50(%rbp),%rdi
lea    0xce9(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     13cf <main+0x1ff>
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x468(%rbp),%esi
sub    $0x4,%esi
mov    0x2c20(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
mov    -0x468(%rbp),%esi
sub    $0x4,%esi
call   10a0 <get_channel_count@plt>
mov    %eax,-0x24(%rbp)
jmp    143f <main+0x26f>
lea    -0x50(%rbp),%rdi
lea    0xc76(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1422 <main+0x252>
lea    0xca4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x468(%rbp),%eax
mov    %eax,-0x470(%rbp)
jmp    146b <main+0x29b>
mov    -0x18(%rbp),%rdi
mov    -0x468(%rbp),%esi
mov    0x2bb5(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
jmp    143f <main+0x26f>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x460(%rbp)
jmp    1324 <main+0x154>
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
imul   $0xac440,-0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x474(%rbp)
mov    -0x474(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
imul   $0xac440,-0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x470(%rbp)
jle    163c <main+0x46c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x480(%rbp)
mov    -0x470(%rbp),%eax
cmp    -0x474(%rbp),%eax
jge    14da <main+0x30a>
mov    -0x470(%rbp),%eax
mov    %eax,-0x484(%rbp)
jmp    14e6 <main+0x316>
mov    -0x474(%rbp),%eax
mov    %eax,-0x484(%rbp)
mov    -0x480(%rbp),%rdi
mov    -0x484(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x460(%rbp)
mov    -0x460(%rbp),%ecx
mov    -0x470(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x470(%rbp)
movl   $0x0,-0x454(%rbp)
mov    -0x454(%rbp),%eax
mov    %eax,-0x488(%rbp)
mov    -0x460(%rbp),%eax
cltd
idivl  -0x24(%rbp)
mov    %eax,%ecx
mov    -0x488(%rbp),%eax
cmp    %ecx,%eax
jge    161c <main+0x44c>
movl   $0x0,-0x458(%rbp)
mov    -0x458(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1603 <main+0x433>
mov    -0x30(%rbp),%rax
mov    -0x454(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x458(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x45c(%rbp)
cmpl   $0x8,-0x45c(%rbp)
jge    15ea <main+0x41a>
mov    -0x3c(%rbp),%edx
and    $0x80,%edx
or     $0x40,%edx
mov    -0x38(%rbp),%rax
mov    -0x454(%rbp),%ecx
imul   -0x24(%rbp),%ecx
shl    $0x3,%ecx
add    -0x458(%rbp),%ecx
mov    -0x45c(%rbp),%esi
imul   -0x24(%rbp),%esi
add    %esi,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x3c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x45c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x45c(%rbp)
jmp    158b <main+0x3bb>
jmp    15ef <main+0x41f>
mov    -0x458(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x458(%rbp)
jmp    1555 <main+0x385>
jmp    1608 <main+0x438>
mov    -0x454(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x454(%rbp)
jmp    1525 <main+0x355>
mov    -0x38(%rbp),%rdi
mov    -0x460(%rbp),%edx
shl    $0x3,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
jmp    149f <main+0x2cf>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xa7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xa70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xae5(%rip),%rdi
mov    $0x2b1100,%esi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    15bc <main+0x3dc>
mov    0x8(%rbx),%rdi
lea    0xe1b(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     15d7 <main+0x3f7>
mov    0x10(%rbx),%rdi
lea    0xe00(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     15e0 <main+0x400>
lea    0x30(%rsp),%rbp
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10c0 <read_ID@plt>
lea    0xdd4(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    15a4 <main+0x3c4>
mov    %rbx,%rdi
call   10d0 <read_ckDataSize@plt>
mov    %eax,%ebp
lea    0x30(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <read_ID@plt>
lea    0xdbf(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    15a4 <main+0x3c4>
mov    %rbx,%rdi
call   1080 <ftell@plt>
add    $0x10,%ebp
cmp    %ebp,%eax
jge    158e <main+0x3ae>
lea    0x30(%rsp),%r12
lea    0xd94(%rip),%r13
jmp    1333 <main+0x153>
cs nopw 0x0(%rax,%rax,1)
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <read_ID@plt>
mov    %r12,%rdi
lea    0xd6c(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1387 <main+0x1a7>
lea    0xd5c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xfffffffc,%r15d
mov    0x2ce0(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   10b0 <get_channel_count@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1080 <ftell@plt>
cmp    %ebp,%eax
jge    158e <main+0x3ae>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <read_ID@plt>
mov    %rbx,%rdi
call   10d0 <read_ckDataSize@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12c0 <main+0xe0>
mov    %r12,%rdi
lea    0xcdc(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     138d <main+0x1ad>
mov    0x2c70(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   10a0 <fseek@plt>
jmp    1323 <main+0x143>
add    $0xfffffffc,%r15d
jmp    1315 <main+0x135>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
imul   $0xac440,%r14d,%ebx
imul   $0x15888,%r14d,%edi
mov    %edi,0x10(%rsp)
call   1090 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,0x28(%rsp)
test   %r15d,%r15d
jle    1539 <main+0x359>
mov    %r15d,%ebx
movslq %r14d,%r13
mov    %r14d,%r12d
shl    $0x2,%r13
lea    0x0(,%r14,8),%r15d
jmp    1417 <main+0x237>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
shl    $0x3,%r8d
mov    0x28(%rsp),%rdi
mov    $0x1,%esi
mov    %r8d,%edx
mov    0x18(%rsp),%rcx
call   1100 <fwrite@plt>
mov    0x14(%rsp),%ebx
test   %ebx,%ebx
jle    1539 <main+0x359>
mov    0x10(%rsp),%edx
cmp    %edx,%ebx
cmovl  %ebx,%edx
mov    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    0x8(%rsp),%rcx
call   1040 <fread@plt>
mov    %eax,%r8d
sub    %eax,%ebx
mov    %ebx,0x14(%rsp)
cltd
idiv   %r14d
test   %eax,%eax
jle    13f0 <main+0x210>
mov    %eax,%r9d
xor    %r10d,%r10d
mov    0x20(%rsp),%rsi
xor    %r11d,%r11d
jmp    146f <main+0x28f>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r11
add    %r15d,%r10d
add    %r13,%rsi
cmp    %r9,%r11
je     13f0 <main+0x210>
test   %r14d,%r14d
jle    1460 <main+0x280>
movslq %r10d,%rax
mov    0x28(%rsp),%rcx
lea    (%rcx,%rax,4),%rcx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsi,%rbp,4),%edi
mov    %edi,%ebx
and    $0x80,%ebx
or     $0x40,%ebx
lea    (%rcx,%rbp,4),%rax
mov    %ebx,(%rcx,%rbp,4)
mov    %edi,%ebx
and    $0x40,%ebx
add    %ebx,%ebx
add    $0x40,%ebx
mov    %ebx,0x0(%r13,%rax,1)
add    %r13,%rax
mov    %edi,%ebx
and    $0x20,%ebx
lea    0x40(,%rbx,4),%ebx
mov    %ebx,0x0(%r13,%rax,1)
add    %r13,%rax
mov    %edi,%ebx
and    $0x10,%ebx
lea    0x40(,%rbx,8),%ebx
mov    %ebx,0x0(%r13,%rax,1)
add    %r13,%rax
mov    %edi,%edx
and    $0x8,%edx
shl    $0x4,%edx
or     $0x40,%edx
mov    %edx,0x0(%r13,%rax,1)
add    %r13,%rax
mov    %edi,%edx
and    $0x4,%edx
shl    $0x5,%edx
or     $0x40,%edx
mov    %edx,0x0(%r13,%rax,1)
add    %r13,%rax
mov    %edi,%edx
shl    $0x6,%edx
or     $0x40,%edx
movzbl %dl,%edx
mov    %edx,0x0(%r13,%rax,1)
add    %r13,%rax
shl    $0x7,%edi
or     $0x40,%edi
movzbl %dil,%edx
mov    %edx,0x0(%r13,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1490 <main+0x2b0>
jmp    1460 <main+0x280>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
mov    0x18(%rsp),%rdi
call   1050 <fclose@plt>
lea    0xc5a(%rip),%rdi
call   1030 <puts@plt>
lea    0xb1b(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xb8d(%rip),%rdi
mov    $0x2b1100,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbfa(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xa80(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    (%rbx),%rsi
lea    0xa3a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xbf4(%rip),%rdi
jmp    1595 <main+0x3b5>
lea    0xbd8(%rip),%rdi
jmp    1595 <main+0x3b5>

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: %s input.dff output.pcm\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"cannot open input\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [20 x i8] c"cannot open output\0A\00"
@.str.5 = [5 x i8] c"FRM8\00"
@.str.6 = [24 x i8] c"not a valid DSDIFF file\00"
@.str.7 = [5 x i8] c"DSD \00"
@.str.8 = [5 x i8] c"PROP\00"
@.str.9 = [12 x i8] c"PROP chunk\0A\00"
@.str.10 = [5 x i8] c"SND \00"
@.str.11 = [41 x i8] c"PROP chunk is not of type SND , skipping\00"
@SEEK_CUR = global i32 0
@.str.12 = [12 x i8] c"DSD chunk\0A\00"
@.str.13 = [21 x i8] c"FAIL: no DSD data!!\0A\00"
@.str.14 = [7 x i8] c"DONE!\0A\00"
@.str.15 = [131 x i8] c"When you load the pcm file, set channels = %d and sample format = 8bit unsigned/signed (doesn't matter for this program's output)\0A\00"
@.str.16 = [145 x i8] c"Set sample rate to %d if possible. If not, set it to anything you like and take this into account when reading timestamps and spectral displays\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 i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [5 x i32]
%13 = alloca [256 x i32]
%14 = alloca i32
%15 = alloca i32
%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 = load i32, i32* %4
%24 = icmp ne i32 %23, 3
br i1 %24, label %25, label %31
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %6
%36 = load i32*, i32** %6
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %31
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %45, i32** %7
%46 = load i32*, i32** %7
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %41
%52 = load i32*, i32** %6
%53 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%54 = call i32 @read_ID(i32* %52, i32* %53)
%55 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%56 = call i64 @strcmp(i32* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %51
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %51
%62 = load i32*, i32** %6
%63 = call i32 @read_ckDataSize(i32* %62)
store i32 %63, i32* %18
%64 = load i32*, i32** %6
%65 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%66 = call i32 @read_ID(i32* %64, i32* %65)
%67 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%68 = call i64 @strcmp(i32* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %61
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %61
%74 = load i32*, i32** %6
%75 = call i32 @ftell(i32* %74)
store i32 %75, i32* %17
br label %76
76: ; preds = %123, %73
%77 = load i32, i32* %17
%78 = load i32, i32* %18
%79 = add nsw i32 16, %78
%80 = icmp slt i32 %77, %79
br i1 %80, label %81, label %126
81: ; preds = %76
%82 = load i32*, i32** %6
%83 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%84 = call i32 @read_ID(i32* %82, i32* %83)
%85 = load i32*, i32** %6
%86 = call i32 @read_ckDataSize(i32* %85)
store i32 %86, i32* %19
%87 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%88 = call i64 @strcmp(i32* %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %110
90: ; preds = %81
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
%92 = load i32*, i32** %6
%93 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%94 = call i32 @read_ID(i32* %92, i32* %93)
%95 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%96 = call i64 @strcmp(i32* %95, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %105
98: ; preds = %90
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.11, i64 0, i64 0))
%100 = load i32*, i32** %6
%101 = load i32, i32* %19
%102 = sub nsw i32 %101, 4
%103 = load i32, i32* @SEEK_CUR
%104 = call i32 @fseek(i32* %100, i32 %102, i32 %103)
br label %105
105: ; preds = %98, %90
%106 = load i32*, i32** %6
%107 = load i32, i32* %19
%108 = sub nsw i32 %107, 4
%109 = call i32 @get_channel_count(i32* %106, i32 %108)
store i32 %109, i32* %8
br label %123
110: ; preds = %81
%111 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%112 = call i64 @strcmp(i32* %111, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%113 = icmp eq i64 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %110
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%116 = load i32, i32* %19
store i32 %116, i32* %21
br label %129
117: ; preds = %110
%118 = load i32*, i32** %6
%119 = load i32, i32* %19
%120 = load i32, i32* @SEEK_CUR
%121 = call i32 @fseek(i32* %118, i32 %119, i32 %120)
br label %122
122: ; preds = %117
br label %123
123: ; preds = %122, %105
%124 = load i32*, i32** %6
%125 = call i32 @ftell(i32* %124)
store i32 %125, i32* %17
br label %76
126: ; preds = %76
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
%128 = call i32 @exit(i32 1)
unreachable
129: ; preds = %114
%130 = load i32, i32* %8
%131 = mul nsw i32 %130, 705600
%132 = sdiv i32 %131, 8
store i32 %132, i32* %22
%133 = load i32, i32* %22
%134 = call i32* @malloc(i32 %133)
store i32* %134, i32** %9
%135 = load i32, i32* %8
%136 = mul nsw i32 %135, 705600
%137 = call i32* @malloc(i32 %136)
store i32* %137, i32** %10
br label %138
138: ; preds = %211, %129
%139 = load i32, i32* %21
%140 = icmp sgt i32 %139, 0
br i1 %140, label %141, label %217
141: ; preds = %138
%142 = load i32*, i32** %9
%143 = load i32, i32* %21
%144 = load i32, i32* %22
%145 = icmp slt i32 %143, %144
br i1 %145, label %146, label %148
146: ; preds = %141
%147 = load i32, i32* %21
br label %150
148: ; preds = %141
%149 = load i32, i32* %22
br label %150
150: ; preds = %148, %146
%151 = phi i32 [ %147, %146 ], [ %149, %148 ]
%152 = load i32*, i32** %6
%153 = call i32 @fread(i32* %142, i32 1, i32 %151, i32* %152)
store i32 %153, i32* %17
%154 = load i32, i32* %17
%155 = load i32, i32* %21
%156 = sub nsw i32 %155, %154
store i32 %156, i32* %21
store i32 0, i32* %14
br label %157
157: ; preds = %208, %150
%158 = load i32, i32* %14
%159 = load i32, i32* %17
%160 = load i32, i32* %8
%161 = sdiv i32 %159, %160
%162 = icmp slt i32 %158, %161
br i1 %162, label %163, label %211
163: ; preds = %157
store i32 0, i32* %15
br label %164
164: ; preds = %204, %163
%165 = load i32, i32* %15
%166 = load i32, i32* %8
%167 = icmp slt i32 %165, %166
br i1 %167, label %168, label %207
168: ; preds = %164
%169 = load i32*, i32** %9
%170 = load i32, i32* %14
%171 = load i32, i32* %8
%172 = mul nsw i32 %170, %171
%173 = load i32, i32* %15
%174 = add nsw i32 %172, %173
%175 = sext i32 %174 to i64
%176 = getelementptr inbounds i32, i32* %169, i64 %175
%177 = load i32, i32* %176
store i32 %177, i32* %11
store i32 0, i32* %16
br label %178
178: ; preds = %200, %168
%179 = load i32, i32* %16
%180 = icmp slt i32 %179, 8
br i1 %180, label %181, label %203
181: ; preds = %178
%182 = load i32, i32* %11
%183 = and i32 %182, 128
%184 = or i32 %183, 64
%185 = load i32*, i32** %10
%186 = load i32, i32* %14
%187 = load i32, i32* %8
%188 = mul nsw i32 %186, %187
%189 = mul nsw i32 %188, 8
%190 = load i32, i32* %15
%191 = add nsw i32 %189, %190
%192 = load i32, i32* %16
%193 = load i32, i32* %8
%194 = mul nsw i32 %192, %193
%195 = add nsw i32 %191, %194
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i32, i32* %185, i64 %196
store i32 %184, i32* %197
%198 = load i32, i32* %11
%199 = shl i32 %198, 1
store i32 %199, i32* %11
br label %200
200: ; preds = %181
%201 = load i32, i32* %16
%202 = add nsw i32 %201, 1
store i32 %202, i32* %16
br label %178
203: ; preds = %178
br label %204
204: ; preds = %203
%205 = load i32, i32* %15
%206 = add nsw i32 %205, 1
store i32 %206, i32* %15
br label %164
207: ; preds = %164
br label %208
208: ; preds = %207
%209 = load i32, i32* %14
%210 = add nsw i32 %209, 1
store i32 %210, i32* %14
br label %157
211: ; preds = %157
%212 = load i32*, i32** %10
%213 = load i32, i32* %17
%214 = mul nsw i32 %213, 8
%215 = load i32*, i32** %7
%216 = call i32 @fwrite(i32* %212, i32 1, i32 %214, i32* %215)
br label %138
217: ; preds = %138
%218 = load i32*, i32** %6
%219 = call i32 @fclose(i32* %218)
%220 = load i32*, i32** %7
%221 = call i32 @fclose(i32* %220)
%222 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0))
%223 = load i32, i32* %8
%224 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.15, i64 0, i64 0), i32 %223)
%225 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.16, i64 0, i64 0), i32 2822400)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Usage: %s input.dff output.pcm\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.5 = [5 x i8] c"FRM8\00"
@.str.6 = [24 x i8] c"not a valid DSDIFF file\00"
@.str.7 = [5 x i8] c"DSD \00"
@.str.8 = [5 x i8] c"PROP\00"
@.str.10 = [5 x i8] c"SND \00"
@.str.11 = [41 x i8] c"PROP chunk is not of type SND , skipping\00"
@SEEK_CUR = global i32 0
@.str.15 = [131 x i8] c"When you load the pcm file, set channels = %d and sample format = 8bit unsigned/signed (doesn't matter for this program's output)\0A\00"
@.str.16 = [145 x i8] c"Set sample rate to %d if possible. If not, set it to anything you like and take this into account when reading timestamps and spectral displays\0A\00"
@str = [20 x i8] c"FAIL: no DSD data!!\00"
@str.17 = [11 x i8] c"DSD chunk\00"
@str.18 = [6 x i8] c"DONE!\00"
@str.19 = [11 x i8] c"PROP chunk\00"
@str.20 = [19 x i8] c"cannot open output\00"
@str.21 = [18 x i8] c"cannot open input\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i32]
%4 = bitcast [5 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.21, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.20, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%28 = call i32 @read_ID(i32* %13, i32* %27)
%29 = call i64 @strcmp(i32* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = call i32 @read_ckDataSize(i32* %13)
%36 = call i32 @read_ID(i32* %13, i32* %27)
%37 = call i64 @strcmp(i32* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = call i32 @ftell(i32* %13)
%44 = add nsw i32 %35, 16
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %94
46: ; preds = %42, %90
%47 = phi i32 [ %91, %90 ], [ undef, %42 ]
%48 = call i32 @read_ID(i32* %13, i32* %27)
%49 = call i32 @read_ckDataSize(i32* %13)
%50 = call i64 @strcmp(i32* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %67
52: ; preds = %46
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.19, i64 0, i64 0))
%54 = call i32 @read_ID(i32* %13, i32* %27)
%55 = call i64 @strcmp(i32* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = add nsw i32 %49, -4
br label %64
59: ; preds = %52
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.11, i64 0, i64 0))
%61 = add nsw i32 %49, -4
%62 = load i32, i32* @SEEK_CUR
%63 = call i32 @fseek(i32* %13, i32 %61, i32 %62)
br label %64
64: ; preds = %57, %59
%65 = phi i32 [ %58, %57 ], [ %61, %59 ]
%66 = call i32 @get_channel_count(i32* %13, i32 %65)
br label %90
67: ; preds = %46
%68 = call i64 @strcmp(i32* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %87
70: ; preds = %67
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.17, i64 0, i64 0))
%72 = mul nsw i32 %47, 705600
%73 = mul nsw i32 %47, 88200
%74 = call i32* @malloc(i32 %73)
%75 = call i32* @malloc(i32 %72)
%76 = icmp sgt i32 %49, 0
br i1 %76, label %77, label %167
77: ; preds = %70
%78 = icmp sgt i32 %47, 0
%79 = sext i32 %47 to i64
%80 = zext i32 %47 to i64
%81 = shl nsw i64 %79, 1
%82 = mul nsw i64 %79, 3
%83 = shl nsw i64 %79, 2
%84 = mul nsw i64 %79, 5
%85 = mul nsw i64 %79, 6
%86 = mul nsw i64 %79, 7
br label %97
87: ; preds = %67
%88 = load i32, i32* @SEEK_CUR
%89 = call i32 @fseek(i32* %13, i32 %49, i32 %88)
br label %90
90: ; preds = %87, %64
%91 = phi i32 [ %66, %64 ], [ %47, %87 ]
%92 = call i32 @ftell(i32* %13)
%93 = icmp slt i32 %92, %44
br i1 %93, label %46, label %94
94: ; preds = %90, %42
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %77, %163
%98 = phi i32 [ %49, %77 ], [ %102, %163 ]
%99 = icmp slt i32 %98, %73
%100 = select i1 %99, i32 %98, i32 %73
%101 = call i32 @fread(i32* %74, i32 1, i32 %100, i32* %13)
%102 = sub nsw i32 %98, %101
%103 = sdiv i32 %101, %47
%104 = icmp sgt i32 %103, 0
br i1 %104, label %105, label %163
105: ; preds = %97
%106 = zext i32 %103 to i64
br label %107
107: ; preds = %105, %160
%108 = phi i64 [ 0, %105 ], [ %161, %160 ]
br i1 %78, label %109, label %160
109: ; preds = %107
%110 = mul nsw i64 %108, %79
%111 = trunc i64 %110 to i32
%112 = shl nsw i32 %111, 3
%113 = sext i32 %112 to i64
br label %114
114: ; preds = %109, %114
%115 = phi i64 [ 0, %109 ], [ %158, %114 ]
%116 = add nsw i64 %115, %110
%117 = getelementptr inbounds i32, i32* %74, i64 %116
%118 = load i32, i32* %117
%119 = add nsw i64 %115, %113
%120 = and i32 %118, 128
%121 = or i32 %120, 64
%122 = getelementptr inbounds i32, i32* %75, i64 %119
store i32 %121, i32* %122
%123 = shl i32 %118, 1
%124 = and i32 %123, 128
%125 = or i32 %124, 64
%126 = add nsw i64 %119, %79
%127 = getelementptr inbounds i32, i32* %75, i64 %126
store i32 %125, i32* %127
%128 = shl i32 %118, 2
%129 = and i32 %128, 128
%130 = or i32 %129, 64
%131 = add nsw i64 %119, %81
%132 = getelementptr inbounds i32, i32* %75, i64 %131
store i32 %130, i32* %132
%133 = shl i32 %118, 3
%134 = and i32 %133, 128
%135 = or i32 %134, 64
%136 = add nsw i64 %119, %82
%137 = getelementptr inbounds i32, i32* %75, i64 %136
store i32 %135, i32* %137
%138 = shl i32 %118, 4
%139 = and i32 %138, 128
%140 = or i32 %139, 64
%141 = add nsw i64 %119, %83
%142 = getelementptr inbounds i32, i32* %75, i64 %141
store i32 %140, i32* %142
%143 = shl i32 %118, 5
%144 = and i32 %143, 128
%145 = or i32 %144, 64
%146 = add nsw i64 %119, %84
%147 = getelementptr inbounds i32, i32* %75, i64 %146
store i32 %145, i32* %147
%148 = shl i32 %118, 6
%149 = and i32 %148, 128
%150 = or i32 %149, 64
%151 = add nsw i64 %119, %85
%152 = getelementptr inbounds i32, i32* %75, i64 %151
store i32 %150, i32* %152
%153 = shl i32 %118, 7
%154 = and i32 %153, 128
%155 = or i32 %154, 64
%156 = add nsw i64 %119, %86
%157 = getelementptr inbounds i32, i32* %75, i64 %156
store i32 %155, i32* %157
%158 = add nuw nsw i64 %115, 1
%159 = icmp eq i64 %158, %80
br i1 %159, label %160, label %114
160: ; preds = %114, %107
%161 = add nuw nsw i64 %108, 1
%162 = icmp eq i64 %161, %106
br i1 %162, label %163, label %107
163: ; preds = %160, %97
%164 = shl nsw i32 %101, 3
%165 = call i32 @fwrite(i32* %75, i32 1, i32 %164, i32* %21)
%166 = icmp sgt i32 %102, 0
br i1 %166, label %97, label %167
167: ; preds = %163, %70
%168 = call i32 @fclose(i32* %13)
%169 = call i32 @fclose(i32* %21)
%170 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.18, i64 0, i64 0))
%171 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([131 x i8], [131 x i8]* @.str.15, i64 0, i64 0), i32 %47)
%172 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([145 x i8], [145 x i8]* @.str.16, i64 0, i64 0), i32 2822400)
ret i32 0
}