#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 asprintf(char **, char *, char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *strdup(char *);
int deviceinfo_from_sysinfo(char **dest, const char *key) {
  FILE *f;
  char *s, *nl, *line = NULL;
  size_t len = 0;
  ssize_t c;
  int rv = -2;
  if (asprintf(&s, "%s/%s", "/tmp/sysinfo", key) == -1)
    return rv;
  f = fopen(s, "rb");
  free(s);
  if (f == NULL)
    return -1;
  if ((c = getline(&line, &len, f)) == -1) {
    fclose(f);
    return -1;
  }
  s = line;
  while (*s && (*s == ' ' || *s == '\t'))
    s++;
  nl = s;
  while (*nl && *nl != '\n' && *nl != '\r')
    nl++;
  *nl = '\0';
  *dest = strdup(s);
  rv = nl - s;
  fclose(f);
  if (line)
    free(line);
  return rv;
}


x86 assembly (clang, -O0):
<deviceinfo_from_sysinfo>:
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)
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xe6a(%rip),%rsi
lea    0xe69(%rip),%rdx
call   1050 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    11b6 <deviceinfo_from_sysinfo+0x56>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1333 <deviceinfo_from_sysinfo+0x1d3>
mov    -0x28(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11ea <deviceinfo_from_sysinfo+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1333 <deviceinfo_from_sysinfo+0x1d3>
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
jne    121c <deviceinfo_from_sysinfo+0xbc>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1333 <deviceinfo_from_sysinfo+0x1d3>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x49(%rbp)
je     1264 <deviceinfo_from_sysinfo+0x104>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x4a(%rbp)
je     125e <deviceinfo_from_sysinfo+0xfe>
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    1274 <deviceinfo_from_sysinfo+0x114>
jmp    1285 <deviceinfo_from_sysinfo+0x125>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1224 <deviceinfo_from_sysinfo+0xc4>
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     12c7 <deviceinfo_from_sysinfo+0x167>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x4b(%rbp)
je     12c7 <deviceinfo_from_sysinfo+0x167>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x4b(%rbp)
mov    -0x4b(%rbp),%al
test   $0x1,%al
jne    12d7 <deviceinfo_from_sysinfo+0x177>
jmp    12e8 <deviceinfo_from_sysinfo+0x188>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    128d <deviceinfo_from_sysinfo+0x12d>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1080 <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     132d <deviceinfo_from_sysinfo+0x1cd>
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_sysinfo>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rcx
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe76(%rip),%rsi
lea    0xe75(%rip),%rdx
mov    %rsp,%rdi
call   1050 <asprintf@plt>
cmp    $0xffffffff,%eax
je     1277 <deviceinfo_from_sysinfo+0x117>
mov    (%rsp),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%ebx
test   %r15,%r15
je     1286 <deviceinfo_from_sysinfo+0x126>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r15,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     127e <deviceinfo_from_sysinfo+0x11e>
mov    0x8(%rsp),%rbx
mov    %rbx,%rax
jmp    1207 <deviceinfo_from_sysinfo+0xa7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
add    $0x1,%ebx
mov    %rax,(%rsp)
movzbl (%rax),%ecx
cmp    $0x9,%cl
je     1200 <deviceinfo_from_sysinfo+0xa0>
cmp    $0x20,%cl
je     1200 <deviceinfo_from_sysinfo+0xa0>
add    $0x1,%rax
mov    $0x2401,%edx
jmp    123a <deviceinfo_from_sysinfo+0xda>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rax),%ecx
add    $0x1,%ebx
add    $0x1,%rax
cmp    $0xd,%cl
ja     1230 <deviceinfo_from_sysinfo+0xd0>
movzbl %cl,%ecx
bt     %rcx,%rdx
jae    1230 <deviceinfo_from_sysinfo+0xd0>
movb   $0x0,-0x1(%rax)
mov    (%rsp),%r12
mov    %r12,%rdi
call   1080 <strdup@plt>
mov    %rax,(%r14)
sub    %r12d,%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1286 <deviceinfo_from_sysinfo+0x126>
call   1030 <free@plt>
jmp    1286 <deviceinfo_from_sysinfo+0x126>
mov    $0xfffffffe,%ebx
jmp    1286 <deviceinfo_from_sysinfo+0x126>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [13 x i8] c"/tmp/sysinfo\00"
@.str.2 = [3 x i8] c"rb\00"
define i32 @deviceinfo_from_sysinfo(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 = load i8*, i8** %5
%14 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* %12
store i32 %17, i32* %3
br label %99
18: ; preds = %2
%19 = load i8*, i8** %7
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i8*, i8** %7
%22 = call i32 @free(i8* %21)
%23 = load i32*, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 -1, i32* %3
br label %99
26: ; preds = %18
%27 = load i32*, i32** %6
%28 = call i32 @getline(i8** %9, i64* %10, i32* %27)
store i32 %28, i32* %11
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
store i32 -1, i32* %3
br label %99
33: ; preds = %26
%34 = load i8*, i8** %9
store i8* %34, i8** %7
br label %35
35: ; preds = %54, %33
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %35
%41 = load i8*, i8** %7
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 32
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i8*, i8** %7
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 9
br label %50
50: ; preds = %45, %40
%51 = phi i1 [ true, %40 ], [ %49, %45 ]
br label %52
52: ; preds = %50, %35
%53 = phi i1 [ false, %35 ], [ %51, %50 ]
br i1 %53, label %54, label %57
54: ; preds = %52
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %7
br label %35
57: ; preds = %52
%58 = load i8*, i8** %7
store i8* %58, i8** %8
br label %59
59: ; preds = %76, %57
%60 = load i8*, i8** %8
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %74
64: ; preds = %59
%65 = load i8*, i8** %8
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp ne i32 %67, 10
br i1 %68, label %69, label %74
69: ; preds = %64
%70 = load i8*, i8** %8
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 13
br label %74
74: ; preds = %69, %64, %59
%75 = phi i1 [ false, %64 ], [ false, %59 ], [ %73, %69 ]
br i1 %75, label %76, label %79
76: ; preds = %74
%77 = load i8*, i8** %8
%78 = getelementptr inbounds i8, i8* %77, i32 1
store i8* %78, i8** %8
br label %59
79: ; preds = %74
%80 = load i8*, i8** %8
store i8 0, i8* %80
%81 = load i8*, i8** %7
%82 = call i8* @strdup(i8* %81)
%83 = load i8**, i8*** %4
store i8* %82, i8** %83
%84 = load i8*, i8** %8
%85 = load i8*, i8** %7
%86 = ptrtoint i8* %84 to i64
%87 = ptrtoint i8* %85 to i64
%88 = sub i64 %86, %87
%89 = trunc i64 %88 to i32
store i32 %89, i32* %12
%90 = load i32*, i32** %6
%91 = call i32 @fclose(i32* %90)
%92 = load i8*, i8** %9
%93 = icmp ne i8* %92, null
br i1 %93, label %94, label %97
94: ; preds = %79
%95 = load i8*, i8** %9
%96 = call i32 @free(i8* %95)
br label %97
97: ; preds = %94, %79
%98 = load i32, i32* %12
store i32 %98, i32* %3
br label %99
99: ; preds = %97, %30, %25, %16
%100 = load i32, i32* %3
ret i32 %100
}

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