#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*/ bzero(char *, int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strstr(char *, char *);
unsigned int hash_num_cpu(void) {
  FILE *fcpu;
  unsigned int proc = 0;
  char buf[128];
  char *status;
  bzero(buf, 128);
  fcpu = fopen("/proc/cpuinfo", "r");
  if (!fcpu) {
    fprintf(stderr,
            "\033[1;31m[hashkill]\033[0m (%s:%d) "
            "Cannot open /proc/cpuinfo! errno=%d",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/gat3way/hashkill/refs/heads/master/src/"
            "threads.c",
            743, errno);
    return 0;
  } else {
    do {
      status = fgets(buf, 128, fcpu);
      if ((status) && (strstr(buf, "processor")))
        proc++;
    } while (status);
    fclose(fcpu);
  }
  fprintf(stderr,
          "\033[1m[hashkill]\033[0m "
          "Detected %d CPUs.\n",
          proc);
  return proc;
}


x86 assembly (clang, -O0):
<hash_num_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x14(%rbp)
lea    -0xa0(%rbp),%rdi
mov    $0x80,%esi
call   1070 <bzero@plt>
lea    0xe76(%rip),%rdi
lea    0xf52(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11de <hash_num_cpu+0x7e>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%r8d
lea    0xe4f(%rip),%rsi
lea    0xe8a(%rip),%rdx
mov    $0x2e7,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    126f <hash_num_cpu+0x10f>
jmp    11e3 <hash_num_cpu+0x83>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1040 <fgets@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     1233 <hash_num_cpu+0xd3>
lea    -0xa0(%rbp),%rdi
lea    0xec0(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1233 <hash_num_cpu+0xd3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1238 <hash_num_cpu+0xd8>
cmpq   $0x0,-0xa8(%rbp)
jne    11e3 <hash_num_cpu+0x83>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_num_cpu>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsp,%rdi
mov    $0x80,%esi
call   1070 <bzero@plt>
lea    0xe7e(%rip),%rdi
lea    0xf5a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     120a <hash_num_cpu+0xaa>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11e7 <hash_num_cpu+0x87>
lea    0xf27(%rip),%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1080 <strstr@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
mov    %r12,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11c0 <hash_num_cpu+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xee6(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1239 <hash_num_cpu+0xd9>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%r8d
lea    0xdea(%rip),%rsi
lea    0xe25(%rip),%rdx
xor    %ebx,%ebx
mov    $0x2e7,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0x88,%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"
@stderr = global i32 0
@.str.2 = [66 x i8] c"\1B[1;31m[hashkill]\1B[0m (%s:%d) Cannot open /proc/cpuinfo! errno=%d\00"
@.str.3 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gat3way/hashkill/refs/heads/master/src/threads.c\00"
@errno = global i32 0
@.str.4 = [10 x i8] c"processor\00"
@.str.5 = [38 x i8] c"\1B[1m[hashkill]\1B[0m Detected %d CPUs.\0A\00"
define i32 @hash_num_cpu() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i8*
store i32 0, i32* %3
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 128)
%8 = 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* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp ne i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.3, i64 0, i64 0), i32 743, i32 %13)
store i32 0, i32* %1
br label %41
15: ; preds = %0
br label %16
16: ; preds = %30, %15
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%18 = load i32*, i32** %2
%19 = call i8* @fgets(i8* %17, i32 128, i32* %18)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %29
22: ; preds = %16
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%24 = call i64 @strstr(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %3
%28 = add i32 %27, 1
store i32 %28, i32* %3
br label %29
29: ; preds = %26, %22, %16
br label %30
30: ; preds = %29
%31 = load i8*, i8** %5
%32 = icmp ne i8* %31, null
br i1 %32, label %16, label %33
33: ; preds = %30
%34 = load i32*, i32** %2
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = load i32, i32* %3
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %3
store i32 %40, i32* %1
br label %41
41: ; preds = %36, %11
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [66 x i8] c"\1B[1;31m[hashkill]\1B[0m (%s:%d) Cannot open /proc/cpuinfo! errno=%d\00"
@.str.3 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gat3way/hashkill/refs/heads/master/src/threads.c\00"
@errno = global i32 0
@.str.4 = [10 x i8] c"processor\00"
@.str.5 = [38 x i8] c"\1B[1m[hashkill]\1B[0m Detected %d CPUs.\0A\00"
define i32 @hash_num_cpu() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i32 @bzero(i8* %2, i32 128)
%4 = 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i8* @fgets(i8* %2, i32 128, i32* %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %21, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.3, i64 0, i64 0), i32 743, i32 %11)
br label %26
13: ; preds = %6, %13
%14 = phi i32 [ %18, %13 ], [ 0, %6 ]
%15 = call i64 @strstr(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i32
%18 = add i32 %14, %17
%19 = call i8* @fgets(i8* %2, i32 128, i32* %4)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %13
21: ; preds = %13, %6
%22 = phi i32 [ 0, %6 ], [ %18, %13 ]
%23 = call i32 @fclose(i32* %4)
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %22)
br label %26
26: ; preds = %21, %9
%27 = phi i32 [ %22, %21 ], [ 0, %9 ]
ret i32 %27
}