#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 */
scalar_t__ cvmx_coremask_is_member(unsigned int);
unsigned int cvmx_coremask_numcores(scalar_t__);
scalar_t__ cvmx_get_core_num();
int cvmx_coremask_first_core(unsigned int coremask) {
  return cvmx_coremask_is_member(coremask) &&
         ((cvmx_get_core_num() == 0) ||
          ((cvmx_coremask_numcores(cvmx_get_core_num()) & coremask) == 0));
}


x86 assembly (clang, -O0):
<cvmx_coremask_first_core>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <cvmx_coremask_is_member@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x5(%rbp)
je     118f <cvmx_coremask_first_core+0x5f>
mov    $0x0,%al
call   1050 <cvmx_get_core_num@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x6(%rbp)
je     1189 <cvmx_coremask_first_core+0x59>
mov    $0x0,%al
call   1050 <cvmx_get_core_num@plt>
mov    %rax,%rdi
call   1040 <cvmx_coremask_numcores@plt>
and    -0x4(%rbp),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvmx_coremask_first_core>:
push   %rbx
mov    %edi,%ebx
call   1030 <cvmx_coremask_is_member@plt>
test   %rax,%rax
je     1163 <cvmx_coremask_first_core+0x33>
xor    %eax,%eax
call   1050 <cvmx_get_core_num@plt>
test   %rax,%rax
je     1167 <cvmx_coremask_first_core+0x37>
xor    %eax,%eax
call   1050 <cvmx_get_core_num@plt>
mov    %rax,%rdi
call   1040 <cvmx_coremask_numcores@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ebx,%ecx
sete   %al
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @cvmx_coremask_first_core(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i64 @cvmx_coremask_is_member(i32 %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = call i64 (...) @cvmx_get_core_num()
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = call i64 (...) @cvmx_get_core_num()
%11 = call i32 @cvmx_coremask_numcores(i64 %10)
%12 = load i32, i32* %2
%13 = and i32 %11, %12
%14 = icmp eq i32 %13, 0
br label %15
15: ; preds = %9, %6
%16 = phi i1 [ true, %6 ], [ %14, %9 ]
br label %17
17: ; preds = %15, %1
%18 = phi i1 [ false, %1 ], [ %16, %15 ]
%19 = zext i1 %18 to i32
ret i32 %19
}

LLVM IR (-O2):
define i32 @cvmx_coremask_first_core(i32 %0) {
%2 = tail call i64 @cvmx_coremask_is_member(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i64 (...) @cvmx_get_core_num()
%6 = icmp eq i64 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i64 (...) @cvmx_get_core_num()
%9 = tail call i32 @cvmx_coremask_numcores(i64 %8)
%10 = and i32 %9, %0
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %4, %7, %1
%14 = phi i32 [ 0, %1 ], [ 1, %4 ], [ %12, %7 ]
ret i32 %14
}