#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char const *, char const *, struct addrinfo *,
                       struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int sendto(int, char const *, int const, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int usend_once(const char *target, const char *target_port, const char *data,
               const int DATA_SIZE) {
  struct addrinfo hints, *servinfo;
  int sockfd;
  int retbytes;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  if (getaddrinfo(target, target_port, &hints, &servinfo) != 0) {
    return -1;
  }
  if ((sockfd = socket(servinfo->ai_family, servinfo->ai_socktype,
                       servinfo->ai_protocol)) == -1) {
    freeaddrinfo(servinfo);
    return -2;
  }
  if ((retbytes = sendto(sockfd, data, DATA_SIZE, 0, servinfo->ai_addr,
                         servinfo->ai_addrlen)) == -1) {
    freeaddrinfo(servinfo);
    return -3;
  }
  freeaddrinfo(servinfo);
  close(sockfd);
  return retbytes;
}


x86 assembly (clang, -O0):
<usend_once>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1060 <getaddrinfo@plt>
cmp    $0x0,%rax
je     11ca <usend_once+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    125d <usend_once+0xfd>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   1080 <socket@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
jne    1205 <usend_once+0xa5>
mov    -0x40(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    125d <usend_once+0xfd>
mov    -0x44(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x40(%rbp),%rax
mov    (%rax),%r9d
xor    %ecx,%ecx
call   1040 <sendto@plt>
mov    %eax,-0x48(%rbp)
cmp    $0xffffffff,%eax
jne    1246 <usend_once+0xe6>
mov    -0x40(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    125d <usend_once+0xfd>
mov    -0x40(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
mov    -0x44(%rbp),%edi
call   1050 <close@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usend_once>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1060 <getaddrinfo@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11d0 <usend_once+0x70>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1080 <socket@plt>
mov    (%rsp),%rdi
cmp    $0xffffffff,%eax
je     121c <usend_once+0xbc>
mov    %eax,%ebp
mov    (%rdi),%r9d
mov    0x4(%rdi),%r8d
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1040 <sendto@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1070 <freeaddrinfo@plt>
cmp    $0xffffffff,%ebx
je     1228 <usend_once+0xc8>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11c1 <usend_once+0x61>
call   1070 <freeaddrinfo@plt>
mov    $0xfffffffe,%ebx
jmp    11c1 <usend_once+0x61>
mov    $0xfffffffd,%ebx
jmp    11c1 <usend_once+0x61>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @usend_once(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%14 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 20)
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_DGRAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %17, i32* %18
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = call i64 @getaddrinfo(i8* %19, i8* %20, %struct.addrinfo* %10, %struct.addrinfo** %11)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %4
store i32 -1, i32* %5
br label %60
24: ; preds = %4
%25 = load %struct.addrinfo*, %struct.addrinfo** %11
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i32 0, i32 4
%27 = load i32, i32* %26
%28 = load %struct.addrinfo*, %struct.addrinfo** %11
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i32 0, i32 3
%30 = load i32, i32* %29
%31 = load %struct.addrinfo*, %struct.addrinfo** %11
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 2
%33 = load i32, i32* %32
%34 = call i32 @socket(i32 %27, i32 %30, i32 %33)
store i32 %34, i32* %12
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %24
%37 = load %struct.addrinfo*, %struct.addrinfo** %11
%38 = call i32 @freeaddrinfo(%struct.addrinfo* %37)
store i32 -2, i32* %5
br label %60
39: ; preds = %24
%40 = load i32, i32* %12
%41 = load i8*, i8** %8
%42 = load i32, i32* %9
%43 = load %struct.addrinfo*, %struct.addrinfo** %11
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = load %struct.addrinfo*, %struct.addrinfo** %11
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @sendto(i32 %40, i8* %41, i32 %42, i32 0, i32 %45, i32 %48)
store i32 %49, i32* %13
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %39
%52 = load %struct.addrinfo*, %struct.addrinfo** %11
%53 = call i32 @freeaddrinfo(%struct.addrinfo* %52)
store i32 -3, i32* %5
br label %60
54: ; preds = %39
%55 = load %struct.addrinfo*, %struct.addrinfo** %11
%56 = call i32 @freeaddrinfo(%struct.addrinfo* %55)
%57 = load i32, i32* %12
%58 = call i32 @close(i32 %57)
%59 = load i32, i32* %13
store i32 %59, i32* %5
br label %60
60: ; preds = %54, %51, %36, %23
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @usend_once(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = bitcast %struct.addrinfo* %5 to i8*
%8 = bitcast %struct.addrinfo** %6 to i8*
%9 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 20)
%10 = load i32, i32* @AF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_DGRAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
store i32 %12, i32* %13
%14 = call i64 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %5, %struct.addrinfo** %6)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %40
16: ; preds = %4
%17 = load %struct.addrinfo*, %struct.addrinfo** %6
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 @socket(i32 %19, i32 %21, i32 %23)
%25 = icmp eq i32 %24, -1
%26 = load %struct.addrinfo*, %struct.addrinfo** %6
br i1 %25, label %27, label %29
27: ; preds = %16
%28 = call i32 @freeaddrinfo(%struct.addrinfo* %26)
br label %40
29: ; preds = %16
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 1
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @sendto(i32 %24, i8* %2, i32 %3, i32 0, i32 %31, i32 %33)
%35 = icmp eq i32 %34, -1
%36 = load %struct.addrinfo*, %struct.addrinfo** %6
%37 = call i32 @freeaddrinfo(%struct.addrinfo* %36)
br i1 %35, label %40, label %38
38: ; preds = %29
%39 = call i32 @close(i32 %24)
br label %40
40: ; preds = %29, %4, %38, %27
%41 = phi i32 [ -2, %27 ], [ %34, %38 ], [ -1, %4 ], [ -3, %29 ]
ret i32 %41
}