#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 World {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ World_get_unchecked(struct World *, size_t, size_t);
size_t World_wrap_x_l(struct World *, size_t, int);
size_t World_wrap_x_r(struct World *, size_t, int);
size_t World_wrap_y_d(struct World *, size_t, int);
size_t World_wrap_y_u(struct World *, size_t, int);
int /*<<< orphan*/ encode_tile(int /*<<< orphan*/, int, char *);
void World_vicinity(struct World *self, size_t x, size_t y, char *dest) {
  size_t x_r = World_wrap_x_r(self, x, 1), x_l = World_wrap_x_l(self, x, 1);
  size_t y_d = World_wrap_y_d(self, y, 1), y_u = World_wrap_y_u(self, y, 1);
  encode_tile(World_get_unchecked(self, x_r, y_d), 0, dest);
  encode_tile(World_get_unchecked(self, x_r, y), 1, dest);
  encode_tile(World_get_unchecked(self, x_r, y_u), 2, dest);
  encode_tile(World_get_unchecked(self, x, y_u), 3, dest);
  encode_tile(World_get_unchecked(self, x_l, y_u), 4, dest);
  encode_tile(World_get_unchecked(self, x_l, y), 5, dest);
  encode_tile(World_get_unchecked(self, x_l, y_d), 6, dest);
  encode_tile(World_get_unchecked(self, x, y_d), 7, dest);
}


