arduino code works slower than arduino code generated by ldmicro

thanks, actually when motor goes to one direction and arrives to a limit switch 1 (boton_input1) it stops waits 5 seconds and goes back, finds another limit switch 2 (boton_input2) it stops again, waits 5 seconds and goes until limit switch 1 stops motor , and repeat process for ever.

I have attached loop process picture i am not good at it so i hope it is understandable

I don´t use delay i just used milli() to counts 1000 milliseconds:

const long intervalo = 1000;
unsigned long b = 0;
byte d = 0;
byte e = 0;

void input1_loop()
{
  if (digitalRead(boton_input1)==HIGH and habilitado==1)  //forget habilitado, don´t use it
    {
      if(millis() - b >= intervalo)
      {
        b=millis();
        e=0; //it stops motor , has to be >= 5 to start motor
        d++; //counts every 1000 milliseconds
        
      }
    }