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

/* Variables and functions */
struct djpoint *get_neigh(struct djpoint *, int);
struct djpoint *get_next_neigh(struct djpoint *pt, uint8_t *position) {
  struct djpoint *neigh = NULL;
  uint8_t pos = *position + 1;
  for (pos = *position + 1; pos < 7; pos++) {
    neigh = get_neigh(pt, pos);
    if (neigh != NULL)
      break;
  }
  *position = pos;
  return neigh;
}


x86 assembly (clang, -O0):
<get_next_neigh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x7,-0x1c(%rbp)
jge    117d <get_next_neigh+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <get_neigh@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116a <get_next_neigh+0x5a>
jmp    117d <get_next_neigh+0x6d>
jmp    116f <get_next_neigh+0x5f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1140 <get_next_neigh+0x30>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_neigh>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    (%rsi),%ecx
cmp    $0x7,%ecx
mov    $0x6,%r13d
cmovge %ecx,%r13d
mov    %rdi,%r12
neg    %r13d
add    $0x1,%ecx
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebx
lea    (%rbx,%r13,1),%eax
cmp    $0x1,%eax
je     1160 <get_next_neigh+0x50>
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <get_neigh@plt>
lea    0x1(%rbx),%ecx
test   %rax,%rax
je     1140 <get_next_neigh+0x30>
mov    %rax,%r15
mov    %ebx,(%r14)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.djpoint = type { i32 }
define %struct.djpoint* @get_next_neigh(%struct.djpoint* %0, i32* %1) {
%3 = alloca %struct.djpoint*
%4 = alloca i32*
%5 = alloca %struct.djpoint*
%6 = alloca i32
store %struct.djpoint* %0, %struct.djpoint** %3
store i32* %1, i32** %4
store %struct.djpoint* null, %struct.djpoint** %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1
store i32 %9, i32* %6
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
store i32 %12, i32* %6
br label %13
13: ; preds = %24, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 7
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load %struct.djpoint*, %struct.djpoint** %3
%18 = load i32, i32* %6
%19 = call %struct.djpoint* @get_neigh(%struct.djpoint* %17, i32 %18)
store %struct.djpoint* %19, %struct.djpoint** %5
%20 = load %struct.djpoint*, %struct.djpoint** %5
%21 = icmp ne %struct.djpoint* %20, null
br i1 %21, label %22, label %23
22: ; preds = %16
br label %27
23: ; preds = %16
br label %24
24: ; preds = %23
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %13
27: ; preds = %22, %13
%28 = load i32, i32* %6
%29 = load i32*, i32** %4
store i32 %28, i32* %29
%30 = load %struct.djpoint*, %struct.djpoint** %5
ret %struct.djpoint* %30
}

LLVM IR (-O2):
%struct.djpoint = type { i32 }
define %struct.djpoint* @get_next_neigh(%struct.djpoint* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = call i32 @llvm.smax.i32(i32 %3, i32 6)
br label %5
5: ; preds = %9, %2
%6 = phi i32 [ %3, %2 ], [ %7, %9 ]
%7 = add nsw i32 %6, 1
%8 = icmp eq i32 %6, %4
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call %struct.djpoint* @get_neigh(%struct.djpoint* %0, i32 %7)
%11 = icmp eq %struct.djpoint* %10, null
br i1 %11, label %5, label %12
12: ; preds = %9, %5
%13 = phi %struct.djpoint* [ %10, %9 ], [ null, %5 ]
store i32 %7, i32* %1
ret %struct.djpoint* %13
}