// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0xe8(%rdi), %r15
orl $0x1, 0x10(%rsi)
cmpq $0x0, 0x28(%rsi)
jne 0x1a489
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x1a653
callq 0x31caa
movq %rax, 0x28(%rbx)
movq 0x28(%rbx), %rsi
movq %r15, %rdi
callq 0x1b41c
movq 0xf0(%r14), %r15
orl $0x2, 0x10(%rbx)
cmpq $0x0, 0x30(%rbx)
jne 0x1a4be
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x1a65f
callq 0x31caa
movq %rax, 0x30(%rbx)
movq 0x30(%rbx), %rsi
movq %r15, %rdi
callq 0x1b41c
movq 0xf8(%r14), %r15
orl $0x4, 0x10(%rbx)
cmpq $0x0, 0x38(%rbx)
jne 0x1a4f3
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x1a66b
callq 0x31d18
movq %rax, 0x38(%rbx)
movq 0x38(%rbx), %rsi
movq %r15, %rdi
callq 0x1b682
movq 0x100(%r14), %r15
orl $0x8, 0x10(%rbx)
cmpq $0x0, 0x40(%rbx)
jne 0x1a528
movq 0x8(%rbx), %rdi
testb $0x1, %dil
jne 0x1a677
callq 0x31d7e
movq %rax, 0x40(%rbx)
movq 0x40(%rbx), %rsi
movq %r15, %rdi
callq 0x1b83c
movq %rbx, -0x30(%rbp)
leaq 0x18(%rbx), %r15
xorl %r12d, %r12d
movq %r14, %rbx
movzbl 0xb8(%r14,%r12), %r14d
movq -0x30(%rbp), %rax
movl 0x18(%rax), %r13d
movl 0x1c(%rax), %esi
cmpl %esi, %r13d
jne 0x1a565
incl %esi
movq %r15, %rdi
callq 0xb670
movq %r15, %rdi
callq 0xb530
movl %r14d, (%rax,%r13,4)
leal 0x1(%r13), %eax
movl %eax, (%r15)
incq %r12
cmpq $0x18, %r12
movq %rbx, %r14
jne 0x1a53f
movl 0xd0(%r14), %ecx
movq -0x30(%rbp), %rsi
movl 0x10(%rsi), %eax
movl %eax, %edx
orl $0x10, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x48(%rsi)
movl 0xd8(%r14), %ecx
movl %eax, %edx
orl $0x30, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x4c(%rsi)
movl 0xe0(%r14), %ecx
movl %eax, %edx
orl $0x70, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x50(%rsi)
movl 0x10(%r14), %ecx
movl %eax, %edx
orl $0xf0, %edx
movl %edx, 0x10(%rsi)
movl %ecx, 0x54(%rsi)
movl 0x14(%r14), %ecx
movl %eax, %edx
orl $0x1f0, %edx            # imm = 0x1F0
movl %edx, 0x10(%rsi)
movl %ecx, 0x58(%rsi)
movl 0x18(%r14), %ecx
movl %eax, %edx
orl $0x3f0, %edx            # imm = 0x3F0
movl %edx, 0x10(%rsi)
movl %ecx, 0x5c(%rsi)
movl 0x1c(%r14), %ecx
movl %eax, %edx
orl $0x7f0, %edx            # imm = 0x7F0
movl %edx, 0x10(%rsi)
movl %ecx, 0x60(%rsi)
movss 0x20(%r14), %xmm0
movl %eax, %ecx
orl $0xff0, %ecx            # imm = 0xFF0
movl %ecx, 0x10(%rsi)
movss %xmm0, 0x64(%rsi)
movss 0x24(%r14), %xmm0
movl %eax, %ecx
orl $0x1ff0, %ecx           # imm = 0x1FF0
movl %ecx, 0x10(%rsi)
movss %xmm0, 0x68(%rsi)
movl 0x28(%r14), %ecx
orl $0x3ff0, %eax           # imm = 0x3FF0
movl %eax, 0x10(%rsi)
movl %ecx, 0x6c(%rsi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x1a480
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x1a4b5
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x1a4ea
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x1a51f
nop