#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ ASIC_DMA_GetChannelAddr(int);
int ASIC_DMA_GetChannelPrescale(int);
int ASIC_GetAnalogueInput(int);
int ASIC_GetDCSR();
int ASIC_GetIVR();
int ASIC_GetPRI();
unsigned char *ASIC_GetRamPtr();
int ASIC_GetSPLT();
int /*<<< orphan*/ ASIC_GetSSA();
int ASIC_GetSSCR();
int ASIC_GetSecondaryRomMapping();
int ASIC_GetSpriteMagnification(int);
int /*<<< orphan*/ ASIC_GetSpriteX(int);
int /*<<< orphan*/ ASIC_GetSpriteY(int);
scalar_t__ ASIC_GetUnLockState();
unsigned char *SnapshotV3_BeginChunk(unsigned char *, unsigned int);
int /*<<< orphan*/ SnapshotV3_EndChunk();
unsigned char *SnapshotV3_WriteByte(unsigned char *, int);
unsigned char *SnapshotV3_WriteDataToChunk(unsigned char *, unsigned char *,
                                           int);
unsigned char *SnapshotV3_WriteWord(unsigned char *, int /*<<< orphan*/);
unsigned char *SnapshotV3_CPCPlus_WriteChunk(unsigned char *buffer) {
  unsigned char *pASICRamPtr;
  unsigned char *pPtr;
  int i;
  pASICRamPtr = ASIC_GetRamPtr();
  buffer = SnapshotV3_BeginChunk(buffer,
                                 (unsigned int)((((unsigned char)'C') << 24) |
                                                (((unsigned char)'P') << 16) |
                                                (((unsigned char)'C') << 8) |
                                                (((unsigned char)'+'))));
  pPtr = &pASICRamPtr[0x04000 - 0x04000];
  for (i = 0; i < ((16 * 16 * 16) >> 1); i++) {
    unsigned char PackedPixels;
    PackedPixels = (pPtr[0] & 0x0f);
    PackedPixels = PackedPixels << 4;
    PackedPixels |= (pPtr[1] & 0x0f);
    pPtr += 2;
    buffer = SnapshotV3_WriteByte(buffer, PackedPixels);
  }
  for (i = 0; i < 16; i++) {
    buffer = SnapshotV3_WriteWord(buffer, ASIC_GetSpriteX(i));
    buffer = SnapshotV3_WriteWord(buffer, ASIC_GetSpriteY(i));
    buffer = SnapshotV3_WriteByte(buffer, ASIC_GetSpriteMagnification(i));
    buffer = SnapshotV3_WriteByte(buffer, 0);
    buffer = SnapshotV3_WriteByte(buffer, 0);
    buffer = SnapshotV3_WriteByte(buffer, 0);
  }
  pPtr = &pASICRamPtr[0x06400 - 0x04000];
  buffer = SnapshotV3_WriteDataToChunk(buffer, pPtr, (32 * 2));
  buffer = SnapshotV3_WriteByte(buffer, ASIC_GetPRI());
  buffer = SnapshotV3_WriteByte(buffer, ASIC_GetSPLT());
  buffer = SnapshotV3_WriteWord(buffer, ASIC_GetSSA());
  buffer = SnapshotV3_WriteByte(buffer, ASIC_GetSSCR());
  buffer = SnapshotV3_WriteByte(buffer, ASIC_GetIVR());
  buffer = SnapshotV3_WriteWord(buffer, 0);
  for (i = 0; i < 8; i++) {
    buffer = SnapshotV3_WriteByte(buffer, ASIC_GetAnalogueInput(i));
  }
  for (i = 0; i < 3; i++) {
    buffer = SnapshotV3_WriteWord(buffer, ASIC_DMA_GetChannelAddr(i));
    buffer = SnapshotV3_WriteByte(buffer, ASIC_DMA_GetChannelPrescale(i));
    buffer = SnapshotV3_WriteByte(buffer, 0);
  }
  buffer = SnapshotV3_WriteWord(buffer, 0);
  buffer = SnapshotV3_WriteByte(buffer, 0);
  buffer = SnapshotV3_WriteByte(buffer, ASIC_GetDCSR());
  for (i = 0; i < 3 * 7; i++) {
    buffer = SnapshotV3_WriteByte(buffer, 0);
  }
  buffer = SnapshotV3_WriteByte(
      buffer, (ASIC_GetSecondaryRomMapping() & 0x01f) | 0x0a0);
  if (ASIC_GetUnLockState()) {
    buffer = SnapshotV3_WriteByte(buffer, 1);
  } else {
    buffer = SnapshotV3_WriteByte(buffer, 0);
  }
  SnapshotV3_EndChunk();
  return buffer;
}


