/// x86-64 implementation of a system call macro
#[macro_export]
macro_rules! syscall {
    ($num:expr $(,)?) => {{
        let mut res = usize::from($num);
        core::arch::asm!(
            "syscall",
            inlateout("rax") res,
            out("rdi") _,
            out("rsi") _,
            out("rdx") _,
            out("r10") _,
            out("r8") _,
            out("r9") _,
            // Clobbered by syscall
            out("rcx") _,
            out("r11") _,
        );
        res
    }};
    ($num:expr, $a0:expr $(,)?) => {{
        let mut res = usize::from($num);
        core::arch::asm!(
            "syscall",
            inlateout("rax") res,
            in("rdi") $a0,
            out("rsi") _,
            out("rdx") _,
            out("r10") _,
            out("r8") _,
            out("r9") _,
            // Clobbered by syscall
            out("rcx") _,
            out("r11") _,
        );
        res
    }};
    ($num:expr, $a0:expr, $a1:expr $(,)?) => {{
        let mut res = usize::from($num);
        core::arch::asm!(
            "syscall",
            inlateout("rax") res,
            in("rdi") $a0,
            in("rsi") $a1,
            out("rdx") _,
            out("r10") _,
            out("r8") _,
            out("r9") _,
            // Clobbered by syscall
            out("rcx") _,
            out("r11") _,
        );
        res
    }};
    ($num:expr, $a0:expr, $a1:expr, $a2:expr $(,)?) => {{
        let mut res = usize::from($num);
        core::arch::asm!(
            "syscall",
            inlateout("rax") res,
            in("rdi") $a0,
            in("rsi") $a1,
            in("rdx") $a2,
            out("r10") _,
            out("r8") _,
            out("r9") _,
            // Clobbered by syscall
            out("rcx") _,
            out("r11") _,
        );
        res
    }};
    ($num:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr $(,)?) => {{
        let mut res = usize::from($num);
        core::arch::asm!(
            "syscall",
            inlateout("rax") res,
            in("rdi") $a0,
            in("rsi") $a1,
            in("rdx") $a2,
            in("r10") $a3,
            out("r8") _,
            out("r9") _,
            // Clobbered by syscall
            out("rcx") _,
            out("r11") _,
        );
        res
    }};
    ($num:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr $(,)?) => {{
        let mut res = usize::from($num);
        core::arch::asm!(
            "syscall",
            inlateout("rax") res,
            in("rdi") $a0,
            in("rsi") $a1,
            in("rdx") $a2,
            in("r10") $a3,
            in("r8") $a4,
            out("r9") _,
            // Clobbered by syscall
            out("rcx") _,
            out("r11") _,
        );
        res
    }};
}
