#include <stddef.h>

void *memcpy(void *destination, const void *source, size_t count) {
    unsigned char *out = destination;
    const unsigned char *in = source;
    for (size_t i = 0u; i < count; ++i) out[i] = in[i];
    return destination;
}

void *memset(void *destination, int value, size_t count) {
    unsigned char *out = destination;
    for (size_t i = 0u; i < count; ++i) out[i] = (unsigned char)value;
    return destination;
}

int memcmp(const void *left, const void *right, size_t count) {
    const unsigned char *a = left;
    const unsigned char *b = right;
    for (size_t i = 0u; i < count; ++i) {
        if (a[i] != b[i]) return (a[i] < b[i]) ? -1 : 1;
    }
    return 0;
}

/* Fail-stop if an unexpected integer divide by zero reaches the runtime. */
__attribute__((noreturn)) int __aeabi_idiv0(int return_value) {
    (void)return_value;
    for (;;) __asm volatile ("bkpt #0");
}

__attribute__((noreturn)) long long __aeabi_ldiv0(long long return_value) {
    (void)return_value;
    for (;;) __asm volatile ("bkpt #0");
}

void __libc_init_array(void) {}
