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

/* Variables and functions */
scalar_t__ CPU_ISSET_S(int, size_t, int /*<<< orphan*/ *);
unsigned long long int cpusettoull(cpu_set_t *bits, size_t sz) {
  unsigned long long mask = 0;
  int i;
  for (i = 0; i < sizeof(mask) * 8; ++i) {
    if (CPU_ISSET_S(i, sz, bits)) {
      mask |= (1ull) << i;
    }
  }
  return mask;
}


x86 assembly (clang, -O0):
<cpusettoull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x40,%rax
jae    117f <cpusettoull+0x6f>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <CPU_ISSET_S@plt>
cmp    $0x0,%rax
je     116c <cpusettoull+0x5c>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1171 <cpusettoull+0x61>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112f <cpusettoull+0x1f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpusettoull>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <CPU_ISSET_S@plt>
mov    $0x1,%edx
mov    %ebx,%ecx
shl    %cl,%rdx
test   %rax,%rax
cmove  %rax,%rdx
or     %rdx,%r12
add    $0x1,%rbx
cmp    $0x40,%rbx
jne    1130 <cpusettoull+0x20>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @cpusettoull(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
store i64 0, i64* %5
store i32 0, i32* %6
br label %7
7: ; preds = %24, %2
%8 = load i32, i32* %6
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, 64
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load i32, i32* %6
%13 = load i64, i64* %4
%14 = load i32*, i32** %3
%15 = call i64 @CPU_ISSET_S(i32 %12, i64 %13, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* %6
%19 = zext i32 %18 to i64
%20 = shl i64 1, %19
%21 = load i64, i64* %5
%22 = or i64 %21, %20
store i64 %22, i64* %5
br label %23
23: ; preds = %17, %11
br label %24
24: ; preds = %23
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %7
27: ; preds = %7
%28 = load i64, i64* %5
ret i64 %28
}

LLVM IR (-O2):
define i64 @cpusettoull(i32* %0, i64 %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i64 [ 0, %2 ], [ %12, %3 ]
%5 = phi i64 [ 0, %2 ], [ %11, %3 ]
%6 = trunc i64 %4 to i32
%7 = tail call i64 @CPU_ISSET_S(i32 %6, i64 %1, i32* %0)
%8 = icmp eq i64 %7, 0
%9 = shl nuw i64 1, %4
%10 = select i1 %8, i64 0, i64 %9
%11 = or i64 %10, %5
%12 = add nuw nsw i64 %4, 1
%13 = icmp eq i64 %12, 64
br i1 %13, label %14, label %3
14: ; preds = %3
ret i64 %11
}