#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
char *strstr(char *, char *);
void identify_myself(int *node_type) {
  FILE *fp;
  char buffer[10 * 1024];
  size_t bytes_read;
  char *match;
  char *model;
  if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) {
    perror("fopen() auf /proc/cpuinfo");
    *node_type = -1;
    return;
  }
  bytes_read = fread(buffer, 1, sizeof(buffer), fp);
  fclose(fp);
  if (bytes_read == 0 || bytes_read == sizeof(buffer)) {
    perror("fopen() - irgendwas stimmt nicht!");
    exit(EXIT_FAILURE);
  }
  buffer[bytes_read] = '\0';
  match = strstr(buffer, "model name");
  if (match == 0) {
    *node_type = -1;
    return;
  }
  if ((model = strstr(buffer, "AMD")) != NULL) {
    *node_type = 0;
  } else if ((model = strstr(buffer, "ARMv6")) != NULL) {
    *node_type = 1;
  } else if ((model = strstr(buffer, "ARMv7")) != NULL) {
    *node_type = 2;
  } else {
    *node_type = -1;
  }
}


x86 assembly (clang, -O0):
<identify_myself>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2830,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe98(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ab <identify_myself+0x4b>
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    1301 <identify_myself+0x1a1>
lea    -0x2810(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2800,%edx
call   1030 <fread@plt>
mov    %rax,-0x2818(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x2818(%rbp)
je     11f4 <identify_myself+0x94>
cmpq   $0x2800,-0x2818(%rbp)
jne    120e <identify_myself+0xae>
lea    0xe21(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x2818(%rbp),%rax
movb   $0x0,-0x2810(%rbp,%rax,1)
lea    -0x2810(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x2820(%rbp)
cmpq   $0x0,-0x2820(%rbp)
jne    1254 <identify_myself+0xf4>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    1301 <identify_myself+0x1a1>
lea    -0x2810(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x2828(%rbp)
cmp    $0x0,%rax
je     1287 <identify_myself+0x127>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
jmp    1301 <identify_myself+0x1a1>
lea    -0x2810(%rbp),%rdi
lea    0xdb8(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x2828(%rbp)
cmp    $0x0,%rax
je     12ba <identify_myself+0x15a>
mov    -0x8(%rbp),%rax
movl   $0x1,(%rax)
jmp    12fc <identify_myself+0x19c>
lea    -0x2810(%rbp),%rdi
lea    0xd8b(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x2828(%rbp)
cmp    $0x0,%rax
je     12ed <identify_myself+0x18d>
mov    -0x8(%rbp),%rax
movl   $0x2,(%rax)
jmp    12f7 <identify_myself+0x197>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    12fc <identify_myself+0x19c>
jmp    1301 <identify_myself+0x1a1>
add    $0x2830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<identify_myself>:
push   %r15
push   %r14
push   %rbx
sub    $0x2800,%rsp
mov    %rdi,%r14
lea    0xe98(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1225 <identify_myself+0xc5>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x2800,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <fclose@plt>
cmp    $0x2800,%rbx
je     1246 <identify_myself+0xe6>
test   %rbx,%rbx
je     1246 <identify_myself+0xe6>
movb   $0x0,(%rsp,%rbx,1)
lea    0xe6f(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     1231 <identify_myself+0xd1>
lea    0xe66(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
xor    %ecx,%ecx
test   %rax,%rax
jne    1236 <identify_myself+0xd6>
lea    0xe54(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
mov    $0x1,%ecx
test   %rax,%rax
jne    1236 <identify_myself+0xd6>
lea    0xe41(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
cmp    $0x1,%rax
sbb    %ecx,%ecx
or     $0x2,%ecx
jmp    1236 <identify_myself+0xd6>
lea    0xdd6(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ecx
mov    %ecx,(%r14)
add    $0x2800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdcf(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"fopen() auf /proc/cpuinfo\00"
@.str.3 = [34 x i8] c"fopen() - irgendwas stimmt nicht!\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [11 x i8] c"model name\00"
@.str.5 = [4 x i8] c"AMD\00"
@.str.6 = [6 x i8] c"ARMv6\00"
@.str.7 = [6 x i8] c"ARMv7\00"
define void @identify_myself(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [10240 x i8]
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %2
%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** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32*, i32** %2
store i32 -1, i32* %12
br label %59
13: ; preds = %1
%14 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i64 @fread(i8* %14, i32 1, i32 10240, i32* %15)
store i64 %16, i64* %5
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
%19 = load i64, i64* %5
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = load i64, i64* %5
%23 = icmp eq i64 %22, 10240
br i1 %23, label %24, label %28
24: ; preds = %21, %13
%25 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %21
%29 = load i64, i64* %5
%30 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%32 = call i8* @strstr(i8* %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = load i32*, i32** %2
store i32 -1, i32* %36
br label %59
37: ; preds = %28
%38 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%39 = call i8* @strstr(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i8* %39, i8** %7
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = load i32*, i32** %2
store i32 0, i32* %42
br label %59
43: ; preds = %37
%44 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%45 = call i8* @strstr(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i8* %45, i8** %7
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = load i32*, i32** %2
store i32 1, i32* %48
br label %58
49: ; preds = %43
%50 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%51 = call i8* @strstr(i8* %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
store i8* %51, i8** %7
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = load i32*, i32** %2
store i32 2, i32* %54
br label %57
55: ; preds = %49
%56 = load i32*, i32** %2
store i32 -1, i32* %56
br label %57
57: ; preds = %55, %53
br label %58
58: ; preds = %57, %47
br label %59
59: ; preds = %10, %35, %58, %41
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"fopen() auf /proc/cpuinfo\00"
@.str.3 = [34 x i8] c"fopen() - irgendwas stimmt nicht!\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [11 x i8] c"model name\00"
@.str.5 = [4 x i8] c"AMD\00"
@.str.6 = [6 x i8] c"ARMv6\00"
@.str.7 = [6 x i8] c"ARMv7\00"
define void @identify_myself(i32* nocapture writeonly %0) {
%2 = alloca [10240 x i8]
%3 = getelementptr inbounds [10240 x i8], [10240 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 %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %29
8: ; preds = %1
%9 = call i64 @fread(i8* %3, i32 1, i32 10240, i32* %4)
%10 = tail call i32 @fclose(i32* %4)
switch i64 %9, label %15 [
i64 10240, label %11
i64 0, label %11
]
11: ; preds = %8, %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %8
%16 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %16
%17 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %29, label %19
19: ; preds = %15
%20 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%27 = icmp eq i8* %26, null
%28 = select i1 %27, i32 -1, i32 2
br label %29
29: ; preds = %25, %22, %19, %15, %6
%30 = phi i32 [ -1, %6 ], [ -1, %15 ], [ 0, %19 ], [ 1, %22 ], [ %28, %25 ]
store i32 %30, i32* %0
ret void
}