LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::readReg(unsigned int)
uint8_t Ppu::readReg(uint32_t reg) {
  uint8_t ret;
  switch (reg) {
  case CONTROL1_REG:
    assert(0);
    // GUESS: Write only registers.
    return regs[reg];
    break;
  case CONTROL2_REG:
    assert(0);
    // GUESS: Write only registers.
    return regs[reg];
    break;
  case STATUS_REG:
    ret = regs[reg];
    // vblank status bit is clear on read
    clearVblankFlag();
    // reset the scroll/vram machine flip flops
    vramToggle = 0;
    // and return the reg value
    return ret;
    break;
  case SPR_ADDR_REG:
  case SPR_DATA_REG:
    // Write only registers.
    assert(0);
    return 0;
    break;
  case VRAM_ADDR_REG1:
    // assert(0);
    // This is a guess, we aren't expecting reads here.
    return vramCurrentAddr;
    break;
  case VRAM_ADDR_REG2:
    assert(0);
    // This is a guess, we aren't expecting reads here.
    return vramTempAddr;
    break;
  case VRAM_DATA_REG:
    ret = vramReadLatch;
    vramReadLatch = nes->vidMemRead(vramCurrentAddr);
    vramCurrentAddr += getVramAddrInc();
    return ret;
    break;
  default:
    assert(0);
    break;
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
cmpl $0x7, %esi
ja 0x13c58
movq %rdi, %rbx
movl %esi, %eax
leaq 0x17204(%rip), %rcx     # 0x2ad80
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb 0x2a(%rbx), %r14b
movl %r14d, %eax
andb $0x7f, %al
movb %al, 0x2a(%rbx)
andl $0x0, 0x130(%rbx)
jmp 0x13bd4
movb 0x138(%rbx), %r14b
jmp 0x13bd4
movb 0x13e(%rbx), %r14b
movq 0x8(%rbx), %rdi
movzwl 0x138(%rbx), %esi
callq 0x1b080
movb %al, 0x13e(%rbx)
testb $0x4, 0x28(%rbx)
pushq $0x1
popq %rax
pushq $0x20
popq %rcx
cmovel %eax, %ecx
addw %cx, 0x138(%rbx)
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x168c1(%rip), %rdi     # 0x2a4a4
leaq 0x172f2(%rip), %rsi     # 0x2aedc
leaq 0x17390(%rip), %rcx     # 0x2af81
movl $0x11a, %edx            # imm = 0x11A
callq 0xb170
leaq 0x168a2(%rip), %rdi     # 0x2a4a4
leaq 0x172d3(%rip), %rsi     # 0x2aedc
leaq 0x17371(%rip), %rcx     # 0x2af81
movl $0x105, %edx            # imm = 0x105
callq 0xb170
leaq 0x16883(%rip), %rdi     # 0x2a4a4
leaq 0x172b4(%rip), %rsi     # 0x2aedc
leaq 0x17352(%rip), %rcx     # 0x2af81
movl $0x10a, %edx            # imm = 0x10A
callq 0xb170
leaq 0x16864(%rip), %rdi     # 0x2a4a4
leaq 0x17295(%rip), %rsi     # 0x2aedc
leaq 0x17333(%rip), %rcx     # 0x2af81
movl $0x123, %edx            # imm = 0x123
callq 0xb170
leaq 0x16845(%rip), %rdi     # 0x2a4a4
leaq 0x17276(%rip), %rsi     # 0x2aedc
leaq 0x17314(%rip), %rcx     # 0x2af81
movl $0x12e, %edx            # imm = 0x12E
callq 0xb170
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: unsigned char Rnes::Ppu::getColorFromPatternTable<false>(unsigned short, int, unsigned int, unsigned int)
uint8_t Ppu::getColorFromPatternTable(uint16_t patternTable, int offset, uint32_t x, uint32_t y) {
  assert(x < 8);
  if (!is8x8) {
    assert(y < 16);
    if ((offset % 2) == 0) {
      patternTable = 0x0000;
    } else {
      patternTable = 0x1000;
      offset--;
    }
    if (y >= 8) {
      offset++;
      y -= 8;
    }
  } else {
    assert(y < 8);
  }
  x = 8 - 1 - x;
  uint16_t byteAddrLower = patternTable + 16 * offset + y;
  uint16_t byteAddrUpper = patternTable + 16 * offset + y + 8;
  uint8_t color = ((load(byteAddrLower) >> x) & 0x1) | (((load(byteAddrUpper) >> (x)) & 0x1) << 1);
  return color;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x8, %ecx
jae 0x1415b
cmpl $0x10, %r8d
jae 0x1417a
movl %ecx, %r14d
movq %rdi, %rbx
movl %edx, %eax
andl $0x8000ffe, %eax        # imm = 0x8000FFE
andl $0x1, %edx
shll $0xc, %edx
leal 0xfff8(%r8), %ecx
xorl %edi, %edi
cmpl $0x8, %r8d
setae %dil
cmovbl %r8d, %ecx
orl %eax, %edi
shll $0x4, %edi
addl %edx, %ecx
leal (%rdi,%rcx), %r15d
addl $0x8, %r15d
movl %ecx, %esi
addl %edi, %esi
movl $0xffff, %r12d          # imm = 0xFFFF
andl %r12d, %esi
movq %rbx, %rdi
callq 0x13440
movzbl %al, %eax
movb $0x7, %cl
subb %r14b, %cl
movzbl %cl, %r14d
xorl %r13d, %r13d
btl %r14d, %eax
setb %r13b
andl %r12d, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x13440
movzbl %al, %eax
movl %r14d, %ecx
shrl %cl, %eax
andl $0x1, %eax
leal (%r13,%rax,2), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16ebb(%rip), %rdi     # 0x2b01d
leaq 0x16d73(%rip), %rsi     # 0x2aedc
leaq 0x16f17(%rip), %rcx     # 0x2b087
movl $0x136, %edx            # imm = 0x136
callq 0xb170
leaq 0x16f65(%rip), %rdi     # 0x2b0e6
leaq 0x16d54(%rip), %rsi     # 0x2aedc
leaq 0x16ef8(%rip), %rcx     # 0x2b087
movl $0x138, %edx            # imm = 0x138
callq 0xb170
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apu.cpp
// Function: Rnes::Apu::clockLengthAndSweep()
void Apu::clockLengthAndSweep() {
  pulseA->clockLengthAndSweep();
  pulseB->clockLengthAndSweep();
  triangle->clockLength();
  noise->clockLength();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xe8(%rdi), %rdi
callq 0x15bbc
movq 0xf0(%rbx), %rdi
callq 0x15bbc
movq 0xf8(%rbx), %rdi
callq 0x15ce8
movq 0x100(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x15ee2
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apu.cpp
// Function: Rnes::Apu::resetFrameCounter()
void Apu::resetFrameCounter() {
  frameDivider = 0;
  step = 0;
  if (!isFourStepFrame()) {
    stepAdvance();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
andq $0x0, 0x10(%rdi)
cmpb $0x0, 0xcf(%rdi)
js 0x143a4
popq %rbp
retq
popq %rbp
jmp 0x143aa
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apu.cpp
// Function: Rnes::Apu::stepAdvance()
void Apu::stepAdvance() {
  uint32_t frameSteps = isFourStepFrame() ? 4 : 5;

  if (isFourStepFrame()) {
    if (step % 2) {
      clockLengthAndSweep();
    }
    clockEnvAndTriangle();
    if ((step == 3) and isFrameIntEnabled()) {
      setRequestFrameIrq();
    }
  } else {
    if (step < 4) {
      clockEnvAndTriangle();
    }
    if (step == 0 or step == 2) {
      clockLengthAndSweep();
    }
  }
  step += 1;
  if (step == frameSteps) {
    step = 0;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
cmpb $0x0, 0xcf(%rdi)
movl 0x14(%rdi), %eax
js 0x143f5
testb $0x1, %al
je 0x143cc
movq %rbx, %rdi
callq 0x1431c
movq %rbx, %rdi
callq 0x1435c
movl 0x14(%rbx), %eax
pushq $0x4
popq %r14
cmpl $0x3, %eax
jne 0x1441b
pushq $0x3
popq %rax
testb $0x40, 0xcf(%rbx)
jne 0x1441b
orb $0x40, 0xcd(%rbx)
jmp 0x1441b
cmpl $0x3, %eax
ja 0x14405
movq %rbx, %rdi
callq 0x1435c
movl 0x14(%rbx), %eax
pushq $0x5
popq %r14
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jne 0x1441b
movq %rbx, %rdi
callq 0x1431c
movl 0x14(%rbx), %eax
incl %eax
xorl %ecx, %ecx
cmpl %r14d, %eax
cmovnel %eax, %ecx
movl %ecx, 0x14(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apu.cpp
// Function: Rnes::Apu::generateSample()
void Apu::generateSample() {
  // float sample = (samples[sampleOffset % sampleBufferSize] + samples[(sampleOffset - 32) %
  // sampleBufferSize]) / 2;
  float sample = 0.0f;
  sample += 0.02051777 * (samples[sampleOffset % sampleBufferSize]);
  sample += 0.06532911 * (samples[(sampleOffset - 1) % sampleBufferSize]);
  sample += 0.16640572 * (samples[(sampleOffset - 2) % sampleBufferSize]);
  sample += 0.2477474 * (samples[(sampleOffset - 3) % sampleBufferSize]);
  sample += 0.2477474 * (samples[(sampleOffset - 4) % sampleBufferSize]);
  sample += 0.16640572 * (samples[(sampleOffset - 5) % sampleBufferSize]);
  sample += 0.06532911 * (samples[(sampleOffset - 6) % sampleBufferSize]);
  sample += 0.02051777 * (samples[(sampleOffset - 7) % sampleBufferSize]);

  int16_t truncSample = (int16_t)((sample) * (1 << 14));

  const unsigned int bufferedSamples = 32;
  sampleBuffer.push_back(truncSample);
  if (sampleBuffer.size() == bufferedSamples) {
    rb->putData(sampleBuffer.data(), bufferedSamples);
    sampleBuffer.clear();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0xb0(%rdi), %eax
movl %eax, %ecx
andl $0x1f, %ecx
cvtss2sd 0x2c(%rdi,%rcx,4), %xmm1
movsd 0x16c5a(%rip), %xmm0    # 0x2b0f0
mulsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
addsd %xmm1, %xmm2
cvtsd2ss %xmm2, %xmm1
leal -0x1(%rax), %ecx
andl $0x1f, %ecx
cvtss2sd 0x2c(%rdi,%rcx,4), %xmm2
cvtss2sd %xmm1, %xmm3
movsd 0x16c3a(%rip), %xmm1    # 0x2b0f8
mulsd %xmm1, %xmm2
addsd %xmm3, %xmm2
cvtsd2ss %xmm2, %xmm2
leal 0x1e(%rax), %ecx
andl $0x1f, %ecx
cvtss2sd 0x2c(%rdi,%rcx,4), %xmm3
cvtss2sd %xmm2, %xmm4
movsd 0x16c1e(%rip), %xmm2    # 0x2b100
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
cvtsd2ss %xmm3, %xmm3
leal 0x1d(%rax), %ecx
andl $0x1f, %ecx
cvtss2sd 0x2c(%rdi,%rcx,4), %xmm4
cvtss2sd %xmm3, %xmm3
movsd 0x16c02(%rip), %xmm5    # 0x2b108
mulsd %xmm5, %xmm4
addsd %xmm3, %xmm4
cvtsd2ss %xmm4, %xmm3
leal 0x1c(%rax), %ecx
andl $0x1f, %ecx
cvtss2sd 0x2c(%rdi,%rcx,4), %xmm4
cvtss2sd %xmm3, %xmm3
mulsd %xmm5, %xmm4
addsd %xmm3, %xmm4
cvtsd2ss %xmm4, %xmm3
leal 0x1b(%rax), %ecx
andl $0x1f, %ecx
cvtss2sd 0x2c(%rdi,%rcx,4), %xmm4
cvtss2sd %xmm3, %xmm3
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
cvtsd2ss %xmm4, %xmm2
leal 0x1a(%rax), %ecx
andl $0x1f, %ecx
cvtss2sd 0x2c(%rdi,%rcx,4), %xmm3
cvtss2sd %xmm2, %xmm2
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
cvtsd2ss %xmm3, %xmm1
addl $0x19, %eax
andl $0x1f, %eax
cvtss2sd 0x2c(%rdi,%rax,4), %xmm2
cvtss2sd %xmm1, %xmm1
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvtsd2ss %xmm2, %xmm0
mulss 0x16b86(%rip), %xmm0    # 0x2b110
cvttss2si %xmm0, %eax
addq $0x118, %rdi            # imm = 0x118
leaq -0xa(%rbp), %rsi
movw %ax, (%rsi)
callq 0x1541c
movq 0x118(%rbx), %rsi
movq 0x120(%rbx), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x145de
movq 0x108(%rbx), %rdi
pushq $0x20
popq %rdx
callq 0x14ef2
movq 0x118(%rbx), %rax
cmpq %rax, 0x120(%rbx)
je 0x145de
movq %rax, 0x120(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apu.cpp
// Function: Rnes::Apu::tick()
void Apu::tick() {
  // Divider logic for frame
  if (frameDivider == 0) {
    stepAdvance();
  }
  frameDivider = (frameDivider + 1) % frameCycles;

  // Divider logic for timers
  stepFastTimers();
  if (halfTimerDivider == 0) {
    stepSlowTimers();
  }
  halfTimerDivider = !halfTimerDivider;

  // Compute output each cycle
  sampleOffset += 1;
  float sample =
      95.88f /
      ((8128.0f / (float(pulseA->getCurrentSample() + pulseB->getCurrentSample()))) + 100.0f);
  sample += 159.79f / (100.0f + (1.0f / ((float(triangle->getCurrentSample()) / 8227.0f) +
                                         float(noise->getCurrentSample()) / 12241.0f)));
  samples[sampleOffset % sampleBufferSize] = sample;

  // Determine when to sample, and sample if needed.
  nextSampleCountdown--;
  if (!nextSampleCountdown) {
    float prevSampleClk = currentSampleClk;
    currentSampleClk += clksPerSample;
    nextSampleCountdown = (uint32_t)currentSampleClk - (uint32_t)prevSampleClk;
    if (currentSampleClk >= float(cpuClk)) {
      currentSampleClk = 0.0f;
    }
    generateSample();
  }

  /*
  if (samplerDivider == 0) {
  }
  samplerDivider = (samplerDivider + 1) % uint32_t(cpuClk/ sampleRate);
  */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl 0x10(%rdi), %eax
testl %eax, %eax
jne 0x14606
movq %rbx, %rdi
callq 0x143aa
movl 0x10(%rbx), %eax
incl %eax
xorl %r14d, %r14d
movl $0x1d21, %ecx           # imm = 0x1D21
xorl %edx, %edx
divl %ecx
movl %edx, 0x10(%rbx)
movq %rbx, %rdi
callq 0x1442e
cmpl $0x0, 0x18(%rbx)
jne 0x14638
movq %rbx, %rdi
callq 0x14440
xorl %r14d, %r14d
cmpl $0x0, 0x18(%rbx)
sete %r14b
movl %r14d, 0x18(%rbx)
incq 0xb0(%rbx)
movq 0xe8(%rbx), %rdi
callq 0x15b1c
movzbl %al, %r14d
movq 0xf0(%rbx), %rdi
callq 0x15b1c
movzbl %al, %eax
addl %r14d, %eax
cvtsi2ss %eax, %xmm0
movss 0x16aa3(%rip), %xmm1    # 0x2b114
divss %xmm0, %xmm1
addss 0x16a9b(%rip), %xmm1    # 0x2b118
movss 0x16a97(%rip), %xmm0    # 0x2b11c
movq 0xf8(%rbx), %rax
movzbl 0x2b(%rax), %eax
cvtsi2ss %eax, %xmm2
divss %xmm1, %xmm0
movss %xmm0, -0x18(%rbp)
movq 0x100(%rbx), %rdi
divss 0x16a74(%rip), %xmm2    # 0x2b120
movss %xmm2, -0x14(%rbp)
callq 0x15df6
movzbl %al, %eax
cvtsi2ss %eax, %xmm0
divss 0x16a5f(%rip), %xmm0    # 0x2b124
addss -0x14(%rbp), %xmm0
movss 0x16a56(%rip), %xmm1    # 0x2b128
divss %xmm0, %xmm1
addss 0x16a3a(%rip), %xmm1    # 0x2b118
movss 0x16a46(%rip), %xmm0    # 0x2b12c
divss %xmm1, %xmm0
addss -0x18(%rbp), %xmm0
movl 0xb0(%rbx), %eax
andl $0x1f, %eax
movss %xmm0, 0x2c(%rbx,%rax,4)
decl 0x28(%rbx)
je 0x1470c
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movss 0x24(%rbx), %xmm0
movss 0x20(%rbx), %xmm1
addss %xmm0, %xmm1
cvttss2si %xmm1, %rax
movss %xmm1, 0x24(%rbx)
cvttss2si %xmm0, %rcx
subl %ecx, %eax
movl %eax, 0x28(%rbx)
ucomiss 0x169fb(%rip), %xmm1    # 0x2b130
jb 0x1473b
andl $0x0, 0x24(%rbx)
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x14474
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apu.cpp
// Function: Rnes::Apu::writeReg(unsigned int, unsigned char)
void Apu::writeReg(uint32_t reg, uint8_t val) {
  regs[reg] = val;
  if (reg == SOFTCLOCK) {
    resetFrameCounter();
  } else if (reg == CONTROL_STATUS) {
    clearRequestDmcIrq();
    // xx what to do with the upper bits here
    if (~val & STATUS_CHANNEL1_LENGTH) {
      pulseA->zeroLength();
    }
    if (~val & STATUS_CHANNEL2_LENGTH) {
      pulseB->zeroLength();
    }
    if (~val & STATUS_CHANNEL3_LENGTH) {
      triangle->zeroLength();
    }
    if (~val & STATUS_CHANNEL4_LENGTH) {
      noise->zeroLength();
    }
  } else if (reg == CHANNEL1_LENGTH) {
    pulseA->resetLength();
    pulseA->resetSequencer();
    pulseA->resetEnvelope();
  } else if (reg == CHANNEL2_LENGTH) {
    pulseB->resetLength();
    pulseB->resetSequencer();
    pulseB->resetEnvelope();
  } else if (reg == CHANNEL3_LENGTH) {
    triangle->resetLength();
    triangle->setHaltFlag();
  } else if (reg == CHANNEL4_LENGTH) {
    noise->resetLength();
    noise->resetEnvelope();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %esi, %eax
movb %dl, 0xb8(%rdi,%rax)
addl $-0x3, %esi
rorl %esi
cmpl $0xa, %esi
ja 0x1486a
leaq 0x1699e(%rip), %rax     # 0x2b134
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq 0xe8(%rdi), %rax
jmp 0x147dd
movq 0xf8(%rdi), %rax
movq 0x20(%rax), %rcx
movzbl 0x3(%rcx), %ecx
shrl $0x3, %ecx
leaq 0x1699f(%rip), %rdx     # 0x2b160
movb (%rcx,%rdx), %cl
movb %cl, 0x28(%rax)
movb $0x1, 0x29(%rax)
jmp 0x1486a
popq %rbp
jmp 0x14390
movq 0xf0(%rdi), %rax
movq 0x8(%rax), %rcx
movzbl 0x3(%rcx), %ecx
shrl $0x3, %ecx
leaq 0x16971(%rip), %rdx     # 0x2b160
movb (%rcx,%rdx), %cl
movb %cl, 0x11(%rax)
andl $0x0, 0x1c(%rax)
movb $0x1, 0x14(%rax)
jmp 0x1486a
movq 0x100(%rdi), %rax
movq (%rax), %rcx
movzbl 0x3(%rcx), %ecx
shrl $0x3, %ecx
leaq 0x16949(%rip), %rdx     # 0x2b160
movb (%rcx,%rdx), %cl
movb %cl, 0x8(%rax)
movb $0x1, 0xe(%rax)
jmp 0x1486a
andb $0x7f, 0xcd(%rdi)
testb $0x1, %dl
jne 0x1483a
movq 0xe8(%rdi), %rax
movb $0x0, 0x11(%rax)
testb $0x2, %dl
jne 0x1484a
movq 0xf0(%rdi), %rax
movb $0x0, 0x11(%rax)
testb $0x4, %dl
jne 0x1485a
movq 0xf8(%rdi), %rax
movb $0x0, 0x28(%rax)
testb $0x8, %dl
jne 0x1486a
movq 0x100(%rdi), %rax
movb $0x0, 0x8(%rax)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0xe8(%rdi), %r15
movq %rsi, %rdi
callq 0x15118
movq %r15, %rdi
movq %rax, %rsi
callq 0x15a7c
movq 0xf0(%r14), %r15
movq %rbx, %rdi
callq 0x15152
movq %r15, %rdi
movq %rax, %rsi
callq 0x15a7c
movq 0xf8(%r14), %r15
movq %rbx, %rdi
callq 0x1518c
movq %r15, %rdi
movq %rax, %rsi
callq 0x15c78
movq 0x100(%r14), %r15
movq %rbx, %rdi
callq 0x151c6
movq %r15, %rdi
movq %rax, %rsi
callq 0x15e1e
pushq $-0x18
popq %r15
testq %r15, %r15
je 0x14969
movzbl 0xd0(%r14,%r15), %esi
movq %rbx, %rdi
callq 0x15200
incq %r15
jmp 0x1494e
movl 0xd0(%r14), %ecx
movl 0x10(%rbx), %eax
movl %ecx, 0x48(%rbx)
movl 0xd8(%r14), %ecx
movl %ecx, 0x4c(%rbx)
movl 0xe0(%r14), %ecx
movl %eax, %edx
orl $0x70, %edx
movl %edx, 0x10(%rbx)
movl %ecx, 0x50(%rbx)
movl 0x10(%r14), %ecx
movl %eax, %edx
orl $0xf0, %edx
movl %edx, 0x10(%rbx)
movl %ecx, 0x54(%rbx)
movl 0x14(%r14), %ecx
movl %eax, %edx
orl $0x1f0, %edx            # imm = 0x1F0
movl %edx, 0x10(%rbx)
movl %ecx, 0x58(%rbx)
movl 0x18(%r14), %ecx
movl %eax, %edx
orl $0x3f0, %edx            # imm = 0x3F0
movl %edx, 0x10(%rbx)
movl %ecx, 0x5c(%rbx)
movl 0x1c(%r14), %ecx
movl %ecx, 0x60(%rbx)
movss 0x20(%r14), %xmm0
movss %xmm0, 0x64(%rbx)
movss 0x24(%r14), %xmm0
movl %eax, %ecx
orl $0x1ff0, %ecx           # imm = 0x1FF0
movl %ecx, 0x10(%rbx)
movss %xmm0, 0x68(%rbx)
movl 0x28(%r14), %ecx
orl $0x3ff0, %eax           # imm = 0x3FF0
movl %eax, 0x10(%rbx)
movl %ecx, 0x6c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apu.cpp
// Function: Rnes::Apu::restore(Rnes::ApuState const&)
void Apu::restore(const ApuState &pb) {
  // Restore sub-units.
  pulseA->restore(pb.pulsea());
  pulseB->restore(pb.pulseb());
  triangle->restore(pb.triangle());
  noise->restore(pb.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 (int i = 0; i < pb.reg_size(); i++) {
    regs[i] = pb.reg(i);
  }

  sampleRate = pb.samplerate();
  fourFrameCount = pb.fourframecount();
  fiveFrameCount = pb.fiveframecount();
  frameDivider = pb.framedivider();
  step = pb.step();
  halfTimerDivider = pb.halftimerdivider();
  samplerDivider = pb.samplerdivider();
  clksPerSample = pb.clkspersample();
  currentSampleClk = pb.currentsampleclk();
  nextSampleCountdown = pb.nextsamplecountdown();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0xe8(%rdi), %rdi
movq 0x28(%rsi), %rsi
testq %rsi, %rsi
leaq 0x2ce11(%rip), %r15     # 0x41840
cmoveq %r15, %rsi
callq 0x15ae0
movq 0xf0(%rbx), %rdi
movq 0x30(%r14), %rsi
testq %rsi, %rsi
cmoveq %r15, %rsi
callq 0x15ae0
movq 0xf8(%rbx), %rdi
movq 0x38(%r14), %rsi
testq %rsi, %rsi
jne 0x14a66
leaq 0x2ce12(%rip), %rsi     # 0x41878
callq 0x15cbe
movq 0x100(%rbx), %rdi
movq 0x40(%r14), %rsi
testq %rsi, %rsi
jne 0x14a82
leaq 0x2ce26(%rip), %rsi     # 0x418a8
callq 0x15e64
xorl %r15d, %r15d
movslq 0x18(%r14), %rax
cmpq %rax, %r15
jge 0x14aab
movq %r14, %rdi
movl %r15d, %esi
callq 0x15220
movb %al, 0xb8(%rbx,%r15)
incq %r15
jmp 0x14a8a
movl 0x48(%r14), %eax
movl %eax, 0xd0(%rbx)
movl 0x4c(%r14), %eax
movq %rax, 0xd8(%rbx)
movl 0x50(%r14), %eax
movq %rax, 0xe0(%rbx)
movl 0x54(%r14), %eax
movl %eax, 0x10(%rbx)
movl 0x58(%r14), %eax
movl %eax, 0x14(%rbx)
movl 0x5c(%r14), %eax
movl %eax, 0x18(%rbx)
movl 0x60(%r14), %eax
movl %eax, 0x1c(%rbx)
movss 0x64(%r14), %xmm0
movss %xmm0, 0x20(%rbx)
movss 0x68(%r14), %xmm0
movss %xmm0, 0x24(%rbx)
movl 0x6c(%r14), %eax
movl %eax, 0x28(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/./ringbuffer.h
// Function: Rnes::RingBuffer<short>::getData(short*, unsigned int)
void getData(T *out, uint32_t count) {
    {
      std::unique_lock<std::mutex> lock(mutex);
      if (!hasData(count)) {
        consumeCv.wait(lock, [&] { return this->hasData(count); });
      }
      for (uint32_t i = 0; i < count; i++) {
        out[i] = buffer[get & (size - 1)];
        get += 1;
      }
    }
    produceCv.notify_one();
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, -0x1c(%rbp)
leaq 0x30(%rdi), %rsi
leaq -0x30(%rbp), %rdi
callq 0x1532e
movl %r15d, %eax
movq 0x20(%rbx), %rcx
addq %rax, %rcx
cmpq 0x28(%rbx), %rcx
jbe 0x14e93
leaq 0x58(%rbx), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x1c(%rbp), %rcx
movq %rbx, %rdx
callq 0x1534e
movl -0x1c(%rbp), %eax
movl 0x18(%rbx), %ecx
decl %ecx
movq (%rbx), %rdx
xorl %esi, %esi
cmpq %rsi, %rax
je 0x14eba
movq 0x20(%rbx), %rdi
andl %ecx, %edi
movzwl (%rdx,%rdi,2), %edi
movw %di, (%r14,%rsi,2)
incq 0x20(%rbx)
incq %rsi
jmp 0x14e9d
leaq -0x30(%rbp), %rdi
callq 0x15388
addq $0x88, %rbx
movq %rbx, %rdi
callq 0xb470
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x15388
movq %rbx, %rdi
callq 0xb4e0
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/./ringbuffer.h
// Function: Rnes::RingBuffer<unsigned short>::putData(unsigned short const*, unsigned int)
void putData(const T *in, uint32_t count) {
    {
      std::unique_lock<std::mutex> lock(mutex);
      if (!hasEmptySpace(count)) {
        produceCv.wait(lock, [&] { return this->hasEmptySpace(count); });
      }
      for (uint32_t i = 0; i < count; i++) {
        buffer[put & (size - 1)] = in[i];
        put += 1;
      }
    }
    consumeCv.notify_one();
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, -0x1c(%rbp)
leaq 0x30(%rdi), %rsi
leaq -0x30(%rbp), %rdi
callq 0x1532e
movl %r15d, %eax
movq 0x28(%rbx), %rdx
addq %rax, %rdx
subq 0x20(%rbx), %rdx
movl 0x18(%rbx), %ecx
cmpq %rcx, %rdx
jbe 0x14f4b
leaq 0x88(%rbx), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x1c(%rbp), %rcx
movq %rbx, %rdx
callq 0x155d0
movl -0x1c(%rbp), %eax
movl 0x18(%rbx), %ecx
decl %ecx
movq (%rbx), %rdx
xorl %esi, %esi
cmpq %rsi, %rax
je 0x14f71
movzwl (%r14,%rsi,2), %edi
movq 0x28(%rbx), %r8
andl %ecx, %r8d
movw %di, (%rdx,%r8,2)
incq 0x28(%rbx)
incq %rsi
jmp 0x14f52
leaq -0x30(%rbp), %rdi
callq 0x15388
addq $0x58, %rbx
movq %rbx, %rdi
callq 0xb470
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x15388
movq %rbx, %rdi
callq 0xb4e0
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/./bin/save.pb.h
// Function: Rnes::ApuState::_internal_mutable_pulsea()
inline ::Rnes::PulseState* ApuState::_internal_mutable_pulsea() {
  _has_bits_[0] |= 0x00000001u;
  if (pulsea_ == nullptr) {
    auto* p = CreateMaybeMessage<::Rnes::PulseState>(GetArena());
    pulsea_ = p;
  }
  return pulsea_;
}

// Assembly:
orb $0x1, 0x10(%rdi)
movq 0x28(%rdi), %rax
testq %rax, %rax
je 0x15126
retq
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
testb $0x1, %dil
jne 0x15149
callq 0x260f6
movq %rax, 0x28(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x15139
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/./bin/save.pb.h
// Function: Rnes::ApuState::_internal_mutable_pulseb()
inline ::Rnes::PulseState* ApuState::_internal_mutable_pulseb() {
  _has_bits_[0] |= 0x00000002u;
  if (pulseb_ == nullptr) {
    auto* p = CreateMaybeMessage<::Rnes::PulseState>(GetArena());
    pulseb_ = p;
  }
  return pulseb_;
}

// Assembly:
orb $0x2, 0x10(%rdi)
movq 0x30(%rdi), %rax
testq %rax, %rax
je 0x15160
retq
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
testb $0x1, %dil
jne 0x15183
callq 0x260f6
movq %rax, 0x30(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x15173
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/./bin/save.pb.h
// Function: Rnes::ApuState::_internal_mutable_triangle()
inline ::Rnes::TriangleState* ApuState::_internal_mutable_triangle() {
  _has_bits_[0] |= 0x00000004u;
  if (triangle_ == nullptr) {
    auto* p = CreateMaybeMessage<::Rnes::TriangleState>(GetArena());
    triangle_ = p;
  }
  return triangle_;
}

// Assembly:
orb $0x4, 0x10(%rdi)
movq 0x38(%rdi), %rax
testq %rax, %rax
je 0x1519a
retq
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
testb $0x1, %dil
jne 0x151bd
callq 0x26152
movq %rax, 0x38(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x151ad
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/./bin/save.pb.h
// Function: Rnes::ApuState::_internal_mutable_noise()
inline ::Rnes::NoiseState* ApuState::_internal_mutable_noise() {
  _has_bits_[0] |= 0x00000008u;
  if (noise_ == nullptr) {
    auto* p = CreateMaybeMessage<::Rnes::NoiseState>(GetArena());
    noise_ = p;
  }
  return noise_;
}

// Assembly:
orb $0x8, 0x10(%rdi)
movq 0x40(%rdi), %rax
testq %rax, %rax
je 0x151d4
retq
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
testb $0x1, %dil
jne 0x151f7
callq 0x261aa
movq %rax, 0x40(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
andq $-0x2, %rdi
movq (%rdi), %rdi
jmp 0x151e7
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Pulse::computeSweepTarget() const
uint16_t Pulse::computeSweepTarget() const {
  uint16_t period = getTimerPeriod();
  uint16_t shiftedPeriod = period >> getSweepShift();
  if (isSweepNegative()) {
    shiftedPeriod = isFirstPulse() ? -shiftedPeriod : -shiftedPeriod + 1;
  }
  uint16_t targetPeriod = period + shiftedPeriod;
  return targetPeriod;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x15f58
movzwl %ax, %edx
movq 0x8(%rbx), %rcx
movb 0x1(%rcx), %sil
movl %esi, %ecx
andb $0x7, %cl
shrl %cl, %edx
movzbl 0x10(%rbx), %ecx
xorl $0x1, %ecx
subl %edx, %ecx
testb $0x8, %sil
cmovel %edx, %ecx
addl %eax, %ecx
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Pulse::sweepPeriod()
void Pulse::sweepPeriod() {
  uint16_t targetPeriod = computeSweepTarget();
  uint16_t period = getTimerPeriod();
  if (targetPeriod > 0x7ff or period < 8) {
    return;
  }
  setTimerPeriod(targetPeriod);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0x159c4
movl %eax, %r14d
movq %rbx, %rdi
callq 0x15f58
cmpw $0x7ff, %r14w           # imm = 0x7FF
ja 0x15a38
cmpw $0x8, %ax
jb 0x15a38
movzwl %r14w, %esi
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x15f74
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Pulse::envelopeDividerClock()
void Pulse::envelopeDividerClock() {
  if (envelope) {
    envelope--;
  } else if (isEnvelopeLoopSet()) {
    envelope = 15;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x12(%rdi), %al
testb %al, %al
je 0x15a6b
decb %al
jmp 0x15a76
movq 0x8(%rdi), %rcx
movb $0xf, %al
testb $0x20, (%rcx)
je 0x15a79
movb %al, 0x12(%rdi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Pulse::save(Rnes::PulseState&)
void Pulse::save(PulseState &pb) {
  // length logic
  pb.set_lengthcounter(lengthCounter);

  // envelope logic
  pb.set_envelope(envelope);
  pb.set_envelopedivider(envelopeDivider);
  pb.set_resetenvelopeanddivider(resetEnvelopeAndDivider);

  // sweep logic
  pb.set_resetsweepdivider(resetSweepDivider);
  pb.set_sweepdivider(sweepDivider);

  // current sample
  pb.set_currentsample(currentSample);

  // timer
  pb.set_timerdivider(timerDivider);

  // sequencer offset
  pb.set_sequenceroffset(sequencerOffset);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzbl 0x11(%rdi), %eax
movl 0x10(%rsi), %ecx
movl %eax, 0x18(%rsi)
movzbl 0x12(%rdi), %eax
movl %eax, 0x1c(%rsi)
movzbl 0x13(%rdi), %eax
movl %eax, 0x20(%rsi)
movb 0x14(%rdi), %al
movb %al, 0x25(%rsi)
movb 0x15(%rdi), %al
movb %al, 0x26(%rsi)
movzbl 0x16(%rdi), %eax
movl %eax, 0x28(%rsi)
movzbl 0x17(%rdi), %eax
movl %ecx, %edx
orl $0xf7, %edx
movl %edx, 0x10(%rsi)
movl %eax, 0x2c(%rsi)
movl 0x18(%rdi), %eax
movl %ecx, %edx
orl $0x1f7, %edx            # imm = 0x1F7
movl %edx, 0x10(%rsi)
movl %eax, 0x30(%rsi)
movl 0x1c(%rdi), %eax
orl $0x3f7, %ecx            # imm = 0x3F7
movl %ecx, 0x10(%rsi)
movl %eax, 0x34(%rsi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Pulse::getCurrentSample() const
uint8_t Pulse::getCurrentSample() const {
  // channel is silenced when period is < 8
  const uint16_t timerPeriod = getTimerPeriod();
  if (timerPeriod < 8) {
    return 0;
  }
  // channel silenced when target is above 0x7ff
  const uint16_t targetPeriod = computeSweepTarget();
  if (targetPeriod > 0x7ff) {
    return 0;
  }
  if (!isNonZeroLength()) {
    return 0;
  }
  if (!currentSample) {
    return 0;
  }
  return getVolume();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x15f58
cmpw $0x8, %ax
jb 0x15b3e
movq %rbx, %rdi
callq 0x159c4
cmpw $0x7ff, %ax             # imm = 0x7FF
jbe 0x15b47
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
xorl %eax, %eax
cmpb $0x0, 0x11(%rbx)
je 0x15b40
cmpb $0x0, 0x17(%rbx)
je 0x15b40
movq 0x8(%rbx), %rax
movb (%rax), %al
movl %eax, %ecx
andb $0xf, %cl
testb $0x10, %al
movzbl 0x12(%rbx), %edx
movzbl %cl, %eax
cmovel %edx, %eax
jmp 0x15b40
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Pulse::clockEnvelope()
void Pulse::clockEnvelope() {
  if (resetEnvelopeAndDivider) {
    envelope = 15;
    envelopeDivider = getEnvelopeN() + 1;
    resetEnvelopeAndDivider = false;
  } else {
    if (envelopeDivider) {
      envelopeDivider--;
    } else {
      envelopeDividerClock();
      envelopeDivider = getEnvelopeN() + 1;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpb $0x1, 0x14(%rdi)
jne 0x15b94
movb $0xf, 0x12(%rbx)
movq 0x8(%rbx), %rax
movb (%rax), %al
andb $0xf, %al
incb %al
movb %al, 0x13(%rbx)
movb $0x0, 0x14(%rbx)
jmp 0x15bb4
movb 0x13(%rbx), %al
testb %al, %al
je 0x15b9f
decb %al
jmp 0x15bb1
movq %rbx, %rdi
callq 0x15a5c
movq 0x8(%rbx), %rax
movb (%rax), %al
andb $0xf, %al
incb %al
movb %al, 0x13(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Pulse::clockLengthAndSweep()
void Pulse::clockLengthAndSweep() {
  // Length
  if (!isHalted() and lengthCounter) {
    lengthCounter--;
  }
  // Sweep
  if (resetSweepDivider) {
    sweepDivider = getSweepP() + 1;
    resetSweepDivider = false;
  } else {
    if (sweepDivider) {
      sweepDivider--;
    } else {
      if (isSweepEnabled()) {
        sweepDivider = getSweepP() + 1;
        sweepPeriod();
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x8(%rdi), %rax
testb $0x20, (%rax)
jne 0x15bd5
movb 0x11(%rdi), %cl
testb %cl, %cl
je 0x15bd5
decb %cl
movb %cl, 0x11(%rdi)
cmpb $0x1, 0x15(%rdi)
jne 0x15bee
movb 0x1(%rax), %al
shrb $0x4, %al
andb $0x7, %al
incb %al
movb %al, 0x16(%rdi)
movb $0x0, 0x15(%rdi)
jmp 0x15c03
movb 0x16(%rdi), %cl
testb %cl, %cl
je 0x15bfc
decb %cl
movb %cl, 0x16(%rdi)
jmp 0x15c03
movb 0x1(%rax), %al
testb %al, %al
js 0x15c05
popq %rbp
retq
shrb $0x4, %al
andb $0x7, %al
incb %al
movb %al, 0x16(%rdi)
popq %rbp
jmp 0x15a00
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Triangle::save(Rnes::TriangleState&)
void Triangle::save(TriangleState &pb) {
  // length logic
  pb.set_lengthcounter(lengthCounter);

  // linear counter logic
  pb.set_linearcounterhalt(linearCounterHalt);
  pb.set_linearcounter(linearCounter);

  // current sample
  pb.set_currentsample(currentSample);

  // timer
  pb.set_timerdivider(timerDivider);

  // sequencer offset
  pb.set_sequenceroffset(sequencerOffset);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzbl 0x28(%rdi), %eax
movl 0x10(%rsi), %ecx
movl %eax, 0x18(%rsi)
movb 0x29(%rdi), %al
movb %al, 0x1c(%rsi)
movzbl 0x2a(%rdi), %eax
movl %eax, 0x20(%rsi)
movzbl 0x2b(%rdi), %eax
movl %ecx, %edx
orl $0xf, %edx
movl %edx, 0x10(%rsi)
movl %eax, 0x24(%rsi)
movl 0x2c(%rdi), %eax
movl %ecx, %edx
orl $0x1f, %edx
movl %edx, 0x10(%rsi)
movl %eax, 0x28(%rsi)
movl 0x30(%rdi), %eax
orl $0x3f, %ecx
movl %ecx, 0x10(%rsi)
movl %eax, 0x2c(%rsi)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Triangle::clockLinearCounter()
void Triangle::clockLinearCounter() {
  if (linearCounterHalt) {
    linearCounter = getLinearCounterReload();
  } else if (linearCounter) {
    linearCounter--;
  }
  if (!getControlFlag()) {
    linearCounterHalt = false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
cmpb $0x1, 0x29(%rdi)
jne 0x15d18
movq 0x20(%rdi), %rax
movb (%rax), %al
andb $0x7f, %al
jmp 0x15d21
movb 0x2a(%rdi), %al
testb %al, %al
je 0x15d24
decb %al
movb %al, 0x2a(%rdi)
movq 0x20(%rdi), %rax
cmpb $0x0, (%rax)
js 0x15d31
movb $0x0, 0x29(%rdi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Noise::getVolume() const
uint8_t Noise::getVolume() const {
  if (isDisabled()) {
    return getEnvelopeN();
  } else {
    return envelope;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq (%rdi), %rax
movb (%rax), %al
testb $0x10, %al
jne 0x15dd0
movl 0xc(%rdi), %eax
jmp 0x15dd5
andb $0xf, %al
movzbl %al, %eax
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Noise::envelopeDividerClock()
void Noise::envelopeDividerClock() {
  if (envelope) {
    envelope--;
  } else if (isEnvelopeLoopSet()) {
    envelope = 15;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0xc(%rdi), %al
testb %al, %al
je 0x15de7
decb %al
jmp 0x15df1
movq (%rdi), %rcx
movb $0xf, %al
testb $0x20, (%rcx)
je 0x15df4
movb %al, 0xc(%rdi)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Noise::getCurrentSample() const
uint8_t Noise::getCurrentSample() const {
  if (!currentSample) {
    return 0;
  }
  if (!isNonZeroLength()) {
    return 0;
  }
  return getVolume();
}

// Assembly:
xorl %eax, %eax
cmpb $0x0, 0xf(%rdi)
je 0x15e1c
cmpb $0x0, 0x8(%rdi)
je 0x15e1c
pushq %rbp
movq %rsp, %rbp
movq (%rdi), %rax
movb (%rax), %al
testb $0x10, %al
jne 0x15e16
movl 0xc(%rdi), %eax
jmp 0x15e1b
andb $0xf, %al
movzbl %al, %eax
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/apuunit.cpp
// Function: Rnes::Noise::save(Rnes::NoiseState&)
void Noise::save(NoiseState &pb) {
  // length logic
  pb.set_lengthcounter(lengthCounter);

  // noise shift register
  pb.set_shiftregister(shiftRegister);

  // envelope logic
  pb.set_envelope(envelope);
  pb.set_envelopedivider(envelopeDivider);
  pb.set_resetenvelopeanddivider(resetEnvelopeAndDivider);

  // current sample
  pb.set_currentsample(currentSample);

  // timer
  pb.set_timerdivider(timerDivider);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzbl 0x8(%rdi), %eax
movl 0x10(%rsi), %ecx
movl %eax, 0x18(%rsi)
movzwl 0xa(%rdi), %eax
movl %eax, 0x1c(%rsi)
movzbl 0xc(%rdi), %eax
movl %eax, 0x20(%rsi)
movzbl 0xd(%rdi), %eax
movl %eax, 0x24(%rsi)
movb 0xe(%rdi), %al
movb %al, 0x28(%rsi)
movzbl 0xf(%rdi), %eax
movl %ecx, %edx
orl $0x3f, %edx
movl %edx, 0x10(%rsi)
movl %eax, 0x2c(%rsi)
movl 0x10(%rdi), %eax
orl $0x7f, %ecx
movl %ecx, 0x10(%rsi)
movl %eax, 0x30(%rsi)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::setZeroAndNeg(unsigned char)
void Cpu::setZeroAndNeg(uint8_t val) {
  if (val == 0) {
    setFlag(ZERO);
  } else {
    clearFlag(ZERO);
  }
  if (val & (1 << 7)) {
    setFlag(NEGATIVE);
  } else {
    clearFlag(NEGATIVE);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x18(%rdi), %al
testl %esi, %esi
je 0x16052
andb $-0x3, %al
testb %sil, %sil
jns 0x16054
orb $-0x80, %al
jmp 0x16056
orb $0x2, %al
andb $0x7f, %al
movb %al, 0x18(%rdi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::doInt()
uint32_t Cpu::doInt() {
  pushStack((uint8_t)(pc >> 8));
  pushStack((uint8_t)pc);
  pushStack(status);
  setFlag(INT_DISABLE);
  pc = load(irqBaseAddr) | ((uint16_t)load(irqBaseAddr + 1) << 8);
  cycle += 7;
  return 7;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movzbl 0xd(%rdi), %esi
callq 0x1605c
movzbl 0xc(%rbx), %esi
movq %rbx, %rdi
callq 0x1605c
movzbl 0x18(%rbx), %esi
movq %rbx, %rdi
callq 0x1605c
orb $0x4, 0x18(%rbx)
movq %rbx, %rdi
movl $0xfffe, %esi           # imm = 0xFFFE
callq 0x15ff4
movzbl %al, %r14d
movq %rbx, %rdi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x15ff4
movzbl %al, %eax
shll $0x8, %eax
orl %r14d, %eax
movw %ax, 0xc(%rbx)
addq $0x7, 0x10(%rbx)
pushq $0x7
popq %rax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::doNmi()
uint32_t Cpu::doNmi() {
  pushStack((uint8_t)(pc >> 8));
  pushStack((uint8_t)pc);
  pushStack(status);
  setFlag(INT_DISABLE);
  pc = load(nmiBaseAddr) | ((uint16_t)load(nmiBaseAddr + 1) << 8);
  cycle += 7;
  return 7;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movzbl 0xd(%rdi), %esi
callq 0x1605c
movzbl 0xc(%rbx), %esi
movq %rbx, %rdi
callq 0x1605c
movzbl 0x18(%rbx), %esi
movq %rbx, %rdi
callq 0x1605c
orb $0x4, 0x18(%rbx)
movq %rbx, %rdi
movl $0xfffa, %esi           # imm = 0xFFFA
callq 0x15ff4
movzbl %al, %r14d
movq %rbx, %rdi
movl $0xfffb, %esi           # imm = 0xFFFB
callq 0x15ff4
movzbl %al, %eax
shll $0x8, %eax
orl %r14d, %eax
movw %ax, 0xc(%rbx)
addq $0x7, 0x10(%rbx)
pushq $0x7
popq %rax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::adcInst(unsigned short)
void Cpu::adcInst(uint16_t addr) {
  uint8_t v = load(addr);
  uint16_t result = a + v + (getFlag(CARRY) ? 1 : 0);
  if (result & (1u << 8)) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  if (isNeg((uint8_t)result) && isPos(a) && isPos(v)) {
    setFlag(OVERFL);
  } else if (isPos((uint8_t)result) && isNeg((a) && isNeg(v))) {
    setFlag(OVERFL);
  } else {
    clearFlag(OVERFL);
  }
  a = (uint8_t)result;
  setZeroAndNeg(a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x15ff4
movzbl 0x8(%rbx), %ecx
movzbl %al, %eax
movl %ecx, %edx
addl %eax, %edx
movzbl 0x18(%rbx), %esi
movl %esi, %edi
andl $0x1, %edi
addl %edx, %edi
andb $-0x42, %sil
movl %edi, %edx
shrl $0x8, %edx
testb %dil, %dil
sets %r8b
orb %cl, %al
setns %al
andb %r8b, %al
orb %sil, %dl
shlb $0x6, %al
orb %dl, %al
movb %al, 0x18(%rbx)
movb %dil, 0x8(%rbx)
movzbl %dil, %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1603c
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::aslInstMem(unsigned short)
void Cpu::aslInstMem(uint16_t addr) {
  uint8_t src = load(addr);
  uint8_t result = src << 1;
  store(addr, result);
  setZeroAndNeg(result);
  if (src & (1 << 7)) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %r14d
movq %rdi, %rbx
callq 0x15ff4
movl %eax, %r15d
leal (%r15,%r15), %eax
movzbl %al, %r12d
movq %rbx, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0x16002
movq %rbx, %rdi
movl %r12d, %esi
callq 0x1603c
movb 0x18(%rbx), %al
andb $-0x2, %al
shrb $0x7, %r15b
orb %al, %r15b
movb %r15b, 0x18(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::aslInstReg(unsigned short)
void Cpu::aslInstReg(uint16_t addr) {
  if (a & (1 << 7)) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }

  a <<= 1;
  setZeroAndNeg(a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x8(%rdi), %al
movb 0x18(%rdi), %cl
andb $-0x2, %cl
movl %eax, %edx
shrb $0x7, %dl
orb %cl, %dl
movb %dl, 0x18(%rdi)
addb %al, %al
movb %al, 0x8(%rdi)
movzbl %al, %esi
popq %rbp
jmp 0x1603c
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::bitInst(unsigned short)
void Cpu::bitInst(uint16_t addr) {
  uint8_t v = load(addr);
  bool zero = (a & v) == 0;
  if (zero) {
    setFlag(ZERO);
  } else {
    clearFlag(ZERO);
  }
  if (v & (1 << 7)) {
    setFlag(NEGATIVE);
  } else {
    clearFlag(NEGATIVE);
  }
  if (v & (1 << 6)) {
    setFlag(OVERFL);
  } else {
    clearFlag(OVERFL);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x15ff4
testb %al, 0x8(%rbx)
sete %cl
movb 0x18(%rbx), %dl
andb $0x3d, %dl
addb %cl, %cl
orb %dl, %cl
andb $-0x40, %al
orb %cl, %al
movb %al, 0x18(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::brkInst(unsigned short)
void Cpu::brkInst(uint16_t) {
  pc++;
  pushStack((uint8_t)(pc >> 8));
  pushStack((uint8_t)pc);
  pushStack(status | BREAK);

  pc = load(irqBaseAddr) | ((uint16_t)load(irqBaseAddr + 1) << 8);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl 0xc(%rdi), %eax
incl %eax
movw %ax, 0xc(%rdi)
movzbl %ah, %esi
callq 0x1605c
movzbl 0xc(%rbx), %esi
movq %rbx, %rdi
callq 0x1605c
movzbl 0x18(%rbx), %esi
orl $0x10, %esi
movq %rbx, %rdi
callq 0x1605c
movq %rbx, %rdi
movl $0xfffe, %esi           # imm = 0xFFFE
callq 0x15ff4
movzbl %al, %r14d
movq %rbx, %rdi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x15ff4
movzbl %al, %eax
shll $0x8, %eax
orl %r14d, %eax
movw %ax, 0xc(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::cmp(unsigned short, unsigned char)
void Cpu::cmp(uint16_t addr, uint8_t val) {
  uint8_t v = load(addr);
  uint8_t result;
  result = val - v;
  setZeroAndNeg(result);
  if (val >= v) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl %edx, %ebx
movq %rdi, %r14
callq 0x15ff4
subb %al, %bl
movzbl %bl, %esi
setae %bl
movq %r14, %rdi
callq 0x1603c
movb 0x18(%r14), %al
andb $-0x2, %al
orb %bl, %al
movb %al, 0x18(%r14)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::jsrInst(unsigned short)
void Cpu::jsrInst(uint16_t addr) {
  uint16_t pcm = pc - 1;
  pushStack((uint8_t)(pcm >> 8));
  pushStack((uint8_t)pcm);
  pc = addr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r15d
movq %rdi, %r14
movl 0xc(%rdi), %ebx
decl %ebx
movzbl %bh, %esi
callq 0x1605c
movzbl %bl, %esi
movq %r14, %rdi
callq 0x1605c
movw %r15w, 0xc(%r14)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rtsInst(unsigned short)
void Cpu::rtsInst(uint16_t) {
  uint16_t newpc;
  newpc = popStack();
  newpc |= (uint16_t)popStack() << 8;
  newpc++;
  pc = newpc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0x16080
movl %eax, %r14d
movq %rbx, %rdi
callq 0x16080
movzbl %al, %eax
shll $0x8, %eax
movzbl %r14b, %ecx
addl %ecx, %eax
incl %eax
movw %ax, 0xc(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::lsrInstMem(unsigned short)
void Cpu::lsrInstMem(uint16_t addr) {
  uint8_t t = load(addr);
  uint8_t result = t >> 1;
  setZeroAndNeg(result);
  if (t & 1) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  store(addr, result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
callq 0x15ff4
movl %eax, %r15d
shrb %al
movzbl %al, %r12d
movq %r14, %rdi
movl %r12d, %esi
callq 0x1603c
andb $0x1, %r15b
movb 0x18(%r14), %al
andb $-0x2, %al
orb %r15b, %al
movb %al, 0x18(%r14)
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x16002
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::lsrInstReg(unsigned short)
void Cpu::lsrInstReg(uint16_t) {
  uint8_t result = a >> 1;
  setZeroAndNeg(result);
  if (a & 1) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  a = result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movb 0x8(%rdi), %al
shrb %al
movzbl %al, %r14d
movl %r14d, %esi
callq 0x1603c
movb 0x8(%rbx), %al
movb 0x18(%rbx), %cl
andb $0x1, %al
andb $-0x2, %cl
orb %al, %cl
movb %cl, 0x18(%rbx)
movb %r14b, 0x8(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rolInstReg(unsigned short)
void Cpu::rolInstReg(uint16_t) {
  uint8_t result = a << 1 | (getFlag(CARRY) ? 1 : 0);
  if (a & (1 << 7)) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  a = result;
  setZeroAndNeg(a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x8(%rdi), %al
movb 0x18(%rdi), %cl
movl %ecx, %edx
andb $-0x2, %dl
movl %eax, %esi
shrb $0x7, %sil
orb %dl, %sil
movb %sil, 0x18(%rdi)
andb $0x1, %cl
addb %al, %al
orb %cl, %al
movb %al, 0x8(%rdi)
movzbl %al, %esi
popq %rbp
jmp 0x1603c
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rolInstMem(unsigned short)
void Cpu::rolInstMem(uint16_t addr) {
  uint8_t t = load(addr);
  uint8_t result = (t << 1) | (getFlag(CARRY) ? 1 : 0);
  if (t & (1 << 7)) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  store(addr, result);
  setZeroAndNeg(result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
callq 0x15ff4
movb 0x18(%r14), %cl
movl %ecx, %edx
andb $-0x2, %dl
movl %eax, %esi
shrb $0x7, %sil
orb %dl, %sil
movb %sil, 0x18(%r14)
andb $0x1, %cl
addb %al, %al
orb %cl, %al
movzbl %al, %r15d
movq %r14, %rdi
movl %ebx, %esi
movl %r15d, %edx
callq 0x16002
movq %r14, %rdi
movl %r15d, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1603c
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/cpu.cpp
// Function: Rnes::Cpu::rorInstReg(unsigned short)
void Cpu::rorInstReg(uint16_t) {
  uint8_t result = (a >> 1) | (getFlag(CARRY) ? 1u << 7 : 0);
  if (a & 1) {
    setFlag(CARRY);
  } else {
    clearFlag(CARRY);
  }
  a = result;
  setZeroAndNeg(a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb 0x8(%rdi), %al
movb 0x18(%rdi), %cl
movl %eax, %edx
andb $0x1, %dl
movl %ecx, %esi
andb $-0x2, %sil
orb %dl, %sil
movb %sil, 0x18(%rdi)
shrb %al
shlb $0x7, %cl
orb %al, %cl
movb %cl, 0x8(%rdi)
movzbl %cl, %esi
popq %rbp
jmp 0x1603c
nop