x86 assembly (clang, -O0):
<SnapshotV3_CPCPlus_WriteChunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   10b0 <ASIC_GetRamPtr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x4350432b,%esi
call   1130 <SnapshotV3_BeginChunk@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x800,-0x1c(%rbp)
jge    12de <SnapshotV3_CPCPlus_WriteChunk+0x9e>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
and    $0xf,%eax
mov    %al,-0x1d(%rbp)
movzbl -0x1d(%rbp),%eax
shl    $0x4,%eax
mov    %al,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%ecx
and    $0xf,%ecx
movzbl -0x1d(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0x1d(%rbp),%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    127b <SnapshotV3_CPCPlus_WriteChunk+0x3b>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    1387 <SnapshotV3_CPCPlus_WriteChunk+0x147>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <ASIC_GetSpriteX@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <ASIC_GetSpriteY@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <ASIC_GetSpriteMagnification@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e5 <SnapshotV3_CPCPlus_WriteChunk+0xa5>
mov    -0x10(%rbp),%rax
add    $0x2400,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x40,%edx
call   10a0 <SnapshotV3_WriteDataToChunk@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   10f0 <ASIC_GetPRI@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   10c0 <ASIC_GetSPLT@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1050 <ASIC_GetSSA@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1100 <ASIC_GetSSCR@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1150 <ASIC_GetIVR@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    148e <SnapshotV3_CPCPlus_WriteChunk+0x24e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1457 <SnapshotV3_CPCPlus_WriteChunk+0x217>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    14fa <SnapshotV3_CPCPlus_WriteChunk+0x2ba>
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <ASIC_DMA_GetChannelAddr@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x1c(%rbp),%edi
call   10e0 <ASIC_DMA_GetChannelPrescale@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1495 <SnapshotV3_CPCPlus_WriteChunk+0x255>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    $0x0,%al
call   1160 <ASIC_GetDCSR@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x15,-0x1c(%rbp)
jge    1564 <SnapshotV3_CPCPlus_WriteChunk+0x324>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    153d <SnapshotV3_CPCPlus_WriteChunk+0x2fd>
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    $0x0,%al
call   10d0 <ASIC_GetSecondaryRomMapping@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
and    $0x1f,%esi
or     $0xa0,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1140 <ASIC_GetUnLockState@plt>
cmp    $0x0,%rax
je     15b9 <SnapshotV3_CPCPlus_WriteChunk+0x379>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
jmp    15c8 <SnapshotV3_CPCPlus_WriteChunk+0x388>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1120 <SnapshotV3_EndChunk@plt>
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SnapshotV3_CPCPlus_WriteChunk>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <ASIC_GetRamPtr@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x4350432b,%esi
call   1130 <SnapshotV3_BeginChunk@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbp,2),%eax
shl    $0x4,%al
movzbl 0x1(%r14,%rbp,2),%ecx
and    $0xf,%ecx
movzbl %al,%esi
or     %ecx,%esi
mov    %rbx,%rdi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
add    $0x1,%rbp
cmp    $0x800,%ebp
jne    1270 <SnapshotV3_CPCPlus_WriteChunk+0x30>
xor    %ebp,%ebp
nop
mov    %ebp,%edi
call   1040 <ASIC_GetSpriteX@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <ASIC_GetSpriteY@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1070 <ASIC_GetSpriteMagnification@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
add    $0x1,%ebp
cmp    $0x10,%ebp
jne    12a0 <SnapshotV3_CPCPlus_WriteChunk+0x60>
add    $0x2400,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   10a0 <SnapshotV3_WriteDataToChunk@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10f0 <ASIC_GetPRI@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10c0 <ASIC_GetSPLT@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <ASIC_GetSSA@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1100 <ASIC_GetSSCR@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1150 <ASIC_GetIVR@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x2,%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x3,%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x5,%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x6,%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x7,%edi
call   1060 <ASIC_GetAnalogueInput@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <ASIC_DMA_GetChannelAddr@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   10e0 <ASIC_DMA_GetChannelPrescale@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1080 <ASIC_DMA_GetChannelAddr@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   10e0 <ASIC_DMA_GetChannelPrescale@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
mov    $0x2,%edi
call   1080 <ASIC_DMA_GetChannelAddr@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,%rbx
mov    $0x2,%edi
call   10e0 <ASIC_DMA_GetChannelPrescale@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1090 <SnapshotV3_WriteWord@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1160 <ASIC_GetDCSR@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10d0 <ASIC_GetSecondaryRomMapping@plt>
and    $0x1f,%eax
lea    0xa0(%rax),%esi
mov    %rbx,%rdi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1140 <ASIC_GetUnLockState@plt>
xor    %esi,%esi
test   %rax,%rax
setne  %sil
mov    %rbx,%rdi
call   1110 <SnapshotV3_WriteByte@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1120 <SnapshotV3_EndChunk@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @SnapshotV3_CPCPlus_WriteChunk(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %2
%7 = call i8* (...) @ASIC_GetRamPtr()
store i8* %7, i8** %3
%8 = load i8*, i8** %2
%9 = call i8* @SnapshotV3_BeginChunk(i8* %8, i32 1129333547)
store i8* %9, i8** %2
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8* %11, i8** %4
store i32 0, i32* %5
br label %12
12: ; preds = %41, %1
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 2048
br i1 %14, label %15, label %44
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = and i32 %19, 15
%21 = trunc i32 %20 to i8
store i8 %21, i8* %6
%22 = load i8, i8* %6
%23 = zext i8 %22 to i32
%24 = shl i32 %23, 4
%25 = trunc i32 %24 to i8
store i8 %25, i8* %6
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = and i32 %29, 15
%31 = load i8, i8* %6
%32 = zext i8 %31 to i32
%33 = or i32 %32, %30
%34 = trunc i32 %33 to i8
store i8 %34, i8* %6
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 2
store i8* %36, i8** %4
%37 = load i8*, i8** %2
%38 = load i8, i8* %6
%39 = zext i8 %38 to i32
%40 = call i8* @SnapshotV3_WriteByte(i8* %37, i32 %39)
store i8* %40, i8** %2
br label %41
41: ; preds = %15
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %12
44: ; preds = %12
store i32 0, i32* %5
br label %45
45: ; preds = %67, %44
%46 = load i32, i32* %5
%47 = icmp slt i32 %46, 16
br i1 %47, label %48, label %70
48: ; preds = %45
%49 = load i8*, i8** %2
%50 = load i32, i32* %5
%51 = call i32 @ASIC_GetSpriteX(i32 %50)
%52 = call i8* @SnapshotV3_WriteWord(i8* %49, i32 %51)
store i8* %52, i8** %2
%53 = load i8*, i8** %2
%54 = load i32, i32* %5
%55 = call i32 @ASIC_GetSpriteY(i32 %54)
%56 = call i8* @SnapshotV3_WriteWord(i8* %53, i32 %55)
store i8* %56, i8** %2
%57 = load i8*, i8** %2
%58 = load i32, i32* %5
%59 = call i32 @ASIC_GetSpriteMagnification(i32 %58)
%60 = call i8* @SnapshotV3_WriteByte(i8* %57, i32 %59)
store i8* %60, i8** %2
%61 = load i8*, i8** %2
%62 = call i8* @SnapshotV3_WriteByte(i8* %61, i32 0)
store i8* %62, i8** %2
%63 = load i8*, i8** %2
%64 = call i8* @SnapshotV3_WriteByte(i8* %63, i32 0)
store i8* %64, i8** %2
%65 = load i8*, i8** %2
%66 = call i8* @SnapshotV3_WriteByte(i8* %65, i32 0)
store i8* %66, i8** %2
br label %67
67: ; preds = %48
%68 = load i32, i32* %5
%69 = add nsw i32 %68, 1
store i32 %69, i32* %5
br label %45
70: ; preds = %45
%71 = load i8*, i8** %3
%72 = getelementptr inbounds i8, i8* %71, i64 9216
store i8* %72, i8** %4
%73 = load i8*, i8** %2
%74 = load i8*, i8** %4
%75 = call i8* @SnapshotV3_WriteDataToChunk(i8* %73, i8* %74, i32 64)
store i8* %75, i8** %2
%76 = load i8*, i8** %2
%77 = call i32 (...) @ASIC_GetPRI()
%78 = call i8* @SnapshotV3_WriteByte(i8* %76, i32 %77)
store i8* %78, i8** %2
%79 = load i8*, i8** %2
%80 = call i32 (...) @ASIC_GetSPLT()
%81 = call i8* @SnapshotV3_WriteByte(i8* %79, i32 %80)
store i8* %81, i8** %2
%82 = load i8*, i8** %2
%83 = call i32 (...) @ASIC_GetSSA()
%84 = call i8* @SnapshotV3_WriteWord(i8* %82, i32 %83)
store i8* %84, i8** %2
%85 = load i8*, i8** %2
%86 = call i32 (...) @ASIC_GetSSCR()
%87 = call i8* @SnapshotV3_WriteByte(i8* %85, i32 %86)
store i8* %87, i8** %2
%88 = load i8*, i8** %2
%89 = call i32 (...) @ASIC_GetIVR()
%90 = call i8* @SnapshotV3_WriteByte(i8* %88, i32 %89)
store i8* %90, i8** %2
%91 = load i8*, i8** %2
%92 = call i8* @SnapshotV3_WriteWord(i8* %91, i32 0)
store i8* %92, i8** %2
store i32 0, i32* %5
br label %93
93: ; preds = %101, %70
%94 = load i32, i32* %5
%95 = icmp slt i32 %94, 8
br i1 %95, label %96, label %104
96: ; preds = %93
%97 = load i8*, i8** %2
%98 = load i32, i32* %5
%99 = call i32 @ASIC_GetAnalogueInput(i32 %98)
%100 = call i8* @SnapshotV3_WriteByte(i8* %97, i32 %99)
store i8* %100, i8** %2
br label %101
101: ; preds = %96
%102 = load i32, i32* %5
%103 = add nsw i32 %102, 1
store i32 %103, i32* %5
br label %93
104: ; preds = %93
store i32 0, i32* %5
br label %105
105: ; preds = %119, %104
%106 = load i32, i32* %5
%107 = icmp slt i32 %106, 3
br i1 %107, label %108, label %122
108: ; preds = %105
%109 = load i8*, i8** %2
%110 = load i32, i32* %5
%111 = call i32 @ASIC_DMA_GetChannelAddr(i32 %110)
%112 = call i8* @SnapshotV3_WriteWord(i8* %109, i32 %111)
store i8* %112, i8** %2
%113 = load i8*, i8** %2
%114 = load i32, i32* %5
%115 = call i32 @ASIC_DMA_GetChannelPrescale(i32 %114)
%116 = call i8* @SnapshotV3_WriteByte(i8* %113, i32 %115)
store i8* %116, i8** %2
%117 = load i8*, i8** %2
%118 = call i8* @SnapshotV3_WriteByte(i8* %117, i32 0)
store i8* %118, i8** %2
br label %119
119: ; preds = %108
%120 = load i32, i32* %5
%121 = add nsw i32 %120, 1
store i32 %121, i32* %5
br label %105
122: ; preds = %105
%123 = load i8*, i8** %2
%124 = call i8* @SnapshotV3_WriteWord(i8* %123, i32 0)
store i8* %124, i8** %2
%125 = load i8*, i8** %2
%126 = call i8* @SnapshotV3_WriteByte(i8* %125, i32 0)
store i8* %126, i8** %2
%127 = load i8*, i8** %2
%128 = call i32 (...) @ASIC_GetDCSR()
%129 = call i8* @SnapshotV3_WriteByte(i8* %127, i32 %128)
store i8* %129, i8** %2
store i32 0, i32* %5
br label %130
130: ; preds = %136, %122
%131 = load i32, i32* %5
%132 = icmp slt i32 %131, 21
br i1 %132, label %133, label %139
133: ; preds = %130
%134 = load i8*, i8** %2
%135 = call i8* @SnapshotV3_WriteByte(i8* %134, i32 0)
store i8* %135, i8** %2
br label %136
136: ; preds = %133
%137 = load i32, i32* %5
%138 = add nsw i32 %137, 1
store i32 %138, i32* %5
br label %130
139: ; preds = %130
%140 = load i8*, i8** %2
%141 = call i32 (...) @ASIC_GetSecondaryRomMapping()
%142 = and i32 %141, 31
%143 = or i32 %142, 160
%144 = call i8* @SnapshotV3_WriteByte(i8* %140, i32 %143)
store i8* %144, i8** %2
%145 = call i64 (...) @ASIC_GetUnLockState()
%146 = icmp ne i64 %145, 0
br i1 %146, label %147, label %150
147: ; preds = %139
%148 = load i8*, i8** %2
%149 = call i8* @SnapshotV3_WriteByte(i8* %148, i32 1)
store i8* %149, i8** %2
br label %153
150: ; preds = %139
%151 = load i8*, i8** %2
%152 = call i8* @SnapshotV3_WriteByte(i8* %151, i32 0)
store i8* %152, i8** %2
br label %153
153: ; preds = %150, %147
%154 = call i32 (...) @SnapshotV3_EndChunk()
%155 = load i8*, i8** %2
ret i8* %155
}

