#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ a_button();
int /*<<< orphan*/ b_button();
int /*<<< orphan*/ clear_motor_position_counter(int);
scalar_t__ detect_side(int);
scalar_t__ detect_straight(int);
int /*<<< orphan*/ drive_forward();
int /*<<< orphan*/ drive_reverse();
int /*<<< orphan*/ drive_stop();
int get_motor_position_counter(int);
int /*<<< orphan*/ msleep(int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ steer_center();
int /*<<< orphan*/ steer_left();
int /*<<< orphan*/ steer_right();
int /*<<< orphan*/ wake();
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;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   10e0 <wake@plt>
movl   $0x2,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <b_button@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    125e <main+0x4e>
jmp    1728 <main+0x518>
mov    $0x2,%edi
call   1100 <clear_motor_position_counter@plt>
mov    $0x2,%edi
call   10d0 <get_motor_position_counter@plt>
mov    %eax,-0x8(%rbp)
mov    $0x2,%eax
cmp    -0x10(%rbp),%eax
jne    12d2 <main+0xc2>
lea    0xd76(%rip),%rdi
call   10a0 <printf@plt>
mov    $0x0,%al
call   1050 <a_button@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12ab <main+0x9b>
jmp    12ba <main+0xaa>
mov    $0x1f4,%edi
call   1090 <msleep@plt>
jmp    128f <main+0x7f>
lea    0xd5d(%rip),%rdi
call   10a0 <printf@plt>
movl   $0x5,-0x10(%rbp)
jmp    1723 <main+0x513>
mov    $0x5,%eax
cmp    -0x10(%rbp),%eax
jne    1301 <main+0xf1>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1070 <steer_center@plt>
mov    $0x0,%al
call   1110 <drive_forward@plt>
movl   $0xa,-0x10(%rbp)
jmp    171e <main+0x50e>
mov    $0xa,%eax
cmp    -0x10(%rbp),%eax
jne    13f3 <main+0x1e3>
mov    $0x0,%al
call   1070 <steer_center@plt>
mov    $0x2,%edi
call   1030 <detect_straight@plt>
cmp    $0x0,%rax
je     1336 <main+0x126>
movl   $0x19,-0x10(%rbp)
jmp    13ee <main+0x1de>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x2,%edi
call   10d0 <get_motor_position_counter@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jl     135f <main+0x14f>
movl   $0x1e,-0x10(%rbp)
jmp    13e9 <main+0x1d9>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     1393 <main+0x183>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     1393 <main+0x183>
movl   $0x19,-0x10(%rbp)
jmp    13e4 <main+0x1d4>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     13b3 <main+0x1a3>
movl   $0xf,-0x10(%rbp)
jmp    13df <main+0x1cf>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     13d3 <main+0x1c3>
movl   $0x14,-0x10(%rbp)
jmp    13da <main+0x1ca>
movl   $0xa,-0x10(%rbp)
jmp    13df <main+0x1cf>
jmp    13e4 <main+0x1d4>
jmp    13e9 <main+0x1d9>
jmp    13ee <main+0x1de>
jmp    1719 <main+0x509>
mov    $0x14,%eax
cmp    -0x10(%rbp),%eax
jne    14e5 <main+0x2d5>
mov    $0x0,%al
call   10b0 <steer_right@plt>
mov    $0x2,%edi
call   1030 <detect_straight@plt>
cmp    $0x0,%rax
je     1428 <main+0x218>
movl   $0x19,-0x10(%rbp)
jmp    14e0 <main+0x2d0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2,%edi
call   10d0 <get_motor_position_counter@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jl     1451 <main+0x241>
movl   $0x1e,-0x10(%rbp)
jmp    14db <main+0x2cb>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     1485 <main+0x275>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     1485 <main+0x275>
movl   $0x19,-0x10(%rbp)
jmp    14d6 <main+0x2c6>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     14a5 <main+0x295>
movl   $0xf,-0x10(%rbp)
jmp    14d1 <main+0x2c1>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     14c5 <main+0x2b5>
movl   $0x14,-0x10(%rbp)
jmp    14cc <main+0x2bc>
movl   $0xa,-0x10(%rbp)
jmp    14d1 <main+0x2c1>
jmp    14d6 <main+0x2c6>
jmp    14db <main+0x2cb>
jmp    14e0 <main+0x2d0>
jmp    1714 <main+0x504>
mov    $0xf,%eax
cmp    -0x10(%rbp),%eax
jne    15d7 <main+0x3c7>
mov    $0x0,%al
call   1040 <steer_left@plt>
mov    $0x2,%edi
call   1030 <detect_straight@plt>
cmp    $0x0,%rax
je     151a <main+0x30a>
movl   $0x19,-0x10(%rbp)
jmp    15d2 <main+0x3c2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x2,%edi
call   10d0 <get_motor_position_counter@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jl     1543 <main+0x333>
movl   $0x1e,-0x10(%rbp)
jmp    15cd <main+0x3bd>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     1577 <main+0x367>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     1577 <main+0x367>
movl   $0x19,-0x10(%rbp)
jmp    15c8 <main+0x3b8>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     1597 <main+0x387>
movl   $0xf,-0x10(%rbp)
jmp    15c3 <main+0x3b3>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     15b7 <main+0x3a7>
movl   $0x14,-0x10(%rbp)
jmp    15be <main+0x3ae>
movl   $0xa,-0x10(%rbp)
jmp    15c3 <main+0x3b3>
jmp    15c8 <main+0x3b8>
jmp    15cd <main+0x3bd>
jmp    15d2 <main+0x3c2>
jmp    170f <main+0x4ff>
mov    $0x19,%eax
cmp    -0x10(%rbp),%eax
jne    16e2 <main+0x4d2>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1080 <drive_stop@plt>
mov    $0x0,%al
call   1130 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1617 <main+0x407>
mov    $0x0,%al
call   10b0 <steer_right@plt>
jmp    161e <main+0x40e>
mov    $0x0,%al
call   1040 <steer_left@plt>
mov    $0x0,%al
call   1060 <drive_reverse@plt>
xor    %edi,%edi
call   1030 <detect_straight@plt>
cmp    $0x0,%rax
jne    1640 <main+0x430>
mov    $0x1,%edi
call   1120 <sleep@plt>
xor    %edi,%edi
call   1030 <detect_straight@plt>
cmp    $0x0,%rax
jne    165b <main+0x44b>
mov    $0x1,%edi
call   1120 <sleep@plt>
mov    $0x0,%al
call   1080 <drive_stop@plt>
cmpl   $0x3,-0xc(%rbp)
jle    1678 <main+0x468>
movl   $0x1e,-0x10(%rbp)
jmp    16dd <main+0x4cd>
mov    $0x2,%edi
call   1030 <detect_straight@plt>
cmp    $0x0,%rax
je     1698 <main+0x488>
movl   $0x19,-0x10(%rbp)
jmp    16d8 <main+0x4c8>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     16cc <main+0x4bc>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
cmp    $0x0,%rax
je     16cc <main+0x4bc>
movl   $0x19,-0x10(%rbp)
jmp    16d3 <main+0x4c3>
movl   $0x5,-0x10(%rbp)
jmp    16d8 <main+0x4c8>
jmp    16dd <main+0x4cd>
jmp    170a <main+0x4fa>
mov    $0x1e,%eax
cmp    -0x10(%rbp),%eax
jne    1705 <main+0x4f5>
mov    $0x0,%al
call   1080 <drive_stop@plt>
mov    $0x0,%al
call   1070 <steer_center@plt>
movl   $0x2,-0x10(%rbp)
jmp    170a <main+0x4fa>
jmp    170f <main+0x4ff>
jmp    1714 <main+0x504>
jmp    1719 <main+0x509>
jmp    171e <main+0x50e>
jmp    1723 <main+0x513>
jmp    1242 <main+0x32>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10e0 <wake@plt>
xor    %eax,%eax
call   10c0 <b_button@plt>
test   %eax,%eax
je     123e <main+0x2e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x2,%ebx
lea    0xdb6(%rip),%r13
lea    0xe23(%rip),%r14
lea    0xe39(%rip),%r15
mov    $0xa,%r12d
jmp    128b <main+0x7b>
xor    %eax,%eax
call   1090 <drive_stop@plt>
xor    %eax,%eax
call   1070 <steer_center@plt>
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10c0 <b_button@plt>
test   %eax,%eax
jne    122d <main+0x1d>
mov    $0x2,%edi
call   1100 <clear_motor_position_counter@plt>
mov    $0x2,%edi
call   10d0 <get_motor_position_counter@plt>
mov    %eax,%ebp
lea    -0x2(%rbx),%eax
cmp    $0x1c,%eax
ja     1280 <main+0x70>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %r14,%rdi
call   1080 <puts@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <a_button@plt>
test   %eax,%eax
jne    13ad <main+0x19d>
mov    $0x1f4,%edi
call   10a0 <msleep@plt>
jmp    12c0 <main+0xb0>
xor    %eax,%eax
call   1070 <steer_center@plt>
xor    %eax,%eax
call   1110 <drive_forward@plt>
mov    $0xa,%ebx
jmp    1280 <main+0x70>
xor    %eax,%eax
call   1070 <steer_center@plt>
jmp    1309 <main+0xf9>
xor    %eax,%eax
call   1040 <steer_left@plt>
jmp    1309 <main+0xf9>
xor    %eax,%eax
call   10b0 <steer_right@plt>
mov    $0x2,%edi
call   1030 <detect_straight@plt>
mov    $0x19,%ebx
test   %rax,%rax
jne    1280 <main+0x70>
mov    $0x2,%edi
call   10d0 <get_motor_position_counter@plt>
mov    $0x1e,%ebx
cmp    %eax,%ebp
jge    1280 <main+0x70>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
test   %rax,%rax
je     135f <main+0x14f>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
mov    $0x19,%ebx
test   %rax,%rax
jne    1280 <main+0x70>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
mov    $0xf,%ebx
test   %rax,%rax
jne    1280 <main+0x70>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
test   %rax,%rax
mov    $0x14,%ebx
cmove  %r12d,%ebx
jmp    1280 <main+0x70>
xor    %eax,%eax
call   1090 <drive_stop@plt>
xor    %eax,%eax
call   1130 <rand@plt>
test   $0x1,%al
jne    13bf <main+0x1af>
xor    %eax,%eax
call   1040 <steer_left@plt>
jmp    13c6 <main+0x1b6>
mov    %r15,%rdi
call   1080 <puts@plt>
mov    $0x5,%ebx
jmp    1280 <main+0x70>
xor    %eax,%eax
call   10b0 <steer_right@plt>
xor    %eax,%eax
call   1060 <drive_reverse@plt>
xor    %edi,%edi
call   1030 <detect_straight@plt>
test   %rax,%rax
jne    13e3 <main+0x1d3>
mov    $0x1,%edi
call   1120 <sleep@plt>
xor    %edi,%edi
call   1030 <detect_straight@plt>
test   %rax,%rax
jne    13f9 <main+0x1e9>
mov    $0x1,%edi
call   1120 <sleep@plt>
xor    %eax,%eax
call   1090 <drive_stop@plt>
mov    $0x2,%edi
call   1030 <detect_straight@plt>
mov    $0x19,%ebx
test   %rax,%rax
jne    1280 <main+0x70>
mov    $0x1,%edi
call   10f0 <detect_side@plt>
test   %rax,%rax
je     143a <main+0x22a>
mov    $0x3,%edi
call   10f0 <detect_side@plt>
test   %rax,%rax
jne    1280 <main+0x70>
mov    $0x5,%ebx
jmp    1280 <main+0x70>

LLVM IR (-O0):
@.str = [30 x i8] c"Waiting for A button to go. \0A\00"
@.str.1 = [26 x i8] c"Press B button to stop. \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (...) @wake()
store i32 2, i32* %4
br label %6
6: ; preds = %188, %0
%7 = call i32 (...) @b_button()
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %189
10: ; preds = %6
%11 = call i32 @clear_motor_position_counter(i32 2)
%12 = call i32 @get_motor_position_counter(i32 2)
store i32 %12, i32* %2
%13 = load i32, i32* %4
%14 = icmp eq i32 2, %13
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %21, %15
%18 = call i32 (...) @a_button()
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @msleep(i32 500)
br label %17
23: ; preds = %17
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 5, i32* %4
br label %188
25: ; preds = %10
%26 = load i32, i32* %4
%27 = icmp eq i32 5, %26
br i1 %27, label %28, label %31
28: ; preds = %25
store i32 0, i32* %3
%29 = call i32 (...) @steer_center()
%30 = call i32 (...) @drive_forward()
store i32 10, i32* %4
br label %187
31: ; preds = %25
%32 = load i32, i32* %4
%33 = icmp eq i32 10, %32
br i1 %33, label %34, label %65
34: ; preds = %31
%35 = call i32 (...) @steer_center()
%36 = call i64 @detect_straight(i32 2)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 25, i32* %4
br label %64
39: ; preds = %34
%40 = load i32, i32* %2
%41 = call i32 @get_motor_position_counter(i32 2)
%42 = icmp sge i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 30, i32* %4
br label %63
44: ; preds = %39
%45 = call i64 @detect_side(i32 1)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = call i64 @detect_side(i32 3)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 25, i32* %4
br label %62
51: ; preds = %47, %44
%52 = call i64 @detect_side(i32 1)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 15, i32* %4
br label %61
55: ; preds = %51
%56 = call i64 @detect_side(i32 3)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %55
store i32 20, i32* %4
br label %60
59: ; preds = %55
store i32 10, i32* %4
br label %60
60: ; preds = %59, %58
br label %61
61: ; preds = %60, %54
br label %62
62: ; preds = %61, %50
br label %63
63: ; preds = %62, %43
br label %64
64: ; preds = %63, %38
br label %186
65: ; preds = %31
%66 = load i32, i32* %4
%67 = icmp eq i32 20, %66
br i1 %67, label %68, label %99
68: ; preds = %65
%69 = call i32 (...) @steer_right()
%70 = call i64 @detect_straight(i32 2)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %68
store i32 25, i32* %4
br label %98
73: ; preds = %68
%74 = load i32, i32* %2
%75 = call i32 @get_motor_position_counter(i32 2)
%76 = icmp sge i32 %74, %75
br i1 %76, label %77, label %78
77: ; preds = %73
store i32 30, i32* %4
br label %97
78: ; preds = %73
%79 = call i64 @detect_side(i32 1)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %78
%82 = call i64 @detect_side(i32 3)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %81
store i32 25, i32* %4
br label %96
85: ; preds = %81, %78
%86 = call i64 @detect_side(i32 1)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %89
88: ; preds = %85
store i32 15, i32* %4
br label %95
89: ; preds = %85
%90 = call i64 @detect_side(i32 3)
%91 = icmp ne i64 %90, 0
br i1 %91, label %92, label %93
92: ; preds = %89
store i32 20, i32* %4
br label %94
93: ; preds = %89
store i32 10, i32* %4
br label %94
94: ; preds = %93, %92
br label %95
95: ; preds = %94, %88
br label %96
96: ; preds = %95, %84
br label %97
97: ; preds = %96, %77
br label %98
98: ; preds = %97, %72
br label %185
99: ; preds = %65
%100 = load i32, i32* %4
%101 = icmp eq i32 15, %100
br i1 %101, label %102, label %133
102: ; preds = %99
%103 = call i32 (...) @steer_left()
%104 = call i64 @detect_straight(i32 2)
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %107
106: ; preds = %102
store i32 25, i32* %4
br label %132
107: ; preds = %102
%108 = load i32, i32* %2
%109 = call i32 @get_motor_position_counter(i32 2)
%110 = icmp sge i32 %108, %109
br i1 %110, label %111, label %112
111: ; preds = %107
store i32 30, i32* %4
br label %131
112: ; preds = %107
%113 = call i64 @detect_side(i32 1)
%114 = icmp ne i64 %113, 0
br i1 %114, label %115, label %119
115: ; preds = %112
%116 = call i64 @detect_side(i32 3)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %119
118: ; preds = %115
store i32 25, i32* %4
br label %130
119: ; preds = %115, %112
%120 = call i64 @detect_side(i32 1)
%121 = icmp ne i64 %120, 0
br i1 %121, label %122, label %123
122: ; preds = %119
store i32 15, i32* %4
br label %129
123: ; preds = %119
%124 = call i64 @detect_side(i32 3)
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %127
126: ; preds = %123
store i32 20, i32* %4
br label %128
127: ; preds = %123
store i32 10, i32* %4
br label %128
128: ; preds = %127, %126
br label %129
129: ; preds = %128, %122
br label %130
130: ; preds = %129, %118
br label %131
131: ; preds = %130, %111
br label %132
132: ; preds = %131, %106
br label %184
133: ; preds = %99
%134 = load i32, i32* %4
%135 = icmp eq i32 25, %134
br i1 %135, label %136, label %176
136: ; preds = %133
store i32 0, i32* %3
%137 = call i32 (...) @drive_stop()
%138 = call i32 (...) @rand()
%139 = srem i32 %138, 2
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %143
141: ; preds = %136
%142 = call i32 (...) @steer_right()
br label %145
143: ; preds = %136
%144 = call i32 (...) @steer_left()
br label %145
145: ; preds = %143, %141
%146 = call i32 (...) @drive_reverse()
%147 = call i64 @detect_straight(i32 0)
%148 = icmp ne i64 %147, 0
br i1 %148, label %151, label %149
149: ; preds = %145
%150 = call i32 @sleep(i32 1)
br label %151
151: ; preds = %149, %145
%152 = call i64 @detect_straight(i32 0)
%153 = icmp ne i64 %152, 0
br i1 %153, label %156, label %154
154: ; preds = %151
%155 = call i32 @sleep(i32 1)
br label %156
156: ; preds = %154, %151
%157 = call i32 (...) @drive_stop()
%158 = load i32, i32* %3
%159 = icmp sgt i32 %158, 3
br i1 %159, label %160, label %161
160: ; preds = %156
store i32 30, i32* %4
br label %175
161: ; preds = %156
%162 = call i64 @detect_straight(i32 2)
%163 = icmp ne i64 %162, 0
br i1 %163, label %164, label %165
164: ; preds = %161
store i32 25, i32* %4
br label %174
165: ; preds = %161
%166 = call i64 @detect_side(i32 1)
%167 = icmp ne i64 %166, 0
br i1 %167, label %168, label %172
168: ; preds = %165
%169 = call i64 @detect_side(i32 3)
%170 = icmp ne i64 %169, 0
br i1 %170, label %171, label %172
171: ; preds = %168
store i32 25, i32* %4
br label %173
172: ; preds = %168, %165
store i32 5, i32* %4
br label %173
173: ; preds = %172, %171
br label %174
174: ; preds = %173, %164
br label %175
175: ; preds = %174, %160
br label %183
176: ; preds = %133
%177 = load i32, i32* %4
%178 = icmp eq i32 30, %177
br i1 %178, label %179, label %182
179: ; preds = %176
%180 = call i32 (...) @drive_stop()
%181 = call i32 (...) @steer_center()
store i32 2, i32* %4
br label %182
182: ; preds = %179, %176
br label %183
183: ; preds = %182, %175
br label %184
184: ; preds = %183, %132
br label %185
185: ; preds = %184, %98
br label %186
186: ; preds = %185, %64
br label %187
187: ; preds = %186, %28
br label %188
188: ; preds = %187, %23
br label %6
189: ; preds = %6
%190 = load i32, i32* %1
ret i32 %190
}

