#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 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int sendto(int, char const *, int, int /*<<< orphan*/, struct sockaddr *, int);
int udp_send(int sock, const char *data, int size, struct sockaddr *sockaddr) {
  int sendSize;
  sendSize = sendto(sock, data, size, 0, sockaddr, sizeof(*sockaddr));
  if (sendSize != size) {
    perror("sendto() failed.");
    return -1;
  }
  return sendSize;
}


x86 assembly (clang, -O0):
<udp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%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)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1178 <udp_send+0x58>
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117e <udp_send+0x5e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_send>:
push   %rbx
mov    %rcx,%r8
mov    %edx,%ebx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
cmp    %ebx,%eax
jne    113b <udp_send+0x1b>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xebe(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1137 <udp_send+0x17>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"sendto() failed.\00"
define i32 @udp_send(i32 %0, i8* %1, i32 %2, %struct.sockaddr* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sockaddr*
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store %struct.sockaddr* %3, %struct.sockaddr** %9
%11 = load i32, i32* %6
%12 = load i8*, i8** %7
%13 = load i32, i32* %8
%14 = load %struct.sockaddr*, %struct.sockaddr** %9
%15 = call i32 @sendto(i32 %11, i8* %12, i32 %13, i32 0, %struct.sockaddr* %14, i32 4)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = load i32, i32* %8
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %23
21: ; preds = %4
%22 = load i32, i32* %10
store i32 %22, i32* %5
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"sendto() failed.\00"
define i32 @udp_send(i32 %0, i8* %1, i32 %2, %struct.sockaddr* %3) {
%5 = tail call i32 @sendto(i32 %0, i8* %1, i32 %2, i32 0, %struct.sockaddr* %3, i32 4)
%6 = icmp eq i32 %5, %2
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %4, %7
%10 = phi i32 [ -1, %7 ], [ %2, %4 ]
ret i32 %10
}