#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 int64_t;

/* Variables and functions */
int LONG_MAX;
int LONG_MIN;
int /*<<< orphan*/ runCommand(char const *, char *, int);
int strtol(char *, int /*<<< orphan*/ *, int);
int64_t env_getCoreCount() {
  char buff[16];
  const char *command = "cat /proc/cpuinfo | grep vendor_id | wc -l";
  runCommand(command, buff, 16);
  int64_t count = strtol(buff, NULL, 10);
  const bool validResult = count <= 0 || count == LONG_MIN || count == LONG_MAX;
  return validResult ? -1 : count;
}


x86 assembly (clang, -O0):
<env_getCoreCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1030 <runCommand@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jle    1192 <env_getCoreCount+0x72>
mov    -0x1c(%rbp),%ecx
mov    $0x1,%al
mov    0x2e73(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x21(%rbp)
je     1192 <env_getCoreCount+0x72>
mov    -0x1c(%rbp),%eax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11b4 <env_getCoreCount+0x94>
mov    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11ba <env_getCoreCount+0x9a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_getCoreCount>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x10,%edx
call   1030 <runCommand@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%eax
mov    0x2e8d(%rip),%rdx
mov    $0xffffffff,%esi
mov    %eax,%ecx
cmove  %esi,%ecx
cmp    (%rdx),%eax
cmove  %esi,%ecx
test   %eax,%eax
cmovle %esi,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"cat /proc/cpuinfo | grep vendor_id | wc -l\00"
@LONG_MIN = global i32 0
@LONG_MAX = global i32 0
define i32 @env_getCoreCount() {
%1 = alloca [16 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%7 = call i32 @runCommand(i8* %5, i8* %6, i32 16)
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%9 = call i32 @strtol(i8* %8, i32* null, i32 10)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %0
%13 = load i32, i32* %3
%14 = load i32, i32* @LONG_MIN
%15 = icmp eq i32 %13, %14
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i32, i32* %3
%18 = load i32, i32* @LONG_MAX
%19 = icmp eq i32 %17, %18
br label %20
20: ; preds = %16, %12, %0
%21 = phi i1 [ true, %12 ], [ true, %0 ], [ %19, %16 ]
%22 = zext i1 %21 to i32
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %28
26: ; preds = %20
%27 = load i32, i32* %3
br label %28
28: ; preds = %26, %25
%29 = phi i32 [ -1, %25 ], [ %27, %26 ]
ret i32 %29
}

LLVM IR (-O2):
@.str = [43 x i8] c"cat /proc/cpuinfo | grep vendor_id | wc -l\00"
@LONG_MIN = global i32 0
@LONG_MAX = global i32 0
define i32 @env_getCoreCount() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = call i32 @runCommand(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %2, i32 16)
%4 = call i32 @strtol(i8* nocapture %2, i32* null, i32 10)
%5 = icmp slt i32 %4, 1
%6 = load i32, i32* @LONG_MIN
%7 = icmp eq i32 %4, %6
%8 = select i1 %5, i1 true, i1 %7
%9 = load i32, i32* @LONG_MAX
%10 = icmp eq i32 %4, %9
%11 = select i1 %8, i1 true, i1 %10
%12 = select i1 %11, i32 -1, i32 %4
ret i32 %12
}