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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
scalar_t__ recv(int, char *, scalar_t__, int /*<<< orphan*/);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ sysError(char *);
void clientStream(int clntSock, char *string) {
  const int BUFF = 1024;
  char buff[BUFF];
  ssize_t bytesSent = 0;
  bytesSent = send(clntSock, string, strlen(string), 0);
  if (bytesSent <= 0)
    sysError("failed to send data");
  fprintf(stdout, "Sent %d bytes of data\n", bytesSent);
  fprintf(stdout, "Data: %s\n", string);
  ssize_t bytesRcvd = 0;
  bytesRcvd = recv(clntSock, buff, bytesSent, 0);
  if (bytesRcvd <= 0)
    sysError("failed to get data");
  buff[bytesRcvd] = '\0';
  fprintf(stdout, "Received %d bytes of data\n\n", bytesRcvd);
}


x86 assembly (clang, -O0):
<clientStream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x400,-0x14(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jg     11c6 <clientStream+0x76>
lea    0xe3f(%rip),%rdi
call   1040 <sysError@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rdx
lea    -0x430(%rbp),%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jg     1230 <clientStream+0xe0>
lea    0xe0a(%rip),%rdi
call   1040 <sysError@plt>
mov    -0x30(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdf8(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clientStream>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,%rbp
test   %rax,%rax
jg     118e <clientStream+0x3e>
lea    0xe77(%rip),%rdi
call   1040 <sysError@plt>
mov    0x2e4b(%rip),%r15
mov    (%r15),%edi
lea    0xe75(%rip),%rsi
mov    %rbp,%rdx
call   1070 <fprintf@plt>
mov    (%r15),%edi
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,%rbx
test   %rax,%rax
jg     11dd <clientStream+0x8d>
lea    0xe5d(%rip),%rdi
call   1040 <sysError@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    (%r15),%edi
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"failed to send data\00"
@stdout = global i32 0
@.str.1 = [23 x i8] c"Sent %d bytes of data\0A\00"
@.str.2 = [10 x i8] c"Data: %s\0A\00"
@.str.3 = [19 x i8] c"failed to get data\00"
@.str.4 = [28 x i8] c"Received %d bytes of data\0A\0A\00"
define void @clientStream(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 1024, i32* %5
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %6
%10 = alloca i8, i64 1024
store i64 0, i64* %7
%11 = load i32, i32* %3
%12 = load i8*, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = call i64 @send(i32 %11, i8* %12, i32 %14, i32 0)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = icmp sle i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @sysError(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = load i32, i32* @stdout
%22 = load i64, i64* %7
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %22)
%24 = load i32, i32* @stdout
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %25 to i64
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %26)
store i64 0, i64* %8
%28 = load i32, i32* %3
%29 = load i64, i64* %7
%30 = call i64 @recv(i32 %28, i8* %10, i64 %29, i32 0)
store i64 %30, i64* %8
%31 = load i64, i64* %8
%32 = icmp sle i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %20
%34 = call i32 @sysError(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %20
%36 = load i64, i64* %8
%37 = getelementptr inbounds i8, i8* %10, i64 %36
store i8 0, i8* %37
%38 = load i32, i32* @stdout
%39 = load i64, i64* %8
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 %39)
%41 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"failed to send data\00"
@stdout = global i32 0
@.str.1 = [23 x i8] c"Sent %d bytes of data\0A\00"
@.str.2 = [10 x i8] c"Data: %s\0A\00"
@.str.3 = [19 x i8] c"failed to get data\00"
@.str.4 = [28 x i8] c"Received %d bytes of data\0A\0A\00"
define void @clientStream(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i64 @send(i32 %0, i8* %1, i32 %5, i32 0)
%7 = icmp slt i64 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @sysError(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = load i32, i32* @stdout
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%13 = load i32, i32* @stdout
%14 = ptrtoint i8* %1 to i64
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %14)
%16 = call i64 @recv(i32 %0, i8* %4, i64 %6, i32 0)
%17 = icmp slt i64 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @sysError(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %10
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %21
%22 = load i32, i32* @stdout
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 %16)
ret void
}