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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *index(char *, char);
int /*<<< orphan*/ line_starts_with(char *, char const *);
char *strdup(char *);
int deviceinfo_from_cpuinfo(char **dest, const char *key) {
  FILE *fp;
  char *start, *nl, *line = NULL;
  size_t len = 0;
  ssize_t c;
  int rv = -2;
  fp = fopen("/proc/cpuinfo", "rb");
  if (fp == NULL)
    return -1;
  while ((c = getline(&line, &len, fp)) != -1) {
    if (!line_starts_with(line, key))
      continue;
    start = index(line, ':');
    if (!start)
      continue;
    start++;
    while (*start && (*start == ' ' || *start == '\t'))
      start++;
    nl = start;
    while (*nl && *nl != '\n' && *nl != '\r')
      nl++;
    *nl = '\0';
    *dest = strdup(start);
    rv = nl - start;
    break;
  }
  fclose(fp);
  if (line)
    free(line);
  return rv;
}


x86 assembly (clang, -O0):
<deviceinfo_from_cpuinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0xfffffffe,-0x48(%rbp)
lea    0xe62(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c5 <deviceinfo_from_cpuinfo+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <deviceinfo_from_cpuinfo+0x1cf>
jmp    11ca <deviceinfo_from_cpuinfo+0x5a>
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
je     131c <deviceinfo_from_cpuinfo+0x1ac>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <line_starts_with@plt>
cmp    $0x0,%eax
jne    1202 <deviceinfo_from_cpuinfo+0x92>
jmp    11ca <deviceinfo_from_cpuinfo+0x5a>
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <index@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1224 <deviceinfo_from_cpuinfo+0xb4>
jmp    11ca <deviceinfo_from_cpuinfo+0x5a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x49(%rbp)
je     1270 <deviceinfo_from_cpuinfo+0x100>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x4a(%rbp)
je     126a <deviceinfo_from_cpuinfo+0xfa>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x4a(%rbp)
mov    -0x4a(%rbp),%al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1280 <deviceinfo_from_cpuinfo+0x110>
jmp    1291 <deviceinfo_from_cpuinfo+0x121>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1230 <deviceinfo_from_cpuinfo+0xc0>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x4b(%rbp)
je     12d3 <deviceinfo_from_cpuinfo+0x163>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x4b(%rbp)
je     12d3 <deviceinfo_from_cpuinfo+0x163>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x4b(%rbp)
mov    -0x4b(%rbp),%al
test   $0x1,%al
jne    12e3 <deviceinfo_from_cpuinfo+0x173>
jmp    12f4 <deviceinfo_from_cpuinfo+0x184>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1299 <deviceinfo_from_cpuinfo+0x129>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x38(%rbp)
je     1339 <deviceinfo_from_cpuinfo+0x1c9>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deviceinfo_from_cpuinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe63(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1291 <deviceinfo_from_cpuinfo+0x121>
mov    %rax,%r12
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
mov    $0xfffffffe,%r15d
cmp    $0xffffffff,%eax
je     1278 <deviceinfo_from_cpuinfo+0x108>
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%rbp
jmp    1203 <deviceinfo_from_cpuinfo+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1278 <deviceinfo_from_cpuinfo+0x108>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <line_starts_with@plt>
test   %eax,%eax
je     11f0 <deviceinfo_from_cpuinfo+0x80>
mov    0x8(%rsp),%rdi
mov    $0x3a,%esi
call   1060 <index@plt>
test   %rax,%rax
je     11f0 <deviceinfo_from_cpuinfo+0x80>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x9,%cl
je     1230 <deviceinfo_from_cpuinfo+0xc0>
cmp    $0x20,%cl
je     1230 <deviceinfo_from_cpuinfo+0xc0>
xor    %r15d,%r15d
mov    $0x2401,%edx
jmp    125a <deviceinfo_from_cpuinfo+0xea>
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rax,%r15,1),%ecx
add    $0x1,%r15
cmp    $0xd,%cl
ja     1250 <deviceinfo_from_cpuinfo+0xe0>
movzbl %cl,%ecx
bt     %rcx,%rdx
jae    1250 <deviceinfo_from_cpuinfo+0xe0>
movb   $0x0,(%rax,%r15,1)
mov    %rax,%rdi
call   1090 <strdup@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1297 <deviceinfo_from_cpuinfo+0x127>
call   1030 <free@plt>
jmp    1297 <deviceinfo_from_cpuinfo+0x127>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x18,%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 = [3 x i8] c"rb\00"
define i32 @deviceinfo_from_cpuinfo(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* null, i8** %9
store i64 0, i64* %10
store i32 -2, i32* %12
%13 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %102
17: ; preds = %2
br label %18
18: ; preds = %33, %27, %17
%19 = load i32*, i32** %6
%20 = call i32 @getline(i8** %9, i64* %10, i32* %19)
store i32 %20, i32* %11
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %92
22: ; preds = %18
%23 = load i8*, i8** %9
%24 = load i8*, i8** %5
%25 = call i32 @line_starts_with(i8* %23, i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
br label %18
28: ; preds = %22
%29 = load i8*, i8** %9
%30 = call i8* @index(i8* %29, i8 signext 58)
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %28
br label %18
34: ; preds = %28
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %7
br label %37
37: ; preds = %56, %34
%38 = load i8*, i8** %7
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %54
42: ; preds = %37
%43 = load i8*, i8** %7
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 32
br i1 %46, label %52, label %47
47: ; preds = %42
%48 = load i8*, i8** %7
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 9
br label %52
52: ; preds = %47, %42
%53 = phi i1 [ true, %42 ], [ %51, %47 ]
br label %54
54: ; preds = %52, %37
%55 = phi i1 [ false, %37 ], [ %53, %52 ]
br i1 %55, label %56, label %59
56: ; preds = %54
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %7
br label %37
59: ; preds = %54
%60 = load i8*, i8** %7
store i8* %60, i8** %8
br label %61
61: ; preds = %78, %59
%62 = load i8*, i8** %8
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %76
66: ; preds = %61
%67 = load i8*, i8** %8
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 10
br i1 %70, label %71, label %76
71: ; preds = %66
%72 = load i8*, i8** %8
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 13
br label %76
76: ; preds = %71, %66, %61
%77 = phi i1 [ false, %66 ], [ false, %61 ], [ %75, %71 ]
br i1 %77, label %78, label %81
78: ; preds = %76
%79 = load i8*, i8** %8
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %8
br label %61
81: ; preds = %76
%82 = load i8*, i8** %8
store i8 0, i8* %82
%83 = load i8*, i8** %7
%84 = call i8* @strdup(i8* %83)
%85 = load i8**, i8*** %4
store i8* %84, i8** %85
%86 = load i8*, i8** %8
%87 = load i8*, i8** %7
%88 = ptrtoint i8* %86 to i64
%89 = ptrtoint i8* %87 to i64
%90 = sub i64 %88, %89
%91 = trunc i64 %90 to i32
store i32 %91, i32* %12
br label %92
92: ; preds = %81, %18
%93 = load i32*, i32** %6
%94 = call i32 @fclose(i32* %93)
%95 = load i8*, i8** %9
%96 = icmp ne i8* %95, null
br i1 %96, label %97, label %100
97: ; preds = %92
%98 = load i8*, i8** %9
%99 = call i32 @free(i8* %98)
br label %100
100: ; preds = %97, %92
%101 = load i32, i32* %12
store i32 %101, i32* %3
br label %102
102: ; preds = %100, %16
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [3 x i8] c"rb\00"
define i32 @deviceinfo_from_cpuinfo(i8** nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %47, label %9
9: ; preds = %2
%10 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%11 = icmp eq i32 %10, -1
br i1 %11, label %40, label %12
12: ; preds = %9, %16
%13 = load i8*, i8** %3
%14 = call i32 @line_starts_with(i8* %13, i8* %1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12, %19
%17 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%18 = icmp eq i32 %17, -1
br i1 %18, label %40, label %12
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = call i8* @index(i8* %20, i8 signext 58)
%22 = icmp eq i8* %21, null
br i1 %22, label %16, label %23
23: ; preds = %19, %27
%24 = phi i8* [ %25, %27 ], [ %21, %19 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
switch i8 %26, label %28 [
i8 9, label %27
i8 32, label %27
]
27: ; preds = %23, %23
br label %23
28: ; preds = %23, %31
%29 = phi i8 [ %33, %31 ], [ %26, %23 ]
%30 = phi i8* [ %32, %31 ], [ %25, %23 ]
switch i8 %29, label %31 [
i8 0, label %34
i8 10, label %34
i8 13, label %34
]
31: ; preds = %28
%32 = getelementptr inbounds i8, i8* %30, i64 1
%33 = load i8, i8* %32
br label %28
34: ; preds = %28, %28, %28
store i8 0, i8* %30
%35 = call i8* @strdup(i8* %25)
store i8* %35, i8** %0
%36 = ptrtoint i8* %30 to i64
%37 = ptrtoint i8* %25 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
br label %40
40: ; preds = %16, %9, %34
%41 = phi i32 [ %39, %34 ], [ -2, %9 ], [ -2, %16 ]
%42 = call i32 @fclose(i32* %7)
%43 = load i8*, i8** %3
%44 = icmp eq i8* %43, null
br i1 %44, label %47, label %45
45: ; preds = %40
%46 = call i32 @free(i8* %43)
br label %47
47: ; preds = %40, %45, %2
%48 = phi i32 [ -1, %2 ], [ %41, %45 ], [ %41, %40 ]
ret i32 %48
}