#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
size_t recv(int const, char *, size_t, int /*<<< orphan*/);
size_t send(int const, char const *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
size_t strlen(char const *);
int /*<<< orphan*/ sysError(char *);
void clientStream(const int servSock, const char *string) {
  size_t stringLen = strlen(string);
  ssize_t bytesSent = 0;
  bytesSent = send(servSock, string, stringLen, 0);
  if (bytesSent < 0)
    sysError("failed to send string");
  else if (bytesSent != stringLen)
    sysError("sent unexpected amount of data");
  char buff[stringLen];
  ssize_t bytesRcvd = 0;
  bytesRcvd = recv(servSock, buff, stringLen, 0);
  if (bytesRcvd < 0)
    sysError("failed to get string");
  else if (bytesRcvd == 0)
    sysError("connection died prematurely");
  buff[bytesRcvd] = '\0';
  fprintf(stdout, "Sent: %s\nReceived: %s\n\n", string, buff);
}


x86 assembly (clang, -O0):
<clientStream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jae    11a6 <clientStream+0x56>
lea    0xe64(%rip),%rdi
call   1040 <sysError@plt>
jmp    11c5 <clientStream+0x75>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11c0 <clientStream+0x70>
lea    0xe5b(%rip),%rdi
call   1040 <sysError@plt>
jmp    11c5 <clientStream+0x75>
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jae    1222 <clientStream+0xd2>
lea    0xe1d(%rip),%rdi
call   1040 <sysError@plt>
jmp    123e <clientStream+0xee>
cmpq   $0x0,-0x38(%rbp)
jne    1239 <clientStream+0xe9>
lea    0xe16(%rip),%rdi
call   1040 <sysError@plt>
jmp    123e <clientStream+0xee>
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%rax
movb   $0x0,(%rcx,%rax,1)
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clientStream>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    %r12,%rax
je     118d <clientStream+0x3d>
lea    0xe78(%rip),%rdi
call   1040 <sysError@plt>
mov    %rsp,%rbx
mov    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11c5 <clientStream+0x75>
lea    0xe5f(%rip),%rdi
call   1040 <sysError@plt>
movb   $0x0,(%rbx,%r15,1)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1070 <fprintf@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"failed to send string\00"
@.str.1 = [31 x i8] c"sent unexpected amount of data\00"
@.str.2 = [21 x i8] c"failed to get string\00"
@.str.3 = [28 x i8] c"connection died prematurely\00"
@stdout = global i32 0
@.str.4 = [24 x i8] c"Sent: %s\0AReceived: %s\0A\0A\00"
define void @clientStream(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %5
store i64 0, i64* %6
%12 = load i32, i32* %3
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = call i64 @send(i32 %12, i8* %13, i64 %14, i32 0)
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = icmp ult i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @sysError(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %27
20: ; preds = %2
%21 = load i64, i64* %6
%22 = load i64, i64* %5
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @sysError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
br label %27
27: ; preds = %26, %18
%28 = load i64, i64* %5
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %7
%30 = alloca i8, i64 %28
store i64 %28, i64* %8
store i64 0, i64* %9
%31 = load i32, i32* %3
%32 = load i64, i64* %5
%33 = call i64 @recv(i32 %31, i8* %30, i64 %32, i32 0)
store i64 %33, i64* %9
%34 = load i64, i64* %9
%35 = icmp ult i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = call i32 @sysError(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %44
38: ; preds = %27
%39 = load i64, i64* %9
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @sysError(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
br label %44
44: ; preds = %43, %36
%45 = load i64, i64* %9
%46 = getelementptr inbounds i8, i8* %30, i64 %45
store i8 0, i8* %46
%47 = load i32, i32* @stdout
%48 = load i8*, i8** %4
%49 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %48, i8* %30)
%50 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str.1 = [31 x i8] c"sent unexpected amount of data\00"
@.str.3 = [28 x i8] c"connection died prematurely\00"
@stdout = global i32 0
@.str.4 = [24 x i8] c"Sent: %s\0AReceived: %s\0A\0A\00"
define void @clientStream(i32 %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i64 @send(i32 %0, i8* %1, i64 %3, i32 0)
%5 = icmp eq i64 %4, %3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @sysError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %2, %6
%9 = alloca i8, i64 %3
%10 = call i64 @recv(i32 %0, i8* %9, i64 %3, i32 0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @sysError(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %8, %12
%15 = getelementptr inbounds i8, i8* %9, i64 %10
store i8 0, i8* %15
%16 = load i32, i32* @stdout
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %9)
ret void
}