How to code two push buttons with 2 limit switch with 1 dc motor

Hey guys! Can I have a brief code how to code two push buttons with 2 limit switches? The process will be button 1 will is pressed then the motor will move clockwise and when the limit switch 1 is triggerred then the dc motor will stop. And if the button 2 is pressed then it will rotate in counter clockwise then it will stop if the limit switch 2 is turned on. I am having difficulty in this part. This are the codes that I used. After I implemented the limit switch it doesn''t work now. The code without the limit switch works. So I assume that the wirings are fine. I test the limit switch individually. It works just fine. I just can't find the problem with the code.
This code is for withoutlimit switch

const int button1 = 44;            
const int button2 = 46;            
const int dc_br =  30;             
const int dc_wr =  32;             

int buttonstate1 = 0;             
int buttonstate2 = 0;             
void setup() {
 
  pinMode(dc_br, OUTPUT); digitalWrite(dc_br,LOW);
  pinMode(dc_wr, OUTPUT); digitalWrite(dc_wr,LOW);
 
  pinMode(button1, INPUT_PULLUP); 
  pinMode(button2, INPUT_PULLUP); 
}

void loop() {
  digitalWrite(dc_br,HIGH);
  digitalWrite(dc_wr,HIGH);
  buttonstate1 = digitalRead(button1);
  if (buttonstate1 == LOW ) {                
    digitalWrite(dc_br, HIGH);             
  } else {                                        
    digitalWrite(dc_br, LOW);              
  }

   // read the state of the pushbutton value:
  buttonstate2 = digitalRead(button2);
  // check if the pushbutton is pressed.
  // if it is, the buttonstate is LOW:
  if (buttonstate2 == LOW) {                 
    digitalWrite(dc_wr, HIGH);                  
  } else {
    digitalWrite(dc_wr, LOW);                 
  }
}

This code with limit switch

#define button_wr 44
#define button_br 46
#define dc_br 30
#define dc_wr 32
#define lim_br 50 // para sa brown rice na button
#define lim_wr 52 //para sa white rice na button
int brownrice;
int whiterice;
int buttonstate1 = 0;
int buttonstate2 = 0;



void setup() {
  // put your setup code here, to run once:
  pinMode(dc_br, OUTPUT);   digitalWrite(dc_br, LOW);
  pinMode(dc_wr, OUTPUT);   digitalWrite(dc_wr, LOW);
  pinMode(button_br, INPUT_PULLUP); 
  pinMode(button_wr, INPUT_PULLUP);
  pinMode(lim_br, INPUT);
  pinMode(lim_wr, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(dc_br, HIGH);
  digitalWrite(dc_wr, HIGH);
  brownrice = digitalRead(lim_br);
  whiterice = digitalRead(lim_wr);
  buttonstate1 = digitalRead(button_br);
  buttonstate2 = digitalRead(button_wr);
  if(buttonstate1 == LOW && brownrice == HIGH ){
    proc_brown_on();
    }
  else if (buttonstate1 == LOW && brownrice == LOW ){
    proc_stop(); 
    }
  else{
    proc_stop(); 
    }
  if(buttonstate2 == LOW && whiterice == HIGH ){
    proc_white_on();
  }
  else if(buttonstate2 == LOW && whiterice == LOW ){
        proc_stop();
      }
  else{
    proc_stop();
    }
}

void proc_brown_on(){
  digitalWrite(dc_br,HIGH);
  digitalWrite(dc_wr,LOW);
}

void proc_white_on(){
  digitalWrite(dc_br,LOW);
  digitalWrite(dc_wr,HIGH);
}

void proc_stop(){
  digitalWrite(dc_br,LOW);
  digitalWrite(dc_wr,LOW);
}

Post the code in code tags, not text file attachments.

Noted. The codes are posted already

do your limit switch inputs also need PULLUPs? (assuming switch pull input LOW when active)

i think there is a condition where a button can be pressed and the limit switch is also active? it's not clear which limit switch is associated with which endpoint

if (LOW == butCw && LOW != limCw)
    moveCW();

and you can simply check for a limit switch to stop

else (LOW == limCw || LOW == limCcw)
    stop();

this also allows changing direction while in motion