#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 /*<<< orphan*/);
int /*<<< orphan*/ create_drive_direct(int, int);
int /*<<< orphan*/ create_stop();
int /*<<< orphan*/ get_create_distance();
int /*<<< orphan*/ msleep(int);
int /*<<< orphan*/ set_create_distance(int /*<<< orphan*/);
void create_drive_segment(int speed, int distance_mm) {
  set_create_distance(0);
  if (distance_mm > 0)
    create_drive_direct(speed, speed);
  else if (distance_mm < 0)
    create_drive_direct(-1 * speed, -1 * speed);
  while (abs(get_create_distance()) < distance_mm)
    msleep(1);
  create_stop();
}


x86 assembly (clang, -O0):
<create_drive_segment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
xor    %edi,%edi
call   1040 <set_create_distance@plt>
cmpl   $0x0,-0x8(%rbp)
jle    118f <create_drive_segment+0x2f>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1070 <create_drive_direct@plt>
jmp    11b1 <create_drive_segment+0x51>
cmpl   $0x0,-0x8(%rbp)
jge    11ac <create_drive_segment+0x4c>
imul   $0xffffffff,-0x4(%rbp),%edi
imul   $0xffffffff,-0x4(%rbp),%esi
call   1070 <create_drive_direct@plt>
jmp    11b1 <create_drive_segment+0x51>
jmp    11b6 <create_drive_segment+0x56>
mov    $0x0,%al
call   1080 <get_create_distance@plt>
mov    %eax,%edi
call   1030 <abs@plt>
cmp    -0x8(%rbp),%eax
jge    11dc <create_drive_segment+0x7c>
mov    $0x1,%edi
call   1060 <msleep@plt>
jmp    11b6 <create_drive_segment+0x56>
mov    $0x0,%al
call   1050 <create_stop@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_drive_segment>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %edi,%edi
call   1030 <set_create_distance@plt>
test   %ebx,%ebx
jle    116d <create_drive_segment+0x1d>
mov    %ebp,%edi
mov    %ebp,%esi
call   1060 <create_drive_direct@plt>
jmp    118a <create_drive_segment+0x3a>
jns    118a <create_drive_segment+0x3a>
neg    %ebp
jmp    1162 <create_drive_segment+0x12>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
call   1050 <msleep@plt>
xor    %eax,%eax
call   1070 <get_create_distance@plt>
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
cmp    %ebx,%ecx
jl     1180 <create_drive_segment+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <create_stop@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 @set_create_distance(i32 0)
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* %3
%10 = load i32, i32* %3
%11 = call i32 @create_drive_direct(i32 %9, i32 %10)
br label %22
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* %3
%17 = mul nsw i32 -1, %16
%18 = load i32, i32* %3
%19 = mul nsw i32 -1, %18
%20 = call i32 @create_drive_direct(i32 %17, i32 %19)
br label %21
21: ; preds = %15, %12
br label %22
22: ; preds = %21, %8
br label %23
23: ; preds = %28, %22
%24 = call i32 (...) @get_create_distance()
%25 = call i32 @abs(i32 %24)
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @msleep(i32 1)
br label %23
30: ; preds = %23
%31 = call i32 (...) @create_stop()
ret void
}

LLVM IR (-O2):
define void @create_drive_segment(i32 %0, i32 %1) {
%3 = tail call i32 @set_create_distance(i32 0)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @create_drive_direct(i32 %0, i32 %0)
br label %12
7: ; preds = %2
%8 = icmp slt i32 %1, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = sub nsw i32 0, %0
%11 = tail call i32 @create_drive_direct(i32 %10, i32 %10)
br label %12
12: ; preds = %7, %9, %5
%13 = tail call i32 (...) @get_create_distance()
%14 = tail call i32 @llvm.abs.i32(i32 %13, i1 true)
%15 = icmp slt i32 %14, %1
br i1 %15, label %16, label %21
16: ; preds = %12, %16
%17 = tail call i32 @msleep(i32 1)
%18 = tail call i32 (...) @get_create_distance()
%19 = tail call i32 @llvm.abs.i32(i32 %18, i1 true)
%20 = icmp slt i32 %19, %1
br i1 %20, label %16, label %21
21: ; preds = %16, %12
%22 = tail call i32 (...) @create_stop()
ret void
}