// File: /workspace/github_c_makefile_star2_O0/ShinyaKato[P]skcc/preprocess.c
// Function: function_macro_invocation
struct pp_list *function_macro_invocation(struct preprocessor *pp, struct macro_entry *macro, struct pp_list **args, int args_size) {
  macro->expanded = 1;

  struct pp_list *replaced_args[MACRO_PARAMS_LIMIT];
  for(int i = 0; i < args_size; i++) {
    if(args[i]->head != NULL) {
      replaced_args[i] = scan_macro(pp, args[i]);
    } else {
      struct pp_token *place_marker = allocate_pp_token();
      place_marker->type = PP_PLACE_MARKER;
      place_marker->name = pp_token_name[PP_PLACE_MARKER];

      replaced_args[i] = allocate_pp_list();
      append_pp_list(replaced_args[i], place_marker);

      append_pp_list(args[i], place_marker);
    }
  }

  struct pp_list *list = allocate_pp_list();
  for(struct pp_node *node = macro->replacement_list->head; node != NULL; node = node->next) {
    if(node->token->type == PP_SHARP) {
      node = node->next;
      if(node->token->type == PP_SPACE) {
        node = node->next;
      }

      int matched;
      for(int i = 0; i < args_size; i++) {
        if(node->token->type == PP_IDENT && strcmp(node->token->text->head, macro->parameters[i]->head) == 0) {
          matched = i;
        }
      }

      struct pp_token *new_token = allocate_pp_token();
      new_token->type = PP_STR;
      new_token->name = pp_token_name[PP_STR];
      append_string(new_token->text, '"');
      for(struct pp_node *arg_node = args[matched]->head; arg_node != NULL; arg_node = arg_node->next) {
        for(int i = 0; i < arg_node->token->text->size; i++) {
          unsigned char c = arg_node->token->text->head[i];
          if(c == '\\' || c == '"') {
            append_string(new_token->text, '\\');
          }
          append_string(new_token->text, c);
        }
      }
      append_string(new_token->text, '"');
      append_pp_list(list, new_token);

      continue;
    }

    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 && middle->token->type == PP_CONCAT && !middle->token->concat) {
      int left_replaced = 0;
      for(int i = 0; i < args_size; i++) {
        if(left->token->type == PP_IDENT && strcmp(left->token->text->head, macro->parameters[i]->head) == 0) {
          for(struct pp_node *arg_node = args[i]->head; arg_node != NULL; arg_node = arg_node->next) {
            append_pp_list(list, arg_node->token);
          }
          left_replaced = 1;
          break;
        }
      }
      if(!left_replaced) {
        append_pp_list(list, left->token);
      }
      if(left->next != middle) {
        append_pp_list(list, left->next->token);
      }
      append_pp_list(list, middle->token);
      if(middle->next != right) {
        append_pp_list(list, middle->next->token);
      }
      int right_replaced = 0;
      for(int i = 0; i < args_size; i++) {
        if(right->token->type == PP_IDENT && strcmp(right->token->text->head, macro->parameters[i]->head) == 0) {
          for(struct pp_node *arg_node = args[i]->head; arg_node != NULL; arg_node = arg_node->next) {
            append_pp_list(list, arg_node->token);
          }
          right_replaced = 1;
          break;
        }
      }
      if(!right_replaced) {
        append_pp_list(list, right->token);
      }
      node = right;
      continue;
    }

    int replaced = 0;
    for(int i = 0; i < args_size; i++) {
      if(node->token->type == PP_IDENT && strcmp(node->token->text->head, macro->parameters[i]->head) == 0) {
        for(struct pp_node *arg_node = replaced_args[i]->head; arg_node != NULL; arg_node = arg_node->next) {
          append_pp_list(list, arg_node->token);
        }
        replaced = 1;
        break;
      }
    }

