#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strlen(char *);
void Send(int sockfd, char *text) {
  int len, bytes_sent, sent;
  fprintf(stdout, "Client -> Server: %s", text);
  len = strlen(text);
  bytes_sent = 0;
  while (bytes_sent != len) {
    if (bytes_sent != 0) {
      fprintf(stdout, "Not all bytes sent, looping!");
    }
    sent = send(sockfd, text + bytes_sent, len - bytes_sent, 0);
    bytes_sent += sent;
    if (sent < 0) {
      fprintf(stderr, "Error sending information");
    }
  }
}


x86 assembly (clang, -O0):
<Send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xead(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11e7 <Send+0xb7>
cmpl   $0x0,-0x18(%rbp)
je     119a <Send+0x6a>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e2 <Send+0xb2>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    116d <Send+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e90(%rip),%r13
mov    0x0(%r13),%edi
lea    0xead(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11cd <Send+0x9d>
mov    %eax,%ebp
lea    0xea3(%rip),%r12
xor    %r15d,%r15d
jmp    1185 <Send+0x55>
nopw   0x0(%rax,%rax,1)
cmp    %r15d,%ebp
je     11cd <Send+0x9d>
test   %r15d,%r15d
je     1198 <Send+0x68>
mov    0x0(%r13),%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
movslq %r15d,%rsi
add    %rbx,%rsi
mov    %ebp,%edx
sub    %r15d,%edx
mov    %r14d,%edi
xor    %ecx,%ecx
call   1040 <send@plt>
add    %eax,%r15d
test   %eax,%eax
jns    1180 <Send+0x50>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1180 <Send+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [21 x i8] c"Client -> Server: %s\00"
@.str.1 = [29 x i8] c"Not all bytes sent, looping!\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Error sending information\00"
define void @Send(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i32, i32* @stdout
%9 = load i8*, i8** %4
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %5
store i32 0, i32* %6
br label %13
13: ; preds = %41, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %42
17: ; preds = %13
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stdout
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* %3
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = sub nsw i32 %29, %30
%32 = call i32 @send(i32 %24, i8* %28, i32 %31, i32 0)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = add nsw i32 %34, %33
store i32 %35, i32* %6
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %23
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %38, %23
br label %13
42: ; preds = %13
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [21 x i8] c"Client -> Server: %s\00"
@.str.1 = [29 x i8] c"Not all bytes sent, looping!\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Error sending information\00"
define void @Send(i32 %0, i8* %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %25, label %7
7: ; preds = %2, %23
%8 = phi i32 [ %18, %23 ], [ 0, %2 ]
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* @stdout
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %7
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = sub nsw i32 %5, %8
%17 = tail call i32 @send(i32 %0, i8* %15, i32 %16, i32 0)
%18 = add nsw i32 %17, %8
%19 = icmp slt i32 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %20, %13
%24 = icmp eq i32 %5, %18
br i1 %24, label %25, label %7
25: ; preds = %23, %2
ret void
}