// File: Sleepwalking[P]world-octave/matlabfunctions.cpp
// Function: (anonymous namespace)::GetParameters(_IO_FILE*, int*, int*, int*)
bool GetParameters(FILE *fp, int *fs, int *nbit, int *wav_length) {
  char data_check[5] = {0};
  data_check[4] = '\0';
  unsigned char for_int_number[4];
  fread(for_int_number, 1, 4, fp);
  *fs = 0;
  for (int i = 3; i >= 0; --i) *fs = *fs * 256 + for_int_number[i];
  // Quantization
  fseek(fp, 6, SEEK_CUR);
  fread(for_int_number, 1, 2, fp);
  *nbit = for_int_number[0];

  // Skip until "data" is found. 2011/03/28
  while (0 != fread(data_check, 1, 1, fp)) {
    if (data_check[0] == 'd') {
      fread(&data_check[1], 1, 3, fp);
      if (0 != strcmp(data_check, "data")) {
        fseek(fp, -3, SEEK_CUR);
      } else {
        break;
      }
    }
  }
  if (0 != strcmp(data_check, "data")) {
    printf("data error.\n");
    return false;
  }

  fread(for_int_number, 1, 4, fp);  // "data"
  *wav_length = 0;
  for (int i = 3; i >= 0; --i)
    *wav_length = *wav_length * 256 + for_int_number[i];
  *wav_length /= (*nbit / 8);
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
leaq -0x2d(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x1080
movb $0x0, -0x29(%rbp)
leaq -0x31(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x1140
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl $0x3, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jl 0x830f
movq -0x18(%rbp), %rax
movl (%rax), %ecx
shll $0x8, %ecx
movslq -0x38(%rbp), %rax
movzbl -0x31(%rbp,%rax), %eax
addl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x82e4
movq -0x10(%rbp), %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x10e0
leaq -0x31(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x2, %edx
callq 0x1140
movzbl -0x31(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
leaq -0x2d(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1140
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x83bb
movsbl -0x2d(%rbp), %eax
cmpl $0x64, %eax
jne 0x83b9
leaq -0x2d(%rbp), %rdi
addq $0x1, %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x3, %edx
callq 0x1140
leaq -0x2d(%rbp), %rdi
leaq 0x1400a(%rip), %rsi     # 0x1c39b
callq 0x1130
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x83b5
movq -0x10(%rbp), %rdi
movq $-0x3, %rsi
movl $0x1, %edx
callq 0x10e0
jmp 0x83b7
jmp 0x83bb
jmp 0x83b9
jmp 0x8343
leaq -0x2d(%rbp), %rdi
leaq 0x13fd5(%rip), %rsi     # 0x1c39b
callq 0x1130
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x83e7
leaq 0x13fc6(%rip), %rdi     # 0x1c3a0
movb $0x0, %al
callq 0x1040
movb $0x0, -0x1(%rbp)
jmp 0x8463
leaq -0x31(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x1140
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movl $0x3, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x843a
movq -0x28(%rbp), %rax
movl (%rax), %ecx
shll $0x8, %ecx
movslq -0x3c(%rbp), %rax
movzbl -0x31(%rbp,%rax), %eax
addl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x840f
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movl (%rax), %eax
cltd
idivl %ecx
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nop