use core::ffi::{c_int, c_long, c_longlong};

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(C)]
pub struct div_t {
    pub quot: c_int,
    pub rem: c_int,
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(C)]
pub struct ldiv_t {
    pub quot: c_long,
    pub rem: c_long,
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(C)]
pub struct lldiv_t {
    pub quot: c_longlong,
    pub rem: c_longlong,
}

#[no_mangle]
unsafe extern "C" fn abs(v: c_int) -> c_int {
    v.abs()
}

#[no_mangle]
unsafe extern "C" fn labs(v: c_long) -> c_long {
    v.abs()
}

#[no_mangle]
unsafe extern "C" fn llabs(v: c_longlong) -> c_longlong {
    v.abs()
}

#[no_mangle]
unsafe extern "C" fn div(x: c_int, y: c_int) -> div_t {
    div_t {
        quot: x / y,
        rem: x % y,
    }
}

#[no_mangle]
unsafe extern "C" fn ldiv(x: c_long, y: c_long) -> ldiv_t {
    ldiv_t {
        quot: x / y,
        rem: x % y,
    }
}

#[no_mangle]
unsafe extern "C" fn lldiv(x: c_longlong, y: c_longlong) -> lldiv_t {
    lldiv_t {
        quot: x / y,
        rem: x % y,
    }
}
