// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_3/exercise_3_03/expand.c
// Function: expand
void expand(char src[], char dest[])
{
  /**
   * a-z
   * a-b-c
   * a-c-h-v
   * a-c-b-v
   * 0-9
   * 1-5
   * a-zA-Z
   * 0-9a-zA-Z
   * -a-z
   * a-z-
   * -a-z-
   */
  int i, j = 0;
  for (i = 0; i < MAXLEN - 1 && j < MAXLEN - 1 && src[i] != EOF; ++i)
  {
    if (isalnum(src[i]) && src[i + 1] == '-' && src[i] < src[i + 2])
    {
      do
      {
        int k;
        for (k = 0; k <= (src[i + 2] - src[i]); ++k)
        {
          int temp = src[i] + k;
          if (dest[j - 1] != temp && (isdigit(temp) || isalpha(temp)))
          {
            dest[j++] = temp;
          }
        }

        i += 2;
      } while (isalnum(src[i]) && src[i + 1] == '-' && src[i] < src[i + 2]);
    }
    else
    {
      dest[j++] = src[i];
    }
  }
  dest[j] = '\0';
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
xorl %eax, %eax
cmpl $0x270f, -0x14(%rbp)    # imm = 0x270F
movb %al, -0x21(%rbp)
jge 0x128f
xorl %eax, %eax
cmpl $0x270f, -0x18(%rbp)    # imm = 0x270F
movb %al, -0x21(%rbp)
jge 0x128f
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $-0x1, %eax
setne %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x129b
jmp 0x1468
callq 0x1050
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1438
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x1438
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x8(%rbp), %rcx
movl -0x14(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jge 0x1438
jmp 0x1303
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl -0x14(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movsbl (%rcx,%rdx), %ecx
movq -0x8(%rbp), %rdx
movslq -0x14(%rbp), %rsi
movsbl (%rdx,%rsi), %edx
subl %edx, %ecx
cmpl %ecx, %eax
jg 0x13ba
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl -0x20(%rbp), %eax
je 0x13aa
callq 0x1050
movq (%rax), %rax
movslq -0x20(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x1390
callq 0x1050
movq (%rax), %rax
movslq -0x20(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x13aa
movl -0x20(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x13ac
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x130a
movl -0x14(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x14(%rbp)
callq 0x1050
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x8, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x22(%rbp)
je 0x142b
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x2d, %ecx
movb %al, -0x22(%rbp)
jne 0x142b
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x8(%rbp), %rcx
movl -0x14(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x22(%rbp)
movb -0x22(%rbp), %al
testb $0x1, %al
jne 0x1303
jmp 0x1458
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x145a
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x125e
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
addq $0x30, %rsp
popq %rbp
retq