#include <stdio.h>
#include <sys/mman.h>
#include <stdint.h>
#include <unistd.h>


int f()
{
    int x = 43;
    int y = x + 1;
    return x;
}

int g()
{
    return 42;
}

int main()
{
    //(int *)f(int x) 
    printf("%ld\n", f);
    for(int i = 0; i < 20; i++){
        //print("hi\n");
        printf("%d: %d\n", i, *( (int*)((char *)f + i)));
    }
    
   // Get the page size and calculate the page-aligned address of f
    long page_size = sysconf(_SC_PAGESIZE);
    void *page = (void *)((uintptr_t)f & ~(page_size - 1));

    // Make the page writable (keep read + exec too)
    if (mprotect(page, page_size, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) {
        perror("mprotect");
        return 1;
    }

    *( (int*)((char *)f + 11)) = 42;
    

    printf("%ld\n", g);
    printf("%d\n", f(12));
    // for(int i = 0; i < 1; i ++)
    //     ((int *)f)[i] = 0;
    //     //printf("%d\n", ((char *)f)[i]);
    // printf("%d\n", f(12));
}