LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/vianna274[P]dropbox/src/WrapperSocket.cpp
// Function: Dropbox::WrapperSocket::receive(int, int)
MessageData* WrapperSocket::receive(int timeout, int time) {
  if(timeout == TIMEOUT_ON) {
    struct pollfd fd;
    fd.fd = this->localSocketHandler;
    fd.events = POLLIN;
    int ret = poll(&fd, 1, time);
    switch(ret) {
      case -1: printf("Error\n");
        return NULL;
      case 0: 
        return NULL;
      default: break;
    }
  }

  char* msg = new char[PACKET_LEN];
  memset(msg, 0, PACKET_LEN);
  bool receivedCorrectly = false;
  MessageData * data;
  while(!receivedCorrectly) {

    int msgSize = recvfrom(this->localSocketHandler, (void *) msg, 
      PACKET_LEN, 0, (struct sockaddr *) &this->remoteSocketAddr, &this->remoteSocketLen);
    if (msgSize < 0) {
      fprintf(stderr, "Error on receiving\n");
      exit(1);
    }
    data = (MessageData *) msg;

    if (data->socketSeq == -1)
      break;
    if (data->socketSeq == 0)
      this->socketSeq = 0;
    if (data->socketSeq == this->socketSeq && data->type != TYPE_ACK) {
      MessageData message = make_packet(TYPE_ACK, data->seq, 1, -1, "");
      this->sendAck(&message);
      this->socketSeq = data->socketSeq + 1;
      receivedCorrectly = true;
    }
  }

  
  // TODO delete msg
  return data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xfd8, %rsp            # imm = 0xFD8
movq %rdi, %rbx
cmpl $0x1, %esi
jne 0xea0a
movl (%rbx), %eax
leaq -0xffc(%rbp), %rdi
movl %eax, (%rdi)
movw $0x1, 0x4(%rdi)
movl $0x1, %esi
callq 0x34a0
testl %eax, %eax
je 0xea02
cmpl $-0x1, %eax
jne 0xea0a
leaq 0x1c5f(%rip), %rdi      # 0x1065c
callq 0x34d0
xorl %r14d, %r14d
jmp 0xeaca
movl $0x1000, %edi           # imm = 0x1000
callq 0x3030
movq %rax, %r14
xorl %r13d, %r13d
movl $0x1000, %edx           # imm = 0x1000
movq %rax, %rdi
xorl %esi, %esi
callq 0x3230
leaq 0x20(%rbx), %r15
leaq 0x40(%rbx), %r12
testb $0x1, %r13b
jne 0xeaca
movl (%rbx), %edi
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
movq %r12, %r9
callq 0x3290
testl %eax, %eax
js 0xeadf
movl 0x10(%r14), %ecx
cmpl $-0x1, %ecx
je 0xeac0
testl %ecx, %ecx
jne 0xea6e
movl $0x0, 0x8(%rbx)
movb $0x1, %al
cmpl 0x8(%rbx), %ecx
jne 0xeac2
cmpl $0x1, (%r14)
je 0xeac2
movl 0x4(%r14), %edx
leaq -0xffc(%rbp), %r13
movq %r13, %rdi
movl $0x1, %esi
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
leaq 0x1b95(%rip), %r9       # 0x10635
callq 0x657c
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf03e
movl 0x10(%r14), %eax
incl %eax
movl %eax, 0x8(%rbx)
movb $0x1, %al
movb $0x1, %r13b
jmp 0xeac2
xorl %eax, %eax
testb %al, %al
jne 0xea31
movq %r14, %rax
addq $0xfd8, %rsp            # imm = 0xFD8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3783
// File: /workspace/github_cpp_makefile_star2_O1/vianna274[P]dropbox/src/WrapperSocket.cpp
// Function: Dropbox::WrapperSocket::send(Dropbox::_MessageData*)
int WrapperSocket::send(MessageData *packet) {
  set_socketSeq(packet, this->socketSeq);
  int tries = 0;
  do{

    if (sendto(this->localSocketHandler, (void *)packet, PACKET_LEN, 0,(const struct sockaddr *) &(this->remoteSocketAddr),sizeof(struct sockaddr_in)) < 0) {
      fprintf(stderr, "Error on sending");
      cout << string(packet->payload) << packet->type << " " << string(packet->username) << endl;
      return -1;
    }
  
  }while(!this->waitAck(packet->seq) && ++tries < TOTAL_TRIES);
  this->socketSeq++;
  
  if(tries == TOTAL_TRIES) return 0;
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x8(%rdi), %esi
movq %rbx, %rdi
callq 0x663e
leaq 0x20(%r14), %rax
movq %rax, -0x30(%rbp)
xorl %r12d, %r12d
movl (%r14), %edi
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rsi
xorl %ecx, %ecx
movq -0x30(%rbp), %r8
movl $0x10, %r9d
callq 0x3070
testq %rax, %rax
js 0xeb96
movl 0x4(%rbx), %r13d
movq %r14, %rdi
movl $0x1, %esi
callq 0xed22
testq %rax, %rax
je 0xeb5c
cmpl $0x1, (%rax)
jne 0xeb58
cmpl %r13d, 0x4(%rax)
jne 0xeb58
movb $0x1, %r15b
jmp 0xeb5f
movb $0x1, %al
jmp 0xeb61
xorl %r15d, %r15d
xorl %eax, %eax
testb %al, %al
jne 0xeb36
testb $0x1, %r15b
jne 0xeb7a
incl %r12d
cmpl $0x3, %r12d
jne 0xeb11
movl $0x3, %r12d
incl 0x8(%r14)
xorl %eax, %eax
cmpl $0x3, %r12d
setne %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x643b(%rip), %rax      # 0x14fd8
movq (%rax), %rcx
leaq 0x1a6a(%rip), %rdi      # 0x10611
movl $0x10, %esi
movl $0x1, %edx
callq 0x35d0
leaq 0x14(%rbx), %r14
leaq -0x60(%rbp), %r12
movq %r12, -0x10(%r12)
movq %r14, %rdi
callq 0x3170
leaq (%rbx,%rax), %rdx
addq $0x14, %rdx
leaq -0x70(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x62de
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x63e0(%rip), %rdi      # 0x14fd0
callq 0x33a0
movl (%rbx), %esi
movq %rax, %rdi
callq 0x3540
movq %rax, %r14
leaq 0x17fd(%rip), %rsi      # 0x10406
movl $0x1, %edx
movq %rax, %rdi
callq 0x33a0
leaq 0xfb4(%rbx), %r15
leaq -0x40(%rbp), %r13
movq %r13, -0x10(%r13)
movq %r15, %rdi
callq 0x3170
leaq (%rbx,%rax), %rdx
addq $0xfb4, %rdx            # imm = 0xFB4
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x62de
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %r14, %rdi
callq 0x33a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3330
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3260
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0xec8c
callq 0x3320
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0xec9a
callq 0x3320
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xeb87
jmp 0xeca6
movq %rax, %rbx
jmp 0xecbc
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0xecbc
callq 0x3320
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0xecca
callq 0x3320
movq %rbx, %rdi
callq 0x3580
// File: /workspace/github_cpp_makefile_star2_O1/vianna274[P]dropbox/src/WrapperSocket.cpp
// Function: Dropbox::WrapperSocket::waitAck(int)
bool WrapperSocket::waitAck(int seq) {
  bool acked = false;
  while(!acked) {
    MessageData *response = this->receive(TIMEOUT_ON);
    if(!response) {
      return false;
    } 
    if(response->type == TYPE_ACK && response->seq == seq) { 
      return true;
    }
  }
  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq %r14, %rdi
movl $0x1, %esi
callq 0xed22
testq %rax, %rax
je 0xed06
cmpl $0x1, (%rax)
jne 0xed02
cmpl %ebx, 0x4(%rax)
jne 0xed02
movb $0x1, %r15b
jmp 0xed09
movb $0x1, %al
jmp 0xed0b
xorl %r15d, %r15d
xorl %eax, %eax
testb %al, %al
jne 0xece1
andb $0x1, %r15b
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/vianna274[P]dropbox/src/WrapperSocket.cpp
// Function: Dropbox::WrapperSocket::receive(int)
MessageData* WrapperSocket::receive(int timeout) {
  if(timeout == TIMEOUT_ON) {
    struct pollfd fd;
    fd.fd = this->localSocketHandler;
    fd.events = POLLIN;
    int ret = poll(&fd, 1, 2000);
    switch(ret) {
      case -1:
        return NULL;
      case 0: printf("Timeout\n");
        return NULL;
      default: break;
    }
  }

  char* msg = new char[PACKET_LEN];
  memset(msg, 0, PACKET_LEN);
  bool receivedCorrectly = false;
  MessageData * data;
  while(!receivedCorrectly) {

    int msgSize = recvfrom(this->localSocketHandler, (void *) msg, 
      PACKET_LEN, 0, (struct sockaddr *) &this->remoteSocketAddr, &this->remoteSocketLen);
    if (msgSize < 0) {
      fprintf(stderr, "Error on receiving\n");
      exit(1);
    }

    data = (MessageData *) msg;

    if (data->type != TYPE_ACK && this->lastData != NULL && this->isEqual(this->lastData, data))
      continue;
    if (data->socketSeq == -1)
      break;
    if (data->socketSeq == 0)
      this->socketSeq = 0;
    if (data->socketSeq == this->socketSeq && data->type != TYPE_ACK) {
      MessageData message = make_packet(TYPE_ACK, data->seq, 1, -1, "");
      this->sendAck(&message);
      this->socketSeq = data->socketSeq + 1;
      break;
    }
  }

  this->lastData = data;
  // TODO delete msg
  return data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xfe0, %rsp            # imm = 0xFE0
movq %rdi, %rbx
cmpl $0x1, %esi
jne 0xed79
movl (%rbx), %eax
leaq -0xff4(%rbp), %rdi
movl %eax, (%rdi)
movw $0x1, 0x4(%rdi)
movl $0x1, %esi
movl $0x7d0, %edx            # imm = 0x7D0
callq 0x34a0
cmpl $-0x1, %eax
je 0xed71
testl %eax, %eax
jne 0xed79
leaq 0x18f6(%rip), %rdi      # 0x10662
callq 0x34d0
xorl %r14d, %r14d
jmp 0xee3a
movl $0x1000, %edi           # imm = 0x1000
callq 0x3030
movq %rax, %r14
movl $0x1000, %edx           # imm = 0x1000
movq %rax, %rdi
xorl %esi, %esi
callq 0x3230
leaq 0x20(%rbx), %r15
leaq 0x40(%rbx), %r12
movl (%rbx), %edi
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
movq %r12, %r9
callq 0x3290
testl %eax, %eax
js 0xee4d
cmpl $0x1, (%r14)
je 0xedd7
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
je 0xedd7
movq %r14, %rdx
callq 0xee52
testb %al, %al
jne 0xed9d
movl 0x10(%r14), %eax
testl %eax, %eax
je 0xede6
cmpl $-0x1, %eax
jne 0xeded
jmp 0xee36
movl $0x0, 0x8(%rbx)
cmpl 0x8(%rbx), %eax
jne 0xed9d
cmpl $0x1, (%r14)
je 0xed9d
movl 0x4(%r14), %edx
leaq 0x1832(%rip), %r9       # 0x10635
leaq -0xff4(%rbp), %r15
movq %r15, %rdi
movl $0x1, %esi
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x657c
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf03e
movl 0x10(%r14), %eax
incl %eax
movl %eax, 0x8(%rbx)
movq %r14, 0x10(%rbx)
movq %r14, %rax
addq $0xfe0, %rsp            # imm = 0xFE0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x37ab
// File: /workspace/github_cpp_makefile_star2_O1/vianna274[P]dropbox/src/WrapperSocket.cpp
// Function: Dropbox::WrapperSocket::isEqual(Dropbox::_MessageData*, Dropbox::_MessageData*)
bool WrapperSocket::isEqual(MessageData * a, MessageData * b) {
  if (a->type != b->type || a->seq != b->seq || a->totalSize != b->totalSize)
    return false;
  if (a->len != b->len || a->socketSeq != b->socketSeq)
    return false;
  if (string(a->payload).compare(string(b->payload)) != 0)
    return false;
  if (string(a->username).compare(string(b->username)) != 0)
    return false;
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl (%rsi), %eax
cmpl (%rdx), %eax
jne 0xefed
movq %rdx, %rbx
movq %rsi, %r14
movl 0x4(%rsi), %eax
cmpl 0x4(%rdx), %eax
jne 0xefed
movl 0x8(%r14), %eax
cmpl 0x8(%rbx), %eax
jne 0xefed
movl 0xc(%r14), %eax
cmpl 0xc(%rbx), %eax
jne 0xefed
movl 0x10(%r14), %eax
cmpl 0x10(%rbx), %eax
jne 0xefed
leaq 0x14(%r14), %r15
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, %rdi
callq 0x3170
leaq (%r14,%rax), %rdx
addq $0x14, %rdx
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
callq 0x62de
leaq 0x14(%rbx), %r15
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, %rdi
callq 0x3170
leaq (%rbx,%rax), %rdx
addq $0x14, %rdx
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x62de
movq -0x60(%rbp), %r12
movq -0x40(%rbp), %r13
cmpq %r12, %r13
movq %r12, %rdx
cmovbq %r13, %rdx
testq %rdx, %rdx
je 0xef22
movq -0x48(%rbp), %rsi
movq -0x68(%rbp), %rdi
callq 0x3350
testl %eax, %eax
sete %r15b
jmp 0xef25
movb $0x1, %r15b
cmpq %r13, %r12
sete %r12b
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xef3e
callq 0x3320
andb %r12b, %r15b
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %r13
cmpq %r13, %rdi
je 0xef53
callq 0x3320
testb %r15b, %r15b
je 0xefed
leaq 0xfb4(%r14), %r15
leaq -0x68(%rbp), %r12
movq %r13, (%r12)
movq %r15, %rdi
callq 0x3170
leaq (%r14,%rax), %rdx
addq $0xfb4, %rdx            # imm = 0xFB4
movq %r12, %rdi
movq %r15, %rsi
callq 0x62de
leaq 0xfb4(%rbx), %r14
leaq -0x48(%rbp), %r15
leaq -0x38(%rbp), %rax
movq %rax, (%r15)
movq %r14, %rdi
callq 0x3170
leaq (%rbx,%rax), %rdx
addq $0xfb4, %rdx            # imm = 0xFB4
movq %r15, %rdi
movq %r14, %rsi
callq 0x62de
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3050
testl %eax, %eax
sete %bl
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xefdd
callq 0x3320
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0xefef
callq 0x3320
jmp 0xefef
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xf01e
callq 0x3320
jmp 0xf01e
jmp 0xf01b
jmp 0xf032
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xf035
callq 0x3320
jmp 0xf035
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3580
nop
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: SetHWPalette(SDL_Palette*)
int SetHWPalette(SDL_Palette* dstpal)
{
	SDL_Color d[256];
	for (int j = 0; j < 256; ++j)
	{
		d[j].a = 255;
		int i = ((j & 0x8) >> 2 | (j & 0x80) >> 7) * 0x11;
		d[j].r = ((j & 0x4) >> 1 | (j & 0x40) >> 6) * 0x44 | i;
		d[j].g = ((j & 0x2) | (j & 0x20) >> 5) * 0x44 | i;
		d[j].b = ((j & 0x1) << 1 | (j & 0x10) >> 4) * 0x44 | i;
	}
	return SDL_SetPaletteColors(dstpal, d, 0, 256);
}

// Assembly:
subq $0x408, %rsp            # imm = 0x408
xorl %eax, %eax
xorl %ecx, %ecx
movb $-0x1, 0x3(%rsp,%rcx,4)
movl %ecx, %edx
shrl $0x2, %edx
andl $0x2, %edx
movl %ecx, %esi
shrl $0x7, %esi
orl %edx, %esi
movl %esi, %edx
shll $0x4, %edx
addl %esi, %edx
movl %ecx, %esi
shrl %esi
andl $0x2, %esi
movl %ecx, %r8d
shrl $0x6, %r8d
andl $0x1, %r8d
orl %esi, %r8d
movl %r8d, %esi
shll $0x6, %esi
leal (%rsi,%r8,4), %esi
orl %edx, %esi
movb %sil, (%rsp,%rcx,4)
movl %ecx, %esi
andl $0x2, %esi
movl %ecx, %r8d
shrl $0x5, %r8d
andl $0x1, %r8d
orl %esi, %r8d
movl %r8d, %esi
shll $0x6, %esi
leal (%rsi,%r8,4), %esi
orl %edx, %esi
movb %sil, 0x1(%rsp,%rcx,4)
movl %eax, %esi
andl $0x2, %esi
movl %ecx, %r8d
shrl $0x4, %r8d
andl $0x1, %r8d
orl %esi, %r8d
movl %r8d, %esi
shll $0x6, %esi
leal (%rsi,%r8,4), %esi
orl %edx, %esi
movb %sil, 0x2(%rsp,%rcx,4)
incq %rcx
addl $0x2, %eax
cmpq $0x100, %rcx            # imm = 0x100
jne 0x7339
movq %rsp, %rsi
xorl %edx, %edx
movl $0x100, %ecx            # imm = 0x100
callq 0x61c0
addq $0x408, %rsp            # imm = 0x408
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: TextWidth(char const*)
int TextWidth(const char* text)
{
	int w = 0;
	while (*text)
	{
		w += hifont[(unsigned char)*text].w;
		++text;
	}
	return w;
}

// Assembly:
movb (%rdi), %dl
testb %dl, %dl
je 0x76a1
incq %rdi
xorl %eax, %eax
leaq 0xca2b(%rip), %rcx      # 0x140b0
movzbl %dl, %edx
movl %edx, %esi
shll $0x5, %esi
leaq (%rsi,%rdx,2), %rdx
movzbl (%rcx,%rdx), %edx
addl %edx, %eax
movb (%rdi), %dl
incq %rdi
testb %dl, %dl
jne 0x7685
retq
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: DrawText(char const*, int&, int, unsigned char, unsigned char, SDL_Surface*)
void DrawText(const char* text, int &x, const int y0, unsigned char fg, unsigned char bg, SDL_Surface* destsurf)
{
	if (destsurf == nullptr)
		return;
	if (destsurf->pixels == nullptr)
		return;
	if (y0 >= destsurf->h)
		return;
	unsigned char c[2] = { bg, fg };
	int mingy = -y0;
	if (mingy < 0)
		mingy = 0;
	int maxgy = destsurf->h - y0;
	if (maxgy > 16)
		maxgy = 16;
	while (*text)
	{
		int gw = hifont[(unsigned char)*text].w;
		unsigned short gbits[16];
		for (unsigned short* src = (unsigned short*)hifont[(unsigned char)*text].bmp, * dst = gbits; src < hifont[(unsigned char)*text].bmp + 16; ++src, ++dst)
			*dst = *src;
		unsigned char* rowstart = (unsigned char*)destsurf->pixels + (long long)destsurf->pitch * y0 + x;
		int mingx = -x;
		int maxgx = destsurf->w - x;
		if (mingx < gw)
		{
			for (int gy = mingy; gy < maxgy; ++gy)
			{
				for (int gx = 0; gx < gw; ++gx)
				{
					if (gx >= mingx && gx < maxgx)
						rowstart[gx] = c[gbits[gy] & 1];
					gbits[gy] >>= 1;
				}
				rowstart += destsurf->pitch;
			}
		}
		if (maxgx <= 0)
			break;
		x += gw;
		++text;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, -0x38(%rsp)
testq %r9, %r9
je 0x780f
cmpq $0x0, 0x20(%r9)
je 0x780f
movl 0x14(%r9), %r10d
subl %edx, %r10d
jle 0x780f
movb %r8b, -0x3a(%rsp)
movb %cl, -0x39(%rsp)
movslq %edx, %rax
movq %rax, -0x30(%rsp)
negl %edx
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
cmpl $0x10, %r10d
movl $0x10, %ecx
cmovll %r10d, %ecx
leaq 0xc9ae(%rip), %rsi      # 0x140b0
movzbl (%rdi), %r11d
testq %r11, %r11
je 0x780f
movzbl (%rdi), %r10d
movl %r10d, %ebx
shll $0x5, %ebx
leaq (%rbx,%r10,2), %rbx
leaq (%rsi,%rbx), %r10
addq $0x2, %r10
addq %rsi, %rbx
addq $0x22, %rbx
cmpq %rbx, %r10
jae 0x7760
leaq -0x28(%rsp), %rbx
movzwl (%r10), %ebp
movw %bp, (%rbx)
addq $0x2, %r10
addq $0x2, %rbx
movzbl (%rdi), %r14d
movl %r14d, %r15d
shll $0x5, %r15d
leaq (%r15,%r14,2), %r14
addq %rsi, %r14
addq $0x22, %r14
cmpq %r14, %r10
jb 0x7736
movl %r11d, %r10d
shll $0x5, %r10d
leaq (%r10,%r11,2), %r10
movzbl (%rsi,%r10), %ebx
movq -0x38(%rsp), %rax
movslq (%rax), %r10
movq %r10, %r14
negq %r14
movslq 0x10(%r9), %r11
subq %r10, %r11
cmpl %ebx, %r14d
jge 0x77f7
cmpl %ecx, %edx
jge 0x77f7
movslq 0x18(%r9), %r15
imulq -0x30(%rsp), %r15
addq 0x20(%r9), %r15
addq %r10, %r15
movl %ebx, %r12d
movq %rdx, %r13
testl %ebx, %ebx
je 0x77e8
movzwl -0x28(%rsp,%r13,2), %ebp
xorl %r10d, %r10d
cmpq %r14, %r10
setge %al
cmpq %r11, %r10
setl %r8b
andb %al, %r8b
movzwl %bp, %ebp
cmpb $0x1, %r8b
jne 0x77d8
movl %ebp, %eax
andl $0x1, %eax
movb -0x3a(%rsp,%rax), %al
movb %al, (%r15,%r10)
shrl %ebp
incq %r10
cmpq %r10, %r12
jne 0x77b2
movw %bp, -0x28(%rsp,%r13,2)
movslq 0x18(%r9), %r10
addq %r10, %r15
incq %r13
cmpq %rcx, %r13
jne 0x77a5
testl %r11d, %r11d
jle 0x7806
movq -0x38(%rsp), %rax
addl %ebx, (%rax)
incq %rdi
testl %r11d, %r11d
jg 0x7702
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: DrawLogo(int, int, SDL_Surface*)
void DrawLogo(int x0, int y0, SDL_Surface* destsurf) {
	char* sptr = (char*)aboutlogopixels;
	char* rptr = (char*)(destsurf->pixels) + y0 * (long long)destsurf->pitch + x0;
	for (int y = 0; y < 27; ++y)
	{
		char* dptr = rptr;
		for (int x = 0; x < 29; ++x)
		{
			*dptr++ = *sptr++;
		}
		rptr += destsurf->pitch;
	}
}

// Assembly:
movslq %esi, %rax
movslq 0x18(%rdx), %rcx
imulq %rax, %rcx
addq 0x20(%rdx), %rcx
movslq %edi, %rax
addq %rcx, %rax
leaq 0xbc0a(%rip), %rcx      # 0x13440
xorl %esi, %esi
xorl %edi, %edi
movb (%rcx,%rdi), %r8b
movb %r8b, (%rax,%rdi)
incq %rdi
cmpq $0x1d, %rdi
jne 0x783a
movslq 0x18(%rdx), %r8
addq %r8, %rax
incl %esi
addq %rdi, %rcx
cmpl $0x1b, %esi
jne 0x7838
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: LogStack(unsigned char)
dlogentry* ExtendLog(dletype etype)
{
	if (debuglogend == debuglogstart)
	{
		++debuglogstart;
		debuglogstart &= dlogidxmask;
	}
	debuglog[debuglogstart].entrytype = dletype::LT_START;
	debuglog[debuglogend].entrytype = etype;
	dlogentry* newentry = debuglog + debuglogend;
	++debuglogend;
	debuglogend &= dlogidxmask;
	return newentry;
}

// Assembly:
movslq 0xfac7(%rip), %rcx      # 0x1c2f8
movl 0x80fff9(%rip), %eax    # 0x81c830
cmpl %eax, %ecx
jne 0xc848
incl %eax
andl $0x7ffff, %eax          # imm = 0x7FFFF
movl %eax, 0x80ffe8(%rip)    # 0x81c830
movl %ecx, %edx
movslq 0x80ffdf(%rip), %rsi    # 0x81c830
shlq $0x4, %rsi
leaq 0xffd4(%rip), %rax      # 0x1c830
movb $0x0, (%rsi,%rax)
shlq $0x4, %rcx
movb $0x8, (%rcx,%rax)
incl %edx
andl $0x7ffff, %edx          # imm = 0x7FFFF
movl %edx, 0xfa82(%rip)      # 0x1c2f8
cmpb $0x0, 0xfe44(%rip)      # 0x1c6c1
jne 0xc8be
addq %rcx, %rax
movzbl %dil, %ecx
incl %ecx
movq 0xfbd1(%rip), %rdx      # 0x1c460
xorl %esi, %esi
movl %ecx, %r8d
orq $0x100, %r8             # imm = 0x100
movb (%rdx,%r8), %r8b
movb %r8b, 0x5(%rax,%rsi)
incq %rsi
incl %ecx
movzbl %cl, %ecx
cmpq $0x7, %rsi
jne 0xc891
movb 0x80ff80(%rip), %cl     # 0x81c838
subb %dil, %cl
movb %cl, 0x4(%rax)
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: StepSoundSchedules()
void StepSoundSchedules()
{
	bool shiftregister[4]{ false, false, false, false };
	bool scheduleisempty[2]{ false, false };
	for (int s = 0; s < 2; ++s)
	{
		if (!soundcndcounter[s])
		{
			for (int v = 0; v < 4; ++v)
			{
				if (soundscvmapregister & (1 << (4 * s + v)))
				{
					soundvolregister[v] = soundqueue[v][0].vol;
					soundfreqregister[v] = soundqueue[v][0].freq;
					soundcndcounter[s] = soundqueuedur[s][0];
					shiftregister[v] = true;
				}
			}
			for (int i = 0; i < 15; ++i)
				soundqueuedur[s][i] = soundqueuedur[s][i + 1];
			soundqueuedur[s][15] = 0xffff;
			++soundncounter[s];
			if (!soundncounter[s])
				scheduleisempty[s] = true;
		}
		--soundcndcounter[s];
	}
	for (int v = 0; v < 4; ++v)
	{
		if (shiftregister[v])
		{
			for (int i = 0; i < 15; ++i)
				soundqueue[v][i] = soundqueue[v][i + 1];
			soundqueue[v][15] = { 0, 0 };
		}
	}
	if (scheduleisempty[0] || scheduleisempty[1])
		; // TODO: trigger interrupt if appropriate flag (?) is set
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl $0x0, -0x4(%rsp)
movzbl 0x1139f(%rip), %eax     # 0x1c6d5
leaq 0x113a3(%rip), %rcx     # 0x1c6e0
xorl %edx, %edx
leaq 0x114da(%rip), %rsi     # 0x1c820
leaq 0x113d5(%rip), %r8      # 0x1c722
leaq 0x114d0(%rip), %r9      # 0x1c824
leaq 0x11375(%rip), %r10     # 0x1c6d0
movq %rcx, %r11
xorl %ebx, %ebx
cmpw $0x0, (%rsi,%rbx,2)
jne 0xb3de
movq %rbx, %r14
shlq $0x5, %r14
leaq (%rcx,%r14), %r15
movq %r8, %r12
leaq 0x1134c(%rip), %r13     # 0x1c6c8
xorl %ebp, %ebp
leal (%rdx,%rbp), %edi
btl %edi, %eax
jae 0xb3a7
movb -0x2(%r12), %dil
movb %dil, (%rbp,%r10)
movzwl (%r12), %edi
movw %di, (%r13)
movzwl (%r15), %edi
movw %di, (%rsi,%rbx,2)
movb $0x1, -0x4(%rsp,%rbp)
incq %rbp
addq $0x2, %r13
addq $0x40, %r12
cmpq $0x4, %rbp
jne 0xb37e
movl $0x1, %r15d
movzwl (%r11,%r15,2), %edi
movw %di, -0x2(%r11,%r15,2)
incq %r15
cmpq $0x10, %r15
jne 0xb3be
movw $0xffff, 0x1e(%r14,%rcx) # imm = 0xFFFF
incb (%rbx,%r9)
decw (%rsi,%rbx,2)
leaq 0x1(%rbx), %rdi
addq $0x4, %rdx
addq $0x20, %r11
testq %rbx, %rbx
movq %rdi, %rbx
je 0xb360
leaq 0x1131f(%rip), %rax     # 0x1c720
xorl %ecx, %ecx
movq %rax, %rdx
cmpb $0x1, -0x4(%rsp,%rcx)
jne 0xb435
movl $0x1, %esi
movl (%rdx,%rsi,4), %edi
movl %edi, -0x4(%rdx,%rsi,4)
incq %rsi
cmpq $0x10, %rsi
jne 0xb412
movq %rcx, %rsi
shlq $0x6, %rsi
movb $0x0, 0x3c(%rsi,%rax)
movw $0x0, 0x3e(%rsi,%rax)
incq %rcx
addq $0x40, %rdx
cmpq $0x4, %rcx
jne 0xb406
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: InitMemory()
int InitMemory()
{
	sysram = new unsigned char[0x10000];
	syspflags = new pageflags[0x100];
	if (!sysram || !syspflags)
	{
		SDL_Log("Could not allocate system address space");
		return -1;
	}
	for (int p = 0x00; p < 0x20; ++p)
		syspflags[p] = pageflags::PF_TRAM;
	{ // Initialize the builtin RAM with deterministic random data
		std::mt19937 gen(1); //TODO: seed with a hash of machine identifying info
		std::uniform_int_distribution<> dis(0x00, 0xFF);
		for (int a = 0x0000; a < 0x2000; ++a)
			sysram[a] = dis(gen);
	}
	for (int p = 0x20; p < 0x100; ++p)
		syspflags[p] = pageflags::PF_TFLOATING;
	syspflags[0x02] = pageflags::PF_INONLY;
	syspflags[0x03] = pageflags::PF_OUTONLY;
	floatgen.seed(seedgen());
	//InitVideoMem(); // no cheating!
	InstallROM();
	for (int p = 0xf0; p < 0x100; ++p)
		syspflags[p] = syspflags[p] | pageflags::PF_DONTLOG;
	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x1390, %rsp           # imm = 0x1390
movl $0x10000, %edi          # imm = 0x10000
callq 0x6040
movq %rax, 0x107bd(%rip)     # 0x1c460
movl $0x100, %edi            # imm = 0x100
callq 0x6040
movq %rax, 0x107b4(%rip)     # 0x1c468
movaps 0xa835(%rip), %xmm0     # 0x164f0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq $0x1, 0x8(%rsp)
movl $0x1, %eax
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, 0x8(%rsp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0xbcd5
leaq 0x8(%rsp), %rbx
movq $0x270, 0x1380(%rbx) # imm = 0x270
movabsq $0xff00000000, %rax     # imm = 0xFF00000000
movq %rsp, %r14
movq %rax, (%r14)
xorl %r15d, %r15d
movq %r14, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x10dde
movq 0x10731(%rip), %rcx     # 0x1c460
movb %al, (%rcx,%r15)
incq %r15
cmpq $0x2000, %r15           # imm = 0x2000
jne 0xbd1a
movq 0x10722(%rip), %rbx     # 0x1c468
leaq 0x20(%rbx), %rdi
movl $0xe0, %edx
xorl %esi, %esi
callq 0x61e0
movw $0xa09, 0x2(%rbx)       # imm = 0xA09
leaq 0x810aed(%rip), %rdi    # 0x81c850
callq 0x6480
movl %eax, %eax
movq %rax, 0x811e67(%rip)    # 0x81dbd8
movl $0x1, %ecx
leaq 0x811e5b(%rip), %rdx    # 0x81dbd8
movq %rax, %rsi
shrq $0x1e, %rsi
xorl %eax, %esi
imull $0x6c078965, %esi, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, (%rdx,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0xbd7d
movq $0x270, 0x8131af(%rip) # imm = 0x270
callq 0xbdd7
xorl %eax, %eax
movq 0x106b1(%rip), %rcx     # 0x1c468
orb $-0x80, 0xf0(%rcx,%rax)
incq %rax
cmpq $0x10, %rax
jne 0xbdb7
xorl %eax, %eax
addq $0x1390, %rsp           # imm = 0x1390
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: InitSound()
int InitSound()
{
	SDL_AudioSpec desiredsoundspec;
	SDL_memset(&desiredsoundspec, 0, sizeof(desiredsoundspec));
	desiredsoundspec.freq = 44100;
	desiredsoundspec.format = AUDIO_U8;
	desiredsoundspec.channels = 2;
	desiredsoundspec.samples = 512;
	desiredsoundspec.callback = GenerateStereoAudio;
	sounddev = SDL_OpenAudioDevice(NULL, false, &desiredsoundspec, &soundspec, 0);
	if (!sounddev)
	{
		SDL_Log("Could not open sound device");
	}
	SDL_PauseAudioDevice(sounddev, 0);
	return 0;
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
movq %rsp, %rbx
movl $0x20, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6180
movl $0xac44, (%rbx)         # imm = 0xAC44
movw $0x8, 0x4(%rbx)
movb $0x2, 0x6(%rbx)
movw $0x200, 0x8(%rbx)       # imm = 0x200
leaq -0x16a8(%rip), %rax     # 0xadf8
movq %rax, 0x10(%rbx)
leaq 0x813e55(%rip), %rcx    # 0x820300
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x63f0
movl %eax, 0x813e60(%rip)    # 0x820320
testl %eax, %eax
jne 0xc4d2
leaq 0xa574(%rip), %rdi      # 0x16a3f
xorl %eax, %eax
callq 0x6470
movl 0x813e48(%rip), %edi    # 0x820320
xorl %esi, %esi
callq 0x6440
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: LogScanline(int)
void LogScanline(int scanline)
{
	if (debuglog[(debuglogend - 1) & dlogidxmask].entrytype == dletype::LT_SCANLINE)
	{
		debuglog[(debuglogend - 1) & dlogidxmask].scanline = scanline;
		return;
	}
	ExtendLog(dletype::LT_SCANLINE)->scanline = scanline;
}

// Assembly:
movslq 0xfb3a(%rip), %rcx      # 0x1c2f8
leal -0x1(%rcx), %edx
andl $0x7ffff, %edx          # imm = 0x7FFFF
shll $0x4, %edx
leaq 0x1005f(%rip), %rax     # 0x1c830
cmpb $0x9, (%rdx,%rax)
jne 0xc7e0
addq %rdx, %rax
addq $0x4, %rax
jmp 0xc827
movl 0x81004a(%rip), %edx    # 0x81c830
cmpl %edx, %ecx
jne 0xc7f8
incl %edx
andl $0x7ffff, %edx          # imm = 0x7FFFF
movl %edx, 0x810038(%rip)    # 0x81c830
movslq 0x810031(%rip), %rdx    # 0x81c830
shlq $0x4, %rdx
movb $0x0, (%rdx,%rax)
movq %rcx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
addq $0x4, %rax
movb $0x9, -0x4(%rax)
incl %ecx
andl $0x7ffff, %ecx          # imm = 0x7FFFF
movl %ecx, 0xfad1(%rip)      # 0x1c2f8
movl %edi, (%rax)
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: LogWrite(unsigned short, unsigned char)
void LogWrite(uint16_t address, uint8_t value)
{
	dlogentry* last = debuglog + ((debuglogend - 1) & dlogidxmask);
	if (suppresslogging && ((bool)(syspflags[address >> 8] & pageflags::PF_IO)
		|| ((syspflags[address >> 8] & pageflags::PF_TMASK) == pageflags::PF_TFLOATING)))
		return;
	if (last->entrytype == dletype::LT_PARTIALINST)
		last->entrytype = dletype::LT_INST;
	dlogentry* newentry = ExtendLog(dletype::LT_WRITE);
	newentry->mementry.address = address;
	newentry->mementry.value = value;
	newentry->mementry.memtype = syspflags[address >> 8];
}

// Assembly:
movslq 0xfa32(%rip), %rcx      # 0x1c2f8
cmpb $0x1, 0xfdf4(%rip)      # 0x1c6c1
movzwl %di, %eax
jne 0xc8f6
movq 0xfb8f(%rip), %rdx      # 0x1c468
movl %eax, %edi
shrl $0x8, %edi
movb (%rdx,%rdi), %dl
movl %edx, %edi
andb $0x8, %dil
shrb $0x3, %dil
testb $0x3, %dl
sete %dl
orb %dil, %dl
jne 0xc96f
leal -0x1(%rcx), %edi
andl $0x7ffff, %edi          # imm = 0x7FFFF
shll $0x4, %edi
leaq 0xff27(%rip), %rdx      # 0x1c830
addq %rdx, %rdi
cmpb $0x6, (%rdi)
jne 0xc914
movb $0x7, (%rdi)
movl 0x80ff16(%rip), %edi    # 0x81c830
cmpl %edi, %ecx
jne 0xc92c
incl %edi
andl $0x7ffff, %edi          # imm = 0x7FFFF
movl %edi, 0x80ff04(%rip)    # 0x81c830
movslq 0x80fefd(%rip), %rdi    # 0x81c830
shlq $0x4, %rdi
movb $0x0, (%rdi,%rdx)
movq %rcx, %rdi
shlq $0x4, %rdi
movb $0x3, (%rdi,%rdx)
incl %ecx
andl $0x7ffff, %ecx          # imm = 0x7FFFF
movl %ecx, 0xf9a4(%rip)      # 0x1c2f8
movw %ax, 0x4(%rdi,%rdx)
movb %sil, 0x6(%rdi,%rdx)
movq 0xfb03(%rip), %rcx      # 0x1c468
shrl $0x8, %eax
movb (%rcx,%rax), %al
movb %al, 0x7(%rdi,%rdx)
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: RandomBitFlip()
void RandomBitFlip()
{
	static std::mt19937 gen(0);
	static std::uniform_int_distribution<> dis(0x0800, 0x1FFF);
	if (dis(gen) & 0xf)
		return;
	int addr = dis(gen);
	int bit = dis(gen) & 7;
	write6502(addr, sysram[addr] ^ (1 << bit));
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movb 0x814a36(%rip), %al     # 0x821740
testb %al, %al
je 0xcd8a
movb 0x814a3c(%rip), %al     # 0x821750
testb %al, %al
je 0xcd94
leaq 0x813699(%rip), %rsi    # 0x8203b8
leaq 0x814a22(%rip), %rdi    # 0x821748
movq %rdi, %rdx
callq 0x10dde
testb $0xf, %al
je 0xcd37
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x81367a(%rip), %rbx    # 0x8203b8
leaq 0x814a03(%rip), %r14    # 0x821748
movq %r14, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x10dde
movl %eax, %ebp
movq %r14, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x10dde
andb $0x7, %al
movl $0x1, %edx
movl %eax, %ecx
shll %cl, %edx
movq 0xf6eb(%rip), %rax      # 0x1c460
movslq %ebp, %rcx
xorb (%rax,%rcx), %dl
movzbl %dl, %esi
movzwl %cx, %edi
popq %rbx
popq %r14
popq %rbp
jmp 0xcd9e
callq 0x66e4
jmp 0xcd0e
callq 0x6743
jmp 0xcd18
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: RenderScanline(int, SDL_Surface*, SDL_Surface*)
void RenderScanline(int scanline, SDL_Surface* framebuffer, SDL_Surface* winsurface)
{
	if (!scanlinedirty[scanline])
		return;
	int y0 = scanline * winsurface->h / 576;
	int y1 = (scanline + 1) * winsurface->h / 576;
	unsigned char* src = (unsigned char*)(framebuffer->pixels) + (long long)framebuffer->pitch * y0;
	unsigned char* dst = (unsigned char*)(winsurface->pixels) + (long long)winsurface->pitch * y0;
	//pitch is assumed same for both surfaces
	unsigned char* stop = (unsigned char*)(framebuffer->pixels) + (long long)framebuffer->pitch * y1;
	while (src < stop)
	{
		*dst = *src;
		++src;
		++dst;
	}
	scanlinedirty[scanline] = false;
}

// Assembly:
movslq %edi, %rax
leaq 0xe140(%rip), %rcx      # 0x1c480
cmpb $0x1, (%rax,%rcx)
jne 0xe3cc
movl 0x14(%rdx), %r8d
movl %r8d, %r9d
imull %edi, %r9d
movslq %r9d, %r9
imulq $0x38e38e39, %r9, %r9   # imm = 0x38E38E39
movq %r9, %r10
shrq $0x3f, %r10
sarq $0x27, %r9
addl %r10d, %r9d
incl %edi
imull %r8d, %edi
movslq %edi, %rdi
imulq $0x38e38e39, %rdi, %rdi # imm = 0x38E38E39
movq %rdi, %r8
shrq $0x3f, %r8
sarq $0x27, %rdi
addl %r8d, %edi
movslq 0x18(%rsi), %r8
movslq %r9d, %r9
movslq %edi, %rdi
imulq %r8, %rdi
imulq %r9, %r8
cmpq %rdi, %r8
jge 0xe3c8
movq 0x20(%rsi), %r10
addq %r10, %rdi
movslq 0x18(%rdx), %rsi
imulq %r9, %rsi
addq 0x20(%rdx), %rsi
addq %r10, %r8
movb (%r8), %dl
movb %dl, (%rsi)
incq %r8
incq %rsi
cmpq %rdi, %r8
jb 0xe3b8
movb $0x0, (%rax,%rcx)
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: PaintCell(unsigned char, unsigned char)
inline void PaintCell(unsigned char col, unsigned char row)
{
	unsigned char glyph = sysram[0x0800 | row << 5 | col];
	unsigned char att[4];
	unsigned char tatt[5];
	tatt[0] = sysram[0x0A40 + ((row & 0x1e) << 4) + col] >> (4 * (row & 0x1));
	tatt[1] = sysram[0x0B60 + ((row & 0x1e) << 4) + col] >> (4 * (row & 0x1));
	tatt[2] = sysram[0x0C80 + ((row & 0x1e) << 4) + col] >> (4 * (row & 0x1));
	tatt[3] = sysram[0x0DA0 + ((row & 0x1e) << 4) + col] >> (4 * (row & 0x1));
	tatt[4] = sysram[0x0EC0 + ((row & 0x1e) << 4) + col] >> (4 * (row & 0x1));
	att[0] = (tatt[0] & 0x1) | (tatt[1] & 0x1) << 1 | (tatt[2] & 0x1) << 2 | (tatt[3] & 0x1) << 3 | (tatt[4] & 0x1) << 4;
	att[1] = (tatt[0] & 0x2) >> 1 | (tatt[1] & 0x2) | (tatt[2] & 0x2) << 1 | (tatt[3] & 0x2) << 2 | (tatt[4] & 0x2) << 3;
	att[2] = (tatt[0] & 0x4) >> 2 | (tatt[1] & 0x4) >> 1 | (tatt[2] & 0x4) | (tatt[3] & 0x4) << 1 | (tatt[4] & 0x4) << 2;
	att[3] = (tatt[0] & 0x8) >> 3 | (tatt[1] & 0x8) >> 2 | (tatt[2] & 0x8) >> 1 | (tatt[3] & 0x8) | (tatt[4] & 0x8) << 1;
	PaintCell(col, row, glyph, att);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq 0xd71d(%rip), %rdx      # 0x1c460
movl %esi, %eax
andl $0x1e, %eax
shll $0x4, %eax
movl %edi, %r11d
addq %rax, %r11
movzbl 0xa40(%rdx,%r11), %eax
leal (,%rsi,4), %ecx
andb $0x4, %cl
shrl %cl, %eax
movl %esi, %ebx
shll $0x5, %ebx
movzbl 0xb60(%rdx,%r11), %r8d
shrl %cl, %r8d
movzbl 0xc80(%rdx,%r11), %r9d
shrl %cl, %r9d
orl %edi, %ebx
orq $0x800, %rbx            # imm = 0x800
movzbl 0xda0(%rdx,%r11), %r10d
shrl %cl, %r10d
movzbl 0xec0(%rdx,%r11), %r11d
shrl %cl, %r11d
movzbl (%rdx,%rbx), %edx
movl %eax, %ecx
andl $0x1, %ecx
movl %r8d, %ebx
andl $0x1, %ebx
leal (%rcx,%rbx,2), %ecx
movl %r9d, %ebx
andl $0x1, %ebx
leal (%rcx,%rbx,4), %ecx
movl %r10d, %ebx
andl $0x1, %ebx
leal (%rcx,%rbx,8), %ecx
movl %r11d, %ebx
shll $0x4, %ebx
andl $0x10, %ebx
orl %ecx, %ebx
leaq 0xc(%rsp), %rcx
movb %bl, (%rcx)
movl %eax, %ebx
shrl %ebx
andl $0x1, %ebx
movl %r8d, %r14d
andl $0x2, %r14d
orl %ebx, %r14d
movl %r9d, %ebx
andl $0x2, %ebx
leal (%r14,%rbx,2), %ebx
movl %r10d, %r14d
andl $0x2, %r14d
leal (%rbx,%r14,4), %ebx
movl %r11d, %r14d
andl $0x2, %r14d
leal (%rbx,%r14,8), %ebx
movb %bl, 0x1(%rcx)
movl %eax, %ebx
shrl $0x2, %ebx
andl $0x1, %ebx
movl %r8d, %ebp
shrl %ebp
andl $0x2, %ebp
orl %ebx, %ebp
movl %r9d, %ebx
andl $0x4, %ebx
orl %ebp, %ebx
movl %r10d, %r14d
andl $0x4, %r14d
leal (%rbx,%r14,2), %ebx
movl %r11d, %r14d
andl $0x4, %r14d
leal (%rbx,%r14,4), %ebx
movb %bl, 0x2(%rcx)
shrl $0x3, %eax
andl $0x1, %eax
shrl $0x2, %r8d
andl $0x2, %r8d
orl %eax, %r8d
shrl %r9d
andl $0x4, %r9d
orl %r8d, %r9d
andl $0x8, %r10d
orl %r9d, %r10d
andl $0x8, %r11d
leal (%r10,%r11,2), %eax
movb %al, 0x3(%rcx)
callq 0xc970
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: pull16
uint16_t pull16() {
    uint16_t temp16;
    temp16 = read6502(BASE_STACK + ((sp + 1) & 0xFF)) | ((uint16_t)read6502(BASE_STACK + ((sp + 2) & 0xFF)) << 8);
    sp += 2;
    return(temp16);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movb 0x81066e(%rip), %al     # 0x82177c
incb %al
movzbl %al, %edi
movl $0x100, %ebx            # imm = 0x100
orl %ebx, %edi
callq 0xe3d3
movzbl %al, %ebp
movb 0x810654(%rip), %al     # 0x82177c
addb $0x2, %al
movzbl %al, %edi
orl %ebx, %edi
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
orl %ebp, %eax
addb $0x2, 0x810639(%rip)    # 0x82177c
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: reset6502
void reset6502() {
    pc = (uint16_t)read6502(0xFFFC) | ((uint16_t)read6502(0xFFFD) << 8);
    a = 0;
    x = 0;
    y = 0;
    sp = 0xFD;
    status |= FLAG_CONSTANT;
}

// Assembly:
pushq %rbx
movl $0xfffc, %edi           # imm = 0xFFFC
callq 0xe3d3
movzbl %al, %ebx
movl $0xfffd, %edi           # imm = 0xFFFD
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
orl %ebx, %eax
movw %ax, 0x8105f1(%rip)     # 0x82177e
xorl %eax, %eax
movb %al, 0x8105eb(%rip)     # 0x821780
movb %al, 0x8105e6(%rip)     # 0x821781
movb %al, 0x8105e1(%rip)     # 0x821782
movb $-0x3, 0x8105d4(%rip)   # 0x82177c
orb $0x20, 0x8105d4(%rip)   # 0x821783
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: nmi6502
void nmi6502() {
    push16(pc);
    push8(status);
    status |= FLAG_INTERRUPT;
    pc = (uint16_t)read6502(0xFFFA) | ((uint16_t)read6502(0xFFFB) << 8);
}

// Assembly:
pushq %rbx
movzwl 0x8105c5(%rip), %edi    # 0x82177e
callq 0x110a8
movzbl 0x8105be(%rip), %esi    # 0x821783
movzbl 0x8105b0(%rip), %edi    # 0x82177c
leal -0x1(%rdi), %eax
movb %al, 0x8105a7(%rip)     # 0x82177c
orl $0x100, %edi            # imm = 0x100
callq 0xcd9e
orb $0x4, 0x81059c(%rip)    # 0x821783
movl $0xfffa, %edi           # imm = 0xFFFA
callq 0xe3d3
movzbl %al, %ebx
movl $0xfffb, %edi           # imm = 0xFFFB
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
orl %ebx, %eax
movw %ax, 0x810571(%rip)     # 0x82177e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: irq6502
void irq6502() {
    push16(pc);
    push8(status);
    status |= FLAG_INTERRUPT;
    pc = (uint16_t)read6502(0xFFFE) | ((uint16_t)read6502(0xFFFF) << 8);
}

// Assembly:
pushq %rbx
movzwl 0x810567(%rip), %edi    # 0x82177e
callq 0x110a8
movzbl 0x810560(%rip), %esi    # 0x821783
movzbl 0x810552(%rip), %edi    # 0x82177c
leal -0x1(%rdi), %eax
movb %al, 0x810549(%rip)     # 0x82177c
orl $0x100, %edi            # imm = 0x100
callq 0xcd9e
orb $0x4, 0x81053e(%rip)    # 0x821783
movl $0xfffe, %edi           # imm = 0xFFFE
callq 0xe3d3
movzbl %al, %ebx
movl $0xffff, %edi           # imm = 0xFFFF
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
orl %ebx, %eax
movw %ax, 0x810513(%rip)     # 0x82177e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: exec6502
void exec6502(uint32_t tickcount) {
    clockgoal6502 += tickcount;
    while ((clockticks6502 - clockgoal6502) & 0x80000000) {
        // MDPKH: while condition changed to account for overflow / wraparound
        opcode = read6502(pc++);
        status |= FLAG_CONSTANT;

        penaltyop = 0;
        penaltyaddr = 0;

        (*addrtable[opcode])();
        (*optable[opcode])();
        clockticks6502 += ticktable[opcode];
        if (penaltyop && penaltyaddr) clockticks6502++;

        instructions++;

        if (callexternal) (*loopexternal)();
    }

}

// Assembly:
addl 0x810505(%rip), %edi    # 0x821778
movl %edi, 0x8104ff(%rip)    # 0x821778
cmpl %edi, 0x8104f5(%rip)    # 0x821774
js 0x11282
retq
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
xorl %ebx, %ebx
leaq 0x9b1d(%rip), %r14      # 0x1adb0
leaq 0xa316(%rip), %r15      # 0x1b5b0
leaq 0x595f(%rip), %r12      # 0x16c00
movzwl 0x8104d6(%rip), %edi    # 0x82177e
leal 0x1(%rdi), %eax
movw %ax, 0x8104cc(%rip)     # 0x82177e
callq 0xe3d3
orb $0x20, 0x8104c5(%rip)   # 0x821783
movb %al, 0x8104c1(%rip)     # 0x821785
movb %bl, 0x8104bc(%rip)     # 0x821786
movb %bl, 0x8104b7(%rip)     # 0x821787
movzbl %al, %ecx
xorl %eax, %eax
callq *(%r14,%rcx,8)
movzbl 0x8104a5(%rip), %ecx    # 0x821785
xorl %eax, %eax
callq *(%r15,%rcx,8)
movzbl 0x810498(%rip), %ecx    # 0x821785
movl 0x810481(%rip), %eax    # 0x821774
addl (%r12,%rcx,4), %eax
movl %eax, 0x810477(%rip)    # 0x821774
cmpb %bl, 0x810483(%rip)     # 0x821786
je 0x11316
cmpb $0x0, 0x81047b(%rip)    # 0x821787
je 0x11316
incl %eax
movl %eax, 0x81045e(%rip)    # 0x821774
incl 0x810454(%rip)          # 0x821770
cmpb $0x0, 0x810461(%rip)    # 0x821784
je 0x1132d
xorl %eax, %eax
callq *0x81045b(%rip)         # 0x821788
movl 0x810441(%rip), %eax    # 0x821774
cmpl 0x81043f(%rip), %eax    # 0x821778
js 0x112a1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: step6502
void step6502() {
    opcode = read6502(pc++);
    status |= FLAG_CONSTANT;

    penaltyop = 0;
    penaltyaddr = 0;

    (*addrtable[opcode])();
    (*optable[opcode])();
    clockticks6502 += ticktable[opcode];
    if (penaltyop && penaltyaddr) clockticks6502++;
    clockgoal6502 = clockticks6502;

    instructions++;

    if (callexternal) (*loopexternal)();
}

// Assembly:
pushq %rbx
movzwl 0x81042b(%rip), %edi    # 0x82177e
leal 0x1(%rdi), %eax
movw %ax, 0x810421(%rip)     # 0x82177e
callq 0xe3d3
movb %al, 0x81041d(%rip)     # 0x821785
orb $0x20, 0x810414(%rip)   # 0x821783
xorl %ebx, %ebx
movb %bl, 0x81040f(%rip)     # 0x821786
movb %bl, 0x81040a(%rip)     # 0x821787
movzbl %al, %ecx
leaq 0x9a29(%rip), %rdx      # 0x1adb0
xorl %eax, %eax
callq *(%rdx,%rcx,8)
movzbl 0x8103f2(%rip), %ecx    # 0x821785
leaq 0xa216(%rip), %rdx      # 0x1b5b0
xorl %eax, %eax
callq *(%rdx,%rcx,8)
movzbl 0x8103df(%rip), %ecx    # 0x821785
leaq 0x5853(%rip), %rdx      # 0x16c00
movl 0x8103c1(%rip), %eax    # 0x821774
addl (%rdx,%rcx,4), %eax
movl %eax, 0x8103b8(%rip)    # 0x821774
cmpb %bl, 0x8103c4(%rip)     # 0x821786
je 0x113d5
cmpb $0x0, 0x8103bc(%rip)    # 0x821787
je 0x113d5
incl %eax
movl %eax, 0x81039f(%rip)    # 0x821774
incl 0x810395(%rip)          # 0x821770
movl 0x810393(%rip), %eax    # 0x821774
movl %eax, 0x810391(%rip)    # 0x821778
cmpb $0x0, 0x810396(%rip)    # 0x821784
je 0x113f9
xorl %eax, %eax
popq %rbx
jmpq *0x81038f(%rip)         # 0x821788
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: indy
static void indy() { // (indirect),Y
    uint16_t eahelp, eahelp2, startpage;
    eahelp = (uint16_t)read6502(pc++);
    eahelp2 = (eahelp & 0xFF00) | ((eahelp + 1) & 0x00FF); //zero-page wraparound
    ea = (uint16_t)read6502(eahelp) | ((uint16_t)read6502(eahelp2) << 8);
    startpage = ea & 0xFF00;
    ea += (uint16_t)y;

    if (startpage != (ea & 0xFF00)) { //one cycle penlty for page-crossing on some opcodes
        penaltyaddr = 1;
    }
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movzwl 0x81026d(%rip), %edi    # 0x82177e
leal 0x1(%rdi), %eax
movw %ax, 0x810263(%rip)     # 0x82177e
callq 0xe3d3
movl %eax, %ebx
movzbl %al, %edi
incb %bl
callq 0xe3d3
movzbl %al, %ebp
movzbl %bl, %edi
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
movl %eax, %ecx
orl %ebp, %ecx
movzbl 0x81023a(%rip), %edx    # 0x821782
addl %ecx, %edx
movw %dx, 0x810241(%rip)     # 0x821792
andl $0xff00, %edx           # imm = 0xFF00
cmpw %dx, %ax
je 0x11563
movb $0x1, 0x810224(%rip)    # 0x821787
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: absy
static void absy() { //absolute,Y
    uint16_t startpage;
    ea = ((uint16_t)read6502(pc) | ((uint16_t)read6502(pc+1) << 8));
    startpage = ea & 0xFF00;
    ea += (uint16_t)y;

    if (startpage != (ea & 0xFF00)) { //one cycle penlty for page-crossing on some opcodes
        penaltyaddr = 1;
    }

    pc += 2;
}

// Assembly:
pushq %rbx
movzwl 0x8101e3(%rip), %edi    # 0x82177e
callq 0xe3d3
movzbl %al, %ebx
movzwl 0x8101d4(%rip), %eax    # 0x82177e
incl %eax
movzwl %ax, %edi
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
movl %eax, %ecx
orl %ebx, %ecx
movzbl 0x8101bd(%rip), %edx    # 0x821782
addl %ecx, %edx
movw %dx, 0x8101c4(%rip)     # 0x821792
andl $0xff00, %edx           # imm = 0xFF00
cmpw %dx, %ax
je 0x115e0
movb $0x1, 0x8101a7(%rip)    # 0x821787
addw $0x2, 0x810196(%rip)    # 0x82177e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: absx
static void absx() { //absolute,X
    uint16_t startpage;
    ea = ((uint16_t)read6502(pc) | ((uint16_t)read6502(pc+1) << 8));
    startpage = ea & 0xFF00;
    ea += (uint16_t)x;

    if (startpage != (ea & 0xFF00)) { //one cycle penlty for page-crossing on some opcodes
        penaltyaddr = 1;
    }

    pc += 2;
}

// Assembly:
pushq %rbx
movzwl 0x81018c(%rip), %edi    # 0x82177e
callq 0xe3d3
movzbl %al, %ebx
movzwl 0x81017d(%rip), %eax    # 0x82177e
incl %eax
movzwl %ax, %edi
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
movl %eax, %ecx
orl %ebx, %ecx
movzbl 0x810165(%rip), %edx    # 0x821781
addl %ecx, %edx
movw %dx, 0x81016d(%rip)     # 0x821792
andl $0xff00, %edx           # imm = 0xFF00
cmpw %dx, %ax
je 0x11637
movb $0x1, 0x810150(%rip)    # 0x821787
addw $0x2, 0x81013f(%rip)    # 0x82177e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: ind
static void ind() { //indirect
    uint16_t eahelp, eahelp2;
    eahelp = (uint16_t)read6502(pc) | (uint16_t)((uint16_t)read6502(pc+1) << 8);
    eahelp2 = (eahelp & 0xFF00) | ((eahelp + 1) & 0x00FF); //replicate 6502 page-boundary wraparound bug
    ea = (uint16_t)read6502(eahelp) | ((uint16_t)read6502(eahelp2) << 8);
    pc += 2;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movzwl 0x810132(%rip), %edi    # 0x82177e
callq 0xe3d3
movzbl %al, %ebx
movzwl 0x810123(%rip), %edi    # 0x82177e
incl %edi
movl $0xffff, %ebp           # imm = 0xFFFF
andl %ebp, %edi
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
leal (%rax,%rbx), %edi
incl %ebx
movzbl %bl, %ebx
orl %eax, %ebx
andl %ebp, %edi
callq 0xe3d3
movzbl %al, %r14d
andl %ebp, %ebx
movl %ebx, %edi
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
orl %r14d, %eax
movw %ax, 0x8100f5(%rip)     # 0x821792
addw $0x2, 0x8100d9(%rip)    # 0x82177e
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: brk
static void brk() {
    pc++;
    push16(pc); //push next instruction address onto stack
    push8(status | FLAG_BREAK); //push CPU status to stack
    setinterrupt(); //set interrupt flag
    pc = (uint16_t)read6502(0xFFFE) | ((uint16_t)read6502(0xFFFF) << 8);
}

// Assembly:
pushq %rbx
movzwl 0x8100a3(%rip), %eax    # 0x82177e
incl %eax
movw %ax, 0x81009a(%rip)     # 0x82177e
movzwl %ax, %edi
callq 0x110a8
movzbl 0x810090(%rip), %esi    # 0x821783
movzbl 0x810082(%rip), %edi    # 0x82177c
leal -0x1(%rdi), %eax
movb %al, 0x810079(%rip)     # 0x82177c
orl $0x100, %edi            # imm = 0x100
orl $0x10, %esi
callq 0xcd9e
orb $0x4, 0x81006b(%rip)    # 0x821783
movl $0xfffe, %edi           # imm = 0xFFFE
callq 0xe3d3
movzbl %al, %ebx
movl $0xffff, %edi           # imm = 0xFFFF
callq 0xe3d3
movzbl %al, %eax
shll $0x8, %eax
orl %ebx, %eax
movw %ax, 0x810040(%rip)     # 0x82177e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/fake6502.c
// Function: ora
static void ora() {
    penaltyop = 1;
    value = getvalue();
    result = (uint16_t)a | value;
   
    zerocalc(result);
    signcalc(result);
   
    saveaccum(result);
}

// Assembly:
movb $0x1, 0x81003f(%rip)    # 0x821786
movzbl 0x810037(%rip), %eax    # 0x821785
leaq 0x965b(%rip), %rcx      # 0x1adb0
leaq -0x2c0(%rip), %rdx      # 0x1149c
cmpq %rdx, (%rcx,%rax,8)
je 0x11775
pushq %rax
movzwl 0x810028(%rip), %edi    # 0x821792
callq 0xe3d3
addq $0x8, %rsp
jmp 0x1177b
movb 0x810005(%rip), %al     # 0x821780
movzbl %al, %eax
movw %ax, 0x810011(%rip)     # 0x821796
orb 0x80fff5(%rip), %al     # 0x821780
movzbl %al, %eax
movw %ax, 0x810003(%rip)     # 0x821798
testb %al, %al
sete %cl
movb 0x80ffe3(%rip), %dl     # 0x821783
andb $0x7d, %dl
addb %cl, %cl
movb %al, 0x80ffd5(%rip)     # 0x821780
andb $-0x80, %al
orb %cl, %al
orb %dl, %al
movb %al, 0x80ffcc(%rip)     # 0x821783
retq