#include <amd64/syscall.h>
#include <stddef.h>
#include <stdint.h>

int msl_amd64_syscall (int syscall_num, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4,
                       uintptr_t a5, uintptr_t a6) {
  uint64_t result;
  __asm__ volatile ("movq %1, %%rax\n"
                    "movq %2, %%rdi\n"
                    "movq %3, %%rsi\n"
                    "movq %4, %%rdx\n"
                    "movq %5, %%r10\n"
                    "movq %6, %%r8\n"
                    "movq %7, %%r9\n"
                    "syscall\n"
                    "movq %%rax, %0\n"
                    : "=r"(result)
                    : "r"((uint64_t)syscall_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5),
                      "r"(a6)
                    : "memory", "cc", "rcx", "r11");
  return (int)result;
}
