#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int get_cpu_count_from_file(char *filename) {
  FILE *file;
  char line[64];
  int cpu_count;
  file = fopen(filename, "r");
  if (!file) {
    fprintf(stderr, "Could not open %s\n", filename);
    exit(EXIT_FAILURE);
  };
  if (!fgets(line, 64, file)) {
    fprintf(stderr, "Could not get %s contents\n", filename);
    exit(EXIT_FAILURE);
  };
  fclose(file);
  if (strcmp(line, "0\n") == 0) {
    return 1;
  }
  if (1 == sscanf(line, "0-%d\n", &cpu_count)) {
    return cpu_count + 1;
  }
  {
    fprintf(stderr, "Unexpected input in file %s (%s).\n", filename, line);
    exit(EXIT_FAILURE);
  };
  return -1;
}


x86 assembly (clang, -O0):
<get_cpu_count_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c4 <get_cpu_count_from_file+0x54>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x40,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    1208 <get_cpu_count_from_file+0x98>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x60(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1237 <get_cpu_count_from_file+0xc7>
movl   $0x1,-0x4(%rbp)
jmp    1295 <get_cpu_count_from_file+0x125>
lea    -0x60(%rbp),%rdi
lea    0xdf1(%rip),%rsi
lea    -0x64(%rbp),%rdx
call   1070 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1268 <get_cpu_count_from_file+0xf8>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1295 <get_cpu_count_from_file+0x125>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_count_from_file>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f3 <get_cpu_count_from_file+0x83>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %eax,%eax
je     1205 <get_cpu_count_from_file+0x95>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe7d(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11e6 <get_cpu_count_from_file+0x76>
lea    0xe6a(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1221 <get_cpu_count_from_file+0xb1>
mov    0xc(%rsp),%eax
add    $0x1,%eax
jmp    11eb <get_cpu_count_from_file+0x7b>
mov    $0x1,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
jmp    1215 <get_cpu_count_from_file+0xa5>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1240 <get_cpu_count_from_file+0xd0>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [27 x i8] c"Could not get %s contents\0A\00"
@.str.3 = [3 x i8] c"0\0A\00"
@.str.4 = [6 x i8] c"0-%d\0A\00"
@.str.5 = [35 x i8] c"Unexpected input in file %s (%s).\0A\00"
define i32 @get_cpu_count_from_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [64 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %4
%20 = call i32 @fgets(i8* %18, i32 64, i32* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %3
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %17
%29 = load i32*, i32** %4
%30 = call i32 @fclose(i32* %29)
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 1, i32* %2
br label %49
35: ; preds = %28
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%37 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%38 = icmp eq i32 1, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %49
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %3
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %44, i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %39, %34
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [27 x i8] c"Could not get %s contents\0A\00"
@.str.3 = [3 x i8] c"0\0A\00"
@.str.4 = [6 x i8] c"0-%d\0A\00"
@.str.5 = [35 x i8] c"Unexpected input in file %s (%s).\0A\00"
define i32 @get_cpu_count_from_file(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = call i32 @fgets(i8* %4, i32 64, i32* %6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %13
%22 = call i32 @fclose(i32* %6)
%23 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %36, label %25
25: ; preds = %21
%26 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
br label %36
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %4)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %21, %28
%37 = phi i32 [ %30, %28 ], [ 1, %21 ]
ret i32 %37
}