user: 请将这段汇编代码片段转换成等效的C代码：

```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    L75
  mov    $0x2,%edi
  lea    D0(%rip),%r12
  lea    D6(%rip),%rbp
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
L150:
  mov    %r12,%rdi
  call   <printf@plt>
  jmp    L300
  nopw   0x0(%rax,%rax,1)
L245:
  mov    $0x1f4,%edi
  call   <msleep@plt>
L300:
  xor    %eax,%eax
  call   <a_button@plt>
  test   %eax,%eax
  je     L245
  mov    %rbp,%rdi
  call   <printf@plt>
L129:
  xor    %eax,%eax
L211:
  call   <b_button@plt>
  test   %eax,%eax
  jne    L75
  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
L24:
  call   <b_button@plt>
  test   %eax,%eax
  jne    L75
  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     L276
L106:
  xor    %eax,%eax
  call   <b_button@plt>
  test   %eax,%eax
  jne    L75
  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     L154
  call   <steer_right@plt>
L22:
  xor    %eax,%eax
  call   <drive_reverse@plt>
  xor    %edi,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  je     L134
L157:
  xor    %edi,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  je     L199
L185:
  xor    %eax,%eax
  call   <drive_stop@plt>
  mov    $0x2,%edi
  call   <detect_straight@plt>
  test   %rax,%rax
  jne    L106
  mov    $0x1,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  je     L211
  mov    $0x3,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  je     L129
  jmp    L106
L196:
  mov    $0x1,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  jne    L76
L257:
  mov    $0x1,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  je     L89
  xor    %eax,%eax
  call   <b_button@plt>
  test   %eax,%eax
  jne    L75
  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    L106
  nopl   (%rax)
L276:
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  cmp    %ebx,%eax
  jg     L196
  xor    %eax,%eax
  call   <b_button@plt>
  test   %eax,%eax
  jne    L75
  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    L75
  mov    $0x2,%edi
  call   <clear_motor_position_counter@plt>
  mov    $0x2,%edi
  call   <get_motor_position_counter@plt>
  jmp    L150
  nop
L75:
  pop    %rbx
  xor    %eax,%eax
  pop    %rbp
  pop    %r12
  ret
L154:
  call   <steer_left@plt>
  jmp    L22
L199:
  mov    $0x1,%edi
  call   <sleep@plt>
  jmp    L185
L134:
  mov    $0x1,%edi
  call   <sleep@plt>
  jmp    L157
L76:
  mov    $0x3,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  je     L257
  jmp    L106
L89:
  mov    $0x3,%edi
  call   <detect_side@plt>
  test   %rax,%rax
  mov    $0x0,%eax
  je     L24
  call   <b_button@plt>
  test   %eax,%eax
  jne    L75
  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    L106
  jmp    L276
```

tool_calls: name: parse_data
arguments: label: D0
datatype: string
name: parse_data
arguments: label: D6
datatype: string

tool: D0: Waiting for A button to go. 


tool: D6: 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;
    }
  }
}
```