#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 /*<<< orphan*/ uint8_t;
typedef int ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ EWOULDBLOCK;
scalar_t__ errno;
int send(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int voip_write_data(int fd, uint8_t *bytes, int len) {
  ssize_t n = 0;
  do {
    n = send(fd, bytes, len, 0);
  } while (n == -1 && errno == EINTR);
  if (n < 0) {
    if (errno != EAGAIN && errno != EWOULDBLOCK) {
      return -1;
    }
    return 0;
  } else {
    return (int)n;
  }
}


x86 assembly (clang, -O0):
<voip_write_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jne    1166 <voip_write_data+0x56>
mov    0x2e8d(%rip),%rax
mov    (%rax),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1129 <voip_write_data+0x19>
cmpl   $0x0,-0x18(%rbp)
jge    11c7 <voip_write_data+0xb7>
mov    0x2e5e(%rip),%rax
mov    (%rax),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11bb <voip_write_data+0xab>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
je     11bb <voip_write_data+0xab>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <voip_write_data+0xbd>
movl   $0x0,-0x4(%rbp)
jmp    11cd <voip_write_data+0xbd>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<voip_write_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb9(%rip),%r15
mov    0x2ea2(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    (%r15),%rcx
cmp    $0xffffffff,%eax
jne    114d <voip_write_data+0x3d>
cmp    (%r12),%rcx
je     1130 <voip_write_data+0x20>
test   %eax,%eax
jns    1172 <voip_write_data+0x62>
mov    0x2e68(%rip),%rax
cmp    (%rax),%rcx
setne  %al
mov    0x2e73(%rip),%rdx
cmp    (%rdx),%rcx
setne  %cl
and    %al,%cl
movzbl %cl,%eax
neg    %eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
define i32 @voip_write_data(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %21, %3
%10 = load i32, i32* %5
%11 = load i32*, i32** %6
%12 = load i32, i32* %7
%13 = call i32 @send(i32 %10, i32* %11, i32 %12, i32 0)
store i32 %13, i32* %8
br label %14
14: ; preds = %9
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
br label %21
21: ; preds = %17, %14
%22 = phi i1 [ false, %14 ], [ %20, %17 ]
br i1 %22, label %9, label %23
23: ; preds = %21
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i64, i64* @errno
%28 = load i64, i64* @EAGAIN
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i64, i64* @errno
%32 = load i64, i64* @EWOULDBLOCK
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 -1, i32* %4
br label %38
35: ; preds = %30, %26
store i32 0, i32* %4
br label %38
36: ; preds = %23
%37 = load i32, i32* %8
store i32 %37, i32* %4
br label %38
38: ; preds = %36, %35, %34
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
define i32 @voip_write_data(i32 %0, i32* %1, i32 %2) {
br label %4
4: ; preds = %4, %3
%5 = tail call i32 @send(i32 %0, i32* %1, i32 %2, i32 0)
%6 = icmp eq i32 %5, -1
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINTR
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %4, label %11
11: ; preds = %4
%12 = icmp slt i32 %5, 0
br i1 %12, label %13, label %20
13: ; preds = %11
%14 = load i64, i64* @EAGAIN
%15 = icmp ne i64 %7, %14
%16 = load i64, i64* @EWOULDBLOCK
%17 = icmp ne i64 %7, %16
%18 = select i1 %15, i1 %17, i1 false
%19 = sext i1 %18 to i32
br label %20
20: ; preds = %13, %11
%21 = phi i32 [ %5, %11 ], [ %19, %13 ]
ret i32 %21
}