#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 */
struct drunkard {
  int dummy;
};

/* Variables and functions */
size_t drunkard_rng_range(struct drunkard *, int /*<<< orphan*/, int);
int /*<<< orphan*/ drunkard_step_by(struct drunkard *, int, int);
void drunkard_step_random(struct drunkard *drunk) {
  int dirs[9][2] = {
      {-1, 0},
      {0, -1},
      {0, 1},
      {1, 0},
  };
  int *dir = dirs[drunkard_rng_range(drunk, 0, 3)];
  int dx = dir[0];
  int dy = dir[1];
  drunkard_step_by(drunk, dx, dy);
}


x86 assembly (clang, -O0):
<drunkard_step_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1040 <memset@plt>
movl   $0xffffffff,-0x50(%rbp)
movl   $0xffffffff,-0x44(%rbp)
movl   $0x1,-0x3c(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <drunkard_rng_range@plt>
mov    %rax,%rcx
lea    -0x50(%rbp),%rax
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x60(%rbp),%edx
call   1050 <drunkard_step_by@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drunkard_step_random>:
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x40(%rsp)
movl   $0xffffffff,(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
movabs $0x100000001,%rax
mov    %rax,0x14(%rsp)
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <drunkard_rng_range@plt>
mov    (%rsp,%rax,8),%esi
mov    0x4(%rsp,%rax,8),%edx
mov    %rbx,%rdi
add    $0x50,%rsp
pop    %rbx
jmp    1040 <drunkard_step_by@plt>

LLVM IR (-O0):
%struct.drunkard = type { i32 }
define void @drunkard_step_random(%struct.drunkard* %0) {
%2 = alloca %struct.drunkard*
%3 = alloca [9 x [2 x i32]]
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store %struct.drunkard* %0, %struct.drunkard** %2
%7 = bitcast [9 x [2 x i32]]* %3 to i8*
%8 = bitcast i8* %7 to [9 x [2 x i32]]*
%9 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %8, i32 0, i32 0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i32 0, i32 0
store i32 -1, i32* %10
%11 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %8, i32 0, i32 1
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i32 0, i32 1
store i32 -1, i32* %12
%13 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %8, i32 0, i32 2
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i32 0, i32 1
store i32 1, i32* %14
%15 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %8, i32 0, i32 3
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i32 0, i32 0
store i32 1, i32* %16
%17 = load %struct.drunkard*, %struct.drunkard** %2
%18 = call i64 @drunkard_rng_range(%struct.drunkard* %17, i32 0, i32 3)
%19 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %3, i64 0, i64 %18
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 0
store i32* %20, i32** %4
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
store i32 %23, i32* %5
%24 = load i32*, i32** %4
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = load i32, i32* %25
store i32 %26, i32* %6
%27 = load %struct.drunkard*, %struct.drunkard** %2
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i32 @drunkard_step_by(%struct.drunkard* %27, i32 %28, i32 %29)
ret void
}

LLVM IR (-O2):
%struct.drunkard = type { i32 }
define void @drunkard_step_random(%struct.drunkard* %0) {
%2 = alloca [9 x [2 x i32]]
%3 = bitcast [9 x [2 x i32]]* %2 to i8*
%4 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %2, i64 0, i64 0, i64 0
store i32 -1, i32* %4
%5 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %2, i64 0, i64 1, i64 1
store i32 -1, i32* %5
%6 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %2, i64 0, i64 2, i64 1
store i32 1, i32* %6
%7 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %2, i64 0, i64 3, i64 0
store i32 1, i32* %7
%8 = tail call i64 @drunkard_rng_range(%struct.drunkard* %0, i32 0, i32 3)
%9 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %2, i64 0, i64 %8, i64 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %2, i64 0, i64 %8, i64 1
%12 = load i32, i32* %11
%13 = tail call i32 @drunkard_step_by(%struct.drunkard* %0, i32 %10, i32 %12)
ret void
}