#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 */

/* Variables and functions */
int /*<<< orphan*/ _SC_NPROCESSORS_CONF;
int /*<<< orphan*/ file_int_extract(char *, int *, int, int *);
int /*<<< orphan*/ snprintf(char *, int, char *);
int sysconf(int /*<<< orphan*/);
int os_sysfs_online_ncpus(void) {
  int cpu_arr[(64 * 128)], num;
  char path[2048];
  if (sysconf(_SC_NPROCESSORS_CONF) > (64 * 128)) {
    return (-1);
  }
  snprintf(path, 2048, "/sys/devices/system/cpu/online");
  if (!file_int_extract(path, cpu_arr, (64 * 128), &num)) {
    return (-1);
  }
  return (num);
}


x86 assembly (clang, -O0):
<os_sysfs_online_ncpus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8820,%rsp
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
cmp    $0x2000,%eax
jle    1160 <os_sysfs_online_ncpus+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <os_sysfs_online_ncpus+0x85>
lea    -0x8820(%rbp),%rdi
mov    $0x800,%esi
lea    0xe8d(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x8820(%rbp),%rdi
lea    -0x8010(%rbp),%rsi
mov    $0x2000,%edx
lea    -0x8014(%rbp),%rcx
call   1040 <file_int_extract@plt>
cmp    $0x0,%eax
jne    11ac <os_sysfs_online_ncpus+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <os_sysfs_online_ncpus+0x85>
mov    -0x8014(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_sysfs_online_ncpus>:
push   %rbx
sub    $0x8810,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x2000,%ecx
jg     1191 <os_sysfs_online_ncpus+0x61>
lea    0xea4(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1030 <snprintf@plt>
lea    0x810(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x2000,%edx
call   1040 <file_int_extract@plt>
cmp    $0x1,%eax
sbb    %eax,%eax
or     0xc(%rsp),%eax
add    $0x8810,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [31 x i8] c"/sys/devices/system/cpu/online\00"
define i32 @os_sysfs_online_ncpus() {
%1 = alloca i32
%2 = alloca [8192 x i32]
%3 = alloca i32
%4 = alloca [2048 x i8]
%5 = load i32, i32* @_SC_NPROCESSORS_CONF
%6 = call i32 @sysconf(i32 %5)
%7 = icmp sgt i32 %6, 8192
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %19
9: ; preds = %0
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 2048, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [8192 x i32], [8192 x i32]* %2, i64 0, i64 0
%14 = call i32 @file_int_extract(i8* %12, i32* %13, i32 8192, i32* %3)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %9
store i32 -1, i32* %1
br label %19
17: ; preds = %9
%18 = load i32, i32* %3
store i32 %18, i32* %1
br label %19
19: ; preds = %17, %16, %8
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@_SC_NPROCESSORS_CONF = global i32 0
@.str = [31 x i8] c"/sys/devices/system/cpu/online\00"
define i32 @os_sysfs_online_ncpus() {
%1 = alloca [8192 x i32]
%2 = alloca i32
%3 = alloca [2048 x i8]
%4 = bitcast [8192 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @_SC_NPROCESSORS_CONF
%8 = tail call i32 @sysconf(i32 %7)
%9 = icmp sgt i32 %8, 8192
br i1 %9, label %17, label %10
10: ; preds = %0
%11 = call i32 @snprintf(i8* %6, i32 2048, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [8192 x i32], [8192 x i32]* %1, i64 0, i64 0
%13 = call i32 @file_int_extract(i8* %6, i32* %12, i32 8192, i32* %2)
%14 = icmp eq i32 %13, 0
%15 = load i32, i32* %2
%16 = select i1 %14, i32 -1, i32 %15
br label %17
17: ; preds = %10, %0
%18 = phi i32 [ -1, %0 ], [ %16, %10 ]
ret i32 %18
}