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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void read_proc_file() {
  FILE *fp_proc;
  size_t bytes_read;
  char buffer[2048];
  fp_proc = fopen("/proc/parallelled", "r");
  if (!fp_proc) {
    printf("/proc/parallelled is not available\n");
    exit(-1);
  }
  bytes_read = fread(buffer, 1, sizeof(buffer), fp_proc);
  fclose(fp_proc);
  if (bytes_read == 0 || bytes_read == sizeof(buffer)) {
    printf("Some unexpected error in read process\n");
    exit(-1);
  }
  printf("Port Status:\n%s\n", buffer);
}


x86 assembly (clang, -O0):
<read_proc_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1195 <read_proc_file+0x45>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1030 <fread@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x10(%rbp)
je     11d5 <read_proc_file+0x85>
cmpq   $0x800,-0x10(%rbp)
jne    11ed <read_proc_file+0x9d>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x810(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_proc_file>:
push   %r14
push   %rbx
sub    $0x808,%rsp
lea    0xe8f(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ca <read_proc_file+0x6a>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   $0xfffffffffffff7ff,%r14
je     11d3 <read_proc_file+0x73>
lea    0xe5f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe54(%rip),%rdi
jmp    11da <read_proc_file+0x7a>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/parallelled\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"/proc/parallelled is not available\0A\00"
@.str.3 = [39 x i8] c"Some unexpected error in read process\0A\00"
@.str.4 = [17 x i8] c"Port Status:\0A%s\0A\00"
define void @read_proc_file() {
%1 = alloca i32*
%2 = alloca i64
%3 = alloca [2048 x i8]
%4 = 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* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %1
%13 = call i64 @fread(i8* %11, i32 1, i32 2048, i32* %12)
store i64 %13, i64* %2
%14 = load i32*, i32** %1
%15 = call i32 @fclose(i32* %14)
%16 = load i64, i64* %2
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %10
%19 = load i64, i64* %2
%20 = icmp eq i64 %19, 2048
br i1 %20, label %21, label %24
21: ; preds = %18, %10
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %18
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/parallelled\00"
@.str.1 = [2 x i8] c"r\00"
@.str.4 = [17 x i8] c"Port Status:\0A%s\0A\00"
@str = [35 x i8] c"/proc/parallelled is not available\00"
@str.5 = [38 x i8] c"Some unexpected error in read process\00"
define void @read_proc_file() {
%1 = alloca [2048 x i8]
%2 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %0
%9 = call i64 @fread(i8* %2, i32 1, i32 2048, i32* %3)
%10 = tail call i32 @fclose(i32* %3)
%11 = and i64 %9, -2049
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %8
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %2)
ret void
}