Language: C

#include<stdio.h>
//#include<stdlib.h>
#define MAX 500000
#define INF 1000000000

void merge(int,int,int,int);
void mergesort(int,int,int);

int count;

int main()
{
  int n,i;
  int A[MAX];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  mergesort(A,0,n);

  for(i = 0;i < n;i++){
    printf("%d ",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

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);
  }
}

void merge(int *A,int left,int mid,int right)
{
  int i,k,j,n1=0,n2=0;
  int *L,*R;

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

  L = (int *)malloc(sizeof(int)*(n1+1));
  R = (int *)malloc(sizeof(int)*(n2+1));

  for(i = 0;i <= n1-1;i++){
    L[i] = A[left + i];
  }

  for(j = 0;j <= n2-1;j++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      count++;
    }
    else {
      A[k] = R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}



Compiler output:
main.c: In function 'main':
main.c:21:13: error: passing argument 1 of 'mergesort' makes integer from pointer without a cast [-Wint-conversion]
   21 |   mergesort(A,0,n);
      |             ^
      |             |
      |             int *
main.c:7:16: note: expected 'int' but argument is of type 'int *'
    7 | void mergesort(int,int,int);
      |                ^~~
main.c: At top level:
main.c:31:6: error: conflicting types for 'mergesort'; have 'void(int *, int,  int)'
   31 | void mergesort(int A[],int left,int right)
      |      ^~~~~~~~~
main.c:7:6: note: previous declaration of 'mergesort' with type 'void(int,  int,  int)'
    7 | void mergesort(int,int,int);
      |      ^~~~~~~~~
main.c: In function 'mergesort':
main.c:38:11: error: passing argument 1 of 'merge' makes integer from pointer without a cast [-Wint-conversion]
   38 |     merge(A,left,mid,right);
      |           ^
      |           |
      |           int *
main.c:6:12: note: expected 'int' but argument is of type 'int *'
    6 | void merge(int,int,int,int);
      |            ^~~
main.c: At top level:
main.c:42:6: error: conflicting types for 'merge'; have 'void(int *, int,  int,  int)'
   42 | void merge(int *A,int left,int mid,int right)
      |      ^~~~~
main.c:6:6: note: previous declaration of 'merge' with type 'void(int,  int,  int,  int)'
    6 | void merge(int,int,int,int);
      |      ^~~~~
main.c: In function 'merge':
main.c:50:14: error: implicit declaration of function 'malloc' [-Wimplicit-function-declaration]
   50 |   L = (int *)malloc(sizeof(int)*(n1+1));
      |              ^~~~~~
main.c:2:1: note: include '<stdlib.h>' or provide a declaration of 'malloc'
    1 | #include<stdio.h>
  +++ |+#include <stdlib.h>
    2 | //#include<stdlib.h>
main.c:50:14: warning: incompatible implicit declaration of built-in function 'malloc' [-Wbuiltin-declaration-mismatch]
   50 |   L = (int *)malloc(sizeof(int)*(n1+1));
      |              ^~~~~~
main.c:50:14: note: include '<stdlib.h>' or provide a declaration of 'malloc'
main.c:69:3: error: implicit declaration of function 'free' [-Wimplicit-function-declaration]
   69 |   free(L);
      |   ^~~~
main.c:69:3: note: include '<stdlib.h>' or provide a declaration of 'free'
main.c:69:3: warning: incompatible implicit declaration of built-in function 'free' [-Wbuiltin-declaration-mismatch]
main.c:69:3: note: include '<stdlib.h>' or provide a declaration of 'free'