#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 send(int, char *, int, int /*<<< orphan*/);
int strlen(char *);
int sendString(int sockfd, char *buffer) {
  int send_bytes = 0;
  int bytes_to_send = strlen(buffer);
  while (bytes_to_send > 0) {
    send_bytes = send(sockfd, buffer, bytes_to_send, 0);
    if (send_bytes == -1)
      return -1;
    bytes_to_send -= send_bytes;
    buffer += send_bytes;
  }
  return 1;
}


x86 assembly (clang, -O0):
<sendString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1197 <sendString+0x77>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1176 <sendString+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    119e <sendString+0x7e>
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1142 <sendString+0x22>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
jle    1176 <sendString+0x56>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     1170 <sendString+0x50>
movslq %eax,%rcx
add    %rcx,%rbx
sub    %eax,%ebp
jg     1150 <sendString+0x30>
jmp    1176 <sendString+0x56>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sendString(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
br label %10
10: ; preds = %21, %2
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = load i32, i32* %7
%17 = call i32 @send(i32 %14, i8* %15, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 -1, i32* %3
br label %30
21: ; preds = %13
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, %22
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = load i8*, i8** %5
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %5
br label %10
29: ; preds = %10
store i32 1, i32* %3
br label %30
30: ; preds = %29, %20
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @sendString(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %2, %10
%6 = phi i32 [ %11, %10 ], [ %3, %2 ]
%7 = phi i8* [ %13, %10 ], [ %1, %2 ]
%8 = tail call i32 @send(i32 %0, i8* %7, i32 %6, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = sub nsw i32 %6, %8
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds i8, i8* %7, i64 %12
%14 = icmp sgt i32 %11, 0
br i1 %14, label %5, label %15
15: ; preds = %5, %10, %2
%16 = phi i32 [ 1, %2 ], [ 1, %10 ], [ -1, %5 ]
ret i32 %16
}