short findResourcesOwnNeighbours(short zone, short *resourcesOwnNeighbours,
                                 int zoneCount) {
  for (int i = 0; i < zoneCount; i++) {
    if (zone == resourcesOwnNeighbours[i * 2])
      return resourcesOwnNeighbours[i * 2 + 1];
  }
  return 0;
}


x86 assembly (clang, -O0):
<findResourcesOwnNeighbours>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1172 <findResourcesOwnNeighbours+0x72>
movswl -0x4(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%edx
shl    $0x1,%edx
movslq %edx,%rdx
movswl (%rcx,%rdx,2),%ecx
cmp    %ecx,%eax
jne    115f <findResourcesOwnNeighbours+0x5f>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,2),%ax
mov    %ax,-0x2(%rbp)
jmp    1178 <findResourcesOwnNeighbours+0x78>
jmp    1164 <findResourcesOwnNeighbours+0x64>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1119 <findResourcesOwnNeighbours+0x19>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<findResourcesOwnNeighbours>:
test   %edx,%edx
jle    111f <findResourcesOwnNeighbours+0x1f>
mov    %edx,%eax
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
cmp    %di,(%rsi,%rcx,4)
je     1122 <findResourcesOwnNeighbours+0x22>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1110 <findResourcesOwnNeighbours+0x10>
xor    %eax,%eax
ret
movzwl 0x2(%rsi,%rcx,4),%eax
ret

LLVM IR (-O0):
define signext i16 @findResourcesOwnNeighbours(i16 signext %0, i16* %1, i32 %2) {
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16*
%7 = alloca i32
%8 = alloca i32
store i16 %0, i16* %5
store i16* %1, i16** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %33, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = load i16, i16* %5
%15 = sext i16 %14 to i32
%16 = load i16*, i16** %6
%17 = load i32, i32* %8
%18 = mul nsw i32 %17, 2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i16, i16* %16, i64 %19
%21 = load i16, i16* %20
%22 = sext i16 %21 to i32
%23 = icmp eq i32 %15, %22
br i1 %23, label %24, label %32
24: ; preds = %13
%25 = load i16*, i16** %6
%26 = load i32, i32* %8
%27 = mul nsw i32 %26, 2
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i16, i16* %25, i64 %29
%31 = load i16, i16* %30
store i16 %31, i16* %4
br label %37
32: ; preds = %13
br label %33
33: ; preds = %32
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %9
36: ; preds = %9
store i16 0, i16* %4
br label %37
37: ; preds = %36, %24
%38 = load i16, i16* %4
ret i16 %38
}

LLVM IR (-O2):
define signext i16 @findResourcesOwnNeighbours(i16 signext %0, i16* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %21
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %9
7: ; preds = %9
%8 = icmp eq i64 %15, %6
br i1 %8, label %21, label %9
9: ; preds = %5, %7
%10 = phi i64 [ 0, %5 ], [ %15, %7 ]
%11 = shl nuw nsw i64 %10, 1
%12 = getelementptr inbounds i16, i16* %1, i64 %11
%13 = load i16, i16* %12
%14 = icmp eq i16 %13, %0
%15 = add nuw nsw i64 %10, 1
br i1 %14, label %16, label %7
16: ; preds = %9
%17 = and i64 %11, 4294967294
%18 = or i64 %17, 1
%19 = getelementptr inbounds i16, i16* %1, i64 %18
%20 = load i16, i16* %19
br label %21
21: ; preds = %7, %3, %16
%22 = phi i16 [ %20, %16 ], [ 0, %3 ], [ 0, %7 ]
ret i16 %22
}