#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*/ create_wait_length(int);
int /*<<< orphan*/ create_write_byte(unsigned int);
void create_drive_segment(unsigned int speed, int distance) {
  ;
  create_write_byte(145);
  if (distance < 0) {
    create_write_byte(((-1 * speed & 0xFFFF) >> 8));
    create_write_byte((-1 * speed & 0xFF));
    create_write_byte(((-1 * speed & 0xFFFF) >> 8));
    create_write_byte((-1 * speed & 0xFF));
  } else {
    create_write_byte(((speed & 0xFFFF) >> 8));
    create_write_byte((speed & 0xFF));
    create_write_byte(((speed & 0xFFFF) >> 8));
    create_write_byte((speed & 0xFF));
  };
  create_wait_length(distance);
}


x86 assembly (clang, -O0):
<create_drive_segment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x91,%edi
call   1030 <create_write_byte@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1195 <create_drive_segment+0x75>
imul   $0xffffffff,-0x4(%rbp),%edi
and    $0xffff,%edi
shr    $0x8,%edi
call   1030 <create_write_byte@plt>
imul   $0xffffffff,-0x4(%rbp),%edi
and    $0xff,%edi
call   1030 <create_write_byte@plt>
imul   $0xffffffff,-0x4(%rbp),%edi
and    $0xffff,%edi
shr    $0x8,%edi
call   1030 <create_write_byte@plt>
imul   $0xffffffff,-0x4(%rbp),%edi
and    $0xff,%edi
call   1030 <create_write_byte@plt>
jmp    11d3 <create_drive_segment+0xb3>
mov    -0x4(%rbp),%edi
and    $0xffff,%edi
shr    $0x8,%edi
call   1030 <create_write_byte@plt>
mov    -0x4(%rbp),%edi
and    $0xff,%edi
call   1030 <create_write_byte@plt>
mov    -0x4(%rbp),%edi
and    $0xffff,%edi
shr    $0x8,%edi
call   1030 <create_write_byte@plt>
mov    -0x4(%rbp),%edi
and    $0xff,%edi
call   1030 <create_write_byte@plt>
mov    -0x8(%rbp),%edi
call   1040 <create_wait_length@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_drive_segment>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    $0x91,%edi
call   1030 <create_write_byte@plt>
mov    %ebp,%ebx
neg    %ebx
test   %r14d,%r14d
cmovns %ebp,%ebx
movzbl %bh,%ebp
mov    %ebp,%edi
call   1030 <create_write_byte@plt>
movzbl %bl,%ebx
mov    %ebx,%edi
call   1030 <create_write_byte@plt>
mov    %ebp,%edi
call   1030 <create_write_byte@plt>
mov    %ebx,%edi
call   1030 <create_write_byte@plt>
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <create_wait_length@plt>

LLVM IR (-O0):
define void @create_drive_segment(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = call i32 @create_write_byte(i32 145)
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %2
%9 = load i32, i32* %3
%10 = mul i32 -1, %9
%11 = and i32 %10, 65535
%12 = lshr i32 %11, 8
%13 = call i32 @create_write_byte(i32 %12)
%14 = load i32, i32* %3
%15 = mul i32 -1, %14
%16 = and i32 %15, 255
%17 = call i32 @create_write_byte(i32 %16)
%18 = load i32, i32* %3
%19 = mul i32 -1, %18
%20 = and i32 %19, 65535
%21 = lshr i32 %20, 8
%22 = call i32 @create_write_byte(i32 %21)
%23 = load i32, i32* %3
%24 = mul i32 -1, %23
%25 = and i32 %24, 255
%26 = call i32 @create_write_byte(i32 %25)
br label %42
27: ; preds = %2
%28 = load i32, i32* %3
%29 = and i32 %28, 65535
%30 = lshr i32 %29, 8
%31 = call i32 @create_write_byte(i32 %30)
%32 = load i32, i32* %3
%33 = and i32 %32, 255
%34 = call i32 @create_write_byte(i32 %33)
%35 = load i32, i32* %3
%36 = and i32 %35, 65535
%37 = lshr i32 %36, 8
%38 = call i32 @create_write_byte(i32 %37)
%39 = load i32, i32* %3
%40 = and i32 %39, 255
%41 = call i32 @create_write_byte(i32 %40)
br label %42
42: ; preds = %27, %8
%43 = load i32, i32* %4
%44 = call i32 @create_wait_length(i32 %43)
ret void
}

LLVM IR (-O2):
define void @create_drive_segment(i32 %0, i32 %1) {
%3 = tail call i32 @create_write_byte(i32 145)
%4 = icmp slt i32 %1, 0
%5 = sub i32 0, %0
%6 = select i1 %4, i32 %5, i32 %0
%7 = lshr i32 %6, 8
%8 = and i32 %7, 255
%9 = tail call i32 @create_write_byte(i32 %8)
%10 = and i32 %6, 255
%11 = tail call i32 @create_write_byte(i32 %10)
%12 = tail call i32 @create_write_byte(i32 %8)
%13 = tail call i32 @create_write_byte(i32 %10)
%14 = tail call i32 @create_wait_length(i32 %1)
ret void
}