LLVM IR (-O2):
@str = [29 x i8] c"Waiting for A button to go. \00"
@str.2 = [25 x i8] c"Press B button to stop. \00"
define i32 @main() {
%1 = tail call i32 (...) @wake()
%2 = tail call i32 (...) @b_button()
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %119
4: ; preds = %0, %115
%5 = phi i32 [ %116, %115 ], [ 2, %0 ]
%6 = tail call i32 @clear_motor_position_counter(i32 2)
%7 = tail call i32 @get_motor_position_counter(i32 2)
switch i32 %5, label %115 [
i32 2, label %8
i32 5, label %18
i32 10, label %21
i32 20, label %41
i32 15, label %61
i32 25, label %81
i32 30, label %112
]
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 (...) @a_button()
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8, %12
%13 = tail call i32 @msleep(i32 500)
%14 = tail call i32 (...) @a_button()
%15 = icmp eq i32 %14, 0
br i1 %15, label %12, label %16
16: ; preds = %12, %8
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.2, i64 0, i64 0))
br label %115
18: ; preds = %4
%19 = tail call i32 (...) @steer_center()
%20 = tail call i32 (...) @drive_forward()
br label %115
21: ; preds = %4
%22 = tail call i32 (...) @steer_center()
%23 = tail call i64 @detect_straight(i32 2)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %115
25: ; preds = %21
%26 = tail call i32 @get_motor_position_counter(i32 2)
%27 = icmp slt i32 %7, %26
br i1 %27, label %28, label %115
28: ; preds = %25
%29 = tail call i64 @detect_side(i32 1)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = tail call i64 @detect_side(i32 3)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %115
34: ; preds = %31, %28
%35 = tail call i64 @detect_side(i32 1)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %115
37: ; preds = %34
%38 = tail call i64 @detect_side(i32 3)
%39 = icmp eq i64 %38, 0
%40 = select i1 %39, i32 10, i32 20
br label %115
41: ; preds = %4
%42 = tail call i32 (...) @steer_right()
%43 = tail call i64 @detect_straight(i32 2)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %115
45: ; preds = %41
%46 = tail call i32 @get_motor_position_counter(i32 2)
%47 = icmp slt i32 %7, %46
br i1 %47, label %48, label %115
48: ; preds = %45
%49 = tail call i64 @detect_side(i32 1)
%50 = icmp eq i64 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = tail call i64 @detect_side(i32 3)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %115
54: ; preds = %51, %48
%55 = tail call i64 @detect_side(i32 1)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %115
57: ; preds = %54
%58 = tail call i64 @detect_side(i32 3)
%59 = icmp eq i64 %58, 0
%60 = select i1 %59, i32 10, i32 20
br label %115
61: ; preds = %4
%62 = tail call i32 (...) @steer_left()
%63 = tail call i64 @detect_straight(i32 2)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %115
65: ; preds = %61
%66 = tail call i32 @get_motor_position_counter(i32 2)
%67 = icmp slt i32 %7, %66
br i1 %67, label %68, label %115
68: ; preds = %65
%69 = tail call i64 @detect_side(i32 1)
%70 = icmp eq i64 %69, 0
br i1 %70, label %74, label %71
71: ; preds = %68
%72 = tail call i64 @detect_side(i32 3)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %115
74: ; preds = %71, %68
%75 = tail call i64 @detect_side(i32 1)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %115
77: ; preds = %74
%78 = tail call i64 @detect_side(i32 3)
%79 = icmp eq i64 %78, 0
%80 = select i1 %79, i32 10, i32 20
br label %115
81: ; preds = %4
%82 = tail call i32 (...) @drive_stop()
%83 = tail call i32 (...) @rand()
%84 = and i32 %83, 1
%85 = icmp eq i32 %84, 0
br i1 %85, label %88, label %86
86: ; preds = %81
%87 = tail call i32 (...) @steer_right()
br label %90
88: ; preds = %81
%89 = tail call i32 (...) @steer_left()
br label %90
90: ; preds = %88, %86
%91 = tail call i32 (...) @drive_reverse()
%92 = tail call i64 @detect_straight(i32 0)
%93 = icmp eq i64 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %90
%95 = tail call i32 @sleep(i32 1)
br label %96
96: ; preds = %94, %90
%97 = tail call i64 @detect_straight(i32 0)
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %96
%100 = tail call i32 @sleep(i32 1)
br label %101
101: ; preds = %99, %96
%102 = tail call i32 (...) @drive_stop()
%103 = tail call i64 @detect_straight(i32 2)
%104 = icmp eq i64 %103, 0
br i1 %104, label %105, label %115
105: ; preds = %101
%106 = tail call i64 @detect_side(i32 1)
%107 = icmp eq i64 %106, 0
br i1 %107, label %111, label %108
108: ; preds = %105
%109 = tail call i64 @detect_side(i32 3)
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %115
111: ; preds = %108, %105
br label %115
112: ; preds = %4
%113 = tail call i32 (...) @drive_stop()
%114 = tail call i32 (...) @steer_center()
br label %115
115: ; preds = %4, %108, %101, %77, %74, %71, %65, %61, %57, %54, %51, %45, %41, %37, %34, %31, %25, %21, %18, %111, %112, %16
%116 = phi i32 [ 5, %16 ], [ 10, %18 ], [ 5, %111 ], [ 2, %112 ], [ 25, %21 ], [ 30, %25 ], [ 25, %31 ], [ 15, %34 ], [ %40, %37 ], [ 25, %41 ], [ 30, %45 ], [ 25, %51 ], [ 15, %54 ], [ %60, %57 ], [ 25, %61 ], [ 30, %65 ], [ 25, %71 ], [ 15, %74 ], [ %80, %77 ], [ 25, %101 ], [ 25, %108 ], [ %5, %4 ]
%117 = tail call i32 (...) @b_button()
%118 = icmp eq i32 %117, 0
br i1 %118, label %4, label %119
119: ; preds = %115, %0
ret i32 0
}