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

uintptr_t 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 %[a4], %%r10\n"
                    "movq %[a5], %%r8\n"
                    "movq %[a6], %%r9\n"
                    "syscall\n"
                    : "=a"(result)
                    : "a"(syscall_num), "D"(a1), "S"(a2),
                      "d"(a3), [a4] "r"(a4), [a5] "r"(a5), [a6] "r"(a6)
                    : "r10", "r8", "r9", "r11", "rcx", "cc", "memory");
  return result;
}
