#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ *fdgets(char *, int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
char *strstr(char *, char *);
int /*<<< orphan*/ uppercase(char *);
int getCores() {
  int totalcores = 0;
  int cmdline = open("/proc/cpuinfo", O_RDONLY);
  char linebuf[4096];
  while (fdgets(linebuf, 4096, cmdline) != NULL) {
    uppercase(linebuf);
    if (strstr(linebuf, "BOGOMIPS") == linebuf)
      totalcores++;
    memset(linebuf, 0, 4096);
  }
  close(cmdline);
  return totalcores;
}


x86 assembly (clang, -O0):
<getCores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x1000,%esi
call   1040 <fdgets@plt>
cmp    $0x0,%rax
je     11f8 <getCores+0x98>
lea    -0x1010(%rbp),%rdi
call   1060 <uppercase@plt>
lea    -0x1010(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <strstr@plt>
lea    -0x1010(%rbp),%rcx
cmp    %rcx,%rax
jne    11e0 <getCores+0x80>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
jmp    118a <getCores+0x2a>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCores>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %eax,%edx
call   1040 <fdgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11d7 <getCores+0x87>
mov    %rsp,%rbx
movabs $0x5350494d4f474f42,%r15
49 50 53
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <uppercase@plt>
xor    %eax,%eax
cmp    %r15,(%rsp)
sete   %al
add    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14d,%edx
call   1040 <fdgets@plt>
test   %rax,%rax
jne    11a0 <getCores+0x50>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"BOGOMIPS\00"
define i32 @getCores() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4096 x i8]
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
br label %6
6: ; preds = %21, %0
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32* @fdgets(i8* %7, i32 4096, i32 %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %24
11: ; preds = %6
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%13 = call i32 @uppercase(i8* %12)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%17 = icmp eq i8* %15, %16
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* %1
%20 = add nsw i32 %19, 1
store i32 %20, i32* %1
br label %21
21: ; preds = %18, %11
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 4096)
br label %6
24: ; preds = %6
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@O_RDONLY = global i32 0
define i32 @getCores() {
%1 = alloca [4096 x i8]
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%5 = call i32* @fdgets(i8* %4, i32 4096, i32 %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %19, label %7
7: ; preds = %0
%8 = bitcast [4096 x i8]* %1 to i64*
br label %9
9: ; preds = %7, %9
%10 = phi i32 [ 0, %7 ], [ %15, %9 ]
%11 = call i32 @uppercase(i8* %4)
%12 = load i64, i64* %8
%13 = icmp eq i64 %12, 6003378899676254018
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %10, %14
%16 = call i32 @memset(i8* %4, i32 0, i32 4096)
%17 = call i32* @fdgets(i8* %4, i32 4096, i32 %3)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %9
19: ; preds = %9, %0
%20 = phi i32 [ 0, %0 ], [ %15, %9 ]
%21 = call i32 @close(i32 %3)
ret i32 %20
}