#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*/ perror(char *);
int send(int, char *, int, int /*<<< orphan*/);
void jsp_send_all(int fd, char *buf, int len) {
  int total_sent = 0;
  int bytes_sent;
  while (total_sent < len) {
    bytes_sent = send(fd, buf, len, 0);
    if (bytes_sent < 0) {
      perror("JSP server socket send failed");
      break;
    }
    total_sent += bytes_sent;
  }
}


x86 assembly (clang, -O0):
<jsp_send_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1182 <jsp_send_all+0x62>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1174 <jsp_send_all+0x54>
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
jmp    1182 <jsp_send_all+0x62>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <jsp_send_all+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jsp_send_all>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1159 <jsp_send_all+0x39>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
js     1164 <jsp_send_all+0x44>
add    %eax,%ebp
cmp    %ebx,%ebp
jl     1140 <jsp_send_all+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe95(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <perror@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"JSP server socket send failed\00"
define void @jsp_send_all(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %22, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call i32 @send(i32 %14, i8* %15, i32 %16, i32 0)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %26
22: ; preds = %13
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = add nsw i32 %24, %23
store i32 %25, i32* %7
br label %9
26: ; preds = %20, %9
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"JSP server socket send failed\00"
define void @jsp_send_all(i32 %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %7, label %14
5: ; preds = %7
%6 = icmp slt i32 %11, %2
br i1 %6, label %7, label %14
7: ; preds = %3, %5
%8 = phi i32 [ %11, %5 ], [ 0, %3 ]
%9 = tail call i32 @send(i32 %0, i8* %1, i32 %2, i32 0)
%10 = icmp slt i32 %9, 0
%11 = add nsw i32 %9, %8
br i1 %10, label %12, label %5
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %5, %3, %12
ret void
}