#include <stdint.h>
#include <stdio.h>

typedef int (*IntFuncHandle)(void);

int main(void) {

  /* compiled code for the function
   * intFunc(void) { return 42; }
   *
   * <intFunc>:
   * 1119:	55                   	push   %rbp
   * 111a:	48 89 e5             	mov    %rsp,%rbp
   * 111d:	b8 2a 00 00 00       	mov    $0x2a,%eax
   * 1122:	5d                   	pop    %rbp
   * 1123:	c3                   	ret
   */

  // Output binary
  unsigned char code_buff[] = {0x55, 0x48, 0x89, 0xe5, 0xb8, 0x2a,
                               0x00, 0x00, 0x00, 0x5d, 0xc3};

  // treat the code as a function
  IntFuncHandle stack_code = (IntFuncHandle)code_buff;

  // call the function
  int ret = stack_code();

  // print the returned value
  printf("return value: %d\n", ret);

  return 0;
}
