#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 */
int /*<<< orphan*/ Warning(char *);
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
char *strtok(char *, char *);
int Get_CPU_Cores(void) {
  FILE *fp;
  char buf[256], *data;
  int cores;
  if ((fp = fopen("/proc/cpuinfo", "r")) != NULL) {
    while (fgets(buf, 256, fp)) {
      if (!strncasecmp(buf, "cpu cores", 9)) {
        strtok(buf, ":");
        data = strtok(NULL, "\n");
        cores = atoi(data);
        fclose(fp);
        return cores;
      }
    }
    fclose(fp);
  }
  Warning("Could not get cpu cores from cpuinfo\n");
  return 0;
}


x86 assembly (clang, -O0):
<Get_CPU_Cores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xe7e(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1242 <Get_CPU_Cores+0xd2>
jmp    11a1 <Get_CPU_Cores+0x31>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1239 <Get_CPU_Cores+0xc9>
lea    -0x110(%rbp),%rdi
lea    0xe42(%rip),%rsi
mov    $0x9,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1234 <Get_CPU_Cores+0xc4>
lea    -0x110(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1080 <strtok@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe41(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x11c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x11c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1255 <Get_CPU_Cores+0xe5>
jmp    11a1 <Get_CPU_Cores+0x31>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdd3(%rip),%rdi
call   1050 <Warning@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Get_CPU_Cores>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe7d(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1212 <Get_CPU_Cores+0xa2>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xe6f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     120a <Get_CPU_Cores+0x9a>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x9,%edx
call   1060 <strncasecmp@plt>
test   %eax,%eax
jne    11b0 <Get_CPU_Cores+0x40>
lea    0xe3a(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strtok@plt>
lea    0xe51(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    1220 <Get_CPU_Cores+0xb0>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xe03(%rip),%rdi
call   1050 <Warning@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
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"cpu cores\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [38 x i8] c"Could not get cpu cores from cpuinfo\0A\00"
define i32 @Get_CPU_Cores() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = 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* %6, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %31
8: ; preds = %0
br label %9
9: ; preds = %27, %8
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i64 @fgets(i8* %10, i32 256, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %9
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%16 = call i32 @strncasecmp(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%17 = icmp ne i32 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %14
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%20 = call i8* @strtok(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %5
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* %5
store i32 %26, i32* %1
br label %33
27: ; preds = %14
br label %9
28: ; preds = %9
%29 = load i32*, i32** %2
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %0
%32 = call i32 @Warning(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %33
33: ; preds = %31, %18
%34 = load i32, i32* %1
ret i32 %34
}

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"cpu cores\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [38 x i8] c"Could not get cpu cores from cpuinfo\0A\00"
define i32 @Get_CPU_Cores() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 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 %18, label %5
5: ; preds = %0, %8
%6 = call i64 @fgets(i8* %2, i32 256, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = call i32 @strncasecmp(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %5
11: ; preds = %8
%12 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @atoi(i8* %13)
%15 = call i32 @fclose(i32* %3)
br label %20
16: ; preds = %5
%17 = call i32 @fclose(i32* %3)
br label %18
18: ; preds = %16, %0
%19 = call i32 @Warning(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = phi i32 [ %14, %11 ], [ 0, %18 ]
ret i32 %21
}