#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*/ res;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int getCoreCount() {
  FILE *fp;
  char res[128] = {0};
  fp = popen("/bin/cat /proc/cpuinfo |grep -c '^processor'", "r");
  fread(res, 1, sizeof(res) - 1, fp);
  fclose(fp);
  if (res)
    return atoi(res);
  return 0;
}


x86 assembly (clang, -O0):
<getCoreCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xe8b(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x7f,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x90(%rbp),%rax
cmp    $0x0,%rax
je     11cd <getCoreCount+0x7d>
lea    -0x90(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    11d4 <getCoreCount+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCoreCount>:
push   %r14
push   %rbx
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe85(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x7f,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1060 <atoi@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [45 x i8] c"/bin/cat /proc/cpuinfo |grep -c '^processor'\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @getCoreCount() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [128 x i8]
%4 = bitcast [128 x i8]* %3 to i8*
%5 = call i32* @popen(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = load i32*, i32** %2
%8 = call i32 @fread(i8* %6, i32 1, i32 127, i32* %7)
%9 = load i32*, i32** %2
%10 = call i32 @fclose(i32* %9)
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %1
br label %17
16: ; preds = %0
store i32 0, i32* %1
br label %17
17: ; preds = %16, %13
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [45 x i8] c"/bin/cat /proc/cpuinfo |grep -c '^processor'\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @getCoreCount() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @fread(i8* %2, i32 1, i32 127, i32* %3)
%5 = tail call i32 @fclose(i32* %3)
%6 = call i32 @atoi(i8* %2)
ret i32 %6
}