#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strtok(char *, char *);
int get_feature(char *search) {
  FILE *infile;
  char buffer[2048], *p, *t;
  p = (char *)NULL;
  infile = fopen("/proc/cpuinfo", "r");
  if (infile == NULL) {
    return 0;
  }
  while (fgets(buffer, sizeof(buffer), infile)) {
    if (!strncmp("Features", buffer, 8)) {
      p = strchr(buffer, ':') + 2;
      break;
    }
  }
  fclose(infile);
  if (p == NULL)
    return 0;
  t = strtok(p, " ");
  if (t != NULL) {
    if (!strcmp(t, search)) {
      return 1;
    }
  }
  while (t = strtok(NULL, " ")) {
    if (!strcmp(t, search)) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_feature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x828(%rbp)
lea    0xe6f(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b8 <get_feature+0x48>
movl   $0x0,-0x4(%rbp)
jmp    12ef <get_feature+0x17f>
jmp    11bd <get_feature+0x4d>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1223 <get_feature+0xb3>
lea    -0x820(%rbp),%rsi
lea    0xe26(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    121e <get_feature+0xae>
lea    -0x820(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
add    $0x2,%rax
mov    %rax,-0x828(%rbp)
jmp    1223 <get_feature+0xb3>
jmp    11bd <get_feature+0x4d>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x828(%rbp)
jne    1246 <get_feature+0xd6>
movl   $0x0,-0x4(%rbp)
jmp    12ef <get_feature+0x17f>
mov    -0x828(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x830(%rbp)
je     1298 <get_feature+0x128>
mov    -0x830(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1293 <get_feature+0x123>
movl   $0x1,-0x4(%rbp)
jmp    12ef <get_feature+0x17f>
jmp    1298 <get_feature+0x128>
jmp    129d <get_feature+0x12d>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd71(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x830(%rbp)
cmp    $0x0,%rax
je     12e8 <get_feature+0x178>
mov    -0x830(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12e3 <get_feature+0x173>
movl   $0x1,-0x4(%rbp)
jmp    12ef <get_feature+0x17f>
jmp    129d <get_feature+0x12d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_feature>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%r14
lea    0xe76(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1251 <get_feature+0xe1>
mov    %rax,%r12
mov    %rsp,%rbx
lea    0xe61(%rip),%r13
nop
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1249 <get_feature+0xd9>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11b0 <get_feature+0x40>
mov    %rsp,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
lea    0x2(%rax),%rbx
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strtok@plt>
test   %rax,%rax
je     1219 <get_feature+0xa9>
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1241 <get_feature+0xd1>
lea    0xdf9(%rip),%rbx
xor    %r15d,%r15d
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     1251 <get_feature+0xe1>
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    1220 <get_feature+0xb0>
mov    $0x1,%r15d
jmp    1251 <get_feature+0xe1>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r15d,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [9 x i8] c"Features\00"
@.str.3 = [2 x i8] c" \00"
define i32 @get_feature(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [2048 x i8]
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %6
%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** %4
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %57
12: ; preds = %1
br label %13
13: ; preds = %26, %12
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i64 @fgets(i8* %14, i32 2048, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%20 = call i32 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32 8)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%24 = call i8* @strchr(i8* %23, i8 signext 58)
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8* %25, i8** %6
br label %27
26: ; preds = %18
br label %13
27: ; preds = %22, %13
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %6
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 0, i32* %2
br label %57
33: ; preds = %27
%34 = load i8*, i8** %6
%35 = call i8* @strtok(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %45
38: ; preds = %33
%39 = load i8*, i8** %7
%40 = load i8*, i8** %3
%41 = call i32 @strcmp(i8* %39, i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %38
store i32 1, i32* %2
br label %57
44: ; preds = %38
br label %45
45: ; preds = %44, %33
br label %46
46: ; preds = %55, %45
%47 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %47, i8** %7
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %56
49: ; preds = %46
%50 = load i8*, i8** %7
%51 = load i8*, i8** %3
%52 = call i32 @strcmp(i8* %50, i8* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %49
store i32 1, i32* %2
br label %57
55: ; preds = %49
br label %46
56: ; preds = %46
store i32 0, i32* %2
br label %57
57: ; preds = %56, %54, %43, %32, %11
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"Features\00"
@.str.3 = [2 x i8] c" \00"
define i32 @get_feature(i8* nocapture %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%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 %30, label %6
6: ; preds = %1, %11
%7 = call i64 @fgets(i8* %3, i32 2048, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @fclose(i32* %4)
br label %30
11: ; preds = %6
%12 = call i32 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 8)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %11
%15 = call i8* @strchr(i8* %3, i8 signext 58)
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = call i32 @fclose(i32* %4)
%18 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = call i32 @strcmp(i8* %18, i8* dereferenceable(1) %0)
%22 = icmp eq i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %20, %14
br label %24
24: ; preds = %23, %27
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i32 @strcmp(i8* %25, i8* dereferenceable(1) %0)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %24
30: ; preds = %24, %27, %9, %20, %1
%31 = phi i32 [ 0, %1 ], [ 1, %20 ], [ 0, %9 ], [ 0, %24 ], [ 1, %27 ]
ret i32 %31
}