#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 INT_MIN;
int getDistance();
scalar_t__ stopWait();
int /*<<< orphan*/ usleep(int);
int waitDistance(int dist, int interrupt) {
  int count = 0, current = 0;
  if (INT_MIN == getDistance())
    return INT_MIN;
  while (1) {
    usleep(20000);
    current = getDistance();
    if (INT_MIN == current)
      return INT_MIN;
    count += current;
    if ((interrupt && stopWait()) || (dist >= 0 && count >= dist) ||
        (dist < 0 && count <= dist))
      break;
  }
  return count;
}


x86 assembly (clang, -O0):
<waitDistance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getDistance@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jne    117d <waitDistance+0x4d>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1219 <waitDistance+0xe9>
jmp    1182 <waitDistance+0x52>
mov    $0x4e20,%edi
call   1050 <usleep@plt>
mov    $0x0,%al
call   1030 <getDistance@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jne    11b9 <waitDistance+0x89>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1219 <waitDistance+0xe9>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11dd <waitDistance+0xad>
mov    $0x0,%al
call   1040 <stopWait@plt>
cmp    $0x0,%rax
jne    1209 <waitDistance+0xd9>
cmpl   $0x0,-0x8(%rbp)
jl     11f3 <waitDistance+0xc3>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1209 <waitDistance+0xd9>
cmpl   $0x0,-0x8(%rbp)
jge    120e <waitDistance+0xde>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     120e <waitDistance+0xde>
jmp    1213 <waitDistance+0xe3>
jmp    1182 <waitDistance+0x52>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitDistance>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
mov    0x2ea5(%rip),%r15
mov    (%r15),%ebx
xor    %eax,%eax
call   1030 <getDistance@plt>
cmp    %eax,%ebx
jne    1156 <waitDistance+0x26>
mov    (%r15),%ebx
jmp    119d <waitDistance+0x6d>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x4e20,%edi
call   1050 <usleep@plt>
xor    %eax,%eax
call   1030 <getDistance@plt>
cmp    %eax,(%r15)
je     119b <waitDistance+0x6b>
add    %eax,%ebx
test   %r14d,%r14d
je     1189 <waitDistance+0x59>
xor    %eax,%eax
call   1040 <stopWait@plt>
test   %rax,%rax
jne    119d <waitDistance+0x6d>
test   %ebp,%ebp
js     1191 <waitDistance+0x61>
cmp    %ebp,%ebx
jge    119d <waitDistance+0x6d>
test   %ebp,%ebp
jns    1160 <waitDistance+0x30>
cmp    %ebp,%ebx
jg     1160 <waitDistance+0x30>
jmp    119d <waitDistance+0x6d>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@INT_MIN = global i32 0
define i32 @waitDistance(i32 %0, i32 %1) {
%3 = load i32, i32* @INT_MIN
%4 = tail call i32 (...) @getDistance()
%5 = icmp eq i32 %3, %4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp eq i32 %1, 0
%8 = icmp slt i32 %0, 0
%9 = icmp sgt i32 %0, -1
br label %12
10: ; preds = %2
%11 = load i32, i32* @INT_MIN
br label %29
12: ; preds = %6, %26
%13 = phi i32 [ %19, %26 ], [ 0, %6 ]
%14 = tail call i32 @usleep(i32 20000)
%15 = tail call i32 (...) @getDistance()
%16 = load i32, i32* @INT_MIN
%17 = icmp eq i32 %16, %15
br i1 %17, label %29, label %18
18: ; preds = %12
%19 = add nsw i32 %15, %13
br i1 %7, label %23, label %20
20: ; preds = %18
%21 = tail call i64 (...) @stopWait()
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20, %18
%24 = icmp slt i32 %19, %0
%25 = select i1 %8, i1 true, i1 %24
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = icmp sgt i32 %19, %0
%28 = select i1 %9, i1 true, i1 %27
br i1 %28, label %12, label %29
29: ; preds = %20, %23, %26, %12, %10
%30 = phi i32 [ %11, %10 ], [ %19, %20 ], [ %19, %23 ], [ %19, %26 ], [ %15, %12 ]
ret i32 %30
}