#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 abs(int);
int /*<<< orphan*/ io_clear_bit(int);
int /*<<< orphan*/ io_set_bit(int);
int /*<<< orphan*/ io_write_analog(scalar_t__, int);
void elev_set_speed(int speed) {
  static int last_speed = 0;
  if (speed > 0)
    io_clear_bit((0x300 + 15));
  else if (speed < 0)
    io_set_bit((0x300 + 15));
  else if (last_speed < 0)
    io_clear_bit((0x300 + 15));
  else if (last_speed > 0)
    io_set_bit((0x300 + 15));
  last_speed = speed;
  io_write_analog((0x100 + 0), 2048 + 4 * abs(speed));
}


x86 assembly (clang, -O0):
<elev_set_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1164 <elev_set_speed+0x24>
mov    $0x30f,%edi
call   1050 <io_clear_bit@plt>
jmp    11bf <elev_set_speed+0x7f>
cmpl   $0x0,-0x4(%rbp)
jge    117d <elev_set_speed+0x3d>
mov    $0x30f,%edi
call   1040 <io_set_bit@plt>
jmp    11ba <elev_set_speed+0x7a>
cmpl   $0x0,0x2ec0(%rip)
jge    1199 <elev_set_speed+0x59>
mov    $0x30f,%edi
call   1050 <io_clear_bit@plt>
jmp    11b5 <elev_set_speed+0x75>
cmpl   $0x0,0x2ea4(%rip)
jle    11b0 <elev_set_speed+0x70>
mov    $0x30f,%edi
call   1040 <io_set_bit@plt>
jmp    11b5 <elev_set_speed+0x75>
jmp    11ba <elev_set_speed+0x7a>
jmp    11bf <elev_set_speed+0x7f>
mov    -0x4(%rbp),%eax
mov    %eax,0x2e7c(%rip)
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%esi
shl    $0x2,%esi
add    $0x800,%esi
mov    $0x100,%edi
call   1060 <io_write_analog@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elev_set_speed>:
push   %rbx
mov    %edi,%ebx
test   %edi,%edi
jle    1143 <elev_set_speed+0x13>
mov    $0x30f,%edi
call   1040 <io_clear_bit@plt>
jmp    115a <elev_set_speed+0x2a>
js     1150 <elev_set_speed+0x20>
cmpl   $0x0,0x2ef0(%rip)
js     1137 <elev_set_speed+0x7>
je     115a <elev_set_speed+0x2a>
mov    $0x30f,%edi
call   1030 <io_set_bit@plt>
mov    %ebx,0x2edc(%rip)
mov    %ebx,%eax
neg    %eax
cmovs  %ebx,%eax
lea    0x800(,%rax,4),%esi
mov    $0x100,%edi
pop    %rbx
jmp    1050 <io_write_analog@plt>

LLVM IR (-O0):
@elev_set_speed.last_speed = internal global i32 0
define void @elev_set_speed(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 @io_clear_bit(i32 783)
br label %25
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @io_set_bit(i32 783)
br label %24
12: ; preds = %7
%13 = load i32, i32* @elev_set_speed.last_speed
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @io_clear_bit(i32 783)
br label %23
17: ; preds = %12
%18 = load i32, i32* @elev_set_speed.last_speed
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @io_set_bit(i32 783)
br label %22
22: ; preds = %20, %17
br label %23
23: ; preds = %22, %15
br label %24
24: ; preds = %23, %10
br label %25
25: ; preds = %24, %5
%26 = load i32, i32* %2
store i32 %26, i32* @elev_set_speed.last_speed
%27 = load i32, i32* %2
%28 = call i32 @abs(i32 %27)
%29 = mul nsw i32 4, %28
%30 = add nsw i32 2048, %29
%31 = call i32 @io_write_analog(i64 256, i32 %30)
ret void
}

LLVM IR (-O2):
@elev_set_speed.last_speed = internal unnamed_addr global i32 0
define void @elev_set_speed(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @io_clear_bit(i32 783)
br label %18
5: ; preds = %1
%6 = icmp slt i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @io_set_bit(i32 783)
br label %18
9: ; preds = %5
%10 = load i32, i32* @elev_set_speed.last_speed
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @io_clear_bit(i32 783)
br label %18
14: ; preds = %9
%15 = icmp eq i32 %10, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @io_set_bit(i32 783)
br label %18
18: ; preds = %7, %14, %16, %12, %3
store i32 %0, i32* @elev_set_speed.last_speed
%19 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%20 = shl nsw i32 %19, 2
%21 = add nuw nsw i32 %20, 2048
%22 = tail call i32 @io_write_analog(i64 256, i32 %21)
ret void
}