// File: 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 %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x238(%rbp)
leaq -0x218(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x2200
movq -0x230(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x10, %edx
callq 0x2040
jmp 0x2a58
movq -0x238(%rbp), %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2a72
movq -0x238(%rbp), %rsi
addq $0x4, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2a90
movq -0x238(%rbp), %rsi
addq $0x8, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2aae
movq -0x238(%rbp), %rsi
addq $0xc, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2acc
movq -0x238(%rbp), %rsi
addq $0x10, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2aea
movq -0x238(%rbp), %rsi
addq $0x14, %rsi
leaq -0x218(%rbp), %rdi
movl $0x2, %edx
callq 0x2170
jmp 0x2b08
movq -0x238(%rbp), %rsi
addq $0x16, %rsi
leaq -0x218(%rbp), %rdi
movl $0x2, %edx
callq 0x2170
jmp 0x2b26
movq -0x238(%rbp), %rsi
addq $0x18, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2b44
movq -0x238(%rbp), %rsi
addq $0x1c, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2b62
movq -0x238(%rbp), %rsi
addq $0x20, %rsi
leaq -0x218(%rbp), %rdi
movl $0x2, %edx
callq 0x2170
jmp 0x2b80
movq -0x238(%rbp), %rsi
addq $0x22, %rsi
leaq -0x218(%rbp), %rdi
movl $0x2, %edx
callq 0x2170
jmp 0x2b9e
movq -0x238(%rbp), %rsi
addq $0x24, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2bbc
movq -0x238(%rbp), %rsi
addq $0x28, %rsi
leaq -0x218(%rbp), %rdi
movl $0x4, %edx
callq 0x2170
jmp 0x2bda
movq -0x238(%rbp), %rax
movzwl 0x16(%rax), %eax
cmpl $0x1, %eax
jne 0x2ce2
movq -0x238(%rbp), %rax
movzwl 0x22(%rax), %eax
cmpl $0x8, %eax
jne 0x2c44
movq -0x238(%rbp), %rax
movq 0x38(%rax), %rsi
movl 0x28(%rax), %eax
movl %eax, %edx
leaq -0x218(%rbp), %rdi
callq 0x2170
jmp 0x2c1c
jmp 0x2cdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x21c0
jmp 0x2e61
movq -0x238(%rbp), %rax
movzwl 0x22(%rax), %eax
cmpl $0x10, %eax
jne 0x2c74
movq -0x238(%rbp), %rax
movq 0x40(%rax), %rsi
movl 0x28(%rax), %eax
movl %eax, %edx
leaq -0x218(%rbp), %rdi
callq 0x2170
jmp 0x2c72
jmp 0x2cdb
movq 0x6355(%rip), %rdi      # 0x8fd0
leaq 0x3419(%rip), %rsi      # 0x609b
callq 0x2100
movq %rax, -0x240(%rbp)
jmp 0x2c90
movq -0x240(%rbp), %rdi
movq -0x238(%rbp), %rax
movzwl 0x22(%rax), %esi
callq 0x21f0
movq %rax, -0x248(%rbp)
jmp 0x2cb0
movq -0x248(%rbp), %rdi
movq 0x6302(%rip), %rsi      # 0x8fc0
callq 0x2130
jmp 0x2cc5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x228(%rbp)
jmp 0x2e49
jmp 0x2cdd
jmp 0x2e2a
movq -0x238(%rbp), %rax
movzwl 0x16(%rax), %eax
cmpl $0x2, %eax
jne 0x2dc4
movq -0x238(%rbp), %rax
movzwl 0x22(%rax), %eax
cmpl $0x8, %eax
jne 0x2d29
movq -0x238(%rbp), %rax
movq 0x48(%rax), %rsi
movl 0x28(%rax), %eax
movl %eax, %edx
leaq -0x218(%rbp), %rdi
callq 0x2170
jmp 0x2d24
jmp 0x2dc2
movq -0x238(%rbp), %rax
movzwl 0x22(%rax), %eax
cmpl $0x10, %eax
jne 0x2d59
movq -0x238(%rbp), %rax
movq 0x50(%rax), %rsi
movl 0x28(%rax), %eax
movl %eax, %edx
leaq -0x218(%rbp), %rdi
callq 0x2170
jmp 0x2d57
jmp 0x2dc0
movq 0x6270(%rip), %rdi      # 0x8fd0
leaq 0x3334(%rip), %rsi      # 0x609b
callq 0x2100
movq %rax, -0x250(%rbp)
jmp 0x2d75
movq -0x250(%rbp), %rdi
movq -0x238(%rbp), %rax
movzwl 0x22(%rax), %esi
callq 0x21f0
movq %rax, -0x258(%rbp)
jmp 0x2d95
movq -0x258(%rbp), %rdi
movq 0x621d(%rip), %rsi      # 0x8fc0
callq 0x2130
jmp 0x2daa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x228(%rbp)
jmp 0x2e49
jmp 0x2dc2
jmp 0x2e28
movq 0x6205(%rip), %rdi      # 0x8fd0
leaq 0x32e4(%rip), %rsi      # 0x60b6
callq 0x2100
movq %rax, -0x260(%rbp)
jmp 0x2de0
movq -0x260(%rbp), %rdi
movq -0x238(%rbp), %rax
movzwl 0x16(%rax), %esi
callq 0x21f0
movq %rax, -0x268(%rbp)
jmp 0x2e00
movq -0x268(%rbp), %rdi
movq 0x61b2(%rip), %rsi      # 0x8fc0
callq 0x2130
jmp 0x2e15
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x228(%rbp)
jmp 0x2e49
jmp 0x2e2a
leaq -0x218(%rbp), %rdi
callq 0x21a0
jmp 0x2e38
movl $0x0, -0x4(%rbp)
movl $0x1, -0x228(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x21c0
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x220(%rbp), %rdi
callq 0x2210
nopl (%rax)