#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;

/* Variables and functions */
int cu_NextPos(int);
int cu_PrevPos(int);
uint8_t chess_GetNextMarked(uint8_t arg, uint8_t is_prev) {
  uint8_t i;
  uint8_t pos = arg;
  for (i = 0; i < 64; i++) {
    if (is_prev != 0)
      pos = cu_PrevPos(pos);
    else
      pos = cu_NextPos(pos);
    if (arg != 255 && pos == 0)
      return 255;
    if (((cp_GetFromBoard(pos)) & 0x20))
      return pos;
  }
  return 255;
}


x86 assembly (clang, -O0):
<chess_GetNextMarked>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x40,-0x10(%rbp)
jge    11d1 <chess_GetNextMarked+0xa1>
cmpl   $0x0,-0xc(%rbp)
je     116f <chess_GetNextMarked+0x3f>
mov    -0x14(%rbp),%edi
call   1050 <cu_PrevPos@plt>
mov    %eax,-0x14(%rbp)
jmp    117a <chess_GetNextMarked+0x4a>
mov    -0x14(%rbp),%edi
call   1040 <cu_NextPos@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xff,-0x8(%rbp)
je     119d <chess_GetNextMarked+0x6d>
cmpl   $0x0,-0x14(%rbp)
jne    119d <chess_GetNextMarked+0x6d>
movl   $0xff,-0x4(%rbp)
jmp    11d8 <chess_GetNextMarked+0xa8>
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1030 <cp_GetFromBoard@plt>
and    $0x20,%eax
cmp    $0x0,%eax
je     11be <chess_GetNextMarked+0x8e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <chess_GetNextMarked+0xa8>
jmp    11c3 <chess_GetNextMarked+0x93>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114b <chess_GetNextMarked+0x1b>
movl   $0xff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chess_GetNextMarked>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%r15d
mov    $0x40,%ebx
mov    %edi,%ebp
mov    $0xff,%r12d
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
test   %r14d,%r14d
je     1160 <chess_GetNextMarked+0x30>
call   1050 <cu_PrevPos@plt>
jmp    1165 <chess_GetNextMarked+0x35>
xchg   %ax,%ax
call   1040 <cu_NextPos@plt>
mov    %eax,%ebp
cmp    $0xff,%r15d
je     1174 <chess_GetNextMarked+0x44>
test   %ebp,%ebp
je     118b <chess_GetNextMarked+0x5b>
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <cp_GetFromBoard@plt>
test   $0x20,%al
jne    1188 <chess_GetNextMarked+0x58>
add    $0xffffffff,%ebx
jne    1150 <chess_GetNextMarked+0x20>
jmp    118b <chess_GetNextMarked+0x5b>
mov    %ebp,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @chess_GetNextMarked(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
store i32 %8, i32* %7
store i32 0, i32* %6
br label %9
9: ; preds = %36, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 64
br i1 %11, label %12, label %39
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %7
%17 = call i32 @cu_PrevPos(i32 %16)
store i32 %17, i32* %7
br label %21
18: ; preds = %12
%19 = load i32, i32* %7
%20 = call i32 @cu_NextPos(i32 %19)
store i32 %20, i32* %7
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 255
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 255, i32* %3
br label %40
28: ; preds = %24, %21
%29 = load i32, i32* %7
%30 = call i32 (i32, ...) bitcast (i32 (...)* @cp_GetFromBoard to i32 (i32, ...)*)(i32 %29)
%31 = and i32 %30, 32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = load i32, i32* %7
store i32 %34, i32* %3
br label %40
35: ; preds = %28
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %9
39: ; preds = %9
store i32 255, i32* %3
br label %40
40: ; preds = %39, %33, %27
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @chess_GetNextMarked(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = icmp ne i32 %0, 255
br label %8
5: ; preds = %19
%6 = add nuw nsw i32 %10, 1
%7 = icmp eq i32 %6, 64
br i1 %7, label %23, label %8
8: ; preds = %2, %5
%9 = phi i32 [ %0, %2 ], [ %16, %5 ]
%10 = phi i32 [ 0, %2 ], [ %6, %5 ]
br i1 %3, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @cu_PrevPos(i32 %9)
br label %15
13: ; preds = %8
%14 = tail call i32 @cu_NextPos(i32 %9)
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %12, %11 ], [ %14, %13 ]
%17 = icmp eq i32 %16, 0
%18 = select i1 %4, i1 %17, i1 false
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = tail call i32 (i32, ...) bitcast (i32 (...)* @cp_GetFromBoard to i32 (i32, ...)*)(i32 %16)
%21 = and i32 %20, 32
%22 = icmp eq i32 %21, 0
br i1 %22, label %5, label %23
23: ; preds = %5, %19, %15
%24 = phi i32 [ 255, %15 ], [ %16, %19 ], [ 255, %5 ]
ret i32 %24
}