#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*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char const *);
int strlen(char *);
char *status_entry(const char *key) {
  char *result = NULL;
  char *line = NULL;
  size_t line_n = 0;
  FILE *fp;
  fp = fopen("/proc/self/status", "r");
  if (!fp)
    goto done;
  while (getline(&line, &line_n, fp) != -1) {
    char *v;
    v = strchr(line, ':');
    if (!v || *v == '\0')
      continue;
    *v = '\0';
    if (strcmp(line, key) != 0)
      continue;
    ++v;
    while (*v == ' ' || *v == '\t')
      ++v;
    if (strlen(v) > 1)
      v[strlen(v) - 1] = '\0';
    if (*v == '\0')
      goto done;
    result = line;
    while ((*line++ = *v++))
      ;
    goto done;
  }
done:
  if (!result)
    free(line);
  if (fp)
    fclose(fp);
  return result;
}


x86 assembly (clang, -O0):
<status_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe65(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bb <status_entry+0x4b>
jmp    130a <status_entry+0x19a>
jmp    11c0 <status_entry+0x50>
mov    -0x28(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     1305 <status_entry+0x195>
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1207 <status_entry+0x97>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    120c <status_entry+0x9c>
jmp    11c0 <status_entry+0x50>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     122f <status_entry+0xbf>
jmp    11c0 <status_entry+0x50>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x31(%rbp)
je     1260 <status_entry+0xf0>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1270 <status_entry+0x100>
jmp    1281 <status_entry+0x111>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    123b <status_entry+0xcb>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jle    12b4 <status_entry+0x144>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12c9 <status_entry+0x159>
jmp    130a <status_entry+0x19a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%al
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     1300 <status_entry+0x190>
jmp    12d1 <status_entry+0x161>
jmp    130a <status_entry+0x19a>
jmp    130a <status_entry+0x19a>
cmpq   $0x0,-0x10(%rbp)
jne    131e <status_entry+0x1ae>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     1332 <status_entry+0x1c2>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<status_entry>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe68(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     12bd <status_entry+0x14d>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %r14,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     12b7 <status_entry+0x147>
mov    %rsp,%r12
lea    0x8(%rsp),%r13
jmp    11f7 <status_entry+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     12b7 <status_entry+0x147>
mov    (%rsp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11e0 <status_entry+0x70>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11e0 <status_entry+0x70>
movb   $0x0,(%rbx)
mov    (%rsp),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11e0 <status_entry+0x70>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x20,%al
je     1230 <status_entry+0xc0>
cmp    $0x9,%al
je     1230 <status_entry+0xc0>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     125b <status_entry+0xeb>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    (%rbx),%al
test   %al,%al
je     12b7 <status_entry+0x147>
mov    (%rsp),%r15
add    $0x1,%rbx
lea    0x1(%r15),%rcx
mov    %rcx,(%rsp)
mov    %al,(%r15)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    (%rsp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rsp)
mov    %al,(%rcx)
test   %al,%al
jne    1280 <status_entry+0x110>
test   %r14,%r14
je     12a6 <status_entry+0x136>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%rsp),%rdi
jmp    12bf <status_entry+0x14f>
xor    %edi,%edi
call   1030 <free@plt>
xor    %r15d,%r15d
test   %r14,%r14
jne    129e <status_entry+0x12e>
jmp    12a6 <status_entry+0x136>

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

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @status_entry(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %54, label %8
8: ; preds = %1
%9 = call i32 @getline(i8** %2, i64* %3, i32* %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %52, label %11
11: ; preds = %8, %49
%12 = load i8*, i8** %2
%13 = call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 58)
%14 = icmp eq i8* %13, null
br i1 %14, label %49, label %15
15: ; preds = %11
%16 = load i8, i8* %13
%17 = icmp eq i8 %16, 0
br i1 %17, label %49, label %18
18: ; preds = %15
store i8 0, i8* %13
%19 = load i8*, i8** %2
%20 = call i64 @strcmp(i8* %19, i8* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %49
22: ; preds = %18, %26
%23 = phi i8* [ %24, %26 ], [ %13, %18 ]
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
switch i8 %25, label %27 [
i8 32, label %26
i8 9, label %26
]
26: ; preds = %22, %22
br label %22
27: ; preds = %22
%28 = call i32 @strlen(i8* %24)
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = call i32 @strlen(i8* %24)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %24, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %30, %27
%36 = load i8, i8* %24
%37 = icmp eq i8 %36, 0
br i1 %37, label %52, label %38
38: ; preds = %35
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8, i8* %23, i64 2
%41 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %41, i8** %2
store i8 %36, i8* %39
br label %42
42: ; preds = %38, %42
%43 = phi i8* [ %40, %38 ], [ %45, %42 ]
%44 = load i8, i8* %43
%45 = getelementptr inbounds i8, i8* %43, i64 1
%46 = load i8*, i8** %2
%47 = getelementptr inbounds i8, i8* %46, i64 1
store i8* %47, i8** %2
store i8 %44, i8* %46
%48 = icmp eq i8 %44, 0
br i1 %48, label %57, label %42
49: ; preds = %18, %11, %15
%50 = call i32 @getline(i8** %2, i64* %3, i32* %6)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %11
52: ; preds = %49, %8, %35
%53 = load i8*, i8** %2
br label %54
54: ; preds = %52, %1
%55 = phi i8* [ %53, %52 ], [ null, %1 ]
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %42, %54
%58 = phi i8* [ null, %54 ], [ %39, %42 ]
br i1 %7, label %61, label %59
59: ; preds = %57
%60 = call i32 @fclose(i32* %6)
br label %61
61: ; preds = %57, %59
ret i8* %58
}