#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 int ssize_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ warn(char *);
int write(int, char const *, size_t);
int send_db(int sfd, const char *buf, size_t buf_len) {
  ssize_t ret;
  while (buf_len != 0 && (ret = write(sfd, buf, buf_len)) != 0) {
    if (ret == -1) {
      if (errno == EINTR)
        continue;
      warn("Can not write to server");
      return -1;
    }
    buf_len -= ret;
    buf += ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
je     115f <send_db+0x3f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    116f <send_db+0x4f>
jmp    11d5 <send_db+0xb5>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11b0 <send_db+0x90>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <send_db+0x78>
jmp    1133 <send_db+0x13>
lea    0xe61(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <send_db+0xbc>
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1133 <send_db+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_db>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdx,%rdx
je     1196 <send_db+0x76>
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r15d
mov    0x2e9d(%rip),%r12
mov    0x2e8e(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    116f <send_db+0x4f>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1150 <send_db+0x30>
jmp    117f <send_db+0x5f>
test   %eax,%eax
je     1193 <send_db+0x73>
cltq
add    %rax,%rbp
sub    %rax,%rbx
jne    1150 <send_db+0x30>
jmp    1196 <send_db+0x76>
lea    0xe7a(%rip),%rdi
call   1030 <warn@plt>
mov    $0xffffffff,%r14d
jmp    1196 <send_db+0x76>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [24 x i8] c"Can not write to server\00"
define i32 @send_db(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
br label %9
9: ; preds = %30, %27, %3
%10 = load i64, i64* %7
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = call i32 @write(i32 %13, i8* %14, i64 %15)
store i32 %16, i32* %8
%17 = icmp ne i32 %16, 0
br label %18
18: ; preds = %12, %9
%19 = phi i1 [ false, %9 ], [ %17, %12 ]
br i1 %19, label %20, label %39
20: ; preds = %18
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i64, i64* @errno
%25 = load i64, i64* @EINTR
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %9
28: ; preds = %23
%29 = call i32 @warn(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %40
30: ; preds = %20
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = load i64, i64* %7
%34 = sub i64 %33, %32
store i64 %34, i64* %7
%35 = load i32, i32* %8
%36 = load i8*, i8** %6
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %6
br label %9
39: ; preds = %18
store i32 0, i32* %4
br label %40
40: ; preds = %39, %28
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [24 x i8] c"Can not write to server\00"
define i32 @send_db(i32 %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %21, label %5
5: ; preds = %3, %16
%6 = phi i64 [ %18, %16 ], [ %2, %3 ]
%7 = phi i8* [ %19, %16 ], [ %1, %3 ]
br label %8
8: ; preds = %5, %10
%9 = tail call i32 @write(i32 %0, i8* %7, i64 %6)
switch i32 %9, label %16 [
i32 0, label %21
i32 -1, label %10
]
10: ; preds = %8
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
br i1 %13, label %8, label %14
14: ; preds = %10
%15 = tail call i32 @warn(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %21
16: ; preds = %8
%17 = sext i32 %9 to i64
%18 = sub i64 %6, %17
%19 = getelementptr inbounds i8, i8* %7, i64 %17
%20 = icmp eq i64 %18, 0
br i1 %20, label %21, label %5
21: ; preds = %16, %8, %3, %14
%22 = phi i32 [ -1, %14 ], [ 0, %3 ], [ %9, %8 ], [ 0, %16 ]
ret i32 %22
}