#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 rand();
int wrap_horizontal(int);
int wrap_vertical(int);
int *random_direction(int x, int y) {
  static int directions[2];
  int direction;
  int horizontal;
  int vertical;
  int total = 96;
  direction = rand() % total;
  if (direction < 6) {
    horizontal = x;
    vertical = y + 1;
  } else if (direction < 24) {
    horizontal = x + 1;
    vertical = y;
  } else if (direction < 30) {
    horizontal = x;
    vertical = y - 1;
  } else if (direction < 48) {
    horizontal = x - 1;
    vertical = y;
  } else if (direction < 60) {
    horizontal = x + 1;
    vertical = y - 1;
  } else if (direction < 72) {
    horizontal = x - 1;
    vertical = y + 1;
  } else if (direction < 84) {
    horizontal = x - 1;
    vertical = y - 1;
  } else if (direction < 96) {
    horizontal = x + 1;
    vertical = y + 1;
  }
  directions[0] = wrap_horizontal(horizontal);
  directions[1] = wrap_vertical(vertical);
  return directions;
}


x86 assembly (clang, -O0):
<random_direction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x60,-0x18(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x18(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jge    1171 <random_direction+0x41>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    126d <random_direction+0x13d>
cmpl   $0x18,-0xc(%rbp)
jge    118f <random_direction+0x5f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1268 <random_direction+0x138>
cmpl   $0x1e,-0xc(%rbp)
jge    11ad <random_direction+0x7d>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1263 <random_direction+0x133>
cmpl   $0x30,-0xc(%rbp)
jge    11cb <random_direction+0x9b>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    125e <random_direction+0x12e>
cmpl   $0x3c,-0xc(%rbp)
jge    11ec <random_direction+0xbc>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1259 <random_direction+0x129>
cmpl   $0x48,-0xc(%rbp)
jge    120d <random_direction+0xdd>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1254 <random_direction+0x124>
cmpl   $0x54,-0xc(%rbp)
jge    122e <random_direction+0xfe>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124f <random_direction+0x11f>
cmpl   $0x60,-0xc(%rbp)
jge    124a <random_direction+0x11a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124f <random_direction+0x11f>
jmp    1254 <random_direction+0x124>
jmp    1259 <random_direction+0x129>
jmp    125e <random_direction+0x12e>
jmp    1263 <random_direction+0x133>
jmp    1268 <random_direction+0x138>
jmp    126d <random_direction+0x13d>
mov    -0x10(%rbp),%edi
call   1040 <wrap_horizontal@plt>
mov    %eax,0x2dc1(%rip)
mov    -0x14(%rbp),%edi
call   1030 <wrap_vertical@plt>
mov    %eax,0x2db7(%rip)
lea    0x2dac(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_direction>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x24,%rcx
add    %edx,%ecx
shl    $0x5,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x5,%eax
jg     1166 <random_direction+0x36>
add    $0x1,%ebx
jmp    119e <random_direction+0x6e>
cmp    $0x17,%eax
ja     1170 <random_direction+0x40>
add    $0x1,%ebp
jmp    119e <random_direction+0x6e>
cmp    $0x1d,%eax
jbe    119b <random_direction+0x6b>
cmp    $0x2f,%eax
ja     117f <random_direction+0x4f>
add    $0xffffffff,%ebp
jmp    119e <random_direction+0x6e>
cmp    $0x3b,%eax
ja     1189 <random_direction+0x59>
add    $0x1,%ebp
jmp    119b <random_direction+0x6b>
cmp    $0x47,%eax
ja     1193 <random_direction+0x63>
add    $0xffffffff,%ebp
jmp    1161 <random_direction+0x31>
cmp    $0x53,%eax
ja     11c9 <random_direction+0x99>
add    $0xffffffff,%ebp
add    $0xffffffff,%ebx
mov    %ebp,%edi
call   1040 <wrap_horizontal@plt>
mov    %eax,0x2e91(%rip)
lea    0x2e8a(%rip),%rbp
mov    %ebx,%edi
call   1030 <wrap_vertical@plt>
mov    %eax,0x2e81(%rip)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
add    $0x1,%ebp
jmp    1161 <random_direction+0x31>

LLVM IR (-O0):
@random_direction.directions = internal global [2 x i32] zeroinitializer
define i32* @random_direction(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 96, i32* %8
%9 = call i32 (...) @rand()
%10 = load i32, i32* %8
%11 = srem i32 %9, %10
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 6
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* %3
store i32 %15, i32* %6
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
br label %78
18: ; preds = %2
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 24
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = load i32, i32* %4
store i32 %24, i32* %7
br label %77
25: ; preds = %18
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 30
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %3
store i32 %29, i32* %6
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %7
br label %76
32: ; preds = %25
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 48
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* %3
%37 = sub nsw i32 %36, 1
store i32 %37, i32* %6
%38 = load i32, i32* %4
store i32 %38, i32* %7
br label %75
39: ; preds = %32
%40 = load i32, i32* %5
%41 = icmp slt i32 %40, 60
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
%45 = load i32, i32* %4
%46 = sub nsw i32 %45, 1
store i32 %46, i32* %7
br label %74
47: ; preds = %39
%48 = load i32, i32* %5
%49 = icmp slt i32 %48, 72
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i32, i32* %3
%52 = sub nsw i32 %51, 1
store i32 %52, i32* %6
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %73
55: ; preds = %47
%56 = load i32, i32* %5
%57 = icmp slt i32 %56, 84
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i32, i32* %3
%60 = sub nsw i32 %59, 1
store i32 %60, i32* %6
%61 = load i32, i32* %4
%62 = sub nsw i32 %61, 1
store i32 %62, i32* %7
br label %72
63: ; preds = %55
%64 = load i32, i32* %5
%65 = icmp slt i32 %64, 96
br i1 %65, label %66, label %71
66: ; preds = %63
%67 = load i32, i32* %3
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %71
71: ; preds = %66, %63
br label %72
72: ; preds = %71, %58
br label %73
73: ; preds = %72, %50
br label %74
74: ; preds = %73, %42
br label %75
75: ; preds = %74, %35
br label %76
76: ; preds = %75, %28
br label %77
77: ; preds = %76, %21
br label %78
78: ; preds = %77, %14
%79 = load i32, i32* %6
%80 = call i32 @wrap_horizontal(i32 %79)
store i32 %80, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @random_direction.directions, i64 0, i64 0)
%81 = load i32, i32* %7
%82 = call i32 @wrap_vertical(i32 %81)
store i32 %82, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @random_direction.directions, i64 0, i64 1)
ret i32* getelementptr inbounds ([2 x i32], [2 x i32]* @random_direction.directions, i64 0, i64 0)
}

LLVM IR (-O2):
@random_direction.directions = internal global [2 x i32] zeroinitializer
define i32* @random_direction(i32 %0, i32 %1) {
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 96
%5 = icmp slt i32 %4, 6
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = add nsw i32 %1, 1
br label %38
8: ; preds = %2
%9 = icmp ult i32 %4, 24
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = add nsw i32 %0, 1
br label %38
12: ; preds = %8
%13 = icmp ult i32 %4, 30
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = add nsw i32 %1, -1
br label %38
16: ; preds = %12
%17 = icmp ult i32 %4, 48
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = add nsw i32 %0, -1
br label %38
20: ; preds = %16
%21 = icmp ult i32 %4, 60
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = add nsw i32 %0, 1
%24 = add nsw i32 %1, -1
br label %38
25: ; preds = %20
%26 = icmp ult i32 %4, 72
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = add nsw i32 %0, -1
%29 = add nsw i32 %1, 1
br label %38
30: ; preds = %25
%31 = icmp ult i32 %4, 84
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = add nsw i32 %0, -1
%34 = add nsw i32 %1, -1
br label %38
35: ; preds = %30
%36 = add nsw i32 %0, 1
%37 = add nsw i32 %1, 1
br label %38
38: ; preds = %10, %18, %27, %35, %32, %22, %14, %6
%39 = phi i32 [ %7, %6 ], [ %1, %10 ], [ %15, %14 ], [ %1, %18 ], [ %24, %22 ], [ %29, %27 ], [ %34, %32 ], [ %37, %35 ]
%40 = phi i32 [ %0, %6 ], [ %11, %10 ], [ %0, %14 ], [ %19, %18 ], [ %23, %22 ], [ %28, %27 ], [ %33, %32 ], [ %36, %35 ]
%41 = tail call i32 @wrap_horizontal(i32 %40)
store i32 %41, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @random_direction.directions, i64 0, i64 0)
%42 = tail call i32 @wrap_vertical(i32 %39)
store i32 %42, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @random_direction.directions, i64 0, i64 1)
ret i32* getelementptr inbounds ([2 x i32], [2 x i32]* @random_direction.directions, i64 0, i64 0)
}