// File: tomfunkhouser[P]gaps/pkgs/jpeg/jerror.c
// Function: format_message
METHODDEF(void)
format_message (j_common_ptr cinfo, char * buffer)
{
  struct jpeg_error_mgr * err = cinfo->err;
  int msg_code = err->msg_code;
  const char * msgtext = NULL;
  const char * msgptr;
  char ch;
  jboolean isstring;

  /* Look up message string in proper table */
  if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
    msgtext = err->jpeg_message_table[msg_code];
  } else if (err->addon_message_table != NULL &&
	     msg_code >= err->first_addon_message &&
	     msg_code <= err->last_addon_message) {
    msgtext = err->addon_message_table[msg_code - err->first_addon_message];
  }

  /* Defend against bogus message number */
  if (msgtext == NULL) {
    err->msg_parm.i[0] = msg_code;
    msgtext = err->jpeg_message_table[0];
  }

  /* Check for string parameter, as indicated by %s in the message text */
  isstring = FALSE;
  msgptr = msgtext;
  while ((ch = *msgptr++) != '\0') {
    if (ch == '%') {
      if (*msgptr == 's') isstring = TRUE;
      break;
    }
  }

  /* Format the message into the passed buffer */
  if (isstring)
    sprintf(buffer, msgtext, err->msg_parm.s);
  else
    sprintf(buffer, msgtext,
	    err->msg_parm.i[0], err->msg_parm.i[1],
	    err->msg_parm.i[2], err->msg_parm.i[3],
	    err->msg_parm.i[4], err->msg_parm.i[5],
	    err->msg_parm.i[6], err->msg_parm.i[7]);
}

// Assembly:
pushq %rbx
subq $0x60, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x44(%rsp)
movq $0x0, 0x38(%rsp)
cmpl $0x0, 0x44(%rsp)
jle 0xf96f5
movl 0x44(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl 0x90(%rcx), %eax
jg 0xf96f5
movq 0x48(%rsp), %rax
movq 0x88(%rax), %rax
movslq 0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
jmp 0xf974f
movq 0x48(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0xf974d
movl 0x44(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl 0xa0(%rcx), %eax
jl 0xf974d
movl 0x44(%rsp), %eax
movq 0x48(%rsp), %rcx
cmpl 0xa4(%rcx), %eax
jg 0xf974d
movq 0x48(%rsp), %rax
movq 0x98(%rax), %rax
movl 0x44(%rsp), %ecx
movq 0x48(%rsp), %rdx
subl 0xa0(%rdx), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
jmp 0xf974f
cmpq $0x0, 0x38(%rsp)
jne 0xf9777
movl 0x44(%rsp), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x2c(%rax)
movq 0x48(%rsp), %rax
movq 0x88(%rax), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x28(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rsp)
movb (%rax), %al
movb %al, 0x2f(%rsp)
movsbl %al, %eax
cmpl $0x0, %eax
je 0xf97cb
movsbl 0x2f(%rsp), %eax
cmpl $0x25, %eax
jne 0xf97c9
movq 0x30(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x73, %eax
jne 0xf97c7
movl $0x1, 0x28(%rsp)
jmp 0xf97cb
jmp 0xf9789
cmpl $0x0, 0x28(%rsp)
je 0xf97ee
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq $0x2c, %rdx
movb $0x0, %al
callq 0xf0f0
jmp 0xf9854
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x48(%rsp), %rax
movl 0x2c(%rax), %edx
movq 0x48(%rsp), %rax
movl 0x30(%rax), %ecx
movq 0x48(%rsp), %rax
movl 0x34(%rax), %r8d
movq 0x48(%rsp), %rax
movl 0x38(%rax), %r9d
movq 0x48(%rsp), %rax
movl 0x3c(%rax), %ebx
movq 0x48(%rsp), %rax
movl 0x40(%rax), %r11d
movq 0x48(%rsp), %rax
movl 0x44(%rax), %r10d
movq 0x48(%rsp), %rax
movl 0x48(%rax), %eax
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0xf0f0
addq $0x60, %rsp
popq %rbx
retq
nopw (%rax,%rax)