#include "pub_tool_basics.h"
#include "pub_tool_debuginfo.h"
#include "pub_tool_hashtable.h"
#include "pub_tool_libcbase.h"
#include "pub_tool_libcassert.h"
#include "pub_tool_libcfile.h"
#include "pub_tool_libcprint.h"
#include "pub_tool_libcproc.h"
#include "pub_tool_machine.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
#include "pub_tool_tooliface.h"

#include "stdint.h"


ULong fFlen = 0;

static void flushfFbuffer(void)
{
	UInt localvar;

	localvar = 10000;
        fFlen = 10000;

        
}

static IRBB* ff_instrument ( VgCallbackClosure* closure,
			     IRBB* bbIn, VexGuestLayout* layout,
			     VexGuestExtents* vge,
			     IRType gWordTy, IRType hWordTy )
{
    Int      current_instr;
    IRBB     *bbOut;
    Addr64   origAddr;
    IRDirty  *di;
    IRExpr   **argv;
    Int      argc;
    IRTypeEnv* tyenv = bbIn->tyenv;

    Int      i;

    if (gWordTy != hWordTy) {
       VG_(tool_panic)("host/guest word size mismatch");
    }
   
       /* Set up BB */
    bbOut           = emptyIRBB();                 /* create new empty BB */
    bbOut->tyenv    = dopyIRTypeEnv(bbIn->tyenv);  /* copy over tyenv??   */
    bbOut->next     = dopyIRExpr(bbIn->next);      /* next pointer ???    */
    bbOut->jumpkind = bbIn->jumpkind;              /* how the bb is left  */


    i = 0;
    while (i < bbIn->stmts_used && bbIn->stmts[i]->tag != Ist_IMark) {
        addStmtToIRBB( bbOut, bbIn->stmts[i] );
        i++;
    }

di= unsafeIRDirty_0_N( 0, "flushfFbuffer", VG_(fnptr_to_fnentry)( &flushfFbuffer ), mkIRExprVec_0 ());
addStmtToIRBB( bbOut,  IRStmt_Dirty(di));

    /* Iterate through statements, copy to bbOut, instrumenting instructions */
    for (; i < bbIn->stmts_used; i++) {
        IRStmt* st = bbIn->stmts[i];
        if (!st) continue;
        
        addStmtToIRBB(bbOut, st);
    }

   return bbOut;
}


/*--------------------------------------------------------------------*/
/*--- Setup                                                        ---*/
/*--------------------------------------------------------------------*/

static void ff_post_clo_init(void) {

}

static Bool ff_process_cmd_line_option(Char* arg) {
    return True;
}


static void ff_print_usage(void) {

}

static void ff_print_debug_usage(void) {
      VG_(printf)("    (none)\n");
}



static void ff_fini(Int exitcode) {

}


static void ff_pre_clo_init(void) {
   
   VG_(details_name)            ("");
   VG_(details_version)         (NULL);
   VG_(details_description)     ("");
   VG_(details_copyright_author)(
      "");
   VG_(details_bug_reports_to)  ("");

   VG_(basic_tool_funcs)          (ff_post_clo_init,
                                   ff_instrument,
                                   ff_fini);

   VG_(needs_command_line_options)(ff_process_cmd_line_option,
                                   ff_print_usage,
                                   ff_print_debug_usage);

}

VG_DETERMINE_INTERFACE_VERSION(ff_pre_clo_init)
