#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*/ wait1Msec(int);
void speedTransition(int currentSpeed, int newSpeed, int motorPow) {
  int diff;
  int diffProg;
  if (newSpeed > currentSpeed) {
    diff = newSpeed - currentSpeed;
    diffProg = 0;
    while (diffProg < diff) {
      currentSpeed += 1;
      diffProg += 1;
      motorPow = currentSpeed;
      wait1Msec(10);
    }
  } else if (newSpeed < currentSpeed) {
    diff = currentSpeed - newSpeed;
    diffProg = diff;
    while (diffProg > 0) {
      currentSpeed -= 1;
      diffProg -= 1;
      motorPow = currentSpeed;
      wait1Msec(10);
    }
  }
}


x86 assembly (clang, -O0):
<speedTransition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    1175 <speedTransition+0x65>
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1170 <speedTransition+0x60>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0xa,%edi
call   1030 <wait1Msec@plt>
jmp    113d <speedTransition+0x2d>
jmp    11cb <speedTransition+0xbb>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c6 <speedTransition+0xb6>
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11c1 <speedTransition+0xb1>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0xa,%edi
call   1030 <wait1Msec@plt>
jmp    1190 <speedTransition+0x80>
jmp    11c6 <speedTransition+0xb6>
jmp    11cb <speedTransition+0xbb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<speedTransition>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
sub    %edi,%ebp
jle    1131 <speedTransition+0x21>
test   %ebp,%ebp
jle    1152 <speedTransition+0x42>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <wait1Msec@plt>
add    $0xffffffff,%ebp
jne    1120 <speedTransition+0x10>
jmp    1152 <speedTransition+0x42>
mov    %edi,%ebx
sub    %esi,%ebx
jle    1152 <speedTransition+0x42>
test   %ebx,%ebx
jle    1152 <speedTransition+0x42>
add    $0x1,%ebx
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <wait1Msec@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1140 <speedTransition+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @speedTransition(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, %0
br i1 %4, label %5, label %13
5: ; preds = %3
%6 = sub i32 %1, %0
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %5, %8
%9 = phi i32 [ %10, %8 ], [ 0, %5 ]
%10 = add nuw nsw i32 %9, 1
%11 = tail call i32 @wait1Msec(i32 10)
%12 = icmp eq i32 %10, %6
br i1 %12, label %23, label %8
13: ; preds = %3
%14 = icmp slt i32 %1, %0
%15 = sub nsw i32 %0, %1
%16 = icmp sgt i32 %15, 0
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %18, label %23
18: ; preds = %13, %18
%19 = phi i32 [ %20, %18 ], [ %15, %13 ]
%20 = add nsw i32 %19, -1
%21 = tail call i32 @wait1Msec(i32 10)
%22 = icmp ugt i32 %19, 1
br i1 %22, label %18, label %23
23: ; preds = %18, %8, %5, %13
ret void
}