// File: /workspace/github_cpp_makefile_star2_O2/jp-myk[P]WAVUtil/src/SimpleWAV/WAV.cpp
// Function: WAV::Write(char const*)
int WAV::Write(const char* WAVFName){
  std::ofstream ofs;
  ofs.open(WAVFName);
  ofs.write((const char*)_riffID, 4);
  ofs.write((const char*)&_size, 4);
  ofs.write((const char*)_wavID, 4);
  ofs.write((const char*)_fmtID, 4);
  ofs.write((const char*)&_fmtSize, 4);
  ofs.write((const char*)&_format, 2);
  ofs.write((const char*)&_channels, 2);
  ofs.write((const char*)&_sampleRate, 4);
  ofs.write((const char*)&_bytePerSec, 4);
  ofs.write((const char*)&_blockSize, 2);
  ofs.write((const char*)&_bit, 2);
  ofs.write((const char*)_dataID, 4);
  ofs.write((const char*)&_dataSize, 4);
  if(_channels==1){
    if(_bit==8){
      ofs.write((const char*)_monoral8, _dataSize);
    }else if(_bit==16){
      ofs.write((const char*)_monoral16, _dataSize);
    }else{
      std::cout << "error: bytePerSec 8 16 => " << _bit << std::endl;
      return -1;
    }
  }else if(_channels==2){
    if(_bit==8){
      ofs.write((const char*)_stereo8, _dataSize);
    }else if(_bit==16){
      ofs.write((const char*)_stereo16, _dataSize);
    }else{
      std::cout << "error: bytePerSec 8 16 => " << _bit << std::endl;
      return -1;
    }
  }else{
    std::cout << "error: channel 1 or 2 => " << _channels  << std::endl;
    return -1;
  }
  
  ofs.close();
  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movq %rsi, %r14
movq %rdi, %rbx
movq %rsp, %r15
movq %r15, %rdi
callq 0x21f0
pushq $0x10
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2040
movq %rsp, %rdi
pushq $0x4
popq %rdx
movq %rbx, %rsi
callq 0x2160
leaq 0x4(%rbx), %rsi
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x2160
leaq 0x8(%rbx), %rsi
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x2160
leaq 0xc(%rbx), %rsi
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x2160
leaq 0x10(%rbx), %rsi
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x2160
leaq 0x14(%rbx), %rsi
movq %rsp, %rdi
pushq $0x2
popq %rdx
callq 0x2160
leaq 0x16(%rbx), %r14
movq %rsp, %rdi
pushq $0x2
popq %rdx
movq %r14, %rsi
callq 0x2160
leaq 0x18(%rbx), %rsi
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x2160
leaq 0x1c(%rbx), %rsi
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x2160
leaq 0x20(%rbx), %rsi
movq %rsp, %rdi
pushq $0x2
popq %rdx
callq 0x2160
leaq 0x22(%rbx), %r15
movq %rsp, %rdi
pushq $0x2
popq %rdx
movq %r15, %rsi
callq 0x2160
leaq 0x24(%rbx), %rsi
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x2160
leaq 0x28(%rbx), %rsi
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x2160
movzwl (%r14), %eax
cmpl $0x2, %eax
je 0x2761
cmpl $0x1, %eax
jne 0x2773
movzwl (%r15), %eax
cmpl $0x8, %eax
je 0x27b7
cmpl $0x10, %eax
jne 0x278b
pushq $0x40
jmp 0x27bd
movzwl (%r15), %eax
cmpl $0x8, %eax
je 0x27bb
cmpl $0x10, %eax
jne 0x278b
pushq $0x50
jmp 0x27bd
movq 0x3856(%rip), %rdi      # 0x5fd0
leaq 0x1921(%rip), %rsi      # 0x40a2
callq 0x2100
movq %r14, %r15
jmp 0x279e
movq 0x383e(%rip), %rdi      # 0x5fd0
leaq 0x18ee(%rip), %rsi      # 0x4087
callq 0x2100
movzwl (%r15), %esi
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20a0
pushq $-0x1
popq %rbx
jmp 0x27d7
pushq $0x38
jmp 0x27bd
pushq $0x48
popq %rax
movq (%rbx,%rax), %rsi
movl 0x28(%rbx), %edx
movq %rsp, %rdi
callq 0x2160
xorl %ebx, %ebx
movq %rsp, %rdi
callq 0x2180
movq %rsp, %rdi
callq 0x21a0
movl %ebx, %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq %rsp, %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x2200
nop