// File: /workspace/github_cpp_makefile_star2_O2/ke6jjj[P]r-dat/AudioFrameReceiver.cc
// Function: AudioFrameReceiver::Stop()
void
AudioFrameReceiver::Stop()
{
  //
  // Processing has stopped. If we were dumping audio to a file, go back
  // and fill in the file headers.
  //
  if (mFile != NULL) {
    //
    // Write WAV header.
    //
    XDR hdr(kWAVHeaderSize);
    hdr.AddString("RIFF", 4);
    hdr.AddU32(kWAVFormatChunkHeaderSize+
               kWAVDataChunkHeaderSize+
               mFramesWritten * 4+
               4);
    hdr.AddString("WAVE", 4);
    
    fseek(mFile, SEEK_SET, 0);
    fwrite(hdr.Data(), hdr.Size(), 1, mFile);

    //
    // Write format chunk.
    //
    XDR xdr(kWAVFormatChunkHeaderSize);
    
    // ID             chunkID;
    xdr.AddString("fmt ", 4);
    // long           chunkSize;
    xdr.AddU32(kWAVFormatChunkHeaderSize-8);
    
    // short          wFormatTag;
    xdr.AddI16(1); // PCM data
    // unsigned short wChannels;
    xdr.AddU16(2);
    // unsigned long  dwSamplesPerSec;
    xdr.AddU32(48000);
    // unsigned long  dwAvgBytesPerSec;
    xdr.AddU32(48000 * 4); // 4 bytes per frame (2 16-bit samples)
    // unsigned short wBlockAlign;
    xdr.AddU16(4); // 4 bytes per frame (2 16-bit samples)
    // unsigned short wBitsPerSample;
    xdr.AddU16(16);

    fwrite(xdr.Data(), xdr.Size(), 1, mFile);

    //
    // Write data chunk.
    //
    XDR data(kWAVDataChunkHeaderSize);

    data.AddString("data", 4);
    data.AddU32(mFramesWritten * 4);

    fwrite(data.Data(), data.Size(), 1, mFile);

    //
    // Close file.
    //
    fclose(mFile);
    mFile = NULL;
  }
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
cmpq $0x0, 0x8(%rdi)
je 0x4710
movq %rdi, %rbx
leaq 0x30(%rsp), %r14
pushq $0xc
popq %rsi
movq %r14, %rdi
callq 0x740c
leaq 0x499e(%rip), %rsi      # 0x8f2e
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x743a
movl 0x10(%rbx), %eax
leal 0x24(,%rax,4), %esi
leaq 0x30(%rsp), %rdi
callq 0x7542
leaq 0x497d(%rip), %rsi      # 0x8f33
leaq 0x30(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x743a
movq 0x8(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2110
leaq 0x30(%rsp), %rdi
callq 0x7598
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x759e
movq 0x8(%rbx), %rcx
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x2200
movq %rsp, %rdi
pushq $0x18
popq %rsi
callq 0x740c
leaq 0x492d(%rip), %rsi      # 0x8f38
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x743a
movq %rsp, %rdi
pushq $0x10
popq %rsi
callq 0x7542
movq %rsp, %rdi
pushq $0x1
popq %rsi
callq 0x7484
movq %rsp, %rdi
pushq $0x2
popq %rsi
callq 0x74b8
movq %rsp, %rdi
movl $0xbb80, %esi           # imm = 0xBB80
callq 0x7542
movq %rsp, %rdi
movl $0x2ee00, %esi          # imm = 0x2EE00
callq 0x7542
movq %rsp, %rdi
pushq $0x4
popq %rsi
callq 0x74b8
movq %rsp, %rdi
pushq $0x10
popq %rsi
callq 0x74b8
movq %rsp, %rdi
callq 0x7598
movq %rax, %r14
movq %rsp, %rdi
callq 0x759e
movq 0x8(%rbx), %rcx
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x2200
leaq 0x18(%rsp), %rdi
pushq $0x8
popq %rsi
callq 0x740c
leaq 0x489d(%rip), %rsi      # 0x8f3d
leaq 0x18(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x743a
movl 0x10(%rbx), %esi
shll $0x2, %esi
leaq 0x18(%rsp), %rdi
callq 0x7542
leaq 0x18(%rsp), %rdi
callq 0x7598
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x759e
movq 0x8(%rbx), %rcx
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x2200
movq 0x8(%rbx), %rdi
callq 0x20d0
andq $0x0, 0x8(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x742c
movq %rsp, %rdi
callq 0x742c
leaq 0x30(%rsp), %rdi
callq 0x742c
addq $0x48, %rsp
popq %rbx
popq %r14
retq
jmp 0x4730
jmp 0x472b
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x742c
jmp 0x4733
movq %rax, %rbx
jmp 0x473b
movq %rax, %rbx
movq %rsp, %rdi
callq 0x742c
leaq 0x30(%rsp), %rdi
callq 0x742c
movq %rbx, %rdi
callq 0x21e0
nop