LLVM IR (-O2):
define i8* @SnapshotV3_CPCPlus_WriteChunk(i8* %0) {
%2 = tail call i8* (...) @ASIC_GetRamPtr()
%3 = tail call i8* @SnapshotV3_BeginChunk(i8* %0, i32 1129333547)
br label %4
4: ; preds = %1, %4
%5 = phi i8* [ %3, %1 ], [ %16, %4 ]
%6 = phi i32 [ 0, %1 ], [ %17, %4 ]
%7 = phi i8* [ %2, %1 ], [ %14, %4 ]
%8 = load i8, i8* %7
%9 = shl i8 %8, 4
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %10
%12 = and i8 %11, 15
%13 = or i8 %12, %9
%14 = getelementptr inbounds i8, i8* %7, i64 2
%15 = zext i8 %13 to i32
%16 = tail call i8* @SnapshotV3_WriteByte(i8* %5, i32 %15)
%17 = add nuw nsw i32 %6, 1
%18 = icmp eq i32 %17, 2048
br i1 %18, label %19, label %4
19: ; preds = %4, %19
%20 = phi i8* [ %30, %19 ], [ %16, %4 ]
%21 = phi i32 [ %31, %19 ], [ 0, %4 ]
%22 = tail call i32 @ASIC_GetSpriteX(i32 %21)
%23 = tail call i8* @SnapshotV3_WriteWord(i8* %20, i32 %22)
%24 = tail call i32 @ASIC_GetSpriteY(i32 %21)
%25 = tail call i8* @SnapshotV3_WriteWord(i8* %23, i32 %24)
%26 = tail call i32 @ASIC_GetSpriteMagnification(i32 %21)
%27 = tail call i8* @SnapshotV3_WriteByte(i8* %25, i32 %26)
%28 = tail call i8* @SnapshotV3_WriteByte(i8* %27, i32 0)
%29 = tail call i8* @SnapshotV3_WriteByte(i8* %28, i32 0)
%30 = tail call i8* @SnapshotV3_WriteByte(i8* %29, i32 0)
%31 = add nuw nsw i32 %21, 1
%32 = icmp eq i32 %31, 16
br i1 %32, label %33, label %19
33: ; preds = %19
%34 = getelementptr inbounds i8, i8* %2, i64 9216
%35 = tail call i8* @SnapshotV3_WriteDataToChunk(i8* %30, i8* %34, i32 64)
%36 = tail call i32 (...) @ASIC_GetPRI()
%37 = tail call i8* @SnapshotV3_WriteByte(i8* %35, i32 %36)
%38 = tail call i32 (...) @ASIC_GetSPLT()
%39 = tail call i8* @SnapshotV3_WriteByte(i8* %37, i32 %38)
%40 = tail call i32 (...) @ASIC_GetSSA()
%41 = tail call i8* @SnapshotV3_WriteWord(i8* %39, i32 %40)
%42 = tail call i32 (...) @ASIC_GetSSCR()
%43 = tail call i8* @SnapshotV3_WriteByte(i8* %41, i32 %42)
%44 = tail call i32 (...) @ASIC_GetIVR()
%45 = tail call i8* @SnapshotV3_WriteByte(i8* %43, i32 %44)
%46 = tail call i8* @SnapshotV3_WriteWord(i8* %45, i32 0)
%47 = tail call i32 @ASIC_GetAnalogueInput(i32 0)
%48 = tail call i8* @SnapshotV3_WriteByte(i8* %46, i32 %47)
%49 = tail call i32 @ASIC_GetAnalogueInput(i32 1)
%50 = tail call i8* @SnapshotV3_WriteByte(i8* %48, i32 %49)
%51 = tail call i32 @ASIC_GetAnalogueInput(i32 2)
%52 = tail call i8* @SnapshotV3_WriteByte(i8* %50, i32 %51)
%53 = tail call i32 @ASIC_GetAnalogueInput(i32 3)
%54 = tail call i8* @SnapshotV3_WriteByte(i8* %52, i32 %53)
%55 = tail call i32 @ASIC_GetAnalogueInput(i32 4)
%56 = tail call i8* @SnapshotV3_WriteByte(i8* %54, i32 %55)
%57 = tail call i32 @ASIC_GetAnalogueInput(i32 5)
%58 = tail call i8* @SnapshotV3_WriteByte(i8* %56, i32 %57)
%59 = tail call i32 @ASIC_GetAnalogueInput(i32 6)
%60 = tail call i8* @SnapshotV3_WriteByte(i8* %58, i32 %59)
%61 = tail call i32 @ASIC_GetAnalogueInput(i32 7)
%62 = tail call i8* @SnapshotV3_WriteByte(i8* %60, i32 %61)
%63 = tail call i32 @ASIC_DMA_GetChannelAddr(i32 0)
%64 = tail call i8* @SnapshotV3_WriteWord(i8* %62, i32 %63)
%65 = tail call i32 @ASIC_DMA_GetChannelPrescale(i32 0)
%66 = tail call i8* @SnapshotV3_WriteByte(i8* %64, i32 %65)
%67 = tail call i8* @SnapshotV3_WriteByte(i8* %66, i32 0)
%68 = tail call i32 @ASIC_DMA_GetChannelAddr(i32 1)
%69 = tail call i8* @SnapshotV3_WriteWord(i8* %67, i32 %68)
%70 = tail call i32 @ASIC_DMA_GetChannelPrescale(i32 1)
%71 = tail call i8* @SnapshotV3_WriteByte(i8* %69, i32 %70)
%72 = tail call i8* @SnapshotV3_WriteByte(i8* %71, i32 0)
%73 = tail call i32 @ASIC_DMA_GetChannelAddr(i32 2)
%74 = tail call i8* @SnapshotV3_WriteWord(i8* %72, i32 %73)
%75 = tail call i32 @ASIC_DMA_GetChannelPrescale(i32 2)
%76 = tail call i8* @SnapshotV3_WriteByte(i8* %74, i32 %75)
%77 = tail call i8* @SnapshotV3_WriteByte(i8* %76, i32 0)
%78 = tail call i8* @SnapshotV3_WriteWord(i8* %77, i32 0)
%79 = tail call i8* @SnapshotV3_WriteByte(i8* %78, i32 0)
%80 = tail call i32 (...) @ASIC_GetDCSR()
%81 = tail call i8* @SnapshotV3_WriteByte(i8* %79, i32 %80)
%82 = tail call i8* @SnapshotV3_WriteByte(i8* %81, i32 0)
%83 = tail call i8* @SnapshotV3_WriteByte(i8* %82, i32 0)
%84 = tail call i8* @SnapshotV3_WriteByte(i8* %83, i32 0)
%85 = tail call i8* @SnapshotV3_WriteByte(i8* %84, i32 0)
%86 = tail call i8* @SnapshotV3_WriteByte(i8* %85, i32 0)
%87 = tail call i8* @SnapshotV3_WriteByte(i8* %86, i32 0)
%88 = tail call i8* @SnapshotV3_WriteByte(i8* %87, i32 0)
%89 = tail call i8* @SnapshotV3_WriteByte(i8* %88, i32 0)
%90 = tail call i8* @SnapshotV3_WriteByte(i8* %89, i32 0)
%91 = tail call i8* @SnapshotV3_WriteByte(i8* %90, i32 0)
%92 = tail call i8* @SnapshotV3_WriteByte(i8* %91, i32 0)
%93 = tail call i8* @SnapshotV3_WriteByte(i8* %92, i32 0)
%94 = tail call i8* @SnapshotV3_WriteByte(i8* %93, i32 0)
%95 = tail call i8* @SnapshotV3_WriteByte(i8* %94, i32 0)
%96 = tail call i8* @SnapshotV3_WriteByte(i8* %95, i32 0)
%97 = tail call i8* @SnapshotV3_WriteByte(i8* %96, i32 0)
%98 = tail call i8* @SnapshotV3_WriteByte(i8* %97, i32 0)
%99 = tail call i8* @SnapshotV3_WriteByte(i8* %98, i32 0)
%100 = tail call i8* @SnapshotV3_WriteByte(i8* %99, i32 0)
%101 = tail call i8* @SnapshotV3_WriteByte(i8* %100, i32 0)
%102 = tail call i8* @SnapshotV3_WriteByte(i8* %101, i32 0)
%103 = tail call i32 (...) @ASIC_GetSecondaryRomMapping()
%104 = and i32 %103, 31
%105 = or i32 %104, 160
%106 = tail call i8* @SnapshotV3_WriteByte(i8* %102, i32 %105)
%107 = tail call i64 (...) @ASIC_GetUnLockState()
%108 = icmp ne i64 %107, 0
%109 = zext i1 %108 to i32
%110 = tail call i8* @SnapshotV3_WriteByte(i8* %106, i32 %109)
%111 = tail call i32 (...) @SnapshotV3_EndChunk()
ret i8* %110
}