#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static int global_value = 42;
int main(void) {
    int local_value = 7;
    int *allocated = malloc(128 * sizeof *allocated);
    if (!allocated) { perror("malloc"); return 1; }
    allocated[0] = 99;
    long page_size = sysconf(_SC_PAGESIZE);
    if (page_size <= 0) { fputs("Cannot determine page size\n", stderr); free(allocated); return 1; }
    printf("PID: %ld; base page size: %ld bytes\n", (long)getpid(), page_size);
    printf("static object: %p (%d)\n", (void *)&global_value, global_value);
    printf("automatic object: %p (%d)\n", (void *)&local_value, local_value);
    printf("allocated object: %p (%d)\n", (void *)allocated, allocated[0]);
#ifdef __linux__
    FILE *f = fopen("/proc/self/maps", "r");
    if (!f) { perror("/proc/self/maps"); free(allocated); return 1; }
    char line[4096];
    while (fgets(line, sizeof line, f)) fputs(line, stdout);
    int failed = ferror(f); fclose(f);
    if (failed) { fputs("Failed to read complete maps\n", stderr); free(allocated); return 1; }
#else
    puts("/proc/self/maps is Linux-specific; this host only demonstrates virtual pointers and page-size discovery.");
#endif
    free(allocated); return 0;
}
