#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, char, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
char *strip(char *);
size_t strlen(char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
char *parse_proc(char *path, char *field) {
  int open_fd = open(path, O_RDONLY);
  if (open_fd < 0)
    return NULL;
  char parse_proc_buffer[1024];
  memset(parse_proc_buffer, '\0', 1024 - 1);
  char *delimiter = "\n";
  int rbytes = read(open_fd, parse_proc_buffer, 1024 - 1);
  close(open_fd);
  if (rbytes < 0)
    return NULL;
  parse_proc_buffer[1024 - 1] = '\0';
  size_t field_length = strlen(field);
  char *proc_field = strtok(parse_proc_buffer, delimiter);
  if (!proc_field)
    return NULL;
  char *field_substr = NULL;
  while (proc_field != NULL && field_substr == NULL) {
    field_substr = strstr(proc_field, field);
    proc_field = strtok(NULL, delimiter);
  }
  if (field_substr == NULL)
    return NULL;
  char *field_str = strip(field_substr + field_length);
  return field_str;
}


x86 assembly (clang, -O0):
<parse_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bf <parse_proc+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    131d <parse_proc+0x19d>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x3ff,%edx
call   1040 <memset@plt>
lea    0xe27(%rip),%rax
mov    %rax,-0x428(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
call   1070 <read@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x42c(%rbp)
jge    121c <parse_proc+0x9c>
movq   $0x0,-0x8(%rbp)
jmp    131d <parse_proc+0x19d>
movb   $0x0,-0x21(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x438(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x440(%rbp)
jne    1265 <parse_proc+0xe5>
movq   $0x0,-0x8(%rbp)
jmp    131d <parse_proc+0x19d>
movq   $0x0,-0x448(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x440(%rbp)
mov    %al,-0x451(%rbp)
je     1297 <parse_proc+0x117>
cmpq   $0x0,-0x448(%rbp)
sete   %al
mov    %al,-0x451(%rbp)
mov    -0x451(%rbp),%al
test   $0x1,%al
jne    12aa <parse_proc+0x12a>
jmp    12dd <parse_proc+0x15d>
mov    -0x440(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x448(%rbp)
mov    -0x428(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1090 <strtok@plt>
mov    %rax,-0x440(%rbp)
jmp    1270 <parse_proc+0xf0>
cmpq   $0x0,-0x448(%rbp)
jne    12f8 <parse_proc+0x178>
movq   $0x0,-0x8(%rbp)
jmp    131d <parse_proc+0x19d>
mov    -0x448(%rbp),%rdi
add    -0x438(%rbp),%rdi
call   1060 <strip@plt>
mov    %rax,-0x450(%rbp)
mov    -0x450(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_proc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r12
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1247 <parse_proc+0xc7>
mov    %eax,%ebx
mov    %rsp,%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x3ff,%edx
call   1040 <memset@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x3ff,%edx
call   1070 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
test   %ebp,%ebp
js     124a <parse_proc+0xca>
movb   $0x0,0x3ff(%rsp)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
lea    0xe0b(%rip),%rsi
mov    %rsp,%rdi
call   1090 <strtok@plt>
test   %rax,%rax
je     1247 <parse_proc+0xc7>
lea    0xdf7(%rip),%r15
nopl   0x0(%rax)
mov    %rax,%rdi
mov    %r12,%rsi
call   10a0 <strstr@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     1232 <parse_proc+0xb2>
test   %rbx,%rbx
je     1210 <parse_proc+0x90>
test   %rbx,%rbx
je     1247 <parse_proc+0xc7>
add    %r14,%rbx
mov    %rbx,%rdi
call   1060 <strip@plt>
mov    %rax,%r14
jmp    124a <parse_proc+0xca>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [2 x i8] c"\0A\00"
define i8* @parse_proc(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%14 = load i8*, i8** %4
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %2
store i8* null, i8** %3
br label %66
20: ; preds = %2
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i8 signext 0, i32 1023)
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %8
%23 = load i32, i32* %6
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%25 = call i32 @read(i32 %23, i8* %24, i32 1023)
store i32 %25, i32* %9
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %9
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %20
store i8* null, i8** %3
br label %66
31: ; preds = %20
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1023
store i8 0, i8* %32
%33 = load i8*, i8** %5
%34 = call i64 @strlen(i8* %33)
store i64 %34, i64* %10
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%36 = load i8*, i8** %8
%37 = call i8* @strtok(i8* %35, i8* %36)
store i8* %37, i8** %11
%38 = load i8*, i8** %11
%39 = icmp ne i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %31
store i8* null, i8** %3
br label %66
41: ; preds = %31
store i8* null, i8** %12
br label %42
42: ; preds = %50, %41
%43 = load i8*, i8** %11
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i8*, i8** %12
%47 = icmp eq i8* %46, null
br label %48
48: ; preds = %45, %42
%49 = phi i1 [ false, %42 ], [ %47, %45 ]
br i1 %49, label %50, label %56
50: ; preds = %48
%51 = load i8*, i8** %11
%52 = load i8*, i8** %5
%53 = call i8* @strstr(i8* %51, i8* %52)
store i8* %53, i8** %12
%54 = load i8*, i8** %8
%55 = call i8* @strtok(i8* null, i8* %54)
store i8* %55, i8** %11
br label %42
56: ; preds = %48
%57 = load i8*, i8** %12
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %60
59: ; preds = %56
store i8* null, i8** %3
br label %66
60: ; preds = %56
%61 = load i8*, i8** %12
%62 = load i64, i64* %10
%63 = getelementptr inbounds i8, i8* %61, i64 %62
%64 = call i8* @strip(i8* %63)
store i8* %64, i8** %13
%65 = load i8*, i8** %13
store i8* %65, i8** %3
br label %66
66: ; preds = %60, %59, %40, %30, %19
%67 = load i8*, i8** %3
ret i8* %67
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [2 x i8] c"\0A\00"
define i8* @parse_proc(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %31, label %7
7: ; preds = %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i8 signext 0, i32 1023)
%10 = call i32 @read(i32 %5, i8* %8, i32 1023)
%11 = call i32 @close(i32 %5)
%12 = icmp slt i32 %10, 0
br i1 %12, label %29, label %13
13: ; preds = %7
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %14
%15 = call i64 @strlen(i8* dereferenceable(1) %1)
%16 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %29, label %18
18: ; preds = %13, %18
%19 = phi i8* [ %21, %18 ], [ %16, %13 ]
%20 = call i8* @strstr(i8* %19, i8* dereferenceable(1) %1)
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i8* %21, null
%23 = icmp eq i8* %20, null
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %18, label %25
25: ; preds = %18
br i1 %23, label %29, label %26
26: ; preds = %25
%27 = getelementptr inbounds i8, i8* %20, i64 %15
%28 = call i8* @strip(i8* %27)
br label %29
29: ; preds = %13, %25, %26, %7
%30 = phi i8* [ null, %7 ], [ null, %13 ], [ %28, %26 ], [ null, %25 ]
br label %31
31: ; preds = %2, %29
%32 = phi i8* [ %30, %29 ], [ null, %2 ]
ret i8* %32
}