#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*/ fast_turn_left();
int /*<<< orphan*/ fast_turn_right();
scalar_t__ get_collision_button();
scalar_t__ get_collision_button2();
int /*<<< orphan*/ handle_collision_button1();
int /*<<< orphan*/ lower_probiscus();
int /*<<< orphan*/ raise_probiscus();
int /*<<< orphan*/ ramming_speed();
int /*<<< orphan*/ stop_moving();
int /*<<< orphan*/ wait1Msec(int);
void handle_side_collision_button(int turn_direction) {
  int count = 0;
  while (!get_collision_button() && !get_collision_button2() && count < 150) {
    if (turn_direction == 0) {
      fast_turn_left();
    } else {
      fast_turn_right();
    }
    wait1Msec(1);
    count++;
  }
  if (get_collision_button()) {
    handle_collision_button1();
  } else if (get_collision_button2()) {
    handle_collision_button1();
  } else {
    stop_moving();
    raise_probiscus();
    ramming_speed();
    wait1Msec(1000);
    while (get_collision_button()) {
      wait1Msec(1000);
    }
    lower_probiscus();
    stop_moving();
  }
}


x86 assembly (clang, -O0):
<handle_side_collision_button>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   10a0 <get_collision_button@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x9(%rbp)
jne    11f1 <handle_side_collision_button+0x51>
mov    $0x0,%al
call   1050 <get_collision_button2@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x9(%rbp)
jne    11f1 <handle_side_collision_button+0x51>
cmpl   $0x96,-0x8(%rbp)
setl   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1201 <handle_side_collision_button+0x61>
jmp    1236 <handle_side_collision_button+0x96>
cmpl   $0x0,-0x4(%rbp)
jne    1217 <handle_side_collision_button+0x77>
mov    $0x0,%al
call   1090 <fast_turn_left@plt>
jmp    121e <handle_side_collision_button+0x7e>
mov    $0x0,%al
call   1030 <fast_turn_right@plt>
mov    $0x1,%edi
call   1060 <wait1Msec@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b2 <handle_side_collision_button+0x12>
mov    $0x0,%al
call   10a0 <get_collision_button@plt>
cmp    $0x0,%rax
je     1253 <handle_side_collision_button+0xb3>
mov    $0x0,%al
call   1040 <handle_collision_button1@plt>
jmp    12c2 <handle_side_collision_button+0x122>
mov    $0x0,%al
call   1050 <get_collision_button2@plt>
cmp    $0x0,%rax
je     1270 <handle_side_collision_button+0xd0>
mov    $0x0,%al
call   1040 <handle_collision_button1@plt>
jmp    12bd <handle_side_collision_button+0x11d>
mov    $0x0,%al
call   10c0 <stop_moving@plt>
mov    $0x0,%al
call   10b0 <raise_probiscus@plt>
mov    $0x0,%al
call   1070 <ramming_speed@plt>
mov    $0x3e8,%edi
call   1060 <wait1Msec@plt>
mov    $0x0,%al
call   10a0 <get_collision_button@plt>
cmp    $0x0,%rax
je     12af <handle_side_collision_button+0x10f>
mov    $0x3e8,%edi
call   1060 <wait1Msec@plt>
jmp    128f <handle_side_collision_button+0xef>
mov    $0x0,%al
call   1080 <lower_probiscus@plt>
mov    $0x0,%al
call   10c0 <stop_moving@plt>
jmp    12c2 <handle_side_collision_button+0x122>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_side_collision_button>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   10a0 <get_collision_button@plt>
test   %rax,%rax
je     11d6 <handle_side_collision_button+0x36>
xor    %eax,%eax
call   10a0 <get_collision_button@plt>
test   %rax,%rax
jne    11c9 <handle_side_collision_button+0x29>
xor    %eax,%eax
call   1050 <get_collision_button2@plt>
test   %rax,%rax
je     121f <handle_side_collision_button+0x7f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <handle_collision_button1@plt>
xor    %ebp,%ebp
jmp    11fe <handle_side_collision_button+0x5e>
nopw   0x0(%rax,%rax,1)
call   1030 <fast_turn_right@plt>
mov    $0x1,%edi
call   1060 <wait1Msec@plt>
add    $0x1,%ebp
xor    %eax,%eax
call   10a0 <get_collision_button@plt>
test   %rax,%rax
jne    11b1 <handle_side_collision_button+0x11>
xor    %eax,%eax
call   1050 <get_collision_button2@plt>
test   %rax,%rax
jne    11b1 <handle_side_collision_button+0x11>
cmp    $0x95,%ebp
ja     11b1 <handle_side_collision_button+0x11>
xor    %eax,%eax
test   %ebx,%ebx
jne    11e0 <handle_side_collision_button+0x40>
call   1090 <fast_turn_left@plt>
jmp    11e5 <handle_side_collision_button+0x45>
xor    %eax,%eax
call   10c0 <stop_moving@plt>
xor    %eax,%eax
call   10b0 <raise_probiscus@plt>
xor    %eax,%eax
call   1070 <ramming_speed@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x3e8,%edi
call   1060 <wait1Msec@plt>
xor    %eax,%eax
call   10a0 <get_collision_button@plt>
test   %rax,%rax
jne    1240 <handle_side_collision_button+0xa0>
xor    %eax,%eax
call   1080 <lower_probiscus@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    10c0 <stop_moving@plt>

