#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*/ numa_bitmask_isbitset(struct bitmask *, unsigned int);
int numa_num_possible_nodes();
unsigned interleave_next(unsigned cur, struct bitmask *mask) {
  int numa_num_nodes = numa_num_possible_nodes();
  ++cur;
  while (!numa_bitmask_isbitset(mask, cur)) {
    cur = (cur + 1) % numa_num_nodes;
  }
  return cur;
}


x86 assembly (clang, -O0):
<interleave_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <numa_num_possible_nodes@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <numa_bitmask_isbitset@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1163 <interleave_next+0x43>
jmp    1176 <interleave_next+0x56>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x14(%rbp)
mov    %edx,-0x4(%rbp)
jmp    1142 <interleave_next+0x22>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interleave_next>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <numa_num_possible_nodes@plt>
mov    %eax,%ebp
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
nopw   0x0(%rax,%rax,1)
call   1030 <numa_bitmask_isbitset@plt>
test   %eax,%eax
jne    115b <interleave_next+0x3b>
add    $0x1,%ebx
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
mov    %edx,%ebx
mov    %r14,%rdi
mov    %edx,%esi
jmp    1140 <interleave_next+0x20>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitmask = type { i32 }
define i32 @interleave_next(i32 %0, %struct.bitmask* %1) {
%3 = alloca i32
%4 = alloca %struct.bitmask*
%5 = alloca i32
store i32 %0, i32* %3
store %struct.bitmask* %1, %struct.bitmask** %4
%6 = call i32 (...) @numa_num_possible_nodes()
store i32 %6, i32* %5
%7 = load i32, i32* %3
%8 = add i32 %7, 1
store i32 %8, i32* %3
br label %9
9: ; preds = %15, %2
%10 = load %struct.bitmask*, %struct.bitmask** %4
%11 = load i32, i32* %3
%12 = call i32 @numa_bitmask_isbitset(%struct.bitmask* %10, i32 %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add i32 %16, 1
%18 = load i32, i32* %5
%19 = urem i32 %17, %18
store i32 %19, i32* %3
br label %9
20: ; preds = %9
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.bitmask = type { i32 }
define i32 @interleave_next(i32 %0, %struct.bitmask* %1) {
%3 = tail call i32 (...) @numa_num_possible_nodes()
%4 = add i32 %0, 1
%5 = tail call i32 @numa_bitmask_isbitset(%struct.bitmask* %1, i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2, %7
%8 = phi i32 [ %10, %7 ], [ %4, %2 ]
%9 = add i32 %8, 1
%10 = urem i32 %9, %3
%11 = tail call i32 @numa_bitmask_isbitset(%struct.bitmask* %1, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %7, label %13
13: ; preds = %7, %2
%14 = phi i32 [ %4, %2 ], [ %10, %7 ]
ret i32 %14
}