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

/* Variables and functions */
scalar_t__ CPU_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sched_getaffinity(int /*<<< orphan*/, int,
                                     int /*<<< orphan*/ *);
int get_cpus(void) {
  cpu_set_t ct;
  sched_getaffinity(0, sizeof(ct), &ct);
  int i, cnt = 0;
  for (i = 0; i < 16; i++)
    if (CPU_ISSET(i, &ct))
      cnt++;
  return cnt;
}


x86 assembly (clang, -O0):
<get_cpus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x4(%rbp),%rdx
call   1040 <sched_getaffinity@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    1182 <get_cpus+0x62>
mov    -0x8(%rbp),%edi
lea    -0x4(%rbp),%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x0,%rax
je     116f <get_cpus+0x4f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1174 <get_cpus+0x54>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <get_cpus+0x26>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpus>:
push   %rbp
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1040 <sched_getaffinity@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x2,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x3,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x4,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x5,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x6,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x7,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x8,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x9,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0xb,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0xc,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0xd,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0xe,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0xf,%edi
mov    %rbx,%rsi
call   1030 <CPU_ISSET@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_cpus() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %1)
store i32 0, i32* %3
store i32 0, i32* %2
br label %5
5: ; preds = %16, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 16
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i64 @CPU_ISSET(i32 %9, i32* %1)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %15
15: ; preds = %12, %8
br label %16
16: ; preds = %15
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %5
19: ; preds = %5
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
define i32 @get_cpus() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sched_getaffinity(i32 0, i32 4, i32* %1)
%4 = call i64 @CPU_ISSET(i32 0, i32* %1)
%5 = icmp ne i64 %4, 0
%6 = zext i1 %5 to i32
%7 = call i64 @CPU_ISSET(i32 1, i32* %1)
%8 = icmp ne i64 %7, 0
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %6, %9
%11 = call i64 @CPU_ISSET(i32 2, i32* %1)
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %10, %13
%15 = call i64 @CPU_ISSET(i32 3, i32* %1)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %14, %17
%19 = call i64 @CPU_ISSET(i32 4, i32* %1)
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i32
%22 = add nuw nsw i32 %18, %21
%23 = call i64 @CPU_ISSET(i32 5, i32* %1)
%24 = icmp ne i64 %23, 0
%25 = zext i1 %24 to i32
%26 = add nuw nsw i32 %22, %25
%27 = call i64 @CPU_ISSET(i32 6, i32* %1)
%28 = icmp ne i64 %27, 0
%29 = zext i1 %28 to i32
%30 = add nuw nsw i32 %26, %29
%31 = call i64 @CPU_ISSET(i32 7, i32* %1)
%32 = icmp ne i64 %31, 0
%33 = zext i1 %32 to i32
%34 = add nuw nsw i32 %30, %33
%35 = call i64 @CPU_ISSET(i32 8, i32* %1)
%36 = icmp ne i64 %35, 0
%37 = zext i1 %36 to i32
%38 = add nuw nsw i32 %34, %37
%39 = call i64 @CPU_ISSET(i32 9, i32* %1)
%40 = icmp ne i64 %39, 0
%41 = zext i1 %40 to i32
%42 = add nuw nsw i32 %38, %41
%43 = call i64 @CPU_ISSET(i32 10, i32* %1)
%44 = icmp ne i64 %43, 0
%45 = zext i1 %44 to i32
%46 = add nuw nsw i32 %42, %45
%47 = call i64 @CPU_ISSET(i32 11, i32* %1)
%48 = icmp ne i64 %47, 0
%49 = zext i1 %48 to i32
%50 = add nuw nsw i32 %46, %49
%51 = call i64 @CPU_ISSET(i32 12, i32* %1)
%52 = icmp ne i64 %51, 0
%53 = zext i1 %52 to i32
%54 = add nuw nsw i32 %50, %53
%55 = call i64 @CPU_ISSET(i32 13, i32* %1)
%56 = icmp ne i64 %55, 0
%57 = zext i1 %56 to i32
%58 = add nuw nsw i32 %54, %57
%59 = call i64 @CPU_ISSET(i32 14, i32* %1)
%60 = icmp ne i64 %59, 0
%61 = zext i1 %60 to i32
%62 = add nuw nsw i32 %58, %61
%63 = call i64 @CPU_ISSET(i32 15, i32* %1)
%64 = icmp ne i64 %63, 0
%65 = zext i1 %64 to i32
%66 = add nuw nsw i32 %62, %65
ret i32 %66
}