#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 */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int EINTR;
int errno;
int sendto(int, char const *, int, int /*<<< orphan*/, struct sockaddr *, int);
int BasSockUdpSend(int sock, const char *buf, int size,
                   struct sockaddr_in *dest) {
  int res;
  int code;
  do {
    res = sendto(sock, buf, size, 0, (struct sockaddr *)dest, sizeof(*dest));
    if (res < 0)
      code = errno;
    else
      code = 0;
  } while (code == EINTR);
  return res;
}


x86 assembly (clang, -O0):
<BasSockUdpSend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    115f <BasSockUdpSend+0x4f>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    1166 <BasSockUdpSend+0x56>
movl   $0x0,-0x28(%rbp)
jmp    116b <BasSockUdpSend+0x5b>
mov    -0x28(%rbp),%eax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%eax
je     1126 <BasSockUdpSend+0x16>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BasSockUdpSend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb3(%rip),%r12
mov    0x2ea4(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x4,%r9d
call   1030 <sendto@plt>
mov    %eax,%ecx
sar    $0x1f,%ecx
and    (%r12),%ecx
cmp    0x0(%r13),%ecx
je     1140 <BasSockUdpSend+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@EINTR = global i32 0
define i32 @BasSockUdpSend(i32 %0, i8* %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %8
br label %11
11: ; preds = %24, %4
%12 = load i32, i32* %5
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%16 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%17 = call i32 @sendto(i32 %12, i8* %13, i32 %14, i32 0, %struct.sockaddr* %16, i32 4)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = load i32, i32* @errno
store i32 %21, i32* %10
br label %23
22: ; preds = %11
store i32 0, i32* %10
br label %23
23: ; preds = %22, %20
br label %24
24: ; preds = %23
%25 = load i32, i32* %10
%26 = load i32, i32* @EINTR
%27 = icmp eq i32 %25, %26
br i1 %27, label %11, label %28
28: ; preds = %24
%29 = load i32, i32* %9
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@EINTR = global i32 0
define i32 @BasSockUdpSend(i32 %0, i8* %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %6
6: ; preds = %6, %4
%7 = tail call i32 @sendto(i32 %0, i8* %1, i32 %2, i32 0, %struct.sockaddr* %5, i32 4)
%8 = icmp slt i32 %7, 0
%9 = load i32, i32* @errno
%10 = select i1 %8, i32 %9, i32 0
%11 = load i32, i32* @EINTR
%12 = icmp eq i32 %10, %11
br i1 %12, label %6, label %13
13: ; preds = %6
ret i32 %7
}