// File: /workspace/github_cpp_makefile_star2_O3/mindbeast[P]rnes/apu.cpp
// Function: Rnes::Apu::save(Rnes::ApuState&)
void Apu::save(ApuState &pb) {
  // Save sub-units.
  pulseA->save(*pb.mutable_pulsea());
  pulseB->save(*pb.mutable_pulseb());
  triangle->save(*pb.mutable_triangle());
  noise->save(*pb.mutable_noise());

  /*
  // Apu register file.
  repeated uint32 reg = 1;
  optional uint32 sampleRate = 2;
  optional uint32 fourFrameCount = 3;
  optional uint32 fiveFrameCount = 4;
  optional uint32 frameDivider = 5;
  optional uint32 step = 6;
  optional uint32 halfTimerDivider = 7;
  optional uint32 samplerDivider = 8;
  optional float clksPerSample = 9;
  optional float currentSampleClk = 10;
  optional uint32 nextSampleCountdown = 11;
  */

  for (unsigned i = 0; i < REG_COUNT; i++) {
    pb.add_reg(regs[i]);
  }
  pb.set_samplerate(sampleRate);
  pb.set_fourframecount(fourFrameCount);
  pb.set_fiveframecount(fiveFrameCount);
  pb.set_framedivider(frameDivider);
  pb.set_step(step);
  pb.set_halftimerdivider(halfTimerDivider);
  pb.set_samplerdivider(samplerDivider);
  pb.set_clkspersample(clksPerSample);
  pb.set_currentsampleclk(currentSampleClk);
  pb.set_nextsamplecountdown(nextSampleCountdown);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r12
movq 0xe8(%rdi), %r15
orl $0x1, 0x10(%rsi)
movq 0x28(%rsi), %rsi
testq %rsi, %rsi
jne 0x19453
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x19609
callq 0x308c6
movq %rax, %rsi
movq %rax, 0x28(%rbx)
movq %r15, %rdi
callq 0x1a3c4
movq 0xf0(%r12), %r15
orl $0x2, 0x10(%rbx)
movq 0x30(%rbx), %rsi
testq %rsi, %rsi
jne 0x1948a
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x19615
callq 0x308c6
movq %rax, %rsi
movq %rax, 0x30(%rbx)
movq %r15, %rdi
callq 0x1a3c4
movq 0xf8(%r12), %r15
orl $0x4, 0x10(%rbx)
movq 0x38(%rbx), %rsi
testq %rsi, %rsi
jne 0x194c1
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x19621
callq 0x30934
movq %rax, %rsi
movq %rax, 0x38(%rbx)
movq %r15, %rdi
callq 0x1a5fe
movq 0x100(%r12), %r15
orl $0x8, 0x10(%rbx)
movq 0x40(%rbx), %rsi
testq %rsi, %rsi
jne 0x194f8
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x1962d
callq 0x3099a
movq %rax, %rsi
movq %rax, 0x40(%rbx)
movq %r15, %rdi
callq 0x1a7a0
leaq 0x18(%rbx), %r15
movq %rbx, -0x30(%rbp)
movl 0x18(%rbx), %r14d
xorl %r13d, %r13d
movq %r12, -0x38(%rbp)
movzbl 0xb8(%r12,%r13), %ebx
leal 0x1(%r14), %r12d
movq -0x30(%rbp), %rax
cmpl 0x1c(%rax), %r14d
jne 0x19535
movq %r15, %rdi
movl %r12d, %esi
callq 0xa670
movq %r15, %rdi
callq 0xa530
movl %r14d, %ecx
movl %ebx, (%rax,%rcx,4)
movl %r12d, (%r15)
incq %r13
movl %r12d, %r14d
cmpq $0x18, %r13
movq -0x38(%rbp), %r12
jne 0x19513
movl 0xd0(%r12), %ecx
movq -0x30(%rbp), %rsi
movl 0x10(%rsi), %eax
movl %ecx, 0x48(%rsi)
movl 0xd8(%r12), %ecx
movl %ecx, 0x4c(%rsi)
movl 0xe0(%r12), %ecx
movl %eax, %edx
orl $0x70, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x50(%rsi)
movl 0x10(%r12), %ecx
movl %eax, %edx
orl $0xf0, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x54(%rsi)
movl 0x14(%r12), %ecx
movl %eax, %edx
orl $0x1f0, %edx            # imm = 0x1F0
movl %edx, 0x10(%rsi)
movl %ecx, 0x58(%rsi)
movl 0x18(%r12), %ecx
movl %eax, %edx
orl $0x3f0, %edx            # imm = 0x3F0
movl %edx, 0x10(%rsi)
movl %ecx, 0x5c(%rsi)
movl 0x1c(%r12), %ecx
movl %ecx, 0x60(%rsi)
movss 0x20(%r12), %xmm0
movss %xmm0, 0x64(%rsi)
movss 0x24(%r12), %xmm0
movl %eax, %ecx
orl $0x1ff0, %ecx           # imm = 0x1FF0
movl %ecx, 0x10(%rsi)
movss %xmm0, 0x68(%rsi)
movl 0x28(%r12), %ecx
orl $0x3ff0, %eax           # imm = 0x3FF0
movl %eax, 0x10(%rsi)
movl %ecx, 0x6c(%rsi)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x19447
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x1947e
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x194b5
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x194ec
nop