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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *ReadProcEntry(char *filename) {
  FILE *boxtype_file = fopen(filename, "r");
  char boxtype_name[20];
  char *real_boxtype_name = NULL;
  char c;
  int i = 0;
  if (boxtype_file) {
    while ((c = fgetc(boxtype_file)) != EOF && i < sizeof(boxtype_name) - 2) {
      if (c == '\n') {
        i--;
        break;
      }
      boxtype_name[i] = c;
      i++;
    }
    boxtype_name[i + 1] = '\0';
    real_boxtype_name = malloc(strlen(boxtype_name) + 1);
    if (real_boxtype_name)
      strcpy(real_boxtype_name, boxtype_name);
    fclose(boxtype_file);
  } else
    puts("[BRANDING] Can not open this proc entry!\n");
  return real_boxtype_name;
}


x86 assembly (clang, -O0):
<ReadProcEntry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1273 <ReadProcEntry+0x103>
jmp    11af <ReadProcEntry+0x3f>
mov    -0x10(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x39(%rbp)
movsbl %al,%ecx
mov    0x2e23(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x41(%rbp)
je     11e3 <ReadProcEntry+0x73>
movslq -0x40(%rbp),%rax
cmp    $0x12,%rax
setb   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11f3 <ReadProcEntry+0x83>
jmp    1227 <ReadProcEntry+0xb7>
movsbl -0x39(%rbp),%eax
cmp    $0xa,%eax
jne    120e <ReadProcEntry+0x9e>
mov    -0x40(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x40(%rbp)
jmp    1227 <ReadProcEntry+0xb7>
mov    -0x39(%rbp),%cl
movslq -0x40(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11af <ReadProcEntry+0x3f>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1265 <ReadProcEntry+0xf5>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
jmp    127f <ReadProcEntry+0x10f>
lea    0xd88(%rip),%rdi
call   1040 <puts@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadProcEntry>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11a8 <ReadProcEntry+0x38>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2e4a(%rip),%r14
cmp    (%r14),%al
jne    11b9 <ReadProcEntry+0x49>
xor    %r12d,%r12d
jmp    11ea <ReadProcEntry+0x7a>
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
jmp    1221 <ReadProcEntry+0xb1>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%al
je     11e3 <ReadProcEntry+0x73>
mov    %al,(%rsp,%rbx,1)
lea    0x1(%rbx),%r12
mov    %r15,%rdi
call   1070 <fgetc@plt>
cmp    (%r14),%al
je     11ea <ReadProcEntry+0x7a>
cmp    $0x11,%rbx
mov    %r12,%rbx
jb     11c0 <ReadProcEntry+0x50>
jmp    11ea <ReadProcEntry+0x7a>
add    $0xffffffffffffffff,%rbx
mov    %rbx,%r12
add    $0x1,%r12d
movslq %r12d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1219 <ReadProcEntry+0xa9>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.1 = [42 x i8] c"[BRANDING] Can not open this proc entry!\0A\00"
define i8* @ReadProcEntry(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [20 x i8]
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
store i8* null, i8** %5
store i32 0, i32* %7
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %58
12: ; preds = %1
br label %13
13: ; preds = %33, %12
%14 = load i32*, i32** %3
%15 = call signext i8 @fgetc(i32* %14)
store i8 %15, i8* %6
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = icmp ult i64 %22, 18
br label %24
24: ; preds = %20, %13
%25 = phi i1 [ false, %13 ], [ %23, %20 ]
br i1 %25, label %26, label %40
26: ; preds = %24
%27 = load i8, i8* %6
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %7
%32 = add nsw i32 %31, -1
store i32 %32, i32* %7
br label %40
33: ; preds = %26
%34 = load i8, i8* %6
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %36
store i8 %34, i8* %37
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %13
40: ; preds = %30, %24
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %43
store i8 0, i8* %44
%45 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%46 = call i64 @strlen(i8* %45)
%47 = add nsw i64 %46, 1
%48 = call i8* @malloc(i64 %47)
store i8* %48, i8** %5
%49 = load i8*, i8** %5
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %55
51: ; preds = %40
%52 = load i8*, i8** %5
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%54 = call i32 @strcpy(i8* %52, i8* %53)
br label %55
55: ; preds = %51, %40
%56 = load i32*, i32** %3
%57 = call i32 @fclose(i32* %56)
br label %60
58: ; preds = %1
%59 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %60
60: ; preds = %58, %55
%61 = load i8*, i8** %5
ret i8* %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.1 = [42 x i8] c"[BRANDING] Can not open this proc entry!\0A\00"
define i8* @ReadProcEntry(i8* nocapture %0) {
%2 = alloca [20 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = icmp eq i32* %3, null
br i1 %5, label %38, label %6
6: ; preds = %1
%7 = tail call signext i8 @fgetc(i32* %3)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %24, label %10
10: ; preds = %6, %16
%11 = phi i64 [ %18, %16 ], [ 0, %6 ]
%12 = phi i8 [ %19, %16 ], [ %7, %6 ]
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = add nsw i64 %11, -1
br label %24
16: ; preds = %10
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %11
store i8 %12, i8* %17
%18 = add nuw nsw i64 %11, 1
%19 = tail call signext i8 @fgetc(i32* %3)
%20 = load i8, i8* @EOF
%21 = icmp ne i8 %19, %20
%22 = icmp ult i64 %11, 17
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %10, label %24
24: ; preds = %16, %6, %14
%25 = phi i64 [ %15, %14 ], [ 0, %6 ], [ %18, %16 ]
%26 = shl i64 %25, 32
%27 = add i64 %26, 4294967296
%28 = ashr exact i64 %27, 32
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %28
store i8 0, i8* %29
%30 = call i64 @strlen(i8* %4)
%31 = add nsw i64 %30, 1
%32 = tail call i8* @malloc(i64 %31)
%33 = icmp eq i8* %32, null
br i1 %33, label %36, label %34
34: ; preds = %24
%35 = call i32 @strcpy(i8* %32, i8* %4)
br label %36
36: ; preds = %34, %24
%37 = call i32 @fclose(i32* %3)
br label %40
38: ; preds = %1
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
%41 = phi i8* [ %32, %36 ], [ null, %38 ]
ret i8* %41
}