LLVM IR (-O0):
define void @handle_side_collision_button(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %22, %1
%5 = call i64 (...) @get_collision_button()
%6 = icmp ne i64 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = call i64 (...) @get_collision_button2()
%9 = icmp ne i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 150
br label %13
13: ; preds = %10, %7, %4
%14 = phi i1 [ false, %7 ], [ false, %4 ], [ %12, %10 ]
br i1 %14, label %15, label %26
15: ; preds = %13
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (...) @fast_turn_left()
br label %22
20: ; preds = %15
%21 = call i32 (...) @fast_turn_right()
br label %22
22: ; preds = %20, %18
%23 = call i32 @wait1Msec(i32 1)
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %4
26: ; preds = %13
%27 = call i64 (...) @get_collision_button()
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (...) @handle_collision_button1()
br label %50
31: ; preds = %26
%32 = call i64 (...) @get_collision_button2()
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 (...) @handle_collision_button1()
br label %49
36: ; preds = %31
%37 = call i32 (...) @stop_moving()
%38 = call i32 (...) @raise_probiscus()
%39 = call i32 (...) @ramming_speed()
%40 = call i32 @wait1Msec(i32 1000)
br label %41
41: ; preds = %44, %36
%42 = call i64 (...) @get_collision_button()
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @wait1Msec(i32 1000)
br label %41
46: ; preds = %41
%47 = call i32 (...) @lower_probiscus()
%48 = call i32 (...) @stop_moving()
br label %49
49: ; preds = %46, %34
br label %50
50: ; preds = %49, %29
ret void
}

LLVM IR (-O2):
define void @handle_side_collision_button(i32 %0) {
%2 = tail call i64 (...) @get_collision_button()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %22
4: ; preds = %1
%5 = icmp eq i32 %0, 0
br label %6
6: ; preds = %4, %17
%7 = phi i32 [ 0, %4 ], [ %19, %17 ]
%8 = tail call i64 (...) @get_collision_button2()
%9 = icmp eq i64 %8, 0
%10 = icmp ult i32 %7, 150
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %22
12: ; preds = %6
br i1 %5, label %13, label %15
13: ; preds = %12
%14 = tail call i32 (...) @fast_turn_left()
br label %17
15: ; preds = %12
%16 = tail call i32 (...) @fast_turn_right()
br label %17
17: ; preds = %15, %13
%18 = tail call i32 @wait1Msec(i32 1)
%19 = add nuw nsw i32 %7, 1
%20 = tail call i64 (...) @get_collision_button()
%21 = icmp eq i64 %20, 0
br i1 %21, label %6, label %22
22: ; preds = %6, %17, %1
%23 = tail call i64 (...) @get_collision_button()
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 (...) @handle_collision_button1()
br label %46
27: ; preds = %22
%28 = tail call i64 (...) @get_collision_button2()
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 (...) @handle_collision_button1()
br label %46
32: ; preds = %27
%33 = tail call i32 (...) @stop_moving()
%34 = tail call i32 (...) @raise_probiscus()
%35 = tail call i32 (...) @ramming_speed()
%36 = tail call i32 @wait1Msec(i32 1000)
%37 = tail call i64 (...) @get_collision_button()
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %32, %39
%40 = tail call i32 @wait1Msec(i32 1000)
%41 = tail call i64 (...) @get_collision_button()
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %39
43: ; preds = %39, %32
%44 = tail call i32 (...) @lower_probiscus()
%45 = tail call i32 (...) @stop_moving()
br label %46
46: ; preds = %30, %43, %25
ret void
}