#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 pow(int, int);
int getNumNeighbours(int size, int ndims, int *n) {
  int n2 = n[0];
  int n3 = n[1];
  int numNeighbours = 0;
  if (size == 1) {
    numNeighbours = 0;
  } else if (size < 27) {
    if (size <= 12) {
      numNeighbours = size - 1;
    } else if (size < 18) {
      size = 11;
    } else
      numNeighbours = 17;
  } else {
    numNeighbours = pow(3, ndims) - 1;
  }
  return numNeighbours;
}


x86 assembly (clang, -O0):
<getNumNeighbours>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1152 <getNumNeighbours+0x42>
movl   $0x0,-0x1c(%rbp)
jmp    11b3 <getNumNeighbours+0xa3>
cmpl   $0x1b,-0x4(%rbp)
jge    119b <getNumNeighbours+0x8b>
cmpl   $0xc,-0x4(%rbp)
jg     1174 <getNumNeighbours+0x64>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1196 <getNumNeighbours+0x86>
cmpl   $0x12,-0x4(%rbp)
jge    118a <getNumNeighbours+0x7a>
movl   $0xb,-0x4(%rbp)
jmp    1191 <getNumNeighbours+0x81>
movl   $0x11,-0x1c(%rbp)
jmp    1196 <getNumNeighbours+0x86>
jmp    11ae <getNumNeighbours+0x9e>
mov    -0x8(%rbp),%esi
mov    $0x3,%edi
call   1030 <pow@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b3 <getNumNeighbours+0xa3>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumNeighbours>:
xor    %eax,%eax
cmp    $0x1,%edi
je     1139 <getNumNeighbours+0x29>
cmp    $0x1a,%edi
jg     1127 <getNumNeighbours+0x17>
cmp    $0xc,%edi
jg     113a <getNumNeighbours+0x2a>
add    $0xffffffff,%edi
mov    %edi,%eax
ret
push   %rax
mov    $0x3,%edi
call   1030 <pow@plt>
add    $0xffffffff,%eax
add    $0x8,%rsp
ret
xor    %ecx,%ecx
cmp    $0x12,%edi
mov    $0x11,%eax
cmovb  %ecx,%eax
ret

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

LLVM IR (-O2):
define i32 @getNumNeighbours(i32 %0, i32 %1, i32* nocapture readnone %2) {
%4 = icmp eq i32 %0, 1
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = icmp slt i32 %0, 27
br i1 %6, label %7, label %14
7: ; preds = %5
%8 = icmp slt i32 %0, 13
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = add nsw i32 %0, -1
br label %17
11: ; preds = %7
%12 = icmp ugt i32 %0, 17
%13 = select i1 %12, i32 17, i32 0
br label %17
14: ; preds = %5
%15 = tail call i32 @pow(i32 3, i32 %1)
%16 = add nsw i32 %15, -1
br label %17
17: ; preds = %11, %3, %14, %9
%18 = phi i32 [ %10, %9 ], [ %16, %14 ], [ 0, %3 ], [ %13, %11 ]
ret i32 %18
}