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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ trim(char *);
int print_proc(char *dirname) {
  char filename[256];
  char linebuf[256];
  char procname[256];
  char pid[32];
  char *key;
  char *value;
  FILE *p_file;
  strcpy(filename, dirname);
  strcat(filename, "/status");
  p_file = fopen(filename, "r");
  if (p_file == NULL) {
    return 1;
  }
  while (fgets(linebuf, sizeof(linebuf), p_file) != NULL) {
    key = strtok(linebuf, ":");
    value = strtok(NULL, ":");
    if (key != NULL && value != NULL) {
      trim(key);
      trim(value);
      if (strcmp(key, "Pid") == 0) {
        strcpy(pid, value);
      } else if (strcmp(key, "Name") == 0) {
        strcpy(procname, value);
      }
    }
  }
  printf("%s (pid: %s)\n", procname, pid);
  return 0;
}


x86 assembly (clang, -O0):
<print_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x348(%rbp)
cmpq   $0x0,-0x348(%rbp)
jne    11e6 <print_proc+0x66>
movl   $0x1,-0x4(%rbp)
jmp    1307 <print_proc+0x187>
jmp    11eb <print_proc+0x6b>
lea    -0x210(%rbp),%rdi
mov    -0x348(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12e6 <print_proc+0x166>
lea    -0x210(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x338(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd8(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x340(%rbp)
cmpq   $0x0,-0x338(%rbp)
je     12e1 <print_proc+0x161>
cmpq   $0x0,-0x340(%rbp)
je     12e1 <print_proc+0x161>
mov    -0x338(%rbp),%rdi
call   1050 <trim@plt>
mov    -0x340(%rbp),%rdi
call   1050 <trim@plt>
mov    -0x338(%rbp),%rdi
lea    0xd8c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12a7 <print_proc+0x127>
lea    -0x330(%rbp),%rdi
mov    -0x340(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12dc <print_proc+0x15c>
mov    -0x338(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12d7 <print_proc+0x157>
lea    -0x310(%rbp),%rdi
mov    -0x340(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12dc <print_proc+0x15c>
jmp    12e1 <print_proc+0x161>
jmp    11eb <print_proc+0x6b>
lea    -0x310(%rbp),%rsi
lea    -0x330(%rbp),%rdx
lea    0xd1a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_proc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x328,%rsp
mov    %rdi,%rsi
lea    0x220(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a8 <print_proc+0x128>
mov    %rax,%rbx
lea    0x120(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1290 <print_proc+0x110>
lea    0xe17(%rip),%r14
lea    0x120(%rsp),%r15
lea    0xe0a(%rip),%r12
jmp    122d <print_proc+0xad>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1290 <print_proc+0x110>
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <strtok@plt>
mov    %rax,%r13
xor    %edi,%edi
mov    %r14,%rsi
call   1090 <strtok@plt>
test   %r13,%r13
je     1218 <print_proc+0x98>
mov    %rax,%rbp
test   %rax,%rax
je     1218 <print_proc+0x98>
mov    %r13,%rdi
call   1050 <trim@plt>
mov    %rbp,%rdi
call   1050 <trim@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
mov    %rsp,%rdi
test   %rax,%rax
je     1210 <print_proc+0x90>
mov    %r13,%rdi
lea    0xd91(%rip),%rsi
call   1070 <strcmp@plt>
lea    0x20(%rsp),%rdi
test   %rax,%rax
jne    1218 <print_proc+0x98>
jmp    1210 <print_proc+0x90>
lea    0xd7e(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <printf@plt>
xor    %eax,%eax
jmp    12ad <print_proc+0x12d>
mov    $0x1,%eax
add    $0x328,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [4 x i8] c"Pid\00"
@.str.4 = [5 x i8] c"Name\00"
@.str.5 = [14 x i8] c"%s (pid: %s)\0A\00"
define i32 @print_proc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = alloca [32 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
store i8* %0, i8** %3
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%15 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %10
%18 = load i32*, i32** %10
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %1
store i32 1, i32* %2
br label %63
21: ; preds = %1
br label %22
22: ; preds = %58, %21
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%24 = load i32*, i32** %10
%25 = call i32* @fgets(i8* %23, i32 256, i32* %24)
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %59
27: ; preds = %22
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = call i8* @strtok(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %29, i8** %8
%30 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %30, i8** %9
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %58
33: ; preds = %27
%34 = load i8*, i8** %9
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %58
36: ; preds = %33
%37 = load i8*, i8** %8
%38 = call i32 @trim(i8* %37)
%39 = load i8*, i8** %9
%40 = call i32 @trim(i8* %39)
%41 = load i8*, i8** %8
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %36
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%46 = load i8*, i8** %9
%47 = call i32 @strcpy(i8* %45, i8* %46)
br label %57
48: ; preds = %36
%49 = load i8*, i8** %8
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%54 = load i8*, i8** %9
%55 = call i32 @strcpy(i8* %53, i8* %54)
br label %56
56: ; preds = %52, %48
br label %57
57: ; preds = %56, %44
br label %58
58: ; preds = %57, %33, %27
br label %22
59: ; preds = %22
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%61 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%62 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %60, i8* %61)
store i32 0, i32* %2
br label %63
63: ; preds = %59, %20
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
@.str = [8 x i8] c"/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [4 x i8] c"Pid\00"
@.str.4 = [5 x i8] c"Name\00"
@.str.5 = [14 x i8] c"%s (pid: %s)\0A\00"
define i32 @print_proc(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%10 = call i32 @strcpy(i8* %6, i8* %0)
%11 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %39, label %14
14: ; preds = %1
%15 = call i32* @fgets(i8* %7, i32 256, i32* %12)
%16 = icmp eq i32* %15, null
br i1 %16, label %37, label %17
17: ; preds = %14, %34
%18 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i8* %18, null
%21 = icmp ne i8* %19, null
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %34
23: ; preds = %17
%24 = call i32 @trim(i8* %18)
%25 = call i32 @trim(i8* %19)
%26 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28, %23
%32 = phi i8* [ %9, %23 ], [ %8, %28 ]
%33 = call i32 @strcpy(i8* %32, i8* %19)
br label %34
34: ; preds = %31, %28, %17
%35 = call i32* @fgets(i8* %7, i32 256, i32* %12)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %17
37: ; preds = %34, %14
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %8, i8* %9)
br label %39
39: ; preds = %1, %37
%40 = phi i32 [ 0, %37 ], [ 1, %1 ]
ret i32 %40
}