x86 assembly (clang, -O0):
<World_vicinity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1060 <World_wrap_x_r@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1070 <World_wrap_x_l@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1050 <World_wrap_y_d@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <World_wrap_y_u@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <encode_tile@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rdx
mov    $0x1,%esi
call   1040 <encode_tile@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rdx
mov    $0x2,%esi
call   1040 <encode_tile@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rdx
mov    $0x3,%esi
call   1040 <encode_tile@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rdx
mov    $0x4,%esi
call   1040 <encode_tile@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rdx
mov    $0x5,%esi
call   1040 <encode_tile@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rdx
mov    $0x6,%esi
call   1040 <encode_tile@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rdx
mov    $0x7,%esi
call   1040 <encode_tile@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<World_vicinity>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
mov    $0x1,%edx
call   1060 <World_wrap_x_r@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <World_wrap_x_l@plt>
mov    %rax,0x18(%rsp)
mov    %r12,%rdi
mov    %r14,%rbx
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <World_wrap_y_d@plt>
mov    %rax,%r14
mov    %rax,0x20(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbx,0x8(%rsp)
mov    $0x1,%edx
call   1030 <World_wrap_y_u@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <encode_tile@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    $0x1,%esi
mov    %r15,%rdx
call   1040 <encode_tile@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    $0x2,%esi
mov    %r15,%rdx
call   1040 <encode_tile@plt>
mov    %r12,%rdi
mov    0x10(%rsp),%r14
mov    %r14,%rsi
mov    %rbp,%rdx
mov    %rbp,%rbx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    $0x3,%esi
mov    %r15,%rdx
call   1040 <encode_tile@plt>
mov    %r12,%rdi
mov    0x18(%rsp),%rbp
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    $0x4,%esi
mov    %r15,%rdx
call   1040 <encode_tile@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    0x8(%rsp),%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    $0x5,%esi
mov    %r15,%rdx
call   1040 <encode_tile@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    0x20(%rsp),%rbp
mov    %rbp,%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    $0x6,%esi
mov    %r15,%rdx
call   1040 <encode_tile@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1080 <World_get_unchecked@plt>
mov    %eax,%edi
mov    $0x7,%esi
mov    %r15,%rdx
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <encode_tile@plt>

LLVM IR (-O0):
%struct.World = type { i32 }
define void @World_vicinity(%struct.World* %0, i64 %1, i64 %2, i8* %3) {
%5 = alloca %struct.World*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store %struct.World* %0, %struct.World** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%13 = load %struct.World*, %struct.World** %5
%14 = load i64, i64* %6
%15 = call i64 @World_wrap_x_r(%struct.World* %13, i64 %14, i32 1)
store i64 %15, i64* %9
%16 = load %struct.World*, %struct.World** %5
%17 = load i64, i64* %6
%18 = call i64 @World_wrap_x_l(%struct.World* %16, i64 %17, i32 1)
store i64 %18, i64* %10
%19 = load %struct.World*, %struct.World** %5
%20 = load i64, i64* %7
%21 = call i64 @World_wrap_y_d(%struct.World* %19, i64 %20, i32 1)
store i64 %21, i64* %11
%22 = load %struct.World*, %struct.World** %5
%23 = load i64, i64* %7
%24 = call i64 @World_wrap_y_u(%struct.World* %22, i64 %23, i32 1)
store i64 %24, i64* %12
%25 = load %struct.World*, %struct.World** %5
%26 = load i64, i64* %9
%27 = load i64, i64* %11
%28 = call i32 @World_get_unchecked(%struct.World* %25, i64 %26, i64 %27)
%29 = load i8*, i8** %8
%30 = call i32 @encode_tile(i32 %28, i32 0, i8* %29)
%31 = load %struct.World*, %struct.World** %5
%32 = load i64, i64* %9
%33 = load i64, i64* %7
%34 = call i32 @World_get_unchecked(%struct.World* %31, i64 %32, i64 %33)
%35 = load i8*, i8** %8
%36 = call i32 @encode_tile(i32 %34, i32 1, i8* %35)
%37 = load %struct.World*, %struct.World** %5
%38 = load i64, i64* %9
%39 = load i64, i64* %12
%40 = call i32 @World_get_unchecked(%struct.World* %37, i64 %38, i64 %39)
%41 = load i8*, i8** %8
%42 = call i32 @encode_tile(i32 %40, i32 2, i8* %41)
%43 = load %struct.World*, %struct.World** %5
%44 = load i64, i64* %6
%45 = load i64, i64* %12
%46 = call i32 @World_get_unchecked(%struct.World* %43, i64 %44, i64 %45)
%47 = load i8*, i8** %8
%48 = call i32 @encode_tile(i32 %46, i32 3, i8* %47)
%49 = load %struct.World*, %struct.World** %5
%50 = load i64, i64* %10
%51 = load i64, i64* %12
%52 = call i32 @World_get_unchecked(%struct.World* %49, i64 %50, i64 %51)
%53 = load i8*, i8** %8
%54 = call i32 @encode_tile(i32 %52, i32 4, i8* %53)
%55 = load %struct.World*, %struct.World** %5
%56 = load i64, i64* %10
%57 = load i64, i64* %7
%58 = call i32 @World_get_unchecked(%struct.World* %55, i64 %56, i64 %57)
%59 = load i8*, i8** %8
%60 = call i32 @encode_tile(i32 %58, i32 5, i8* %59)
%61 = load %struct.World*, %struct.World** %5
%62 = load i64, i64* %10
%63 = load i64, i64* %11
%64 = call i32 @World_get_unchecked(%struct.World* %61, i64 %62, i64 %63)
%65 = load i8*, i8** %8
%66 = call i32 @encode_tile(i32 %64, i32 6, i8* %65)
%67 = load %struct.World*, %struct.World** %5
%68 = load i64, i64* %6
%69 = load i64, i64* %11
%70 = call i32 @World_get_unchecked(%struct.World* %67, i64 %68, i64 %69)
%71 = load i8*, i8** %8
%72 = call i32 @encode_tile(i32 %70, i32 7, i8* %71)
ret void
}

LLVM IR (-O2):
%struct.World = type { i32 }
define void @World_vicinity(%struct.World* %0, i64 %1, i64 %2, i8* %3) {
%5 = tail call i64 @World_wrap_x_r(%struct.World* %0, i64 %1, i32 1)
%6 = tail call i64 @World_wrap_x_l(%struct.World* %0, i64 %1, i32 1)
%7 = tail call i64 @World_wrap_y_d(%struct.World* %0, i64 %2, i32 1)
%8 = tail call i64 @World_wrap_y_u(%struct.World* %0, i64 %2, i32 1)
%9 = tail call i32 @World_get_unchecked(%struct.World* %0, i64 %5, i64 %7)
%10 = tail call i32 @encode_tile(i32 %9, i32 0, i8* %3)
%11 = tail call i32 @World_get_unchecked(%struct.World* %0, i64 %5, i64 %2)
%12 = tail call i32 @encode_tile(i32 %11, i32 1, i8* %3)
%13 = tail call i32 @World_get_unchecked(%struct.World* %0, i64 %5, i64 %8)
%14 = tail call i32 @encode_tile(i32 %13, i32 2, i8* %3)
%15 = tail call i32 @World_get_unchecked(%struct.World* %0, i64 %1, i64 %8)
%16 = tail call i32 @encode_tile(i32 %15, i32 3, i8* %3)
%17 = tail call i32 @World_get_unchecked(%struct.World* %0, i64 %6, i64 %8)
%18 = tail call i32 @encode_tile(i32 %17, i32 4, i8* %3)
%19 = tail call i32 @World_get_unchecked(%struct.World* %0, i64 %6, i64 %2)
%20 = tail call i32 @encode_tile(i32 %19, i32 5, i8* %3)
%21 = tail call i32 @World_get_unchecked(%struct.World* %0, i64 %6, i64 %7)
%22 = tail call i32 @encode_tile(i32 %21, i32 6, i8* %3)
%23 = tail call i32 @World_get_unchecked(%struct.World* %0, i64 %1, i64 %7)
%24 = tail call i32 @encode_tile(i32 %23, i32 7, i8* %3)
ret void
}