#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 */
scalar_t__ abs(int);
scalar_t__ distanceNotTraveled(int);
int /*<<< orphan*/ initalizeEncoders();
int /*<<< orphan*/ leftSpeed(int);
int /*<<< orphan*/ rightSpeed(int);
int /*<<< orphan*/ wait1Msec(int);
void turnRight(int power, int encoder) {
  int currentPower = 0;
  encoder = encoder * 2 / 3;
  initalizeEncoders();
  while (distanceNotTraveled(encoder)) {
    if (abs(currentPower) < abs(power)) {
      if (power > 0) {
        currentPower++;
      }
      if (power < 0) {
        currentPower--;
      }
      wait1Msec(20);
    }
    rightSpeed(currentPower);
    leftSpeed(-currentPower);
  }
  rightSpeed(0);
  leftSpeed(0);
}


x86 assembly (clang, -O0):
<turnRight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <initalizeEncoders@plt>
mov    -0x8(%rbp),%edi
call   1080 <distanceNotTraveled@plt>
cmp    $0x0,%rax
je     120a <turnRight+0xaa>
mov    -0xc(%rbp),%edi
call   1050 <abs@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <abs@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
jge    11f3 <turnRight+0x93>
cmpl   $0x0,-0x4(%rbp)
jle    11d6 <turnRight+0x76>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11e9 <turnRight+0x89>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    $0x14,%edi
call   1070 <wait1Msec@plt>
mov    -0xc(%rbp),%edi
call   1030 <rightSpeed@plt>
xor    %edi,%edi
sub    -0xc(%rbp),%edi
call   1060 <leftSpeed@plt>
jmp    118d <turnRight+0x2d>
xor    %edi,%edi
call   1030 <rightSpeed@plt>
xor    %edi,%edi
call   1060 <leftSpeed@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<turnRight>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
add    %esi,%esi
movslq %esi,%rax
imul   $0x55555556,%rax,%r15
mov    %r15,%rax
shr    $0x3f,%rax
shr    $0x20,%r15
add    %eax,%r15d
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <initalizeEncoders@plt>
mov    %r15d,%edi
call   1080 <distanceNotTraveled@plt>
test   %rax,%rax
je     11f3 <turnRight+0x93>
xor    %eax,%eax
test   %r14d,%r14d
setg   %al
mov    %r14d,%r12d
sar    $0x1f,%r12d
add    %eax,%r12d
jmp    11cd <turnRight+0x6d>
nop
mov    %ebp,%edi
call   1030 <rightSpeed@plt>
mov    %ebp,%edi
neg    %edi
call   1060 <leftSpeed@plt>
mov    %r15d,%edi
call   1080 <distanceNotTraveled@plt>
test   %rax,%rax
je     11f3 <turnRight+0x93>
mov    %ebp,%edi
call   1050 <abs@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1050 <abs@plt>
cmp    %rax,%rbx
jge    11b0 <turnRight+0x50>
add    %r12d,%ebp
mov    $0x14,%edi
call   1070 <wait1Msec@plt>
jmp    11b0 <turnRight+0x50>
xor    %edi,%edi
call   1030 <rightSpeed@plt>
xor    %edi,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <leftSpeed@plt>

LLVM IR (-O0):
define void @turnRight(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
%7 = mul nsw i32 %6, 2
%8 = sdiv i32 %7, 3
store i32 %8, i32* %4
%9 = call i32 (...) @initalizeEncoders()
br label %10
10: ; preds = %34, %2
%11 = load i32, i32* %4
%12 = call i64 @distanceNotTraveled(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %40
14: ; preds = %10
%15 = load i32, i32* %5
%16 = call i64 @abs(i32 %15)
%17 = load i32, i32* %3
%18 = call i64 @abs(i32 %17)
%19 = icmp slt i64 %16, %18
br i1 %19, label %20, label %34
20: ; preds = %14
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %5
%31 = add nsw i32 %30, -1
store i32 %31, i32* %5
br label %32
32: ; preds = %29, %26
%33 = call i32 @wait1Msec(i32 20)
br label %34
34: ; preds = %32, %14
%35 = load i32, i32* %5
%36 = call i32 @rightSpeed(i32 %35)
%37 = load i32, i32* %5
%38 = sub nsw i32 0, %37
%39 = call i32 @leftSpeed(i32 %38)
br label %10
40: ; preds = %10
%41 = call i32 @rightSpeed(i32 0)
%42 = call i32 @leftSpeed(i32 0)
ret void
}

LLVM IR (-O2):
define void @turnRight(i32 %0, i32 %1) {
%3 = shl nsw i32 %1, 1
%4 = sdiv i32 %3, 3
%5 = tail call i32 (...) @initalizeEncoders()
%6 = tail call i64 @distanceNotTraveled(i32 %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %2
%9 = icmp sgt i32 %0, 0
%10 = zext i1 %9 to i32
%11 = ashr i32 %0, 31
%12 = add nsw i32 %11, %10
br label %13
13: ; preds = %8, %21
%14 = phi i32 [ 0, %8 ], [ %22, %21 ]
%15 = tail call i64 @abs(i32 %14)
%16 = tail call i64 @abs(i32 %0)
%17 = icmp slt i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = add i32 %12, %14
%20 = tail call i32 @wait1Msec(i32 20)
br label %21
21: ; preds = %18, %13
%22 = phi i32 [ %19, %18 ], [ %14, %13 ]
%23 = tail call i32 @rightSpeed(i32 %22)
%24 = sub nsw i32 0, %22
%25 = tail call i32 @leftSpeed(i32 %24)
%26 = tail call i64 @distanceNotTraveled(i32 %4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %13
28: ; preds = %21, %2
%29 = tail call i32 @rightSpeed(i32 0)
%30 = tail call i32 @leftSpeed(i32 0)
ret void
}