// File: /workspace/github_c_makefile_star2_O0/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_1/exercise_1_23/c_remove_comments.c
// Function: remove_comments
void remove_comments(char str[], char no_com_str[])
{
  int in_quote = FALSE;
  int line_comment = FALSE;
  int block_comment = FALSE;

  int i = 0, j = 0;
  while (str[i] != '\0')
  {
    if (!block_comment)
    {
      if (!in_quote && str[i] == '"')
    {
      in_quote = TRUE;
    }
    else if (in_quote && str[i] == '"')
    {
      in_quote = FALSE;
    }
    }

    if (!in_quote)
    {
      if (str[i] == '/' && str[i + 1] == '*' && !line_comment)
      {
        block_comment = TRUE;
      }

      if (str[i] == '*' && str[i + 1] == '/')
      {
        block_comment = FALSE;
        i += 2;
      }

      if (str[i] == '/' && str[i + 1] == '/')
      {
        line_comment = TRUE;
      }

      if (str[i] == '\n')
      {
        line_comment = FALSE;
      }

      if (line_comment || block_comment)
      {
        ++i;
      }
      else if (!line_comment || !block_comment)
      {
        no_com_str[j++] = str[i++];
      }
    }
    else
    {
      no_com_str[j++] = str[i++];
    }
  }

  no_com_str[j] = '\0';
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x13f7
cmpl $0x0, -0x1c(%rbp)
jne 0x12bc
cmpl $0x0, -0x14(%rbp)
jne 0x129a
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0x129a
movl $0x1, -0x14(%rbp)
jmp 0x12ba
cmpl $0x0, -0x14(%rbp)
je 0x12b8
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0x12b8
movl $0x0, -0x14(%rbp)
jmp 0x12ba
jmp 0x12bc
cmpl $0x0, -0x14(%rbp)
jne 0x13c8
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x12fa
movq -0x8(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2a, %eax
jne 0x12fa
cmpl $0x0, -0x18(%rbp)
jne 0x12fa
movl $0x1, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2a, %eax
jne 0x1331
movq -0x8(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x1331
movl $0x0, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x135f
movq -0x8(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x135f
movl $0x1, -0x18(%rbp)
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x1377
movl $0x0, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x1383
cmpl $0x0, -0x1c(%rbp)
je 0x138e
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x13c6
cmpl $0x0, -0x18(%rbp)
je 0x139a
cmpl $0x0, -0x1c(%rbp)
jne 0x13c4
movq -0x8(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x20(%rbp)
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x24(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x13c6
jmp 0x13f2
movq -0x8(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x20(%rbp)
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x24(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x125f
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb $0x0, (%rax,%rcx)
popq %rbp
retq