// File: /workspace/github_cpp_makefile_star2_O1/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 0x2260
movq %r15, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x2050
movq %rsp, %rdi
movl $0x4, %edx
movq %rbx, %rsi
callq 0x21d0
leaq 0x4(%rbx), %rsi
movq %rsp, %rdi
movl $0x4, %edx
callq 0x21d0
leaq 0x8(%rbx), %rsi
movq %rsp, %rdi
movl $0x4, %edx
callq 0x21d0
leaq 0xc(%rbx), %rsi
movq %rsp, %rdi
movl $0x4, %edx
callq 0x21d0
leaq 0x10(%rbx), %rsi
movq %rsp, %rdi
movl $0x4, %edx
callq 0x21d0
leaq 0x14(%rbx), %rsi
movq %rsp, %rdi
movl $0x2, %edx
callq 0x21d0
leaq 0x16(%rbx), %r14
movq %rsp, %rdi
movl $0x2, %edx
movq %r14, %rsi
callq 0x21d0
leaq 0x18(%rbx), %rsi
movq %rsp, %rdi
movl $0x4, %edx
callq 0x21d0
leaq 0x1c(%rbx), %rsi
movq %rsp, %rdi
movl $0x4, %edx
callq 0x21d0
leaq 0x20(%rbx), %rsi
movq %rsp, %rdi
movl $0x2, %edx
callq 0x21d0
leaq 0x22(%rbx), %r15
movq %rsp, %rdi
movl $0x2, %edx
movq %r15, %rsi
callq 0x21d0
leaq 0x24(%rbx), %rsi
movq %rsp, %rdi
movl $0x4, %edx
callq 0x21d0
leaq 0x28(%rbx), %rsi
movq %rsp, %rdi
movl $0x4, %edx
callq 0x21d0
movzwl (%r14), %eax
cmpl $0x2, %eax
je 0x290e
cmpl $0x1, %eax
jne 0x2927
movzwl (%r15), %eax
cmpl $0x8, %eax
je 0x296b
cmpl $0x10, %eax
jne 0x2995
movl $0x40, %eax
jmp 0x2977
movzwl (%r15), %eax
cmpl $0x8, %eax
je 0x2972
cmpl $0x10, %eax
jne 0x29d6
movl $0x50, %eax
jmp 0x2977
movq 0x36a2(%rip), %rdi      # 0x5fd0
leaq 0x176d(%rip), %rsi      # 0x40a2
movl $0x19, %edx
callq 0x2190
movzwl (%r14), %esi
movq 0x3686(%rip), %rdi      # 0x5fd0
callq 0x20f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
jmp 0x2a15
movl $0x38, %eax
jmp 0x2977
movl $0x48, %eax
movq (%rbx,%rax), %rsi
movl 0x28(%rbx), %edx
movq %rsp, %rdi
callq 0x21d0
xorl %ebx, %ebx
movq %rsp, %rdi
callq 0x21f0
jmp 0x2a2d
movq 0x3634(%rip), %rdi      # 0x5fd0
leaq 0x16e4(%rip), %rsi      # 0x4087
movl $0x1a, %edx
callq 0x2190
movzwl (%r15), %esi
movq 0x3618(%rip), %rdi      # 0x5fd0
callq 0x20f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
jmp 0x2a15
movq 0x35f3(%rip), %rdi      # 0x5fd0
leaq 0x16a3(%rip), %rsi      # 0x4087
movl $0x1a, %edx
callq 0x2190
movzwl (%r15), %esi
movq 0x35d7(%rip), %rdi      # 0x5fd0
callq 0x20f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2100
movq 0x3594(%rip), %rax      # 0x5fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x8(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, (%rsp,%rcx)
callq 0x2130
leaq 0xf8(%rsp), %rdi
callq 0x2090
movl %ebx, %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x2270