#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void merge(int *nums1, int nums1Size, int m, int *nums2, int nums2Size, int n) {
  int *base = malloc(sizeof(int) * (m + n));
  int idx1 = 0;
  int idx2 = 0;
  int idx = 0;

  while (idx1 < m && idx2 < n) {
    if (nums1[idx1] < nums2[idx2])
      base[idx++] = nums1[idx1++];
    else
      base[idx++] = nums2[idx2++];
  }

  for (int i = idx1; i < m; i++)
    base[idx++] = nums1[i];

  for (int i = idx2; i < n; i++)
    base[idx++] = nums2[i];

  memcpy(nums1, base, nums1Size * sizeof(int));

  free(base);
}

int main() {
  int nums1[1] = {1};
  int nums2[0] = {};

  merge(nums1, 1, 1, nums2, 0, 0);

  for (int i = 0; i < 1; i++)
    printf("%d ", nums1[i]);

  printf("\n");

  return 0;
}
