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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ hasPrefix(char *, char *);
scalar_t__ snprintf(char *, int, char *, char *);
int strcmp(char *, char *);
int checkProcessName(pid_t pid, char *pname) {
  FILE *fp;
  char *line = NULL;
  char pproc[PATH_MAX];
  char cline[PATH_MAX];
  size_t len = 0;
  ssize_t read;
  if (snprintf(cline, PATH_MAX - 1, "Name:	%s\n", pname) < 0) {
    return -1;
  }
  if (snprintf(pproc, PATH_MAX - 1, "/proc/%ld/status", pid) < 0) {
    return -1;
  }
  fp = fopen(pproc, "r");
  if (fp == NULL) {
    return -1;
  }
  int retval = -1;
  while (retval == -1 && (read = getline(&line, &len, fp)) != -1) {
    if (hasPrefix(line, "Name:") >= 0) {
      retval = strcmp(cline, line);
      break;
    }
  }
  fclose(fp);
  if (line) {
    free(line);
  }
  return retval;
}


x86 assembly (clang, -O0):
<checkProcessName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x60(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x18(%rbp),%rcx
lea    0xe0f(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x0,%rax
jge    1213 <checkProcessName+0xa3>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    1323 <checkProcessName+0x1b3>
mov    -0x68(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%rcx
lea    0xddc(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x0,%rax
jge    1250 <checkProcessName+0xe0>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    1323 <checkProcessName+0x1b3>
mov    -0x68(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1282 <checkProcessName+0x112>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    1323 <checkProcessName+0x1b3>
movl   $0xffffffff,-0x54(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x54(%rbp)
mov    %al,-0x69(%rbp)
jne    12b5 <checkProcessName+0x145>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0xffffffff,%eax
setne  %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    12c5 <checkProcessName+0x155>
jmp    12f9 <checkProcessName+0x189>
mov    -0x28(%rbp),%rdi
lea    0xd4d(%rip),%rsi
call   1070 <hasPrefix@plt>
cmp    $0x0,%rax
jl     12f4 <checkProcessName+0x184>
mov    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %eax,-0x54(%rbp)
jmp    12f9 <checkProcessName+0x189>
jmp    1289 <checkProcessName+0x119>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     1316 <checkProcessName+0x1a6>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkProcessName>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rcx
mov    %rdi,%r15
mov    %rsp,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e56(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x0(%r13),%eax
mov    %rsp,%r12
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%r12
mov    %r12,%rsp
movq   $0x0,-0x40(%rbp)
lea    -0x1(%rax),%esi
lea    0xe27(%rip),%rdx
mov    %r12,%rdi
call   1050 <snprintf@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     1291 <checkProcessName+0x121>
mov    0x0(%r13),%esi
add    $0xffffffff,%esi
lea    0xe0c(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rcx
call   1050 <snprintf@plt>
test   %rax,%rax
js     1291 <checkProcessName+0x121>
lea    0xe02(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1291 <checkProcessName+0x121>
mov    %rax,%rbx
lea    -0x30(%rbp),%r14
lea    -0x40(%rbp),%r15
lea    0xde5(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     1275 <checkProcessName+0x105>
mov    -0x30(%rbp),%rdi
mov    %r13,%rsi
call   1070 <hasPrefix@plt>
test   %rax,%rax
js     1240 <checkProcessName+0xd0>
mov    -0x30(%rbp),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
mov    %eax,%r14d
jmp    127b <checkProcessName+0x10b>
mov    $0xffffffff,%r14d
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
test   %rdi,%rdi
je     1291 <checkProcessName+0x121>
call   1030 <free@plt>
mov    -0x38(%rbp),%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [10 x i8] c"Name:\09%s\0A\00"
@.str.1 = [17 x i8] c"/proc/%ld/status\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"Name:\00"
define i32 @checkProcessName(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %7
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load i32, i32* @PATH_MAX
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
store i64 %20, i64* %10
store i64 0, i64* %11
%22 = load i32, i32* @PATH_MAX
%23 = sub nsw i32 %22, 1
%24 = load i8*, i8** %5
%25 = call i64 @snprintf(i8* %21, i32 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %2
store i32 -1, i32* %3
store i32 1, i32* %13
br label %68
28: ; preds = %2
%29 = load i32, i32* @PATH_MAX
%30 = sub nsw i32 %29, 1
%31 = load i8*, i8** %4
%32 = call i64 @snprintf(i8* %18, i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 -1, i32* %3
store i32 1, i32* %13
br label %68
35: ; preds = %28
%36 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %36, i32** %6
%37 = load i32*, i32** %6
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 -1, i32* %3
store i32 1, i32* %13
br label %68
40: ; preds = %35
store i32 -1, i32* %14
br label %41
41: ; preds = %57, %40
%42 = load i32, i32* %14
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32*, i32** %6
%46 = call i32 @getline(i8** %7, i64* %11, i32* %45)
store i32 %46, i32* %12
%47 = icmp ne i32 %46, -1
br label %48
48: ; preds = %44, %41
%49 = phi i1 [ false, %41 ], [ %47, %44 ]
br i1 %49, label %50, label %58
50: ; preds = %48
%51 = load i8*, i8** %7
%52 = call i64 @hasPrefix(i8* %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp sge i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i8*, i8** %7
%56 = call i32 @strcmp(i8* %21, i8* %55)
store i32 %56, i32* %14
br label %58
57: ; preds = %50
br label %41
58: ; preds = %54, %48
%59 = load i32*, i32** %6
%60 = call i32 @fclose(i32* %59)
%61 = load i8*, i8** %7
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i8*, i8** %7
%65 = call i32 @free(i8* %64)
br label %66
66: ; preds = %63, %58
%67 = load i32, i32* %14
store i32 %67, i32* %3
store i32 1, i32* %13
br label %68
68: ; preds = %66, %39, %34, %27
%69 = load i8*, i8** %8
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [10 x i8] c"Name:\09%s\0A\00"
@.str.1 = [17 x i8] c"/proc/%ld/status\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"Name:\00"
define i32 @checkProcessName(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = alloca i8, i64 %11
%13 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%14 = add nsw i32 %10, -1
%15 = call i64 @snprintf(i8* %12, i32 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %1)
%16 = icmp slt i64 %15, 0
br i1 %16, label %42, label %17
17: ; preds = %2
%18 = load i32, i32* @PATH_MAX
%19 = add nsw i32 %18, -1
%20 = call i64 @snprintf(i8* %9, i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = icmp slt i64 %20, 0
br i1 %21, label %42, label %22
22: ; preds = %17
%23 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %42, label %25
25: ; preds = %22, %28
%26 = call i32 @getline(i8** %3, i64* %4, i32* %23)
%27 = icmp eq i32 %26, -1
br i1 %27, label %35, label %28
28: ; preds = %25
%29 = load i8*, i8** %3
%30 = call i64 @hasPrefix(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp sgt i64 %30, -1
br i1 %31, label %32, label %25
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = call i32 @strcmp(i8* %12, i8* dereferenceable(1) %33)
br label %35
35: ; preds = %25, %32
%36 = phi i32 [ %34, %32 ], [ -1, %25 ]
%37 = call i32 @fclose(i32* %23)
%38 = load i8*, i8** %3
%39 = icmp eq i8* %38, null
br i1 %39, label %42, label %40
40: ; preds = %35
%41 = call i32 @free(i8* %38)
br label %42
42: ; preds = %35, %40, %22, %17, %2
%43 = phi i32 [ -1, %2 ], [ -1, %17 ], [ -1, %22 ], [ %36, %40 ], [ %36, %35 ]
ret i32 %43
}