    if(!replaced) {
      append_pp_list(list, node->token);
    }
  }

  struct pp_list *concat_list = concat_macro_token(list);
  struct pp_list *result = scan_macro(pp, concat_list);

  macro->expanded = 0;
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl $0x1, 0x420(%rax)
movl $0x0, -0x424(%rbp)
movl -0x424(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x62fc
movq -0x18(%rbp), %rax
movslq -0x424(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq $0x0, (%rax)
je 0x6265
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x424(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x5c00
movq %rax, %rcx
movslq -0x424(%rbp), %rax
movq %rcx, -0x420(%rbp,%rax,8)
jmp 0x62e6
movb $0x0, %al
callq 0x2800
movq %rax, -0x430(%rbp)
movq -0x430(%rbp), %rax
movl $0x3f, (%rax)
movq -0x430(%rbp), %rax
leaq 0x3e22(%rip), %rcx      # 0xa0b0
addq $0x7e0, %rcx            # imm = 0x7E0
movq %rcx, 0x8(%rax)
callq 0x53b0
movq %rax, %rcx
movslq -0x424(%rbp), %rax
movq %rcx, -0x420(%rbp,%rax,8)
movslq -0x424(%rbp), %rax
movq -0x420(%rbp,%rax,8), %rdi
movq -0x430(%rbp), %rsi
callq 0x5460
movq -0x18(%rbp), %rax
movslq -0x424(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x430(%rbp), %rsi
callq 0x5460
jmp 0x62e8
movl -0x424(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x424(%rbp)
jmp 0x6212
callq 0x53b0
movq %rax, -0x438(%rbp)
movq -0x10(%rbp), %rax
movq 0x418(%rax), %rax
movq (%rax), %rax
movq %rax, -0x440(%rbp)
cmpq $0x0, -0x440(%rbp)
je 0x698a
movq -0x440(%rbp), %rax
movq (%rax), %rax
cmpl $0x39, (%rax)
jne 0x6534
movq -0x440(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x440(%rbp)
movq -0x440(%rbp), %rax
movq (%rax), %rax
cmpl $0x3c, (%rax)
jne 0x6371
movq -0x440(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x440(%rbp)
movl $0x0, -0x448(%rbp)
movl -0x448(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x63e2
movq -0x440(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x63cf
movq -0x440(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x448(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rax
movq (%rax), %rsi
callq 0x1070
cmpl $0x0, %eax
jne 0x63cf
movl -0x448(%rbp), %eax
movl %eax, -0x444(%rbp)
jmp 0x63d1
movl -0x448(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x448(%rbp)
jmp 0x637b
movb $0x0, %al
callq 0x2800
movq %rax, -0x450(%rbp)
movq -0x450(%rbp), %rax
movl $0x4, (%rax)
movq -0x450(%rbp), %rax
leaq 0x3ca5(%rip), %rcx      # 0xa0b0
addq $0x80, %rcx
movq %rcx, 0x8(%rax)
movq -0x450(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x22, %esi
callq 0x20c0
movq -0x18(%rbp), %rax
movslq -0x444(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x458(%rbp)
cmpq $0x0, -0x458(%rbp)
je 0x6507
movl $0x0, -0x45c(%rbp)
movl -0x45c(%rbp), %eax
movq -0x458(%rbp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x64ee
movq -0x458(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movslq -0x45c(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x45d(%rbp)
movzbl -0x45d(%rbp), %eax
cmpl $0x5c, %eax
je 0x64ae
movzbl -0x45d(%rbp), %eax
cmpl $0x22, %eax
jne 0x64c3
movq -0x450(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x5c, %esi
callq 0x20c0
movq -0x450(%rbp), %rax
movq 0x10(%rax), %rdi
movzbl -0x45d(%rbp), %esi
callq 0x20c0
movl -0x45c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x45c(%rbp)
jmp 0x645c
jmp 0x64f0
movq -0x458(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x458(%rbp)
jmp 0x6444
movq -0x450(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x22, %esi
callq 0x20c0
movq -0x438(%rbp), %rdi
movq -0x450(%rbp), %rsi
callq 0x5460
jmp 0x6973
movq -0x440(%rbp), %rax
movq %rax, -0x468(%rbp)
movq -0x468(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x470(%rbp)
cmpq $0x0, -0x470(%rbp)
je 0x657f
movq -0x470(%rbp), %rax
movq (%rax), %rax
cmpl $0x3c, (%rax)
jne 0x657f
movq -0x470(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x470(%rbp)
cmpq $0x0, -0x470(%rbp)
je 0x659d
movq -0x470(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x4c0(%rbp)
jmp 0x65a8
xorl %eax, %eax
movq %rax, -0x4c0(%rbp)
jmp 0x65a8
movq -0x4c0(%rbp), %rax
movq %rax, -0x478(%rbp)
cmpq $0x0, -0x478(%rbp)
je 0x65e1
movq -0x478(%rbp), %rax
movq (%rax), %rax
cmpl $0x3c, (%rax)
jne 0x65e1
movq -0x478(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x478(%rbp)
cmpq $0x0, -0x470(%rbp)
je 0x687f
movq -0x470(%rbp), %rax
movq (%rax), %rax
cmpl $0x3a, (%rax)
jne 0x687f
movq -0x470(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x18(%rax)
jne 0x687f
movl $0x0, -0x47c(%rbp)
movl $0x0, -0x480(%rbp)
movl -0x480(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x66e9
movq -0x468(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x66d3
movq -0x468(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x480(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rax
movq (%rax), %rsi
callq 0x1070
cmpl $0x0, %eax
jne 0x66d3
movq -0x18(%rbp), %rax
movslq -0x480(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x488(%rbp)
cmpq $0x0, -0x488(%rbp)
je 0x66c7
movq -0x438(%rbp), %rdi
movq -0x488(%rbp), %rax
movq (%rax), %rsi
callq 0x5460
movq -0x488(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x488(%rbp)
jmp 0x6693
movl $0x1, -0x47c(%rbp)
jmp 0x66e9
jmp 0x66d5
movl -0x480(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x480(%rbp)
jmp 0x662a
cmpl $0x0, -0x47c(%rbp)
jne 0x6708
movq -0x438(%rbp), %rdi
movq -0x468(%rbp), %rax
movq (%rax), %rsi
callq 0x5460
movq -0x468(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x470(%rbp), %rax
je 0x6736
movq -0x438(%rbp), %rdi
movq -0x468(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rsi
callq 0x5460
movq -0x438(%rbp), %rdi
movq -0x470(%rbp), %rax
movq (%rax), %rsi
callq 0x5460
movq -0x470(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x478(%rbp), %rax
je 0x677a
movq -0x438(%rbp), %rdi
movq -0x470(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rsi
callq 0x5460
movl $0x0, -0x48c(%rbp)
movl $0x0, -0x490(%rbp)
movl -0x490(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x684d
movq -0x478(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x6837
movq -0x478(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x490(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rax
movq (%rax), %rsi
callq 0x1070
cmpl $0x0, %eax
jne 0x6837
movq -0x18(%rbp), %rax
movslq -0x490(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x498(%rbp)
cmpq $0x0, -0x498(%rbp)
je 0x682b
movq -0x438(%rbp), %rdi
movq -0x498(%rbp), %rax
movq (%rax), %rsi
callq 0x5460
movq -0x498(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x498(%rbp)
jmp 0x67f7
movl $0x1, -0x48c(%rbp)
jmp 0x684d
jmp 0x6839
movl -0x490(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x490(%rbp)
jmp 0x678e
cmpl $0x0, -0x48c(%rbp)
jne 0x686c
movq -0x438(%rbp), %rdi
movq -0x478(%rbp), %rax
movq (%rax), %rsi
callq 0x5460
movq -0x478(%rbp), %rax
movq %rax, -0x440(%rbp)
jmp 0x6973
movl $0x0, -0x49c(%rbp)
movl $0x0, -0x4a0(%rbp)
movl -0x4a0(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x6952
movq -0x440(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x693c
movq -0x440(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x4a0(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rax
movq (%rax), %rsi
callq 0x1070
cmpl $0x0, %eax
jne 0x693c
movslq -0x4a0(%rbp), %rax
movq -0x420(%rbp,%rax,8), %rax
movq (%rax), %rax
movq %rax, -0x4a8(%rbp)
cmpq $0x0, -0x4a8(%rbp)
je 0x6930
movq -0x438(%rbp), %rdi
movq -0x4a8(%rbp), %rax
movq (%rax), %rsi
callq 0x5460
movq -0x4a8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x4a8(%rbp)
jmp 0x68fc
movl $0x1, -0x49c(%rbp)
jmp 0x6952
jmp 0x693e
movl -0x4a0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4a0(%rbp)
jmp 0x6893
cmpl $0x0, -0x49c(%rbp)
jne 0x6971
movq -0x438(%rbp), %rdi
movq -0x440(%rbp), %rax
movq (%rax), %rsi
callq 0x5460
jmp 0x6973
movq -0x440(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x440(%rbp)
jmp 0x631d
movq -0x438(%rbp), %rdi
callq 0x69e0
movq %rax, -0x4b0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x4b0(%rbp), %rsi
callq 0x5c00
movq %rax, -0x4b8(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x420(%rax)
movq -0x4b8(%rbp), %rax
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbp
retq
nopw %cs:(%rax,%rax)