// File: /workspace/github_c_makefile_star2_O1/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, %r14
callq 0x3ad0
movq %rax, %rbx
movq (%r14), %r12
testq %r12, %r12
je 0x4c84
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x4a89
movq (%rax), %rcx
cmpl $0x3c, (%rcx)
jne 0x4a8b
movq 0x8(%rax), %rax
jmp 0x4a8b
xorl %eax, %eax
testq %rax, %rax
je 0x4a96
movq 0x8(%rax), %r15
jmp 0x4a99
xorl %r15d, %r15d
testq %r15, %r15
je 0x4aac
movq (%r15), %rcx
cmpl $0x3c, (%rcx)
jne 0x4aaf
movq 0x8(%r15), %r15
jmp 0x4aaf
xorl %r15d, %r15d
testq %rax, %rax
je 0x4ac7
testq %r15, %r15
je 0x4ac7
movq (%rax), %rax
cmpl $0x3a, (%rax)
jne 0x4ac7
cmpl $0x0, 0x18(%rax)
je 0x4b00
movq (%r12), %r14
movl $0x18, %edi
callq 0x10b0
movq %r14, (%rax)
leaq 0x8(%rax), %rcx
movq $0x0, 0x8(%rax)
movl $0x0, 0x10(%rax)
movq 0x8(%rbx), %rdx
movq %rax, (%rdx)
movq %rcx, 0x8(%rbx)
movq 0x8(%r12), %r12
jmp 0x4a68
movq (%r12), %r12
movq (%r15), %r14
xorl %eax, %eax
callq 0x19e8
movq %rax, %rbp
movq %r12, 0x18(%rsp)
movq 0x10(%r12), %rsi
movq %rax, %rdi
callq 0x1ac2
movq %r14, 0x20(%rsp)
movq 0x10(%r14), %rsi
movq %rbp, %rdi
callq 0x1ac2
movslq 0x8(%rbp), %r14
leaq 0x4(,%r14,4), %rax
incq %r14
leaq (%rax,%rax,2), %rdi
callq 0x10b0
movq %rax, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
movl %r14d, 0x60(%rsp)
movl $0x3, 0x64(%rsp)
cmpl $0x0, 0x8(%rbp)
jle 0x4bda
xorl %r13d, %r13d
movq (%rbp), %rax
movslq %r13d, %r14
movzbl (%rax,%r14), %edi
callq 0x14a0
movl %eax, %r12d
movl %eax, 0xc(%rsp)
testl %eax, %eax
jle 0x4ba6
movq (%rbp), %rsi
addq %r14, %rsi
movl %r12d, %edx
leaq 0x10(%rsp), %rdi
callq 0x10a0
addl %r12d, %r14d
movl %r14d, %r13d
movslq %r12d, %rax
movb $0x0, 0x10(%rsp,%rax)
movq 0x50(%rsp), %rax
movslq 0x5c(%rsp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x5c(%rsp)
leaq (%rcx,%rcx,2), %rcx
movl 0x14(%rsp), %edx
movl %edx, 0x8(%rax,%rcx,4)
movq 0xc(%rsp), %rdx
movq %rdx, (%rax,%rcx,4)
cmpl 0x8(%rbp), %r13d
jl 0x4b70
movq 0x50(%rsp), %rax
movslq 0x5c(%rsp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x5c(%rsp)
leaq (%rcx,%rcx,2), %rcx
leaq 0x64a2(%rip), %rsi      # 0xb098
movl 0x8(%rsi), %edx
movl %edx, 0x8(%rax,%rcx,4)
movq (%rsi), %rdx
movq %rdx, (%rax,%rcx,4)
leaq 0x28(%rsp), %rdi
callq 0x21c1
movq %rax, %rbp
movl $0x1, 0x18(%rax)
cmpl $0x1, 0x5c(%rsp)
jle 0x4c51
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %r8
leaq 0x31f2(%rip), %rdi      # 0x7e30
movl $0x153, %esi            # imm = 0x153
leaq 0x3252(%rip), %rdx      # 0x7e9c
xorl %eax, %eax
callq 0x140c
movl $0x18, %edi
callq 0x10b0
movq %rbp, (%rax)
leaq 0x8(%rax), %rcx
movq $0x0, 0x8(%rax)
movl $0x0, 0x10(%rax)
movq 0x8(%rbx), %rdx
movq %rax, (%rdx)
movq %rcx, 0x8(%rbx)
movq %r15, %r12
jmp 0x4af6
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x4cae
movq %rbx, %rax
movq (%rcx), %rdx
addq $0x8, %rcx
cmpl $0x3f, (%rdx)
jne 0x4ca3
movq (%rcx), %rcx
movq %rcx, (%rax)
jmp 0x4ca6
movq %rcx, %rax
movq (%rax), %rcx
testq %rcx, %rcx
jne 0x4c8f
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq