user: Translate the below assembly code into C programming language:

```asm
<main>:
  endbr64
  push   %r12
  xor    %eax,%eax
  push   %rbp
  push   %rbx
  call   <wake@plt>
  xor    %eax,%eax
  call   <b_button@plt>
  test   %eax,%eax
  jne    L144
  mov    $0x2,%edi
  lea    D16(%rip),%r12
  lea    D8(%rip),%rbp
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
L32:
  mov    %r12,%rdi
  call   <printf@plt>
  jmp    L257
  nopw   0x0(%rax,%rax,1)
L101:
  mov    $0x1f4,%edi
  call   <msleep@plt>
L257:
  xor    %eax,%eax
  call   <a_button@plt>
  test   %eax,%eax
  je     L101
  mov    %rbp,%rdi
  call   <printf@plt>
L281:
  xor    %eax,%eax
L235:
  call   <b_button@plt>
  test   %eax,%eax
  jne    L144
  mov    $0x2,%edi
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  xor    %eax,%eax
  call   <steer_center@plt>
  xor    %eax,%eax
  call   <drive_forward@plt>
  xor    %eax,%eax
L115:
  call   <b_button@plt>
  test   %eax,%eax
  jne    L144
  mov    $0x2,%edi
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  mov    %eax,%ebx
  xor    %eax,%eax
  call   <steer_center@plt>
  mov    $0x2,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  je     L129
L278:
  xor    %eax,%eax
  call   <b_button@plt>
  test   %eax,%eax
  jne    L144
  mov    $0x2,%edi
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  xor    %eax,%eax
  call   <drive_stop@plt>
  xor    %eax,%eax
  call   <rand@plt>
  test   $0x1,%al
  mov    $0x0,%eax
  je     L229
  call   <steer_right@plt>
L194:
  xor    %eax,%eax
  call   <drive_reverse@plt>
  xor    %edi,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  je     L46
L303:
  xor    %edi,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  je     L181
L12:
  xor    %eax,%eax
  call   <drive_stop@plt>
  mov    $0x2,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  jne    L278
  mov    $0x1,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  je     L235
  mov    $0x3,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  je     L281
  jmp    L278
L240:
  mov    $0x1,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  jne    L42
L87:
  mov    $0x1,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  je     L21
  xor    %eax,%eax
  call   <b_button@plt>
  test   %eax,%eax
  jne    L144
  mov    $0x2,%edi
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  mov    %eax,%ebx
  xor    %eax,%eax
  call   <steer_left@plt>
  mov    $0x2,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  jne    L278
  nopl   (%rax)
L129:
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  cmp    %ebx,%eax
  jg     L240
  xor    %eax,%eax
  call   <b_button@plt>
  test   %eax,%eax
  jne    L144
  mov    $0x2,%edi
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  xor    %eax,%eax
  call   <drive_stop@plt>
  xor    %eax,%eax
  call   <steer_center@plt>
  xor    %eax,%eax
  call   <b_button@plt>
  test   %eax,%eax
  jne    L144
  mov    $0x2,%edi
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  jmp    L32
  nop
L144:
  pop    %rbx
  xor    %eax,%eax
  pop    %rbp
  pop    %r12
  ret
L229:
  call   <steer_left@plt>
  jmp    L194
L181:
  mov    $0x1,%edi
  call   <sleep@plt>
  jmp    L12
L46:
  mov    $0x1,%edi
  call   <sleep@plt>
  jmp    L303
L42:
  mov    $0x3,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  je     L87
  jmp    L278
L21:
  mov    $0x3,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  mov    $0x0,%eax
  je     L115
  call   <b_button@plt>
  test   %eax,%eax
  jne    L144
  mov    $0x2,%edi
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  mov    %eax,%ebx
  xor    %eax,%eax
  call   <steer_right@plt>
  mov    $0x2,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  jne    L278
  jmp    L129
```

tool_calls: name: read_data
arguments: data_tag: D16
type: string
name: read_data
arguments: data_tag: D8
type: string

tool: D16: Waiting for A button to go. 


tool: D8: Press B button to stop. 


assistant: ```c
int main() {
  int mpos_count = 0;
  int avoid_count = 0;
  int state = 0;
  wake();
  state = 2;
  while (!b_button()) {
    clear_motor_position_counter(2);
    mpos_count = get_motor_position_counter(2);
    if (2 == state) {
      printf("Waiting for A button to go. \n");
      while (!a_button()) {
        msleep(500);
      }
      printf("Press B button to stop. \n");
      state = 5;
    } else if (5 == state) {
      avoid_count = 0;
      steer_center();
      drive_forward();
      state = 10;
    } else if (10 == state) {
      steer_center();
      if (detect_straight(2)) {
        state = 25;
      } else if (mpos_count >= get_motor_position_counter(2)) {
        state = 30;
      } else if (detect_side(1) && detect_side(3)) {
        state = 25;
      } else if (detect_side(1)) {
        state = 15;
      } else if (detect_side(3)) {
        state = 20;
      } else {
        state = 10;
      }
    } else if (20 == state) {
      steer_right();
      if (detect_straight(2)) {
        state = 25;
      } else if (mpos_count >= get_motor_position_counter(2)) {
        state = 30;
      } else if (detect_side(1) && detect_side(3)) {
        state = 25;
      } else if (detect_side(1)) {
        state = 15;
      } else if (detect_side(3)) {
        state = 20;
      } else {
        state = 10;
      }
    } else if (15 == state) {
      steer_left();
      if (detect_straight(2)) {
        state = 25;
      } else if (mpos_count >= get_motor_position_counter(2)) {
        state = 30;
      } else if (detect_side(1) && detect_side(3)) {
        state = 25;
      } else if (detect_side(1)) {
        state = 15;
      } else if (detect_side(3)) {
        state = 20;
      } else {
        state = 10;
      }
    } else if (25 == state) {
      avoid_count = 0;
      drive_stop();
      if ((rand() % 2)) {
        steer_right();
      } else {
        steer_left();
      }
      drive_reverse();
      if (!detect_straight(0)) {
        sleep(1);
      }
      if (!detect_straight(0)) {
        sleep(1);
      }
      drive_stop();
      if (avoid_count > 3) {
        state = 30;
      } else if (detect_straight(2)) {
        state = 25;
      } else if (detect_side(1) && detect_side(3)) {
        state = 25;
      } else {
        state = 5;
      }
    } else if (30 == state) {
      drive_stop();
      steer_center();
      state = 2;
    }
  }
}
```