// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_3/exercise_3_02/escape.c
// Function: escape
void escape(char dest[], char src[])
{
  int i, j;
  for (i = j = 0; src[i] != '\0'; ++i, ++j)
  {
    switch (src[i])
    {
    case '\a':
      dest[j++] = '\\';
      dest[j] = 'a';
      break;

    case '\b':
      dest[j++] = '\\';
      dest[j] = 'b';
      break;

    case '\f':
      dest[j++] = '\\';
      dest[j] = 'f';
      break;

    case '\n':
      dest[j++] = '\\';
      dest[j] = 'n';
      break;

    case '\r':
      dest[j++] = '\\';
      dest[j] = 'r';
      break;

    case '\t':
      dest[j++] = '\\';
      dest[j] = 't';
      break;

    case '\v':
      dest[j++] = '\\';
      dest[j] = 'v';
      break;

    case '\\':
      dest[j++] = '\\';
      dest[j] = '\\';
      break;

    case '\?':
      dest[j++] = '\\';
      dest[j] = '?';
      break;

    case '\'':
      dest[j++] = '\\';
      dest[j] = '\'';
      break;

    case '\"':
      dest[j++] = '\\';
      dest[j] = '"';
      break;

    default:
      dest[j] = src[i];
      break;
    }
  }

  if (src[i] == '\0')
  {
    dest[j] = src[i];
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x14c4
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl $-0x7, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x55, %eax
ja 0x1495
movq -0x20(%rbp), %rax
leaq 0xd1c(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x61, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x62, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x66, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x6e, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x72, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x74, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x76, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x5c, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x3f, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x27, (%rax,%rcx)
jmp 0x14ab
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movb $0x5c, (%rax,%rcx)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x22, (%rax,%rcx)
jmp 0x14ab
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x14ad
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x12aa
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x14eb
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb %dl, (%rax,%rcx)
popq %rbp
retq
nopl (%rax)