#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 *);
scalar_t__ get_feature(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strncmp(char *, char *, int);
scalar_t__ strstr(char *, char *);
int cpu_detect(void) {
  FILE *infile;
  char buffer[512], *p;
  p = (char *)NULL;
  infile = fopen("/proc/cpuinfo", "r");
  if (infile == NULL) {
    return 0;
  }
  while (fgets(buffer, sizeof(buffer), infile)) {
    if (!strncmp("CPU part", buffer, 8)) {
      p = strchr(buffer, ':') + 2;
      break;
    }
  }
  fclose(infile);
  if (p != NULL) {
    if (strstr(p, "0xc09")) {
      if (get_feature("neon"))
        return 2;
      else
        return 1;
    }
    if (strstr(p, "0xc0f")) {
      if (get_feature("neon"))
        return 3;
      else
        return 1;
    }
  }
  p = (char *)NULL;
  infile = fopen("/proc/cpuinfo", "r");
  if (infile == NULL) {
    return 0;
  }
  while (fgets(buffer, sizeof(buffer), infile)) {
    if ((!strncmp("model name", buffer, 10)) ||
        (!strncmp("Processor", buffer, 9))) {
      p = strchr(buffer, ':') + 2;
      break;
    }
  }
  fclose(infile);
  if (p != NULL) {
    if (strstr(p, "ARMv7")) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cpu_detect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movq   $0x0,-0x218(%rbp)
lea    0xe73(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <cpu_detect+0x44>
movl   $0x0,-0x4(%rbp)
jmp    13e2 <cpu_detect+0x272>
jmp    11b9 <cpu_detect+0x49>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     121f <cpu_detect+0xaf>
lea    -0x210(%rbp),%rsi
lea    0xe28(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    121a <cpu_detect+0xaa>
lea    -0x210(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
add    $0x2,%rax
mov    %rax,-0x218(%rbp)
jmp    121f <cpu_detect+0xaf>
jmp    11b9 <cpu_detect+0x49>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x218(%rbp)
je     12d1 <cpu_detect+0x161>
mov    -0x218(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1281 <cpu_detect+0x111>
lea    0xdc3(%rip),%rdi
call   1060 <get_feature@plt>
cmp    $0x0,%rax
je     1275 <cpu_detect+0x105>
movl   $0x2,-0x4(%rbp)
jmp    13e2 <cpu_detect+0x272>
movl   $0x1,-0x4(%rbp)
jmp    13e2 <cpu_detect+0x272>
mov    -0x218(%rbp),%rdi
lea    0xd93(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     12cc <cpu_detect+0x15c>
lea    0xd78(%rip),%rdi
call   1060 <get_feature@plt>
cmp    $0x0,%rax
je     12c0 <cpu_detect+0x150>
movl   $0x3,-0x4(%rbp)
jmp    13e2 <cpu_detect+0x272>
movl   $0x1,-0x4(%rbp)
jmp    13e2 <cpu_detect+0x272>
jmp    12d1 <cpu_detect+0x161>
movq   $0x0,-0x218(%rbp)
lea    0xd1d(%rip),%rdi
lea    0xd51(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    130a <cpu_detect+0x19a>
movl   $0x0,-0x4(%rbp)
jmp    13e2 <cpu_detect+0x272>
jmp    130f <cpu_detect+0x19f>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1396 <cpu_detect+0x226>
lea    -0x210(%rbp),%rsi
lea    0xcec(%rip),%rdi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     1370 <cpu_detect+0x200>
lea    -0x210(%rbp),%rsi
lea    0xcd6(%rip),%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1391 <cpu_detect+0x221>
lea    -0x210(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
add    $0x2,%rax
mov    %rax,-0x218(%rbp)
jmp    1396 <cpu_detect+0x226>
jmp    130f <cpu_detect+0x19f>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x218(%rbp)
je     13db <cpu_detect+0x26b>
mov    -0x218(%rbp),%rdi
lea    0xc82(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     13d6 <cpu_detect+0x266>
movl   $0x1,-0x4(%rbp)
jmp    13e2 <cpu_detect+0x272>
jmp    13db <cpu_detect+0x26b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_detect>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
lea    0xe7c(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1080 <fopen@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1327 <cpu_detect+0x1b7>
mov    %rax,%rbx
mov    %rsp,%rbp
lea    0xe65(%rip),%r15
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     122c <cpu_detect+0xbc>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11b0 <cpu_detect+0x40>
mov    %rsp,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,%rbp
add    $0x2,%rbp
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe1b(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     12e6 <cpu_detect+0x176>
lea    0xe09(%rip),%rdi
call   1060 <get_feature@plt>
cmp    $0x1,%rax
mov    $0x2,%r14d
sbb    $0x0,%r14d
jmp    1327 <cpu_detect+0x1b7>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdc5(%rip),%rdi
lea    0xdf9(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1327 <cpu_detect+0x1b7>
mov    %rax,%rbx
mov    %rsp,%rbp
lea    0xdcb(%rip),%r14
lea    0xdcf(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     131c <cpu_detect+0x1ac>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     12b1 <cpu_detect+0x141>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1270 <cpu_detect+0x100>
mov    %rsp,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
lea    0x2(%rax),%rbp
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd6c(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strstr@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    1327 <cpu_detect+0x1b7>
jmp    1324 <cpu_detect+0x1b4>
lea    0xd35(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     1234 <cpu_detect+0xc4>
lea    0xd18(%rip),%rdi
call   1060 <get_feature@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,1),%r14d
add    $0x1,%r14d
jmp    1327 <cpu_detect+0x1b7>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x208,%rsp
pop    %rbx
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"
@.str.2 = [9 x i8] c"CPU part\00"
@.str.3 = [6 x i8] c"0xc09\00"
@.str.4 = [5 x i8] c"neon\00"
@.str.5 = [6 x i8] c"0xc0f\00"
@.str.6 = [11 x i8] c"model name\00"
@.str.7 = [10 x i8] c"Processor\00"
@.str.8 = [6 x i8] c"ARMv7\00"
define i32 @cpu_detect() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [512 x i8]
%4 = alloca i8*
store i8* null, i8** %4
%5 = 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* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 0, i32* %1
br label %84
9: ; preds = %0
br label %10
10: ; preds = %23, %9
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i64 @fgets(i8* %11, i32 512, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%17 = call i32 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %16, i32 8)
%18 = icmp ne i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%21 = call i8* @strchr(i8* %20, i8 signext 58)
%22 = getelementptr inbounds i8, i8* %21, i64 2
store i8* %22, i8** %4
br label %24
23: ; preds = %15
br label %10
24: ; preds = %19, %10
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
%27 = load i8*, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %48
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = call i64 @strstr(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = call i64 @get_feature(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 2, i32* %1
br label %84
37: ; preds = %33
store i32 1, i32* %1
br label %84
38: ; preds = %29
%39 = load i8*, i8** %4
%40 = call i64 @strstr(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = call i64 @get_feature(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 3, i32* %1
br label %84
46: ; preds = %42
store i32 1, i32* %1
br label %84
47: ; preds = %38
br label %48
48: ; preds = %47, %24
store i8* null, i8** %4
%49 = 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* %49, i32** %2
%50 = load i32*, i32** %2
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 0, i32* %1
br label %84
53: ; preds = %48
br label %54
54: ; preds = %71, %53
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%56 = load i32*, i32** %2
%57 = call i64 @fgets(i8* %55, i32 512, i32* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %72
59: ; preds = %54
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%61 = call i32 @strncmp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %60, i32 10)
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %59
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%65 = call i32 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %64, i32 9)
%66 = icmp ne i32 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %63, %59
%68 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%69 = call i8* @strchr(i8* %68, i8 signext 58)
%70 = getelementptr inbounds i8, i8* %69, i64 2
store i8* %70, i8** %4
br label %72
71: ; preds = %63
br label %54
72: ; preds = %67, %54
%73 = load i32*, i32** %2
%74 = call i32 @fclose(i32* %73)
%75 = load i8*, i8** %4
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %83
77: ; preds = %72
%78 = load i8*, i8** %4
%79 = call i64 @strstr(i8* %78, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %77
store i32 1, i32* %1
br label %84
82: ; preds = %77
br label %83
83: ; preds = %82, %72
store i32 0, i32* %1
br label %84
84: ; preds = %83, %81, %52, %46, %45, %37, %36, %8
%85 = load i32, i32* %1
ret i32 %85
}

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"CPU part\00"
@.str.3 = [6 x i8] c"0xc09\00"
@.str.4 = [5 x i8] c"neon\00"
@.str.5 = [6 x i8] c"0xc0f\00"
@.str.6 = [11 x i8] c"model name\00"
@.str.7 = [10 x i8] c"Processor\00"
@.str.8 = [6 x i8] c"ARMv7\00"
define i32 @cpu_detect() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 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 %51, label %5
5: ; preds = %0, %10
%6 = call i64 @fgets(i8* %2, i32 512, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @fclose(i32* %3)
br label %30
10: ; preds = %5
%11 = call i32 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %5
13: ; preds = %10
%14 = call i8* @strchr(i8* %2, i8 signext 58)
%15 = getelementptr inbounds i8, i8* %14, i64 2
%16 = call i32 @fclose(i32* %3)
%17 = call i64 @strstr(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = call i64 @get_feature(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 1, i32 2
br label %51
23: ; preds = %13
%24 = call i64 @strstr(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = call i64 @get_feature(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i32 1, i32 3
br label %51
30: ; preds = %8, %23
%31 = 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))
%32 = icmp eq i32* %31, null
br i1 %32, label %51, label %33
33: ; preds = %30, %41
%34 = call i64 @fgets(i8* %2, i32 512, i32* %31)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @fclose(i32* %31)
br label %50
38: ; preds = %33
%39 = call i32 @strncmp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %2, i32 10)
%40 = icmp eq i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = call i32 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %2, i32 9)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %33
44: ; preds = %41, %38
%45 = call i8* @strchr(i8* %2, i8 signext 58)
%46 = getelementptr inbounds i8, i8* %45, i64 2
%47 = call i32 @fclose(i32* %31)
%48 = call i64 @strstr(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %36, %44
br label %51
51: ; preds = %44, %30, %26, %19, %0, %50
%52 = phi i32 [ 0, %50 ], [ 0, %0 ], [ %22, %19 ], [ %29, %26 ], [ 0, %30 ], [ 1, %44 ]
ret i32 %52
}