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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
long _get_ncpus_proc_cpuinfo(FILE *cpuinfo_fp) {
  char line_buffer[1024] = {0};
  long ncpus = 0;
  while (fgets(line_buffer, sizeof(line_buffer), cpuinfo_fp)) {
    if (strncmp("processor", line_buffer, sizeof("processor") - 1) != 0) {
      continue;
    }
    char *colon_position = strchr(line_buffer, ':');
    if (colon_position == NULL) {
      continue;
    }
    if (!(line_buffer[sizeof("processor") - 1] == ' ' ||
          line_buffer[sizeof("processor") - 1] == '\t' ||
          line_buffer[sizeof("processor") - 1] == ':')) {
      continue;
    }
    ncpus++;
  }
  return ncpus;
}


x86 assembly (clang, -O0):
<_get_ncpus_proc_cpuinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movq   $0x0,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     122a <_get_ncpus_proc_cpuinfo+0xea>
lea    -0x410(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11b3 <_get_ncpus_proc_cpuinfo+0x73>
jmp    116d <_get_ncpus_proc_cpuinfo+0x2d>
lea    -0x410(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jne    11de <_get_ncpus_proc_cpuinfo+0x9e>
jmp    116d <_get_ncpus_proc_cpuinfo+0x2d>
movsbl -0x407(%rbp),%eax
cmp    $0x20,%eax
je     1213 <_get_ncpus_proc_cpuinfo+0xd3>
movsbl -0x407(%rbp),%eax
cmp    $0x9,%eax
je     1213 <_get_ncpus_proc_cpuinfo+0xd3>
movsbl -0x407(%rbp),%eax
cmp    $0x3a,%eax
je     1213 <_get_ncpus_proc_cpuinfo+0xd3>
jmp    116d <_get_ncpus_proc_cpuinfo+0x2d>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    116d <_get_ncpus_proc_cpuinfo+0x2d>
mov    -0x418(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_ncpus_proc_cpuinfo>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r15
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe91(%rip),%r12
movabs $0x400000100000200,%r13
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d3 <_get_ncpus_proc_cpuinfo+0x93>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1180 <_get_ncpus_proc_cpuinfo+0x40>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1180 <_get_ncpus_proc_cpuinfo+0x40>
movzbl 0x9(%rsp),%eax
cmp    $0x3a,%rax
ja     1180 <_get_ncpus_proc_cpuinfo+0x40>
bt     %rax,%r13
jae    1180 <_get_ncpus_proc_cpuinfo+0x40>
add    $0x1,%r14
jmp    1180 <_get_ncpus_proc_cpuinfo+0x40>
mov    %r14,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"processor\00"
define i64 @_get_ncpus_proc_cpuinfo(i32* %0) {
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i64
%5 = alloca i8*
store i32* %0, i32** %2
%6 = bitcast [1024 x i8]* %3 to i8*
store i64 0, i64* %4
br label %7
7: ; preds = %39, %38, %22, %16, %1
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = load i32*, i32** %2
%10 = call i64 @fgets(i8* %8, i32 1024, i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %42
12: ; preds = %7
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = call i64 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %13, i32 9)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
br label %7
17: ; preds = %12
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = call i8* @strchr(i8* %18, i8 signext 58)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
br label %7
23: ; preds = %17
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 9
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br i1 %27, label %39, label %28
28: ; preds = %23
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 9
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 9
br i1 %32, label %39, label %33
33: ; preds = %28
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 9
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 58
br i1 %37, label %39, label %38
38: ; preds = %33
br label %7
39: ; preds = %33, %28, %23
%40 = load i64, i64* %4
%41 = add nsw i64 %40, 1
store i64 %41, i64* %4
br label %7
42: ; preds = %7
%43 = load i64, i64* %4
ret i64 %43
}

LLVM IR (-O2):
@.str = [10 x i8] c"processor\00"
define i64 @_get_ncpus_proc_cpuinfo(i32* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 9
br label %5
5: ; preds = %20, %1
%6 = phi i64 [ %21, %20 ], [ 0, %1 ]
br label %7
7: ; preds = %19, %5
br label %8
8: ; preds = %7, %11
%9 = call i64 @fgets(i8* %3, i32 1024, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %8
%12 = call i64 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3, i32 9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %11
%15 = call i8* @strchr(i8* %3, i8 signext 58)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = load i8, i8* %4
switch i8 %18, label %19 [
i8 58, label %20
i8 32, label %20
i8 9, label %20
]
19: ; preds = %17, %14
br label %7
20: ; preds = %17, %17, %17
%21 = add nuw nsw i64 %6, 1
br label %5
22: ; preds = %8
ret i64 %6
}