#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *index(char *, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
int getChipVersion(void) {
  char line[80];
  FILE *fp;
  char cpu[32], rev[8];
  char *str;
  static int nChipVersion = 0;
  if (nChipVersion) {
    return nChipVersion;
  }
  if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) {
    printf("can't access /proc/cpuinfo\n");
    return -1;
  }
  while (fgets(line, 80, fp) != NULL) {
    if (strncmp(line, "Hardware", 8) == 0) {
      str = index(line, ':');
      strcpy(cpu, str + 2);
    }
    if (strncmp(line, "Revision", 8) == 0) {
      str = index(line, ':');
      strcpy(rev, str + 2);
    }
  }
  fclose(fp);
  if (strlen(cpu) == 0) {
    printf("can't get the chip info.\n");
    return -1;
  } else if (strstr(cpu, "MX27ADS") == NULL) {
    printf("VPU does not support %s\n", cpu);
    return -1;
  }
  if (strncmp(rev, "0020", 4) == 0) {
    ;
    nChipVersion = 0x1882101D;
  } else {
    ;
    nChipVersion = 0x0882101D;
  }
  return nChipVersion;
}


x86 assembly (clang, -O0):
<getChipVersion>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
cmpl   $0x0,0x2eca(%rip)
je     11b6 <getChipVersion+0x26>
mov    0x2ebe(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    136d <getChipVersion+0x1dd>
lea    0xe43(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    11f1 <getChipVersion+0x61>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136d <getChipVersion+0x1dd>
jmp    11f6 <getChipVersion+0x66>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x50,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     12ad <getChipVersion+0x11d>
lea    -0x60(%rbp),%rdi
lea    0xe0f(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    125d <getChipVersion+0xcd>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1080 <index@plt>
mov    %rax,-0xa0(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
add    $0x2,%rsi
call   1040 <strcpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xdcd(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a8 <getChipVersion+0x118>
lea    -0x60(%rbp),%rdi
mov    $0x3a,%esi
call   1080 <index@plt>
mov    %rax,-0xa0(%rbp)
lea    -0x98(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
add    $0x2,%rsi
call   1040 <strcpy@plt>
jmp    11f6 <getChipVersion+0x66>
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x90(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jne    12e6 <getChipVersion+0x156>
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136d <getChipVersion+0x1dd>
lea    -0x90(%rbp),%rdi
lea    0xd64(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
jne    1324 <getChipVersion+0x194>
lea    -0x90(%rbp),%rsi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136d <getChipVersion+0x1dd>
jmp    1329 <getChipVersion+0x199>
lea    -0x98(%rbp),%rdi
lea    0xd42(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    135a <getChipVersion+0x1ca>
movl   $0x1882101d,0x2d17(%rip)
10 82 18
jmp    1364 <getChipVersion+0x1d4>
movl   $0x882101d,0x2d08(%rip)
10 82 08
mov    0x2d02(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getChipVersion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2ec5(%rip),%eax
test   %eax,%eax
jne    1308 <getChipVersion+0x178>
lea    0xeaa(%rip),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12d9 <getChipVersion+0x149>
mov    %rax,%r15
lea    0x30(%rsp),%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1283 <getChipVersion+0xf3>
lea    0xe12(%rip),%r14
lea    0x30(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0xe0a(%rip),%r13
lea    0x8(%rsp),%rbp
jmp    1225 <getChipVersion+0x95>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1283 <getChipVersion+0xf3>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1253 <getChipVersion+0xc3>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1080 <index@plt>
lea    0x2(%rax),%rsi
mov    %r12,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1210 <getChipVersion+0x80>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1080 <index@plt>
lea    0x2(%rax),%rsi
mov    %rbp,%rdi
call   1040 <strcpy@plt>
jmp    1210 <getChipVersion+0x80>
mov    %r15,%rdi
call   1060 <fclose@plt>
cmpb   $0x0,0x10(%rsp)
je     12e2 <getChipVersion+0x152>
lea    0xd7b(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10b0 <strstr@plt>
test   %rax,%rax
je     12f0 <getChipVersion+0x160>
lea    0xd86(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
shl    $0x1c,%eax
or     $0x882101d,%eax
mov    %eax,0x2d95(%rip)
jmp    1308 <getChipVersion+0x178>
lea    0xd73(%rip),%rdi
jmp    12e9 <getChipVersion+0x159>
lea    0xd51(%rip),%rdi
call   1050 <puts@plt>
jmp    1303 <getChipVersion+0x173>
lea    0xd25(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@getChipVersion.nChipVersion = internal global i32 0
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"can't access /proc/cpuinfo\0A\00"
@.str.3 = [9 x i8] c"Hardware\00"
@.str.4 = [9 x i8] c"Revision\00"
@.str.5 = [26 x i8] c"can't get the chip info.\0A\00"
@.str.6 = [8 x i8] c"MX27ADS\00"
@.str.7 = [25 x i8] c"VPU does not support %s\0A\00"
@.str.8 = [5 x i8] c"0020\00"
define i32 @getChipVersion() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i32*
%4 = alloca [32 x i8]
%5 = alloca [8 x i8]
%6 = alloca i8*
%7 = load i32, i32* @getChipVersion.nChipVersion
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = load i32, i32* @getChipVersion.nChipVersion
store i32 %10, i32* %1
br label %69
11: ; preds = %0
%12 = 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* %12, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %69
16: ; preds = %11
br label %17
17: ; preds = %44, %16
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = call i32* @fgets(i8* %18, i32 80, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %45
22: ; preds = %17
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%24 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%28 = call i8* @index(i8* %27, i8 signext 58)
store i8* %28, i8** %6
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = call i32 @strcpy(i8* %29, i8* %31)
br label %33
33: ; preds = %26, %22
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%35 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%39 = call i8* @index(i8* %38, i8 signext 58)
store i8* %39, i8** %6
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = call i32 @strcpy(i8* %40, i8* %42)
br label %44
44: ; preds = %37, %33
br label %17
45: ; preds = %17
%46 = load i32*, i32** %3
%47 = call i32 @fclose(i32* %46)
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%49 = call i64 @strlen(i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %69
53: ; preds = %45
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%55 = call i32* @strstr(i8* %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %58)
store i32 -1, i32* %1
br label %69
60: ; preds = %53
br label %61
61: ; preds = %60
%62 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%63 = call i64 @strncmp(i8* %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 4)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %61
store i32 411176989, i32* @getChipVersion.nChipVersion
br label %67
66: ; preds = %61
store i32 142741533, i32* @getChipVersion.nChipVersion
br label %67
67: ; preds = %66, %65
%68 = load i32, i32* @getChipVersion.nChipVersion
store i32 %68, i32* %1
br label %69
69: ; preds = %67, %57, %51, %14, %9
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
@getChipVersion.nChipVersion = internal unnamed_addr global i32 0
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"Hardware\00"
@.str.4 = [9 x i8] c"Revision\00"
@.str.6 = [8 x i8] c"MX27ADS\00"
@.str.7 = [25 x i8] c"VPU does not support %s\0A\00"
@.str.8 = [5 x i8] c"0020\00"
@str = [25 x i8] c"can't get the chip info.\00"
@str.9 = [27 x i8] c"can't access /proc/cpuinfo\00"
define i32 @getChipVersion() {
%1 = alloca [80 x i8]
%2 = alloca [32 x i8]
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @getChipVersion.nChipVersion
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %49
9: ; preds = %0
%10 = 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))
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i32* @fgets(i8* %4, i32 80, i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %34, label %17
15: ; preds = %9
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.9, i64 0, i64 0))
br label %49
17: ; preds = %12, %31
%18 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i8* @index(i8* %4, i8 signext 58)
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = call i32 @strcpy(i8* %5, i8* %22)
br label %24
24: ; preds = %20, %17
%25 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = call i8* @index(i8* %4, i8 signext 58)
%29 = getelementptr inbounds i8, i8* %28, i64 2
%30 = call i32 @strcpy(i8* %6, i8* %29)
br label %31
31: ; preds = %27, %24
%32 = call i32* @fgets(i8* %4, i32 80, i32* %10)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %17
34: ; preds = %31, %12
%35 = call i32 @fclose(i32* %10)
%36 = load i8, i8* %5
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %49
40: ; preds = %34
%41 = call i32* @strstr(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %5)
br label %49
45: ; preds = %40
%46 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 4)
%47 = icmp eq i64 %46, 0
%48 = select i1 %47, i32 411176989, i32 142741533
store i32 %48, i32* @getChipVersion.nChipVersion
br label %49
49: ; preds = %0, %45, %43, %38, %15
%50 = phi i32 [ -1, %15 ], [ -1, %38 ], [ -1, %43 ], [ %48, %45 ], [ %7, %0 ]
ret i32 %50
}