#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 */
scalar_t__ EINTR;
scalar_t__ errno;
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
int write_to_client(int clientsd, char *message) {
  ssize_t written, w;
  w = 0;
  written = 0;
  while (written < strlen(message)) {
    w = write(clientsd, message + written, strlen(message) - written);
    if (w == -1) {
      if (errno != EINTR)
        return -1;
    } else
      written += w;
  }
  return written;
}


x86 assembly (clang, -O0):
<write_to_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jge    11d9 <write_to_client+0xb9>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
sub    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    11c8 <write_to_client+0xa8>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
je     11c3 <write_to_client+0xa3>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <write_to_client+0xc0>
jmp    11d4 <write_to_client+0xb4>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    113f <write_to_client+0x1f>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_client>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strlen@plt>
xor    %ebx,%ebx
test   %rax,%rax
jle    1185 <write_to_client+0x65>
mov    0x2e9d(%rip),%r15
mov    0x2e8e(%rip),%r12
jmp    1160 <write_to_client+0x40>
nopl   0x0(%rax)
add    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rbx,%rax
jle    1185 <write_to_client+0x65>
lea    (%r14,%rbx,1),%rsi
sub    %rbx,%rax
mov    %ebp,%edi
mov    %rax,%rdx
call   1030 <write@plt>
cmp    $0xffffffffffffffff,%rax
jne    1150 <write_to_client+0x30>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1153 <write_to_client+0x33>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @write_to_client(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 0, i64* %7
store i64 0, i64* %6
br label %8
8: ; preds = %35, %2
%9 = load i64, i64* %6
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = icmp slt i64 %9, %11
br i1 %12, label %13, label %36
13: ; preds = %8
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = load i64, i64* %6
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i8*, i8** %5
%19 = call i64 @strlen(i8* %18)
%20 = load i64, i64* %6
%21 = sub nsw i64 %19, %20
%22 = call i64 @write(i32 %14, i8* %17, i64 %21)
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = icmp eq i64 %23, -1
br i1 %24, label %25, label %31
25: ; preds = %13
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINTR
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %3
br label %39
30: ; preds = %25
br label %35
31: ; preds = %13
%32 = load i64, i64* %7
%33 = load i64, i64* %6
%34 = add nsw i64 %33, %32
store i64 %34, i64* %6
br label %35
35: ; preds = %31, %30
br label %8
36: ; preds = %8
%37 = load i64, i64* %6
%38 = trunc i64 %37 to i32
store i32 %38, i32* %3
br label %39
39: ; preds = %36, %29
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @write_to_client(i32 %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %2, %18
%6 = phi i64 [ %20, %18 ], [ %3, %2 ]
%7 = phi i64 [ %19, %18 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = sub nsw i64 %6, %7
%10 = tail call i64 @write(i32 %0, i8* %8, i64 %9)
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %5
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br i1 %15, label %18, label %25
16: ; preds = %5
%17 = add nsw i64 %10, %7
br label %18
18: ; preds = %12, %16
%19 = phi i64 [ %7, %12 ], [ %17, %16 ]
%20 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%21 = icmp sgt i64 %20, %19
br i1 %21, label %5, label %22
22: ; preds = %18, %2
%23 = phi i64 [ 0, %2 ], [ %19, %18 ]
%24 = trunc i64 %23 to i32
br label %25
25: ; preds = %12, %22
%26 = phi i32 [ %24, %22 ], [ -1, %12 ]
ret i32 %26
}