#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*/ free(char *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *FileIO_getNamedPipeContent(char *named_pipe_path) {
  int bytes_read;
  char *total_buffer = malloc(sizeof(char) * 1024 * 100000);
  int fd = open(named_pipe_path, O_RDONLY);
  strcpy(total_buffer, "");
  while (true) {
    char named_pipe_buffer[1024];
    bytes_read = read(fd, named_pipe_buffer, 1024 - 1);
    if (bytes_read == 0) {
      break;
    }
    named_pipe_buffer[bytes_read] = '\0';
    strcat(total_buffer, named_pipe_buffer);
  }
  close(fd);
  int buffer_length = strlen(total_buffer);
  char *file_contents = malloc(sizeof(char) * buffer_length + 1);
  snprintf(file_contents, buffer_length, "%s", total_buffer);
  file_contents[buffer_length] = 0;
  free(total_buffer);
  return file_contents;
}


x86 assembly (clang, -O0):
<FileIO_getNamedPipeContent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x61a8000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
call   1080 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11f8 <FileIO_getNamedPipeContent+0x68>
jmp    1219 <FileIO_getNamedPipeContent+0x89>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10b0 <strcat@plt>
jmp    11d2 <FileIO_getNamedPipeContent+0x42>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x424(%rbp)
movslq -0x424(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rdi
mov    -0x424(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xd9b(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x430(%rbp),%rax
movslq -0x424(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x430(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileIO_getNamedPipeContent>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
mov    $0x61a8000,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
lea    0xe3d(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x3ff,%edx
call   1080 <read@plt>
test   %eax,%eax
je     1214 <FileIO_getNamedPipeContent+0x84>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <strcat@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1080 <read@plt>
test   %eax,%eax
jne    11f0 <FileIO_getNamedPipeContent+0x60>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
lea    0x1(%rbx),%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
lea    0xdc8(%rip),%rdx
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r14,%rcx
call   1060 <snprintf@plt>
movb   $0x0,0x0(%rbp,%rbx,1)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define i8* @FileIO_getNamedPipeContent(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %2
%9 = call i8* @malloc(i32 102400000)
store i8* %9, i8** %4
%10 = load i8*, i8** %2
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %5
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %1, %22
%16 = load i32, i32* %5
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 1023)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
br label %29
22: ; preds = %15
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %4
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%28 = call i32 @strcat(i8* %26, i8* %27)
br label %15
29: ; preds = %21
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
%32 = load i8*, i8** %4
%33 = call i32 @strlen(i8* %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = mul i64 1, %35
%37 = add i64 %36, 1
%38 = trunc i64 %37 to i32
%39 = call i8* @malloc(i32 %38)
store i8* %39, i8** %8
%40 = load i8*, i8** %8
%41 = load i32, i32* %7
%42 = load i8*, i8** %4
%43 = call i32 @snprintf(i8* %40, i32 %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %8
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %4
%49 = call i32 @free(i8* %48)
%50 = load i8*, i8** %8
ret i8* %50
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define i8* @FileIO_getNamedPipeContent(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = tail call dereferenceable_or_null(102400000) i8* @malloc(i32 102400000)
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = call i32 @read(i32 %5, i8* %7, i32 1023)
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %1, %10
%11 = phi i32 [ %15, %10 ], [ %8, %1 ]
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @strcat(i8* %3, i8* %7)
%15 = call i32 @read(i32 %5, i8* %7, i32 1023)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %10
17: ; preds = %10, %1
%18 = call i32 @close(i32 %5)
%19 = call i32 @strlen(i8* %3)
%20 = sext i32 %19 to i64
%21 = add i32 %19, 1
%22 = call i8* @malloc(i32 %21)
%23 = call i32 @snprintf(i8* %22, i32 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%24 = getelementptr inbounds i8, i8* %22, i64 %20
store i8 0, i8* %24
%25 = call i32 @free(i8* %3)
ret i8* %22
}