#include   <stdio.h>
#include   <fcntl.h>
#include   "BPatch.h"
#include   "BPatch_process.h"
#include   "BPatch_function.h"
#include   "BPatch_Vector.h"
#include   "BPatch_thread.h"

using namespace std;

int main(int argc,char *argv[]) {
    BPatch bpatch;

    BPatch_process *appProc;
    const char *arg[2];
    char file[] = "mutatee/mutatee";
    arg[0] = &file[0];
    arg[1] = NULL;

    int pid = atoi(argv[1]);
    //appProc  = bpatch.processCreate(argv[1], arg);
    appProc = bpatch.processAttach(NULL,pid);

    BPatch_image *appImage = appProc->getImage();

    BPatch_Vector<BPatch_function*> funcs;
    appImage->findFunction("Proc", funcs);
    BPatch_Vector<BPatch_point *> *points;
    points = funcs[0]->findPoint(BPatch_entry);
    if ((*points).size() == 0) {
        printf("No funcs");
            return 0;
    }
    BPatch_variableExpr *intCounter = appProc->malloc(*appImage->findType("int"));
    BPatch_arithExpr addOne(BPatch_assign, *intCounter,
    BPatch_arithExpr(BPatch_plus, *intCounter, BPatch_constExpr(1)));
    appProc->insertSnippet(addOne, *points);
    return 0;
}
