#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 */
struct dyString {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ dyStringAppendN(struct dyString *, char *, int);
struct dyString *newDyString(int);
int read(int, char *, int);
struct dyString *netSlurpFile(int sd) {
  char buf[4 * 1024];
  int readSize;
  struct dyString *dy = newDyString(4 * 1024);
  while ((readSize = read(sd, buf, sizeof(buf))) > 0)
    dyStringAppendN(dy, buf, readSize);
  return dy;
}


x86 assembly (clang, -O0):
<netSlurpFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x1000,%edi
call   1040 <newDyString@plt>
mov    %rax,-0x1020(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <read@plt>
mov    %eax,-0x1014(%rbp)
cmp    $0x0,%eax
jle    1190 <netSlurpFile+0x60>
mov    -0x1020(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    -0x1014(%rbp),%edx
call   1050 <dyStringAppendN@plt>
jmp    114f <netSlurpFile+0x1f>
mov    -0x1020(%rbp),%rax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netSlurpFile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %edi,%r14d
mov    $0x1000,%edi
call   1040 <newDyString@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x1000,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    1191 <netSlurpFile+0x61>
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <dyStringAppendN@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1030 <read@plt>
test   %eax,%eax
jg     1170 <netSlurpFile+0x40>
mov    %rbx,%rax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dyString = type { i32 }
define %struct.dyString* @netSlurpFile(i32 %0) {
%2 = alloca i32
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = alloca %struct.dyString*
store i32 %0, i32* %2
%6 = call %struct.dyString* @newDyString(i32 4096)
store %struct.dyString* %6, %struct.dyString** %5
br label %7
7: ; preds = %12, %1
%8 = load i32, i32* %2
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 4096)
store i32 %10, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = load %struct.dyString*, %struct.dyString** %5
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* %4
%16 = call i32 @dyStringAppendN(%struct.dyString* %13, i8* %14, i32 %15)
br label %7
17: ; preds = %7
%18 = load %struct.dyString*, %struct.dyString** %5
ret %struct.dyString* %18
}

LLVM IR (-O2):
%struct.dyString = type { i32 }
define %struct.dyString* @netSlurpFile(i32 %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = tail call %struct.dyString* @newDyString(i32 4096)
%5 = call i32 @read(i32 %0, i8* %3, i32 4096)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1, %7
%8 = phi i32 [ %10, %7 ], [ %5, %1 ]
%9 = call i32 @dyStringAppendN(%struct.dyString* %4, i8* %3, i32 %8)
%10 = call i32 @read(i32 %0, i8* %3, i32 4096)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %7, label %12
12: ; preds = %7, %1
ret %struct.dyString* %4
}