#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*/ cycle();
int /*<<< orphan*/ drive(int, int);
int loc_x();
int loc_y();
void run() {
  static enum { EAST, NORTH, WEST, SOUTH } last_dir;
  int x, y;
  int i = 0;
  x = loc_x();
  y = loc_y();
  if (last_dir == EAST || last_dir == WEST)
    last_dir = (y > 500 ? SOUTH : NORTH);
  else
    last_dir = (x > 500 ? WEST : EAST);
  switch (last_dir) {
  case SOUTH:
    drive(90, 100);
    while (y - 100 < loc_y() && i++ < 100)
      cycle();
    break;
  case NORTH:
    drive(270, 100);
    while (y + 100 > loc_y() && i++ < 100)
      cycle();
    break;
  case WEST:
    drive(180, 100);
    while (x - 100 < loc_x() && i++ < 100)
      cycle();
    break;
  case EAST:
    drive(0, 100);
    while (x + 100 > loc_x() && i++ < 100)
      cycle();
    break;
  }
  drive(0, 0);
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <loc_x@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <loc_y@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,0x2eda(%rip)
je     117d <run+0x3d>
cmpl   $0x2,0x2ecd(%rip)
jne    119e <run+0x5e>
mov    -0x8(%rbp),%edx
mov    $0x1,%eax
mov    $0x3,%ecx
cmp    $0x1f4,%edx
cmovg  %ecx,%eax
mov    %eax,0x2eab(%rip)
jmp    11b7 <run+0x77>
mov    -0x4(%rbp),%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x1f4,%edx
cmovg  %ecx,%eax
mov    %eax,0x2e8d(%rip)
mov    0x2e87(%rip),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     1374 <run+0x234>
mov    -0x18(%rbp),%rax
lea    0xe2a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x5a,%edi
mov    $0x64,%esi
call   1050 <drive@plt>
mov    -0x8(%rbp),%eax
sub    $0x64,%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <loc_y@plt>
mov    -0x20(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x19(%rbp)
jge    1224 <run+0xe4>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x64,%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1234 <run+0xf4>
jmp    1240 <run+0x100>
mov    $0x0,%al
call   1060 <cycle@plt>
jmp    11ee <run+0xae>
jmp    1374 <run+0x234>
mov    $0x10e,%edi
mov    $0x64,%esi
call   1050 <drive@plt>
mov    -0x8(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <loc_y@plt>
mov    -0x28(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x21(%rbp)
jle    128a <run+0x14a>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x64,%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    129a <run+0x15a>
jmp    12a6 <run+0x166>
mov    $0x0,%al
call   1060 <cycle@plt>
jmp    1254 <run+0x114>
jmp    1374 <run+0x234>
mov    $0xb4,%edi
mov    $0x64,%esi
call   1050 <drive@plt>
mov    -0x4(%rbp),%eax
sub    $0x64,%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <loc_x@plt>
mov    -0x30(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x29(%rbp)
jge    12f0 <run+0x1b0>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x64,%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1300 <run+0x1c0>
jmp    130c <run+0x1cc>
mov    $0x0,%al
call   1060 <cycle@plt>
jmp    12ba <run+0x17a>
jmp    1374 <run+0x234>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <drive@plt>
mov    -0x4(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <loc_x@plt>
mov    -0x38(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x31(%rbp)
jle    1353 <run+0x213>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x64,%eax
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1363 <run+0x223>
jmp    136f <run+0x22f>
mov    $0x0,%al
call   1060 <cycle@plt>
jmp    131d <run+0x1dd>
jmp    1374 <run+0x234>
xor    %esi,%esi
mov    %esi,%edi
call   1050 <drive@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <loc_x@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <loc_y@plt>
mov    %eax,%ebp
xor    %eax,%eax
cmp    $0x1f5,%ebx
setge  %al
add    %eax,%eax
xor    %ecx,%ecx
cmp    $0x1f5,%ebp
setge  %cl
testl  $0xfffffffd,0x2ecd(%rip)
ff ff ff
lea    0x1(%rcx,%rcx,1),%ecx
cmovne %eax,%ecx
mov    %ecx,0x2ec0(%rip)
lea    0xe75(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <drive@plt>
add    $0x64,%ebx
xor    %eax,%eax
call   1040 <loc_x@plt>
cmp    %eax,%ebx
jle    12bc <run+0x17c>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <cycle@plt>
xor    %eax,%eax
call   1040 <loc_x@plt>
cmp    %eax,%ebx
jle    12bc <run+0x17c>
lea    0x1(%rbp),%eax
cmp    $0x63,%ebp
mov    %eax,%ebp
jb     11c0 <run+0x80>
jmp    12bc <run+0x17c>
mov    $0xb4,%edi
mov    $0x64,%esi
call   1050 <drive@plt>
add    $0xffffff9c,%ebx
xor    %eax,%eax
call   1040 <loc_x@plt>
cmp    %eax,%ebx
jge    12bc <run+0x17c>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <cycle@plt>
xor    %eax,%eax
call   1040 <loc_x@plt>
cmp    %eax,%ebx
jge    12bc <run+0x17c>
lea    0x1(%rbp),%eax
cmp    $0x63,%ebp
mov    %eax,%ebp
jb     1210 <run+0xd0>
jmp    12bc <run+0x17c>
mov    $0x5a,%edi
mov    $0x64,%esi
call   1050 <drive@plt>
add    $0xffffff9c,%ebp
xor    %eax,%eax
call   1030 <loc_y@plt>
cmp    %eax,%ebp
jge    12bc <run+0x17c>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <cycle@plt>
xor    %eax,%eax
call   1030 <loc_y@plt>
cmp    %eax,%ebp
jge    12bc <run+0x17c>
lea    0x1(%rbx),%eax
cmp    $0x63,%ebx
mov    %eax,%ebx
jb     1260 <run+0x120>
jmp    12bc <run+0x17c>
mov    $0x10e,%edi
mov    $0x64,%esi
call   1050 <drive@plt>
add    $0x64,%ebp
xor    %eax,%eax
call   1030 <loc_y@plt>
cmp    %eax,%ebp
jle    12bc <run+0x17c>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1060 <cycle@plt>
xor    %eax,%eax
call   1030 <loc_y@plt>
cmp    %eax,%ebp
jle    12bc <run+0x17c>
lea    0x1(%rbx),%eax
cmp    $0x63,%ebx
mov    %eax,%ebx
jb     12a0 <run+0x160>
xor    %edi,%edi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <drive@plt>

LLVM IR (-O0):
@run.last_dir = internal global i32 0
define void @run() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 (...) @loc_x()
store i32 %4, i32* %1
%5 = call i32 (...) @loc_y()
store i32 %5, i32* %2
%6 = load i32, i32* @run.last_dir
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i32, i32* @run.last_dir
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %8, %0
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 500
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 3, i32 1
store i32 %15, i32* @run.last_dir
br label %21
16: ; preds = %8
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 500
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 2, i32 0
store i32 %20, i32* @run.last_dir
br label %21
21: ; preds = %16, %11
%22 = load i32, i32* @run.last_dir
switch i32 %22, label %87 [
i32 3, label %23
i32 1, label %39
i32 2, label %55
i32 0, label %71
]
23: ; preds = %21
%24 = call i32 @drive(i32 90, i32 100)
br label %25
25: ; preds = %36, %23
%26 = load i32, i32* %2
%27 = sub nsw i32 %26, 100
%28 = call i32 (...) @loc_y()
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
%33 = icmp slt i32 %31, 100
br label %34
34: ; preds = %30, %25
%35 = phi i1 [ false, %25 ], [ %33, %30 ]
br i1 %35, label %36, label %38
36: ; preds = %34
%37 = call i32 (...) @cycle()
br label %25
38: ; preds = %34
br label %87
39: ; preds = %21
%40 = call i32 @drive(i32 270, i32 100)
br label %41
41: ; preds = %52, %39
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 100
%44 = call i32 (...) @loc_y()
%45 = icmp sgt i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
%49 = icmp slt i32 %47, 100
br label %50
50: ; preds = %46, %41
%51 = phi i1 [ false, %41 ], [ %49, %46 ]
br i1 %51, label %52, label %54
52: ; preds = %50
%53 = call i32 (...) @cycle()
br label %41
54: ; preds = %50
br label %87
55: ; preds = %21
%56 = call i32 @drive(i32 180, i32 100)
br label %57
57: ; preds = %68, %55
%58 = load i32, i32* %1
%59 = sub nsw i32 %58, 100
%60 = call i32 (...) @loc_x()
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
%65 = icmp slt i32 %63, 100
br label %66
66: ; preds = %62, %57
%67 = phi i1 [ false, %57 ], [ %65, %62 ]
br i1 %67, label %68, label %70
68: ; preds = %66
%69 = call i32 (...) @cycle()
br label %57
70: ; preds = %66
br label %87
71: ; preds = %21
%72 = call i32 @drive(i32 0, i32 100)
br label %73
73: ; preds = %84, %71
%74 = load i32, i32* %1
%75 = add nsw i32 %74, 100
%76 = call i32 (...) @loc_x()
%77 = icmp sgt i32 %75, %76
br i1 %77, label %78, label %82
78: ; preds = %73
%79 = load i32, i32* %3
%80 = add nsw i32 %79, 1
store i32 %80, i32* %3
%81 = icmp slt i32 %79, 100
br label %82
82: ; preds = %78, %73
%83 = phi i1 [ false, %73 ], [ %81, %78 ]
br i1 %83, label %84, label %86
84: ; preds = %82
%85 = call i32 (...) @cycle()
br label %73
86: ; preds = %82
br label %87
87: ; preds = %21, %86, %70, %54, %38
%88 = call i32 @drive(i32 0, i32 0)
ret void
}

LLVM IR (-O2):
@run.last_dir = internal unnamed_addr global i32 0
define void @run() {
%1 = tail call i32 (...) @loc_x()
%2 = tail call i32 (...) @loc_y()
%3 = load i32, i32* @run.last_dir
%4 = and i32 %3, -3
%5 = icmp eq i32 %4, 0
%6 = icmp sgt i32 %1, 500
%7 = select i1 %6, i32 2, i32 0
%8 = icmp sgt i32 %2, 500
%9 = select i1 %8, i32 3, i32 1
%10 = select i1 %5, i32 %9, i32 %7
store i32 %10, i32* @run.last_dir
switch i32 %10, label %63 [
i32 3, label %11
i32 1, label %24
i32 2, label %37
i32 0, label %50
]
11: ; preds = %0
%12 = tail call i32 @drive(i32 90, i32 100)
%13 = add nsw i32 %2, -100
%14 = tail call i32 (...) @loc_y()
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %64
16: ; preds = %11, %16
%17 = phi i32 [ %18, %16 ], [ 0, %11 ]
%18 = add nuw nsw i32 %17, 1
%19 = tail call i32 (...) @cycle()
%20 = tail call i32 (...) @loc_y()
%21 = icmp slt i32 %13, %20
%22 = icmp ult i32 %17, 99
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %16, label %64
24: ; preds = %0
%25 = tail call i32 @drive(i32 270, i32 100)
%26 = add nsw i32 %2, 100
%27 = tail call i32 (...) @loc_y()
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %64
29: ; preds = %24, %29
%30 = phi i32 [ %31, %29 ], [ 0, %24 ]
%31 = add nuw nsw i32 %30, 1
%32 = tail call i32 (...) @cycle()
%33 = tail call i32 (...) @loc_y()
%34 = icmp sgt i32 %26, %33
%35 = icmp ult i32 %30, 99
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %29, label %64
37: ; preds = %0
%38 = tail call i32 @drive(i32 180, i32 100)
%39 = add nsw i32 %1, -100
%40 = tail call i32 (...) @loc_x()
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %64
42: ; preds = %37, %42
%43 = phi i32 [ %44, %42 ], [ 0, %37 ]
%44 = add nuw nsw i32 %43, 1
%45 = tail call i32 (...) @cycle()
%46 = tail call i32 (...) @loc_x()
%47 = icmp slt i32 %39, %46
%48 = icmp ult i32 %43, 99
%49 = select i1 %47, i1 %48, i1 false
br i1 %49, label %42, label %64
50: ; preds = %0
%51 = tail call i32 @drive(i32 0, i32 100)
%52 = add nsw i32 %1, 100
%53 = tail call i32 (...) @loc_x()
%54 = icmp sgt i32 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %50, %55
%56 = phi i32 [ %57, %55 ], [ 0, %50 ]
%57 = add nuw nsw i32 %56, 1
%58 = tail call i32 (...) @cycle()
%59 = tail call i32 (...) @loc_x()
%60 = icmp sgt i32 %52, %59
%61 = icmp ult i32 %56, 99
%62 = select i1 %60, i1 %61, i1 false
br i1 %62, label %55, label %64
63: ; preds = %0
unreachable
64: ; preds = %55, %42, %29, %16, %50, %37, %24, %11
%65 = tail call i32 @drive(i32 0, i32 0)
ret void
}