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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int get_numCPUs() {
  int cpucount = 0;
  char line[1024];
  FILE *fp = fopen("/proc/cpuinfo", "r");
  if (fp != NULL) {
    while (fgets(line, 1024, fp)) {
      if (strncmp(line, "processor", 9) == 0) {
        cpucount++;
      }
    }
  }
  return cpucount;
}


x86 assembly (clang, -O0):
<get_numCPUs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     11c6 <get_numCPUs+0x96>
jmp    116f <get_numCPUs+0x3f>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11c1 <get_numCPUs+0x91>
lea    -0x410(%rbp),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11bc <get_numCPUs+0x8c>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116f <get_numCPUs+0x3f>
jmp    11c6 <get_numCPUs+0x96>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_numCPUs>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xebb(%rip),%rdi
lea    0xeca(%rip),%rsi
call   1050 <fopen@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11ac <get_numCPUs+0x7c>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11ac <get_numCPUs+0x7c>
xor    %ebx,%ebx
lea    0xe95(%rip),%r15
mov    %rsp,%r12
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebx
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1180 <get_numCPUs+0x50>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"processor\00"
define i32 @get_numCPUs() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %22
7: ; preds = %0
br label %8
8: ; preds = %20, %7
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i64 @fgets(i8* %9, i32 1024, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %20
20: ; preds = %17, %13
br label %8
21: ; preds = %8
br label %22
22: ; preds = %21, %0
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"processor\00"
define i32 @get_numCPUs() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %16, label %5
5: ; preds = %0
%6 = call i64 @fgets(i8* %2, i32 1024, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5, %8
%9 = phi i32 [ %13, %8 ], [ 0, %5 ]
%10 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %9, %12
%14 = call i64 @fgets(i8* %2, i32 1024, i32* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %5, %0
%17 = phi i32 [ 0, %0 ], [ 0, %5 ], [ %13, %8 ]
ret i32 %17
}