// File: /workspace/github_c_makefile_star2_O2/ShinyaKato[P]skcc/preprocess.c
// Function: concat_macro_token
struct pp_list *concat_macro_token(struct pp_list *list) {
  struct pp_list *result = allocate_pp_list();

  for(struct pp_node *node = list->head; node != NULL; node = node->next) {
    struct pp_node *left = node;
    struct pp_node *middle = left->next;
    if(middle != NULL && middle->token->type == PP_SPACE) {
      middle = middle->next;
    }
    struct pp_node *right = middle != NULL ? middle->next : NULL;
    if(right != NULL && right->token->type == PP_SPACE) {
      right = right->next;
    }

    if(middle != NULL && right != NULL && middle->token->type == PP_CONCAT && !middle->token->concat) {
      struct pp_token *l = left->token;
      struct pp_token *r = right->token;

      struct string *str = allocate_string();
      concat_string(str, l->text);
      concat_string(str, r->text);

      struct pp_token_lexer lexer;
      lexer.queue = (struct utf8c *) malloc(sizeof(struct utf8c) * (str->size + 1));
      lexer.queue_head = 0;
      lexer.queue_size = 0;
      lexer.queue_allocate_size = str->size + 1;
      lexer.context = CTX_NORMAL;

      for(int i = 0; i < str->size;) {
        struct utf8c uc;
        uc.bytes = count_bytes(str->head[i]);
        for(int j = 0; j < uc.bytes; j++) {
          uc.sequence[j] = str->head[i++];
        }
        uc.sequence[uc.bytes] = '\0';
        lexer.queue[lexer.queue_size++] = uc;
      }
      lexer.queue[lexer.queue_size++] = ueof;

      struct pp_token *new_token = next_pp_token(&lexer);
      new_token->concat = 1;
      if(lexer.queue_size > 1) {
        error("invalid token concatnation: %s ## %s\n", l->text->head, r->text->head);
      }
      append_pp_list(result, new_token);

      node = right;
    } else {
      append_pp_list(result, node->token);
    }
  }

  // remove place marker
  for(struct pp_node **node = &(result->head); *node != NULL;) {
    if((*node)->token->type == PP_PLACE_MARKER) {
      *node = (*node)->next;
    } else {
      node = &((*node)->next);
    }
  }

  return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r13
callq 0x325c
movq %rax, %rbx
movq (%r13), %r13
testq %r13, %r13
je 0x3f70
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x3dfe
movq (%rax), %rcx
cmpl $0x3c, (%rcx)
jne 0x3dd6
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x3dfe
movq 0x8(%rax), %r15
testq %r15, %r15
je 0x3dfe
movq (%r15), %rcx
cmpl $0x3c, (%rcx)
jne 0x3df0
movq 0x8(%r15), %r15
testq %r15, %r15
je 0x3dfe
movq (%rax), %rax
cmpl $0x3a, (%rax)
jne 0x3dfe
cmpl $0x0, 0x18(%rax)
je 0x3e10
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x32b4
addq $0x8, %r13
jmp 0x3daf
movq (%r13), %r12
movq (%r15), %r14
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x1904
movq %rax, %r13
movq %r12, 0x18(%rsp)
movq 0x10(%r12), %rsi
movq %rax, %rdi
callq 0x19da
movq %r14, 0x20(%rsp)
movq 0x10(%r14), %rsi
movq %r13, %rdi
callq 0x19da
movslq 0x8(%r13), %r12
movq %r12, %r14
incq %r14
imulq $0xc, %r14, %rdi
callq 0x10b0
movq %rax, 0x50(%rsp)
andq $0x0, 0x58(%rsp)
movl %r14d, 0x60(%rsp)
movl $0x3, 0x64(%rsp)
cmpl %r12d, %ebp
jge 0x3ee6
movq (%r13), %rax
movslq %ebp, %r12
movzbl (%rax,%r12), %edi
callq 0x1408
movl %eax, 0xc(%rsp)
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x3eb1
movq (%r13), %rsi
addq %r12, %rsi
movb (%rdx,%rsi), %sil
movb %sil, 0x10(%rsp,%rdx)
incq %rdx
jmp 0x3e97
addl %edx, %ebp
cltq
movb $0x0, 0x10(%rsp,%rax)
movq 0x50(%rsp), %rax
movslq 0x5c(%rsp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x5c(%rsp)
imulq $0xc, %rcx, %rcx
movl 0x14(%rsp), %edx
movl %edx, 0x8(%rax,%rcx)
movq 0xc(%rsp), %rdx
movq %rdx, (%rax,%rcx)
movl 0x8(%r13), %r12d
jmp 0x3e71
movq 0x50(%rsp), %rax
movslq 0x5c(%rsp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x5c(%rsp)
imulq $0xc, %rcx, %rcx
leaq 0x618e(%rip), %rsi      # 0xa090
movl 0x8(%rsi), %edx
movl %edx, 0x8(%rax,%rcx)
movq (%rsi), %rdx
movq %rdx, (%rax,%rcx)
leaq 0x28(%rsp), %rdi
callq 0x202c
movq %rax, %r13
movl $0x1, 0x18(%rax)
cmpl $0x1, 0x5c(%rsp)
jle 0x3f5d
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %r8
leaq 0x2fc6(%rip), %rdi      # 0x6f10
movl $0x153, %esi            # imm = 0x153
leaq 0x3026(%rip), %rdx      # 0x6f7c
xorl %eax, %eax
callq 0x1252
movq %rbx, %rdi
movq %r13, %rsi
callq 0x32b4
movq %r15, %r13
jmp 0x3e0a
movq %rbx, %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x3f94
movq (%rcx), %rdx
addq $0x8, %rcx
cmpl $0x3f, (%rdx)
jne 0x3f8f
movq (%rcx), %rcx
movq %rcx, (%rax)
jmp 0x3f76
movq %rcx, %rax
jmp 0x3f73
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq