Language: C

int main()
{
  int n,left,right,i;
  int *S;

  count = 0;

  /* 入力 */
  scanf("%d",&n);
  S = (int *)malloc(sizeof(int) * n);
  if(S == NULL) exit(0);
  for(i = 0;i < n;i++){
    scanf("%d",&S[i]);
  }

  mergeSort(S,0,n);

  for(i = 0;i < n;i++){
    printf("%d",S[i]);
    if(i != (n - 1)) printf(" ");
  }
  printf("\n");
  printf("%d\n",count);

  free(S);

  return 0;
}

/* n1,n2個の整数が格納された配列LとRを配列Aにマージ */
void merge(int *A,int left,int mid,int right)
{
  int n1,n2,i,j,k;
  int *L,*R;

  n1 = mid - left;
  n2 = right - mid;

  L = (int *)malloc(sizeof(int) * (n1 + 1));
  if(L == NULL) exit(0);
  R = (int *)malloc(sizeof(int) * (n2 + 1));
  if(R == NULL) exit(0);

  for(i = 0;i < n1;i++){
    L[i] = A[left + i];
  }
  for(i = 0;i < n2;i++){
    R[i] = A[mid + i];
  }

  /* 番兵として、どの要素よりも大きな値を末尾に配置 */
  L[n1] = 100000000;
  R[n2] = 100000000;

  /* ソートしつつ連結する */
  i = 0;
  j = 0;
  for(k = left;k < right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
      count++;
    }
    else{
      A[k] = R[j];
      j = j + 1;
      count++;
    }
  }
  free(R);
  free(L);
}

void mergeSort(int *A,int left,int right)
{
  int mid;  

  if((left + 1) < right){
    mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

  
    

Compiler output:
main.c: In function 'main':
main.c:6:3: error: 'count' undeclared (first use in this function)
    6 |   count = 0;
      |   ^~~~~
main.c:6:3: note: each undeclared identifier is reported only once for each function it appears in
main.c:9:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    9 |   scanf("%d",&n);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | int main()
main.c:9:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    9 |   scanf("%d",&n);
      |   ^~~~~
main.c:9:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:10:14: error: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
   10 |   S = (int *)malloc(sizeof(int) * n);
      |              ^~~~~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'malloc'
  +++ |+#include <stdlib.h>
    1 | int main()
main.c:10:14: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
   10 |   S = (int *)malloc(sizeof(int) * n);
      |              ^~~~~~
main.c:10:14: note: include '<stdlib.h>' or provide a declaration of 'malloc'
main.c:11:11: error: 'NULL' undeclared (first use in this function)
   11 |   if(S == NULL) exit(0);
      |           ^~~~
main.c:1:1: note: 'NULL' is defined in header '<stddef.h>'; this is probably fixable by adding '#include <stddef.h>'
  +++ |+#include <stddef.h>
    1 | int main()
main.c:11:17: error: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
   11 |   if(S == NULL) exit(0);
      |                 ^~~~
main.c:11:17: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:11:17: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
main.c:11:17: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:16:3: error: implicit declaration of function 'mergeSort' [-Wimplicit-function-declaration]
   16 |   mergeSort(S,0,n);
      |   ^~~~~~~~~
main.c:19:5: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   19 |     printf("%d",S[i]);
      |     ^~~~~~
main.c:19:5: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:19:5: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:19:5: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:22:3: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   22 |   printf("\n");
      |   ^~~~~~
main.c:22:3: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:25:3: error: implicit declaration of function 'free' [-Wimplicit-function-declaration]
   25 |   free(S);
      |   ^~~~
main.c:25:3: note: include '<stdlib.h>' or provide a declaration of 'free'
main.c:25:3: warning: incompatible implicit declaration of built-in function 'free' [-Wbuiltin-declaration-mismatch]
main.c:25:3: note: include '<stdlib.h>' or provide a declaration of 'free'
main.c: In function 'merge':
main.c:39:14: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
   39 |   L = (int *)malloc(sizeof(int) * (n1 + 1));
      |              ^~~~~~
main.c:39:14: note: include '<stdlib.h>' or provide a declaration of 'malloc'
main.c:40:11: error: 'NULL' undeclared (first use in this function)
   40 |   if(L == NULL) exit(0);
      |           ^~~~
main.c:40:11: note: 'NULL' is defined in header '<stddef.h>'; this is probably fixable by adding '#include <stddef.h>'
main.c:40:17: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
   40 |   if(L == NULL) exit(0);
      |                 ^~~~
main.c:40:17: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:42:17: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
   42 |   if(R == NULL) exit(0);
      |                 ^~~~
main.c:42:17: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:62:7: error: 'count' undeclared (first use in this function)
   62 |       count++;
      |       ^~~~~
main.c:70:3: warning: incompatible implicit declaration of built-in function 'free' [-Wbuiltin-declaration-mismatch]
   70 |   free(R);
      |   ^~~~
main.c:70:3: note: include '<stdlib.h>' or provide a declaration of 'free'
main.c: At top level:
main.c:74:6: warning: conflicting types for 'mergeSort'; have 'void(int *, int,  int)'
   74 | void mergeSort(int *A,int left,int right)
      |      ^~~~~~~~~
main.c:16:3: note: previous implicit declaration of 'mergeSort' with type 'void(int *, int,  int)'
   16 |   mergeSort(S,0,n);
      |   ^~~~~~~~~