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

/* Variables and functions */
int /*<<< orphan*/ getpol(int *, struct bitmask *);
struct bitmask *numa_allocate_nodemask();
int /*<<< orphan*/ numa_bitmask_free(struct bitmask *);
scalar_t__ numa_bitmask_isbitset(struct bitmask *, int);
int numa_num_possible_nodes();
int numa_preferred(void) {
  int policy;
  int ret;
  struct bitmask *bmp;
  bmp = numa_allocate_nodemask();
  getpol(&policy, bmp);
  if (policy == 1 || policy == 2) {
    int i;
    int max = numa_num_possible_nodes();
    for (i = 0; i < max; i++)
      if (numa_bitmask_isbitset(bmp, i)) {
        ret = i;
        goto end;
      }
  }
  ret = 0;
end:
  numa_bitmask_free(bmp);
  return ret;
}


x86 assembly (clang, -O0):
<numa_preferred>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <numa_allocate_nodemask@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x4(%rbp),%rdi
call   1030 <getpol@plt>
cmpl   $0x1,-0x4(%rbp)
je     1184 <numa_preferred+0x34>
cmpl   $0x2,-0x4(%rbp)
jne    11da <numa_preferred+0x8a>
mov    $0x0,%al
call   1070 <numa_num_possible_nodes@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d5 <numa_preferred+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <numa_bitmask_isbitset@plt>
cmp    $0x0,%rax
je     11c2 <numa_preferred+0x72>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11e1 <numa_preferred+0x91>
jmp    11c7 <numa_preferred+0x77>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1195 <numa_preferred+0x45>
jmp    11da <numa_preferred+0x8a>
movl   $0x0,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <numa_bitmask_free@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numa_preferred>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <numa_allocate_nodemask@plt>
mov    %rax,%r14
lea    0xc(%rsp),%rdi
mov    %rax,%rsi
call   1030 <getpol@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x1,%eax
ja     11a8 <numa_preferred+0x58>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <numa_num_possible_nodes@plt>
test   %eax,%eax
jle    11a8 <numa_preferred+0x58>
mov    %eax,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <numa_bitmask_isbitset@plt>
test   %rax,%rax
jne    11a8 <numa_preferred+0x58>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1190 <numa_preferred+0x40>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1060 <numa_bitmask_free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitmask = type { i32 }
define i32 @numa_preferred() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.bitmask*
%4 = alloca i32
%5 = alloca i32
%6 = call %struct.bitmask* (...) @numa_allocate_nodemask()
store %struct.bitmask* %6, %struct.bitmask** %3
%7 = load %struct.bitmask*, %struct.bitmask** %3
%8 = call i32 @getpol(i32* %1, %struct.bitmask* %7)
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %32
14: ; preds = %11, %0
%15 = call i32 (...) @numa_num_possible_nodes()
store i32 %15, i32* %5
store i32 0, i32* %4
br label %16
16: ; preds = %28, %14
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load %struct.bitmask*, %struct.bitmask** %3
%22 = load i32, i32* %4
%23 = call i64 @numa_bitmask_isbitset(%struct.bitmask* %21, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %33
27: ; preds = %20
br label %28
28: ; preds = %27
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %16
31: ; preds = %16
br label %32
32: ; preds = %31, %11
store i32 0, i32* %2
br label %33
33: ; preds = %32, %25
%34 = load %struct.bitmask*, %struct.bitmask** %3
%35 = call i32 @numa_bitmask_free(%struct.bitmask* %34)
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
%struct.bitmask = type { i32 }
define i32 @numa_preferred() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call %struct.bitmask* (...) @numa_allocate_nodemask()
%4 = call i32 @getpol(i32* %1, %struct.bitmask* %3)
%5 = load i32, i32* %1
%6 = add i32 %5, -1
%7 = icmp ult i32 %6, 2
br i1 %7, label %8, label %18
8: ; preds = %0
%9 = call i32 (...) @numa_num_possible_nodes()
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8, %15
%12 = phi i32 [ %16, %15 ], [ 0, %8 ]
%13 = call i64 @numa_bitmask_isbitset(%struct.bitmask* %3, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = add nuw nsw i32 %12, 1
%17 = icmp eq i32 %16, %9
br i1 %17, label %18, label %11
18: ; preds = %11, %15, %8, %0
%19 = phi i32 [ 0, %0 ], [ 0, %8 ], [ %12, %11 ], [ 0, %15 ]
%20 = call i32 @numa_bitmask_free(%struct.bitmask* %3)
ret i32 %19
}