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


x86 assembly (clang, -O0):
<send_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1190 <send_string+0x70>
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    116f <send_string+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1197 <send_string+0x77>
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    113b <send_string+0x1b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    115e <send_string+0x3e>
mov    %eax,%ebp
xor    %r15d,%r15d
xchg   %ax,%ax
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     1164 <send_string+0x44>
movslq %eax,%rcx
add    %rcx,%rbx
sub    %eax,%ebp
jg     1140 <send_string+0x20>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @send_string(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
%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 0, 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 @send_string(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 ], [ 0, %5 ]
ret i32 %16
}