#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 */
scalar_t__ check_feature(char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strchr(char *, char);
int parse_proc_cpuinfo(int bufsize, const char *feature) {
  char *buffer = (char *)malloc(bufsize);
  FILE *fd;
  int feature_support = 0;
  if (!buffer)
    return 0;
  fd = fopen("/proc/cpuinfo", "r");
  if (fd) {
    while (fgets(buffer, bufsize, fd)) {
      if (!strchr(buffer, '\n') && !feof(fd)) {
        fclose(fd);
        free(buffer);
        return -1;
      }
      if (check_feature(buffer, feature))
        feature_support = 1;
    }
    fclose(fd);
  }
  free(buffer);
  return feature_support;
}


x86 assembly (clang, -O0):
<parse_proc_cpuinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b9 <parse_proc_cpuinfo+0x39>
movl   $0x0,-0x4(%rbp)
jmp    127c <parse_proc_cpuinfo+0xfc>
lea    0xe40(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     126d <parse_proc_cpuinfo+0xed>
jmp    11e0 <parse_proc_cpuinfo+0x60>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1264 <parse_proc_cpuinfo+0xe4>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
cmp    $0x0,%eax
jne    1241 <parse_proc_cpuinfo+0xc1>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
jne    1241 <parse_proc_cpuinfo+0xc1>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127c <parse_proc_cpuinfo+0xfc>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <check_feature@plt>
cmp    $0x0,%rax
je     125f <parse_proc_cpuinfo+0xdf>
movl   $0x1,-0x24(%rbp)
jmp    11e0 <parse_proc_cpuinfo+0x60>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_proc_cpuinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
call   1080 <malloc@plt>
test   %rax,%rax
je     1231 <parse_proc_cpuinfo+0xb1>
mov    %rax,%rbx
lea    0xe57(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1235 <parse_proc_cpuinfo+0xb5>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1227 <parse_proc_cpuinfo+0xa7>
mov    $0x1,%r13d
jmp    1205 <parse_proc_cpuinfo+0x85>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <check_feature@plt>
test   %rax,%rax
cmovne %r13d,%ebp
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1227 <parse_proc_cpuinfo+0xa7>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %eax,%eax
jne    11e0 <parse_proc_cpuinfo+0x60>
mov    %r12,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11e0 <parse_proc_cpuinfo+0x60>
mov    $0xffffffff,%ebp
mov    %r12,%rdi
call   1040 <fclose@plt>
jmp    1237 <parse_proc_cpuinfo+0xb7>
xor    %ebp,%ebp
jmp    123f <parse_proc_cpuinfo+0xbf>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @parse_proc_cpuinfo(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i32, i32* %4
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
store i32 0, i32* %8
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 0, i32* %3
br label %53
15: ; preds = %2
%16 = 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* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %49
19: ; preds = %15
br label %20
20: ; preds = %45, %19
%21 = load i8*, i8** %6
%22 = load i32, i32* %4
%23 = load i32*, i32** %7
%24 = call i64 @fgets(i8* %21, i32 %22, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %46
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = call i32 @strchr(i8* %27, i8 signext 10)
%29 = icmp ne i32 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %26
%31 = load i32*, i32** %7
%32 = call i32 @feof(i32* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = load i32*, i32** %7
%36 = call i32 @fclose(i32* %35)
%37 = load i8*, i8** %6
%38 = call i32 @free(i8* %37)
store i32 -1, i32* %3
br label %53
39: ; preds = %30, %26
%40 = load i8*, i8** %6
%41 = load i8*, i8** %5
%42 = call i64 @check_feature(i8* %40, i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
store i32 1, i32* %8
br label %45
45: ; preds = %44, %39
br label %20
46: ; preds = %20
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
br label %49
49: ; preds = %46, %15
%50 = load i8*, i8** %6
%51 = call i32 @free(i8* %50)
%52 = load i32, i32* %8
store i32 %52, i32* %3
br label %53
53: ; preds = %49, %34, %14
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @parse_proc_cpuinfo(i32 %0, i8* %1) {
%3 = tail call i64 @malloc(i32 %0)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %31, label %6
6: ; preds = %2
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = tail call i64 @fgets(i8* %4, i32 %0, i32* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %9, %19
%13 = phi i32 [ %22, %19 ], [ 0, %9 ]
%14 = tail call i32 @strchr(i8* %4, i8 signext 10)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @feof(i32* %7)
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16, %12
%20 = tail call i64 @check_feature(i8* %4, i8* %1)
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 %13, i32 1
%23 = tail call i64 @fgets(i8* %4, i32 %0, i32* %7)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %12
25: ; preds = %19, %16, %9
%26 = phi i32 [ 0, %9 ], [ -1, %16 ], [ %22, %19 ]
%27 = tail call i32 @fclose(i32* %7)
br label %28
28: ; preds = %25, %6
%29 = phi i32 [ 0, %6 ], [ %26, %25 ]
%30 = tail call i32 @free(i8* %4)
br label %31
31: ; preds = %28, %2
%32 = phi i32 [ 0, %2 ], [ %29, %28 ]
ret i32 %32
}