#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 /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
void mask_to_cpuset(cpu_set_t *cpuset, unsigned int mask) {
  int core = 0;
  if (mask == 0)
    return;
  CPU_ZERO(cpuset);
  for (core = 0; core < 31; core++) {
    if ((1 << core) & mask) {
      CPU_SET(core, cpuset);
    }
  }
}


x86 assembly (clang, -O0):
<mask_to_cpuset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1145 <mask_to_cpuset+0x25>
jmp    1194 <mask_to_cpuset+0x74>
mov    -0x8(%rbp),%rdi
call   1030 <CPU_ZERO@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x1f,-0x10(%rbp)
jge    1194 <mask_to_cpuset+0x74>
mov    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     1181 <mask_to_cpuset+0x61>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <CPU_SET@plt>
jmp    1186 <mask_to_cpuset+0x66>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1155 <mask_to_cpuset+0x35>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mask_to_cpuset>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
je     1159 <mask_to_cpuset+0x39>
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <CPU_ZERO@plt>
xor    %ebp,%ebp
jmp    1148 <mask_to_cpuset+0x28>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x1f,%ebp
je     1159 <mask_to_cpuset+0x39>
bt     %ebp,%ebx
jae    1140 <mask_to_cpuset+0x20>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <CPU_SET@plt>
jmp    1140 <mask_to_cpuset+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @mask_to_cpuset(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
br label %29
9: ; preds = %2
%10 = load i32*, i32** %3
%11 = call i32 @CPU_ZERO(i32* %10)
store i32 0, i32* %5
br label %12
12: ; preds = %26, %9
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 31
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i32, i32* %5
%17 = shl i32 1, %16
%18 = load i32, i32* %4
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* %5
%23 = load i32*, i32** %3
%24 = call i32 @CPU_SET(i32 %22, i32* %23)
br label %25
25: ; preds = %21, %15
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %12
29: ; preds = %8, %12
ret void
}

LLVM IR (-O2):
define void @mask_to_cpuset(i32* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = tail call i32 @CPU_ZERO(i32* %0)
br label %6
6: ; preds = %4, %13
%7 = phi i32 [ 0, %4 ], [ %14, %13 ]
%8 = shl nuw nsw i32 1, %7
%9 = and i32 %8, %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 @CPU_SET(i32 %7, i32* %0)
br label %13
13: ; preds = %6, %11
%14 = add nuw nsw i32 %7, 1
%15 = icmp eq i32 %14, 31
br i1 %15, label %16, label %6
16: ; preds = %13, %2
ret void
}