LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/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 0x58aa
leaq 0x20(%r14), %r15
xorl %r13d, %r13d
pushq $0x10
popq %r12
movl (%r14), %edi
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rsi
xorl %ecx, %ecx
movq %r15, %r8
movl %r12d, %r9d
callq 0x3060
testq %rax, %rax
js 0xb8d2
movl 0x4(%rbx), %esi
movq %r14, %rdi
callq 0xb996
testb %al, %al
jne 0xb8b6
incl %r13d
cmpl $0x3, %r13d
jne 0xb87d
pushq $0x3
popq %r13
incl 0x8(%r14)
xorl %eax, %eax
cmpl $0x3, %r13d
setne %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x56f7(%rip), %rax      # 0x10fd0
movq (%rax), %rcx
leaq 0xcf6(%rip), %rdi       # 0xc5d9
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x3580
leaq 0x14(%rbx), %rsi
leaq -0x70(%rbp), %r14
leaq -0x2a(%rbp), %rdx
movq %r14, %rdi
callq 0x3130
movq 0x56bf(%rip), %rdi      # 0x10fc8
movq %r14, %rsi
callq 0x32b0
movl (%rbx), %esi
movq %rax, %rdi
callq 0x3500
leaq 0xaac(%rip), %rsi       # 0xc3ce
movq %rax, %rdi
callq 0x3310
movq %rax, %r14
addq $0xfb4, %rbx            # imm = 0xFB4
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
movq %rbx, %rsi
callq 0x3130
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x32b0
movq %rax, %rdi
callq 0x31c0
leaq -0x50(%rbp), %rdi
callq 0x3170
leaq -0x70(%rbp), %rdi
callq 0x3170
pushq $-0x1
popq %rax
jmp 0xb8c3
jmp 0xb982
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x3170
jmp 0xb985
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x3540
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x1
popq %r15
movq %r14, %rdi
movl %r15d, %esi
callq 0xb9d4
testq %rax, %rax
je 0xb9c3
cmpl $0x1, (%rax)
jne 0xb9a9
cmpl %ebx, 0x4(%rax)
jne 0xb9a9
testq %rax, %rax
setne %al
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0xba29
movl (%rbx), %eax
leaq -0xff4(%rbp), %rdi
movl %eax, (%rdi)
movw $0x1, 0x4(%rdi)
pushq $0x1
popq %rsi
movl $0x7d0, %edx            # imm = 0x7D0
callq 0x3460
cmpl $-0x1, %eax
je 0xba21
testl %eax, %eax
jne 0xba29
leaq 0xc0e(%rip), %rdi       # 0xc62a
callq 0x3490
xorl %r14d, %r14d
jmp 0xbae0
movl $0x1000, %edi           # imm = 0x1000
callq 0x3030
movq %rax, %r14
movl $0x1000, %edx           # imm = 0x1000
movq %rax, %rdi
xorl %esi, %esi
callq 0x3220
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 0x3260
testl %eax, %eax
js 0xbaf3
cmpl $0x1, (%r14)
je 0xba87
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
je 0xba87
movq %r14, %rdx
callq 0xbb18
testb %al, %al
jne 0xba4d
movl 0x10(%r14), %eax
testl %eax, %eax
je 0xba9b
cmpl $-0x1, %eax
je 0xbadc
cmpl 0x8(%rbx), %eax
jne 0xba4d
jmp 0xba9f
andl $0x0, 0x8(%rbx)
cmpl $0x1, (%r14)
je 0xba4d
movl 0x4(%r14), %edx
leaq 0xb4d(%rip), %r9        # 0xc5fd
leaq -0xff4(%rbp), %r15
pushq $0x1
popq %rcx
pushq $-0x1
popq %r8
movq %r15, %rdi
movl %ecx, %esi
callq 0x57f0
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbc2e
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
movq 0x54d6(%rip), %rax      # 0x10fd0
movq (%rax), %rcx
leaq 0xae6(%rip), %rdi       # 0xc5ea
pushq $0x13
popq %rsi
pushq $0x1
popq %rdx
callq 0x3580
pushq $0x1
popq %rdi
callq 0x3370
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x48, %rsp
movl (%rsi), %eax
cmpl (%rdx), %eax
jne 0xbb9d
movq %rdx, %rbx
movq %rsi, %r14
movl 0x4(%rsi), %eax
cmpl 0x4(%rdx), %eax
jne 0xbb9d
movl 0x8(%r14), %eax
cmpl 0x8(%rbx), %eax
jne 0xbb9d
movl 0xc(%r14), %eax
cmpl 0xc(%rbx), %eax
jne 0xbb9d
movl 0x10(%r14), %eax
cmpl 0x10(%rbx), %eax
jne 0xbb9d
leaq 0x14(%r14), %rsi
leaq -0x60(%rbp), %rdi
leaq -0x1a(%rbp), %rdx
callq 0x3130
leaq 0x14(%rbx), %rsi
leaq -0x40(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x3130
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3040
movl %eax, %r15d
leaq -0x40(%rbp), %rdi
callq 0x3170
leaq -0x60(%rbp), %rdi
callq 0x3170
testl %r15d, %r15d
je 0xbbac
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
addq $0xfb4, %r14            # imm = 0xFB4
leaq -0x60(%rbp), %rdi
leaq -0x1a(%rbp), %rdx
movq %r14, %rsi
callq 0x3130
addq $0xfb4, %rbx            # imm = 0xFB4
leaq -0x40(%rbp), %rdi
leaq -0x19(%rbp), %rdx
movq %rbx, %rsi
callq 0x3130
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3040
testl %eax, %eax
sete %bl
leaq -0x40(%rbp), %rdi
callq 0x3170
leaq -0x60(%rbp), %rdi
callq 0x3170
jmp 0xbb9f
jmp 0xbc06
jmp 0xbc14
jmp 0xbc22
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x3170
jmp 0xbc17
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x3170
jmp 0xbc25
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3540
nop
// File: /workspace/github_cpp_makefile_star2_O2/vianna274[P]dropbox/server.cpp
// Function: main
int main(int argc, char *argv[])
{	
	Server *server;
	if(argc == 2){
		// main
		string ipLocal(argv[1]);
		server = new Server(ipLocal);
	}
	else{
		// backups
		string ipLocal(argv[1]);
		string ipMain(argv[2]);
		vector<string> ipBackups;
		for(int i = 3; i<argc; i++){
			ipBackups.push_back(argv[i]);
		}
		server = new Server(ipLocal, ipMain, ipBackups);
	}
	
	server->run();

	delete server;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rbx
cmpl $0x2, %edi
jne 0xbcf0
movq 0x8(%rbx), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x3130
movl $0xa00, %edi            # imm = 0xA00
callq 0x3320
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x33d0
leaq -0x108(%rbp), %rsi
movq %rbx, %rdi
callq 0x6c94
leaq -0x108(%rbp), %rdi
jmp 0xbdfd
movl %edi, %r15d
movq 0x8(%rbx), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x3130
movq 0x10(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x128(%rbp), %rdx
callq 0x3130
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movslq %r15d, %r13
pushq $0x3
popq %r14
leaq -0x128(%rbp), %r15
leaq -0x29(%rbp), %r12
cmpq %r13, %r14
jge 0xbd6c
movq (%rbx,%r14,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x3130
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0xadd4
movq %r15, %rdi
callq 0x3170
incq %r14
jmp 0xbd3f
movl $0xa00, %edi            # imm = 0xA00
callq 0x3320
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x33d0
leaq -0xc8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x33d0
leaq -0xa8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xa1da
leaq -0xe8(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
leaq -0xa8(%rbp), %rcx
movq %rbx, %rdi
callq 0x717e
leaq -0xa8(%rbp), %rdi
callq 0xa056
leaq -0xc8(%rbp), %rdi
callq 0x3170
leaq -0xe8(%rbp), %rdi
callq 0x3170
leaq -0x70(%rbp), %rdi
callq 0xa056
leaq -0x90(%rbp), %rdi
callq 0x3170
leaq -0x50(%rbp), %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x73b0
movq %rbx, %rdi
callq 0x821e
movq %rbx, %rdi
callq 0x32f0
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0xa8(%rbp), %rdi
callq 0xa056
jmp 0xbe4b
movq %rax, %r14
leaq -0xc8(%rbp), %rdi
callq 0x3170
jmp 0xbe5c
movq %rax, %r14
leaq -0xe8(%rbp), %rdi
callq 0x3170
jmp 0xbe6d
movq %rax, %r14
movq %rbx, %rdi
callq 0x32f0
jmp 0xbeb9
jmp 0xbeb6
movq %rax, %r14
leaq -0x108(%rbp), %rdi
callq 0x3170
jmp 0xbe8d
movq %rax, %r14
movq %rbx, %rdi
callq 0x32f0
jmp 0xbece
jmp 0xbe99
movq %rax, %r14
jmp 0xbece
jmp 0xbea0
movq %rax, %r14
jmp 0xbed7
movq %rax, %r14
leaq -0x128(%rbp), %rdi
callq 0x3170
jmp 0xbeb9
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0xa056
leaq -0x90(%rbp), %rdi
callq 0x3170
leaq -0x50(%rbp), %rdi
callq 0x3170
movq %r14, %rdi
callq 0x3540
// File: /workspace/github_cpp_makefile_star2_O2/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
cmpq $0x100, %rcx            # imm = 0x100
je 0x6fa8
movb $-0x1, 0x3(%rsp,%rcx,4)
movl %ecx, %edx
shrl $0x2, %edx
andl $0x2, %edx
movl %ecx, %esi
shrl $0x7, %esi
orl %edx, %esi
imull $0x11, %esi, %edx
movl %ecx, %esi
shrl %esi
andl $0x2, %esi
movl %ecx, %r8d
shrl $0x6, %r8d
andl $0x1, %r8d
orl %esi, %r8d
imull $0x44, %r8d, %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
imull $0x44, %r8d, %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
imull $0x44, %r8d, %esi
orl %edx, %esi
movb %sil, 0x2(%rsp,%rcx,4)
incq %rcx
addl $0x2, %eax
jmp 0x6f22
movq %rsp, %rsi
xorl %edx, %edx
movl $0x100, %ecx            # imm = 0x100
callq 0x61e0
addq $0x408, %rsp            # imm = 0x408
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
xorl %eax, %eax
leaq 0xaf27(%rip), %rcx      # 0x12130
movzbl (%rdi), %edx
testq %rdx, %rdx
je 0x7220
imulq $0x22, %rdx, %rdx
movzbl (%rdx,%rcx), %edx
addl %edx, %eax
incq %rdi
jmp 0x7209
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
testq %r9, %r9
je 0x7350
cmpq $0x0, 0x20(%r9)
je 0x7350
movl 0x14(%r9), %r10d
subl %edx, %r10d
jle 0x7350
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movb %r8b, -0x32(%rsp)
movb %cl, -0x31(%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
movslq %ecx, %rcx
leaq 0xaeb3(%rip), %r8       # 0x12130
movzbl (%rdi), %r10d
testq %r10, %r10
je 0x7346
imulq $0x22, %r10, %rbx
leaq (%rbx,%r8), %r11
addq $0x2, %r11
movzbl -0x2(%r11), %r10d
addq %r8, %rbx
addq $0x22, %rbx
xorl %r14d, %r14d
leaq (%r11,%r14), %r15
cmpq %rbx, %r15
jae 0x72be
movzwl (%r15), %ebp
movw %bp, -0x28(%rsp,%r14)
addq $0x2, %r14
jmp 0x72a5
movslq (%rsi), %r15
movq %r15, %r11
negq %r11
movslq 0x10(%r9), %rbx
subq %r15, %rbx
cmpl %r10d, %r11d
jge 0x7337
movslq 0x18(%r9), %r14
imulq -0x30(%rsp), %r14
addq 0x20(%r9), %r14
addq %r15, %r14
movl %r10d, %r15d
movq %rdx, %r12
cmpq %rcx, %r12
jge 0x7337
xorl %r13d, %r13d
cmpq %r13, %r15
je 0x732b
cmpq %r11, %r13
setge %bpl
cmpq %rbx, %r13
setl %al
andb %bpl, %al
movzwl -0x28(%rsp,%r12,2), %ebp
cmpb $0x1, %al
jne 0x731e
movl %ebp, %eax
andl $0x1, %eax
movb -0x32(%rsp,%rax), %al
movb %al, (%r14,%r13)
shrl %ebp
movw %bp, -0x28(%rsp,%r12,2)
incq %r13
jmp 0x72f2
movslq 0x18(%r9), %r13
addq %r13, %r14
incq %r12
jmp 0x72ea
testl %ebx, %ebx
jle 0x7346
addl %r10d, (%rsi)
incq %rdi
jmp 0x727d
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
xorl %ecx, %ecx
leaq 0xa151(%rip), %rsi      # 0x114c0
cmpl $0x1b, %ecx
je 0x7396
xorl %edi, %edi
cmpl $0x1d, %edi
je 0x7388
movb (%rsi,%rdi), %r8b
movb %r8b, (%rax,%rdi)
incq %rdi
jmp 0x7376
movslq 0x18(%rdx), %r8
addq %r8, %rax
incl %ecx
addq %rdi, %rsi
jmp 0x736f
retq
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/main.cpp
// Function: ExtendLog(dletype)
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 0x11240(%rip), %rcx     # 0x1b308
movl 0x811772(%rip), %eax    # 0x81b840
leal 0x1(%rcx), %edx
andl $0x7ffff, %edx          # imm = 0x7FFFF
cmpl %eax, %ecx
jne 0xa0e3
movl %edx, 0x81175f(%rip)    # 0x81b840
movl %edx, %eax
cltq
shlq $0x4, %rax
leaq 0x11750(%rip), %rsi     # 0x1b840
movb $0x0, (%rax,%rsi)
shlq $0x4, %rcx
leaq (%rsi,%rcx), %rax
movb %dil, (%rcx,%rsi)
movl %edx, 0x11202(%rip)     # 0x1b308
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
andl $0x0, -0x4(%rsp)
movzbl 0x110b1(%rip), %eax     # 0x1b6e5
leaq 0x110b5(%rip), %rcx     # 0x1b6f0
xorl %edx, %edx
leaq 0x111ec(%rip), %rsi     # 0x1b830
movabsq $0x1, %r9
leaq 0x1108b(%rip), %r11     # 0x1b6e0
movq %rcx, %rbx
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0xa714
movzwl (%rsi,%r14,2), %r15d
testw %r15w, %r15w
jne 0xa6fc
movq %r14, %r12
shlq $0x5, %r12
leaq (%rcx,%r12), %r13
xorl %r15d, %r15d
leaq 0x110a9(%rip), %rbp     # 0x1b732
leaq 0x11048(%rip), %rdi     # 0x1b6d8
xorl %r8d, %r8d
cmpq $0x4, %r8
je 0xa6d1
leal (%rdx,%r8), %r10d
btl %r10d, %eax
jae 0xa6c4
movb -0x2(%rbp), %r10b
movb %r10b, (%r8,%r11)
movzwl (%rbp), %r10d
movw %r10w, (%rdi)
movzwl (%r13), %r15d
movw %r15w, (%rsi,%r14,2)
movb $0x1, -0x4(%rsp,%r8)
incq %r8
addq $0x2, %rdi
addq $0x40, %rbp
jmp 0xa693
movq %r9, %rdi
cmpq $0x10, %rdi
je 0xa6ea
movzwl (%rbx,%rdi,2), %r8d
movw %r8w, -0x2(%rbx,%rdi,2)
incq %rdi
jmp 0xa6d4
orw $-0x1, 0x1e(%r12,%rcx)
leaq 0x1113c(%rip), %rdi     # 0x1b834
incb (%r14,%rdi)
decl %r15d
movw %r15w, (%rsi,%r14,2)
incq %r14
addq $0x4, %rdx
addq $0x20, %rbx
jmp 0xa65b
leaq 0x11015(%rip), %rax     # 0x1b730
xorl %ecx, %ecx
movabsq $0x1, %rdx
movq %rax, %rsi
cmpq $0x4, %rcx
je 0xa769
cmpb $0x1, -0x4(%rsp,%rcx)
jne 0xa760
movq %rdx, %rdi
cmpq $0x10, %rdi
je 0xa74e
movl (%rsi,%rdi,4), %r8d
movl %r8d, -0x4(%rsi,%rdi,4)
incq %rdi
jmp 0xa73a
movq %rcx, %rdi
shlq $0x6, %rdi
movb $0x0, 0x3c(%rdi,%rax)
andw $0x0, 0x3e(%rdi,%rax)
incq %rcx
addq $0x40, %rsi
jmp 0xa72a
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/main.cpp
// Function: InitEmulator()
int InitEmulator()
{
	for (int y = 0; y < 18; ++y)
		for (int x = 0; x < 32; ++x)
		{
			PaintCell(x, y);
		}
	debuglog[debuglogstart].entrytype = dletype::LT_START;
	hookexternal((void*)LogStep);
	keypressregister = 0;
	{
		unsigned int uebase = SDL_RegisterEvents(1);
		UE_RESETCPU = uebase;
	}
	{
		SDL_Event newevent;
		newevent.type = UE_RESETCPU;
		SDL_PushEvent(&newevent);
	}
	soundfreqregister[0] = 0;
	soundfreqregister[1] = 0;
	soundfreqregister[2] = 0;
	soundfreqregister[3] = 0;
	soundvolregister[0] = 0x00;
	soundvolregister[1] = 0x00;
	soundvolregister[2] = 0x00;
	soundvolregister[3] = 0x00;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
xorl %ebp, %ebp
cmpl $0x12, %ebp
je 0xa7b8
xorl %r14d, %r14d
movzbl %bpl, %ebx
cmpl $0x20, %r14d
je 0xa7b4
movzbl %r14b, %edi
movl %ebx, %esi
callq 0xd5f0
incl %r14d
jmp 0xa79e
incl %ebp
jmp 0xa792
movslq 0x811081(%rip), %rax    # 0x81b840
shlq $0x4, %rax
leaq 0x11076(%rip), %rcx     # 0x1b840
xorl %ebx, %ebx
movb %bl, (%rax,%rcx)
leaq 0x3f(%rip), %rdi        # 0xa815
callq 0xfbc5
movb %bl, 0x10ef3(%rip)      # 0x1b6d4
pushq $0x1
popq %rdi
callq 0x6380
movl %eax, 0x814b45(%rip)    # 0x81f334
leaq 0x8(%rsp), %rdi
movl %eax, (%rdi)
callq 0x6570
andq $0x0, 0x10ed5(%rip)     # 0x1b6d8
andl $0x0, 0x10ed6(%rip)     # 0x1b6e0
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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, 0x1079d(%rip)     # 0x1b470
movl $0x100, %edi            # imm = 0x100
callq 0x6040
movq %rax, 0x10794(%rip)     # 0x1b478
xorl %ecx, %ecx
cmpq $0x20, %rcx
je 0xacf5
movb $0x2, (%rax,%rcx)
incq %rcx
jmp 0xace6
leaq 0x8(%rsp), %rbx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xd740
movabsq $0xff00000000, %rax     # imm = 0xFF00000000
movq %rsp, %r14
movq %rax, (%r14)
xorl %r15d, %r15d
cmpq $0x2000, %r15           # imm = 0x2000
je 0xad3c
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd738
movq 0x1073d(%rip), %rcx     # 0x1b470
movb %al, (%rcx,%r15)
incq %r15
jmp 0xad18
pushq $0x20
popq %rcx
movq 0x10732(%rip), %rax     # 0x1b478
cmpq $0x100, %rcx            # imm = 0x100
je 0xad58
movb $0x0, (%rax,%rcx)
incq %rcx
jmp 0xad46
movw $0xa09, 0x2(%rax)       # imm = 0xA09
leaq 0x810afb(%rip), %rdi    # 0x81b860
callq 0x64b0
movl %eax, %esi
leaq 0x811e75(%rip), %rdi    # 0x81cbe8
callq 0xd740
callq 0xada8
xorl %eax, %eax
movq 0x106f2(%rip), %rcx     # 0x1b478
cmpq $0x10, %rax
je 0xad99
orb $-0x80, 0xf0(%rcx,%rax)
incq %rax
jmp 0xad86
xorl %eax, %eax
addq $0x1390, %rsp           # imm = 0x1390
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x20
popq %rdx
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 -0x12df(%rip), %rax     # 0xa107
movq %rax, 0x10(%rbx)
leaq 0x813f1f(%rip), %rcx    # 0x81f310
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x63f0
movl %eax, 0x813f2a(%rip)    # 0x81f330
testl %eax, %eax
jne 0xb41e
leaq 0x964e(%rip), %rdi      # 0x14a5f
xorl %eax, %eax
callq 0x6480
movl 0x813f12(%rip), %eax    # 0x81f330
movl %eax, %edi
xorl %esi, %esi
callq 0x6440
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/main.cpp
// Function: LogFVMC(unsigned short, unsigned short, unsigned char)
void LogFVMC(uint16_t dest, uint16_t src, uint8_t value)
{
	dlogentry* newentry = ExtendLog(dletype::LT_FVMC);
	newentry->fvmcentry.dest = dest;
	newentry->fvmcentry.src = src;
	newentry->fvmcentry.value = value;
	newentry->fvmcentry.memtype = syspflags[src >> 8];
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %ebx
movl %esi, %r14d
movl %edi, %ebp
pushq $0x4
popq %rdi
callq 0xa0c1
movw %bp, 0x4(%rax)
movw %r14w, 0x6(%rax)
movb %bl, 0x8(%rax)
movq 0xfff4(%rip), %rcx      # 0x1b478
shrl $0x8, %r14d
movb (%rcx,%r14), %cl
movb %cl, 0x9(%rax)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/main.cpp
// Function: LogStack(unsigned char)
void LogStack(unsigned char sp)
{
	dlogentry* newentry = ExtendLog(dletype::LT_STACK);
	if (suppresslogging)
		return;
	for (unsigned i = 0, j = sp + 1; i < 7; ++i, ++j, j &= 0xff)
	{
		newentry->stackentry.stack[i] = sysram[j | 0x100];
	}
	newentry->stackentry.nstack = stackbase - sp;
	//DoDebugger();
}

// Assembly:
pushq %rbx
movl %edi, %ebx
pushq $0x8
popq %rdi
callq 0xa0c1
cmpb $0x0, 0x10087(%rip)     # 0x1b6d1
jne 0xb687
movzbl %bl, %ecx
incl %ecx
pushq $-0x7
popq %rdx
testq %rdx, %rdx
je 0xb67c
movq 0xfe10(%rip), %rsi      # 0x1b470
movl %ecx, %edi
orq $0x100, %rdi            # imm = 0x100
movb (%rsi,%rdi), %sil
movb %sil, 0xc(%rax,%rdx)
incl %ecx
movzbl %cl, %ecx
incq %rdx
jmp 0xb654
movb 0x8101c6(%rip), %cl     # 0x81b848
subb %bl, %cl
movb %cl, 0x4(%rax)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movl 0xfc73(%rip), %eax      # 0x1b308
cmpb $0x1, 0x10035(%rip)     # 0x1b6d1
movzwl %di, %r14d
jne 0xb6c4
movq 0xfdcf(%rip), %rcx      # 0x1b478
movl %r14d, %edx
shrl $0x8, %edx
movb (%rcx,%rdx), %cl
movl %ecx, %edx
andb $0x8, %dl
shrb $0x3, %dl
testb $0x3, %cl
sete %cl
orb %dl, %cl
jne 0xb702
decl %eax
andl $0x7ffff, %eax          # imm = 0x7FFFF
shll $0x4, %eax
leaq 0x1016b(%rip), %rcx     # 0x1b840
addq %rax, %rcx
cmpb $0x6, (%rcx)
jne 0xb6e0
movb $0x7, (%rcx)
pushq $0x3
popq %rdi
callq 0xa0c1
movw %r14w, 0x4(%rax)
movb %bl, 0x6(%rax)
movq 0xfd81(%rip), %rcx      # 0x1b478
shrl $0x8, %r14d
movb (%rcx,%r14), %cl
movb %cl, 0x7(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x814ca6(%rip), %al     # 0x820750
testb %al, %al
je 0xbb23
movb 0x814cac(%rip), %al     # 0x820760
testb %al, %al
je 0xbb56
leaq 0x814c95(%rip), %rdi    # 0x820758
leaq 0x8138fe(%rip), %rsi    # 0x81f3c8
callq 0xd738
testb $0xf, %al
je 0xbad8
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x814c79(%rip), %rbx    # 0x820758
leaq 0x8138e2(%rip), %r14    # 0x81f3c8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd738
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd738
andb $0x7, %al
pushq $0x1
popq %rdx
movl %eax, %ecx
shll %cl, %edx
movq 0xf962(%rip), %rax      # 0x1b470
movslq %ebp, %rcx
xorb (%rax,%rcx), %dl
movzbl %dl, %esi
movzwl %cx, %edi
popq %rbx
popq %r14
popq %rbp
jmp 0xbba3
leaq 0x814c26(%rip), %rdi    # 0x820750
callq 0x65a0
testl %eax, %eax
je 0xbaae
leaq 0x81388a(%rip), %rdi    # 0x81f3c8
xorl %esi, %esi
callq 0xd740
leaq 0x814c04(%rip), %rdi    # 0x820750
callq 0x6270
jmp 0xbaae
leaq 0x814c03(%rip), %rdi    # 0x820760
callq 0x65a0
testl %eax, %eax
je 0xbabc
movabsq $0x1fff00000800, %rax   # imm = 0x1FFF00000800
movq %rax, 0x814bdd(%rip)    # 0x820758
leaq 0x814bde(%rip), %rdi    # 0x820760
callq 0x6270
jmp 0xbabc
movq %rax, %rbx
leaq 0x814bba(%rip), %rdi    # 0x820750
callq 0x6250
movq %rbx, %rdi
callq 0x6580
// File: /workspace/github_cpp_makefile_star2_O2/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, %r9
leaq 0xe8f4(%rip), %r10      # 0x1b490
cmpb $0x1, (%r9,%r10)
jne 0xcc05
pushq %rbx
movq %rdx, %rcx
movl 0x14(%rdx), %r11d
movl %r11d, %eax
imull %edi, %eax
movl $0x240, %ebx            # imm = 0x240
cltd
idivl %ebx
movl %eax, %r8d
incl %edi
imull %r11d, %edi
movl %edi, %eax
cltd
idivl %ebx
movq 0x20(%rsi), %rdi
movslq 0x18(%rsi), %rdx
movslq %r8d, %r8
cltq
imulq %rdx, %rax
imulq %r8, %rdx
addq %rdi, %rdx
movslq 0x18(%rcx), %rsi
imulq %r8, %rsi
addq 0x20(%rcx), %rsi
addq %rdi, %rax
cmpq %rax, %rdx
jae 0xcbff
movb (%rdx), %cl
movb %cl, (%rsi)
incq %rdx
incq %rsi
jmp 0xcbee
movb $0x0, (%r9,%r10)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/main.cpp
// Function: DisplayHexWord(char*, short)
inline void DisplayHexWord(char* dest, short val)
{
	const char nybbles[16] = {
		0x30, 0x31, 0x32, 0x33,
		0x34, 0x35, 0x36, 0x37,
		0x38, 0x39, 0x41, 0x42,
		0x43, 0x44, 0x45, 0x46,
	};
	*dest = nybbles[(val >> 12) & 0xf];
	*++dest = nybbles[(val >> 8) & 0xf];
	*++dest = nybbles[(val >> 4) & 0xf];
	*++dest = nybbles[val & 0xf];
}

// Assembly:
movzwl %si, %eax
shrl $0xc, %eax
leaq 0x3fe1(%rip), %rcx      # 0x110a0
movb (%rax,%rcx), %al
movb %al, (%rdi)
movl %esi, %eax
shrl $0x8, %eax
andl $0xf, %eax
movb (%rax,%rcx), %al
movb %al, 0x1(%rdi)
movl %esi, %eax
shrl $0x4, %eax
andl $0xf, %eax
movb (%rax,%rcx), %al
movb %al, 0x2(%rdi)
andl $0xf, %esi
movb (%rsi,%rcx), %al
movb %al, 0x3(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/main.cpp
// Function: bool cilstreq<char const*>(char const*, char const*)
bool cilstreq(T a, T b)
// case-insensitive c-string equality comparison,
// optimized by assuming b is already lowercase
{
	if (a == b)
		return true;
	while (true)
	{
		if (*a == 0 && *b == 0)
			return true;
		if (tolower(*a) != *b)
			return false;
		++a;
		++b;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
cmpq %rsi, %rdi
je 0xd473
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
movsbl (%r14,%r15), %edi
movb (%rbx,%r15), %al
movl %edi, %ecx
orb %al, %cl
sete %bpl
je 0xd476
movsbl %al, %r12d
callq 0x64d0
cmpl %r12d, %eax
jne 0xd476
incq %r15
jmp 0xd44d
movb $0x1, %bpl
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/main.cpp
// Function: bare_read6502(unsigned short)
inline uint8_t bare_read6502(uint16_t address)
{
	static std::uniform_int_distribution<> dis(0x00, 0xFF);
	if ((address & 0xff00) == 0x0200)
	{
		switch (address & 0xff)
		{
			unsigned char t;
		case 0x44: // keyboard
			t = keypressregister;
			keypressregister = 0;
			return t;
		case 0xfc: // video flags
			return videostate;
		default:
			return dis(floatgen);
		}
	}
	if ((syspflags[address >> 8] & pageflags::PF_TMASK) == pageflags::PF_TFLOATING
		|| (syspflags[address >> 8] & (pageflags::PF_IO | pageflags::PF_TMASK)) == pageflags::PF_OUTONLY)
	{
		return dis(floatgen); // TODO: more realistic open-bus behavior?
	}
	return sysram[address];
}

// Assembly:
pushq %rbx
movl %edi, %ebx
movb 0x8125b6(%rip), %al     # 0x820778
testb %al, %al
je 0xe240
movzwl %bx, %eax
movl %eax, %ecx
andl $0xff00, %ecx           # imm = 0xFF00
cmpl $0x200, %ecx            # imm = 0x200
jne 0xe1f5
cmpb $-0x4, %bl
je 0xe238
movzbl %bl, %eax
cmpl $0x44, %eax
jne 0xe217
movb 0xd4e8(%rip), %al       # 0x1b6d4
movb $0x0, 0xd4e1(%rip)      # 0x1b6d4
jmp 0xe23e
movq 0xd27c(%rip), %rcx      # 0x1b478
movl %eax, %edx
shrl $0x8, %edx
movb (%rcx,%rdx), %cl
testb $0x3, %cl
setne %dl
andb $0xb, %cl
cmpb $0xa, %cl
setne %cl
testb %cl, %dl
jne 0xe22c
leaq 0x81254e(%rip), %rdi    # 0x82076c
leaq 0x80e9c3(%rip), %rsi    # 0x81cbe8
callq 0xd738
jmp 0xe23e
movq 0xd23d(%rip), %rcx      # 0x1b470
movb (%rcx,%rax), %al
jmp 0xe23e
movb 0xd494(%rip), %al       # 0x1b6d2
popq %rbx
retq
leaq 0x812531(%rip), %rdi    # 0x820778
callq 0x65a0
testl %eax, %eax
je 0xe1c6
movabsq $0xff00000000, %rax     # imm = 0xFF00000000
movq %rax, 0x812507(%rip)    # 0x82076c
leaq 0x81250c(%rip), %rdi    # 0x820778
callq 0x6270
jmp 0xe1c6
// File: /workspace/github_cpp_makefile_star2_O2/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 0x810e86(%rip), %al     # 0x82078c
incb %al
movzbl %al, %edi
movl $0x100, %ebx            # imm = 0x100
orl %ebx, %edi
callq 0xcc0c
movzbl %al, %ebp
movb 0x810e6c(%rip), %al     # 0x82078c
addb $0x2, %al
movzbl %al, %edi
orl %ebx, %edi
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
orl %ebp, %eax
addb $0x2, 0x810e51(%rip)    # 0x82078c
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0xcc0c
movzbl %al, %ebx
movl $0xfffd, %edi           # imm = 0xFFFD
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
orl %ebx, %eax
movw %ax, 0x810e09(%rip)     # 0x82078e
xorl %eax, %eax
movb %al, 0x810e03(%rip)     # 0x820790
movb %al, 0x810dfe(%rip)     # 0x820791
movb %al, 0x810df9(%rip)     # 0x820792
movb $-0x3, 0x810dec(%rip)   # 0x82078c
orb $0x20, 0x810dec(%rip)   # 0x820793
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x810ddd(%rip), %edi    # 0x82078e
callq 0xf8a0
movzbl 0x810dd6(%rip), %edi    # 0x820793
callq 0xf8e0
orb $0x4, 0x810dca(%rip)    # 0x820793
movl $0xfffa, %edi           # imm = 0xFFFA
callq 0xcc0c
movzbl %al, %ebx
movl $0xfffb, %edi           # imm = 0xFFFB
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
orl %ebx, %eax
movw %ax, 0x810d9f(%rip)     # 0x82078e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x810d95(%rip), %edi    # 0x82078e
callq 0xf8a0
movzbl 0x810d8e(%rip), %edi    # 0x820793
callq 0xf8e0
orb $0x4, 0x810d82(%rip)    # 0x820793
movl $0xfffe, %edi           # imm = 0xFFFE
callq 0xcc0c
movzbl %al, %ebx
movl $0xffff, %edi           # imm = 0xFFFF
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
orl %ebx, %eax
movw %ax, 0x810d57(%rip)     # 0x82078e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
addl 0x810d41(%rip), %edi    # 0x820788
movl %edi, 0x810d3b(%rip)    # 0x820788
movl 0x810d31(%rip), %eax    # 0x820784
xorl %ebx, %ebx
leaq 0xa354(%rip), %r14      # 0x19db0
leaq 0xab4d(%rip), %r15      # 0x1a5b0
leaq 0x51b6(%rip), %r12      # 0x14c20
cmpl %edi, %eax
jns 0xfb0f
movzwl 0x810d15(%rip), %edi    # 0x82078e
leal 0x1(%rdi), %eax
movw %ax, 0x810d0b(%rip)     # 0x82078e
callq 0xcc0c
orb $0x20, 0x810d04(%rip)   # 0x820793
movb %al, 0x810d00(%rip)     # 0x820795
movb %bl, 0x810cfb(%rip)     # 0x820796
movb %bl, 0x810cf6(%rip)     # 0x820797
movzbl %al, %ecx
xorl %eax, %eax
callq *(%r14,%rcx,8)
movzbl 0x810ce4(%rip), %ecx    # 0x820795
xorl %eax, %eax
callq *(%r15,%rcx,8)
movzbl 0x810cd7(%rip), %ecx    # 0x820795
movl 0x810cc0(%rip), %eax    # 0x820784
addl (%r12,%rcx,4), %eax
movl %eax, 0x810cb6(%rip)    # 0x820784
cmpb %bl, 0x810cc2(%rip)     # 0x820796
je 0xfae7
cmpb $0x0, 0x810cba(%rip)    # 0x820797
je 0xfae7
incl %eax
movl %eax, 0x810c9d(%rip)    # 0x820784
incl 0x810c93(%rip)          # 0x820780
cmpb $0x0, 0x810ca0(%rip)    # 0x820794
je 0xfb04
xorl %eax, %eax
callq *0x810c9a(%rip)         # 0x820798
movl 0x810c80(%rip), %eax    # 0x820784
movl 0x810c7e(%rip), %edi    # 0x820788
jmp 0xfa6a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x810c6b(%rip), %edi    # 0x82078e
leal 0x1(%rdi), %eax
movw %ax, 0x810c61(%rip)     # 0x82078e
callq 0xcc0c
movb %al, 0x810c5d(%rip)     # 0x820795
orb $0x20, 0x810c54(%rip)   # 0x820793
xorl %ebx, %ebx
movb %bl, 0x810c4f(%rip)     # 0x820796
movb %bl, 0x810c4a(%rip)     # 0x820797
movzbl %al, %ecx
leaq 0xa259(%rip), %rdx      # 0x19db0
xorl %eax, %eax
callq *(%rdx,%rcx,8)
movzbl 0x810c32(%rip), %ecx    # 0x820795
leaq 0xaa46(%rip), %rdx      # 0x1a5b0
xorl %eax, %eax
callq *(%rdx,%rcx,8)
movzbl 0x810c1f(%rip), %ecx    # 0x820795
leaq 0x50a3(%rip), %rdx      # 0x14c20
movl 0x810c01(%rip), %eax    # 0x820784
addl (%rdx,%rcx,4), %eax
movl %eax, 0x810bf8(%rip)    # 0x820784
cmpb %bl, 0x810c04(%rip)     # 0x820796
je 0xfba5
cmpb $0x0, 0x810bfc(%rip)    # 0x820797
je 0xfba5
incl %eax
movl %eax, 0x810bdf(%rip)    # 0x820784
incl 0x810bd5(%rip)          # 0x820780
movl %eax, 0x810bd7(%rip)    # 0x820788
cmpb $0x0, 0x810bdc(%rip)    # 0x820794
je 0xfbc3
xorl %eax, %eax
popq %rbx
jmpq *0x810bd5(%rip)         # 0x820798
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x810ab3(%rip), %edi    # 0x82078e
leal 0x1(%rdi), %eax
movw %ax, 0x810aa9(%rip)     # 0x82078e
callq 0xcc0c
movl %eax, %ebx
movzbl %al, %edi
incb %bl
callq 0xcc0c
movzbl %al, %ebp
movzbl %bl, %edi
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
movl %eax, %ecx
orl %ebp, %ecx
movzbl 0x810a80(%rip), %edx    # 0x820792
addl %ecx, %edx
movw %dx, 0x810a87(%rip)     # 0x8207a2
andl $0xff00, %edx           # imm = 0xFF00
cmpw %dx, %ax
je 0xfd2d
movb $0x1, 0x810a6a(%rip)    # 0x820797
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x810a29(%rip), %edi    # 0x82078e
callq 0xcc0c
movzbl %al, %ebx
movzwl 0x810a1a(%rip), %eax    # 0x82078e
incl %eax
movzwl %ax, %edi
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
movl %eax, %ecx
orl %ebx, %ecx
movzbl 0x810a03(%rip), %edx    # 0x820792
addl %ecx, %edx
movw %dx, 0x810a0a(%rip)     # 0x8207a2
andl $0xff00, %edx           # imm = 0xFF00
cmpw %dx, %ax
je 0xfdaa
movb $0x1, 0x8109ed(%rip)    # 0x820797
addw $0x2, 0x8109dc(%rip)    # 0x82078e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x8109d2(%rip), %edi    # 0x82078e
callq 0xcc0c
movzbl %al, %ebx
movzwl 0x8109c3(%rip), %eax    # 0x82078e
incl %eax
movzwl %ax, %edi
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
movl %eax, %ecx
orl %ebx, %ecx
movzbl 0x8109ab(%rip), %edx    # 0x820791
addl %ecx, %edx
movw %dx, 0x8109b3(%rip)     # 0x8207a2
andl $0xff00, %edx           # imm = 0xFF00
cmpw %dx, %ax
je 0xfe01
movb $0x1, 0x810996(%rip)    # 0x820797
addw $0x2, 0x810985(%rip)    # 0x82078e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x810978(%rip), %edi    # 0x82078e
callq 0xcc0c
movzbl %al, %ebx
movzwl 0x810969(%rip), %edi    # 0x82078e
incl %edi
movl $0xffff, %ebp           # imm = 0xFFFF
andl %ebp, %edi
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
leal (%rax,%rbx), %edi
incl %ebx
movzbl %bl, %ebx
orl %eax, %ebx
andl %ebp, %edi
callq 0xcc0c
movzbl %al, %r14d
andl %ebp, %ebx
movl %ebx, %edi
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
orl %r14d, %eax
movw %ax, 0x81093b(%rip)     # 0x8207a2
addw $0x2, 0x81091f(%rip)    # 0x82078e
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x8108e9(%rip), %eax    # 0x82078e
incl %eax
movw %ax, 0x8108e0(%rip)     # 0x82078e
movzwl %ax, %edi
callq 0xf8a0
movzbl 0x8108d6(%rip), %edi    # 0x820793
orl $0x10, %edi
callq 0xf8e0
orb $0x4, 0x8108c7(%rip)    # 0x820793
movl $0xfffe, %edi           # imm = 0xFFFE
callq 0xcc0c
movzbl %al, %ebx
movl $0xffff, %edi           # imm = 0xFFFF
callq 0xcc0c
movzbl %al, %eax
shll $0x8, %eax
orl %ebx, %eax
movw %ax, 0x81089c(%rip)     # 0x82078e
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rax
movb $0x1, 0x81089a(%rip)    # 0x820796
callq 0xff48
movzbl 0x810888(%rip), %ecx    # 0x820790
orl %eax, %ecx
cmpw $0x7f, %cx
seta %dl
movw %ax, 0x81088e(%rip)     # 0x8207a6
movw %cx, 0x810889(%rip)     # 0x8207a8
testw %cx, %cx
sete %al
movb 0x810867(%rip), %sil    # 0x820793
andb $0x7d, %sil
addb %al, %al
orb %sil, %al
shlb $0x7, %dl
orb %al, %dl
movb %dl, 0x810853(%rip)     # 0x820793
movb %cl, 0x81084a(%rip)     # 0x820790
popq %rax
retq
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/fake6502.c
// Function: asl
static void asl() {
    value = getvalue();
    result = value << 1;

    carrycalc(result);
    zerocalc(result);
    signcalc(result);
   
    putvalue(result);
}

// Assembly:
pushq %rax
callq 0xff48
movw %ax, 0x8107d0(%rip)     # 0x8207a6
leal (%rax,%rax), %ecx
movw %cx, 0x8107c8(%rip)     # 0x8207a8
cmpw $0x7f, %ax
seta %dl
movb 0x8107a5(%rip), %sil    # 0x820793
andb $0x7c, %sil
testb $0x7f, %al
sete %dil
addb %dil, %dil
orb %dl, %dil
addb %al, %al
andb $-0x80, %al
orb %dil, %al
orb %sil, %al
movb %al, 0x810785(%rip)     # 0x820793
movzwl %cx, %edi
popq %rax
jmp 0x10014
// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/fake6502.c
// Function: bpl
static void bpl() {
    if ((status & FLAG_SIGN) == 0) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

// Assembly:
cmpb $0x0, 0x810734(%rip)    # 0x820793
js 0x10098
movzwl 0x810726(%rip), %eax    # 0x82078e
movw %ax, 0x810731(%rip)     # 0x8207a0
movzwl 0x81072e(%rip), %ecx    # 0x8207a4
addw %ax, %cx
movw %cx, 0x81070e(%rip)     # 0x82078e
xorl %ecx, %eax
cmpw $0x100, %ax             # imm = 0x100
movl 0x8106f8(%rip), %eax    # 0x820784
sbbl $0x0, %eax
addl $0x2, %eax
movl %eax, 0x8106ec(%rip)    # 0x820784
retq