#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*/ wmem_size;
struct sockaddr_storage {
  int dummy;
};
struct addrinfo {
  int ai_family;
  int ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_SNDBUF;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
scalar_t__ geteuid();
int /*<<< orphan*/ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(struct sockaddr_storage *, int /*<<< orphan*/, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned int *, int);
int socket(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int Unicast_send_socket(const char *hostname, const char *sendport, int family,
                        unsigned int wmem_size, struct sockaddr_storage *addr,
                        int *addrlen) {
  struct addrinfo hints, *res, *ressave;
  int n, sockfd;
  unsigned int wmem_actual;
  socklen_t optlen;
  if (!hostname || !sendport) {
    fprintf(stderr, "hostname and listen port required!\n");
    syslog(LOG_ERR, "hostname and listen port required!\n");
    return -1;
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = family;
  hints.ai_socktype = SOCK_DGRAM;
  n = getaddrinfo(hostname, sendport, &hints, &res);
  if (n < 0) {
    fprintf(stderr, "getaddrinfo error: [%s]\n", strerror(errno));
    return -1;
  }
  ressave = res;
  sockfd = -1;
  while (res) {
    sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (!(sockfd < 0)) {
      if (connect(sockfd, res->ai_addr, res->ai_addrlen) == 0) {
        close(sockfd);
        sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
        break;
      }
      close(sockfd);
      sockfd = -1;
    }
    res = res->ai_next;
  }
  if (sockfd < 0) {
    freeaddrinfo(ressave);
    fprintf(stderr,
            "Send socket error: could not open the requested socket: %s\n",
            strerror(errno));
    syslog(LOG_ERR,
           "Send socket error: could not open the requested socket: %s\n",
           strerror(errno));
    return -1;
  }
  *addrlen = res->ai_addrlen;
  memcpy(addr, res->ai_addr, res->ai_addrlen);
  freeaddrinfo(ressave);
  if (wmem_size > 0) {
    if (geteuid() == 0) {
      setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &wmem_size, sizeof(wmem_size));
      getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &wmem_actual, &optlen);
      if (wmem_size != wmem_actual) {
        printf("Warning: Socket write buffer size requested: %u set: %u\n",
               wmem_size, wmem_actual);
      }
    } else {
      printf("Warning: Socket buffer size can only be changed by root!\n");
    }
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<Unicast_send_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1217 <Unicast_send_socket+0x37>
cmpq   $0x0,-0x18(%rbp)
jne    1251 <Unicast_send_socket+0x71>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14bf <Unicast_send_socket+0x2df>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jge    12cf <Unicast_send_socket+0xef>
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14bf <Unicast_send_socket+0x2df>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0xffffffff,-0x68(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1378 <Unicast_send_socket+0x198>
mov    -0x58(%rbp),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    0x1c(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jl     1367 <Unicast_send_socket+0x187>
mov    -0x68(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jne    1358 <Unicast_send_socket+0x178>
mov    -0x68(%rbp),%edi
call   1070 <close@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    0x1c(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x68(%rbp)
jmp    1378 <Unicast_send_socket+0x198>
mov    -0x68(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x68(%rbp)
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    12de <Unicast_send_socket+0xfe>
cmpl   $0x0,-0x68(%rbp)
jge    13f3 <Unicast_send_socket+0x213>
mov    -0x60(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    0x2c36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    %rax,%rdx
lea    0xc8b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2bf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x78(%rbp),%edi
mov    %rax,%rdx
lea    0xc5d(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14bf <Unicast_send_socket+0x2df>
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%edx
call   10a0 <memcpy@plt>
mov    -0x60(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
cmpl   $0x0,-0x20(%rbp)
jbe    14b9 <Unicast_send_socket+0x2d9>
mov    $0x0,%al
call   1060 <geteuid@plt>
cmp    $0x0,%rax
jne    14a6 <Unicast_send_socket+0x2c6>
mov    -0x68(%rbp),%edi
mov    0x2ba3(%rip),%rax
mov    (%rax),%esi
mov    0x2b92(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x68(%rbp),%edi
mov    0x2b7f(%rip),%rax
mov    (%rax),%esi
mov    0x2b6e(%rip),%rax
mov    (%rax),%edx
lea    -0x6c(%rbp),%rcx
lea    -0x70(%rbp),%r8
call   1080 <getsockopt@plt>
mov    -0x20(%rbp),%eax
cmp    -0x6c(%rbp),%eax
je     14a1 <Unicast_send_socket+0x2c1>
mov    -0x20(%rbp),%esi
mov    -0x6c(%rbp),%edx
lea    0xbdf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14b4 <Unicast_send_socket+0x2d4>
lea    0xc05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14b9 <Unicast_send_socket+0x2d9>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Unicast_send_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %ecx,0x10(%rsp)
test   %rdi,%rdi
je     1334 <Unicast_send_socket+0x144>
mov    %rsi,%rbp
test   %rsi,%rsi
je     1334 <Unicast_send_socket+0x144>
mov    %r9,%r15
mov    %ecx,%r13d
mov    %edx,%r12d
mov    %rdi,%rbx
mov    %r8,0x18(%rsp)
lea    0x28(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    %r12d,0x28(%rsp)
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x44(%rsp)
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
js     13be <Unicast_send_socket+0x1ce>
mov    0x8(%rsp),%r12
test   %r12,%r12
je     1366 <Unicast_send_socket+0x176>
mov    %r12,%rax
jmp    1297 <Unicast_send_socket+0xa7>
nopl   0x0(%rax)
mov    0x8(%rsp),%rax
mov    0x10(%rax),%rax
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1366 <Unicast_send_socket+0x176>
mov    0x1c(%rax),%esi
mov    (%rax),%edi
mov    0x18(%rax),%edx
call   1110 <socket@plt>
test   %eax,%eax
js     1280 <Unicast_send_socket+0x90>
mov    %eax,%ebx
mov    0x8(%rsp),%rax
mov    0x4(%rax),%edx
mov    0x8(%rax),%esi
mov    %ebx,%edi
call   10d0 <connect@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   1080 <close@plt>
test   %rbp,%rbp
jne    1280 <Unicast_send_socket+0x90>
mov    0x8(%rsp),%rax
mov    0x1c(%rax),%esi
mov    (%rax),%edi
mov    0x18(%rax),%edx
call   1110 <socket@plt>
test   %eax,%eax
js     1366 <Unicast_send_socket+0x176>
mov    %eax,%ebp
mov    0x8(%rsp),%rax
mov    0x4(%rax),%ecx
mov    %ecx,(%r15)
mov    0x4(%rax),%edx
mov    0x8(%rax),%esi
mov    0x18(%rsp),%rdi
call   10b0 <memcpy@plt>
mov    %r12,%rdi
call   1100 <freeaddrinfo@plt>
test   %r13d,%r13d
je     13ed <Unicast_send_socket+0x1fd>
xor    %eax,%eax
call   1070 <geteuid@plt>
test   %rax,%rax
je     13fe <Unicast_send_socket+0x20e>
lea    0xd88(%rip),%rdi
call   1030 <puts@plt>
jmp    13ed <Unicast_send_socket+0x1fd>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
lea    0xcbc(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <syslog@plt>
jmp    13e8 <Unicast_send_socket+0x1f8>
mov    %r12,%rdi
call   1100 <freeaddrinfo@plt>
mov    0x2c53(%rip),%rax
mov    (%rax),%ebx
mov    0x2c42(%rip),%r14
mov    (%r14),%edi
call   10f0 <strerror@plt>
lea    0xcb0(%rip),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x2c0d(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%edi
call   10f0 <strerror@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <syslog@plt>
jmp    13e8 <Unicast_send_socket+0x1f8>
mov    0x2c03(%rip),%rax
mov    (%rax),%ebx
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc48(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2be3(%rip),%r14
mov    (%r14),%esi
mov    0x2bd1(%rip),%rbx
mov    (%rbx),%edx
lea    0x10(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    (%r14),%esi
mov    (%rbx),%edx
lea    0x14(%rsp),%rcx
lea    0x24(%rsp),%r8
mov    %ebp,%edi
call   1090 <getsockopt@plt>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
cmp    %edx,%esi
je     13ed <Unicast_send_socket+0x1fd>
lea    0xc2d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    13ed <Unicast_send_socket+0x1fd>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.addrinfo = type { i32, i32, i32, %struct.addrinfo*, i32, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"hostname and listen port required!\0A\00"
@LOG_ERR = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [25 x i8] c"getaddrinfo error: [%s]\0A\00"
@errno = global i32 0
@.str.2 = [60 x i8] c"Send socket error: could not open the requested socket: %s\0A\00"
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@.str.3 = [57 x i8] c"Warning: Socket write buffer size requested: %u set: %u\0A\00"
@.str.4 = [58 x i8] c"Warning: Socket buffer size can only be changed by root!\0A\00"
define i32 @Unicast_send_socket(i8* %0, i8* %1, i32 %2, i32 %3, %struct.sockaddr_storage* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_storage*
%13 = alloca i32*
%14 = alloca %struct.addrinfo
%15 = alloca %struct.addrinfo*
%16 = alloca %struct.addrinfo*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store %struct.sockaddr_storage* %4, %struct.sockaddr_storage** %12
store i32* %5, i32** %13
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %6
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %31, label %26
26: ; preds = %23, %6
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @LOG_ERR
%30 = call i32 (i32, i8*, ...) @syslog(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %7
br label %151
31: ; preds = %23
%32 = call i32 @memset(%struct.addrinfo* %14, i32 0, i32 32)
%33 = load i32, i32* %10
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* @SOCK_DGRAM
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 5
store i32 %35, i32* %36
%37 = load i8*, i8** %8
%38 = load i8*, i8** %9
%39 = call i32 @getaddrinfo(i8* %37, i8* %38, %struct.addrinfo* %14, %struct.addrinfo** %15)
store i32 %39, i32* %17
%40 = load i32, i32* %17
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %31
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %45)
store i32 -1, i32* %7
br label %151
47: ; preds = %31
%48 = load %struct.addrinfo*, %struct.addrinfo** %15
store %struct.addrinfo* %48, %struct.addrinfo** %16
store i32 -1, i32* %18
br label %49
49: ; preds = %91, %47
%50 = load %struct.addrinfo*, %struct.addrinfo** %15
%51 = icmp ne %struct.addrinfo* %50, null
br i1 %51, label %52, label %95
52: ; preds = %49
%53 = load %struct.addrinfo*, %struct.addrinfo** %15
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %15
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 5
%58 = load i32, i32* %57
%59 = load %struct.addrinfo*, %struct.addrinfo** %15
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 4
%61 = load i32, i32* %60
%62 = call i32 @socket(i32 %55, i32 %58, i32 %61)
store i32 %62, i32* %18
%63 = load i32, i32* %18
%64 = icmp slt i32 %63, 0
br i1 %64, label %91, label %65
65: ; preds = %52
%66 = load i32, i32* %18
%67 = load %struct.addrinfo*, %struct.addrinfo** %15
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %67, i32 0, i32 2
%69 = load i32, i32* %68
%70 = load %struct.addrinfo*, %struct.addrinfo** %15
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %70, i32 0, i32 1
%72 = load i32, i32* %71
%73 = call i64 @connect(i32 %66, i32 %69, i32 %72)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %88
75: ; preds = %65
%76 = load i32, i32* %18
%77 = call i32 @close(i32 %76)
%78 = load %struct.addrinfo*, %struct.addrinfo** %15
%79 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %78, i32 0, i32 0
%80 = load i32, i32* %79
%81 = load %struct.addrinfo*, %struct.addrinfo** %15
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %81, i32 0, i32 5
%83 = load i32, i32* %82
%84 = load %struct.addrinfo*, %struct.addrinfo** %15
%85 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %84, i32 0, i32 4
%86 = load i32, i32* %85
%87 = call i32 @socket(i32 %80, i32 %83, i32 %86)
store i32 %87, i32* %18
br label %95
88: ; preds = %65
%89 = load i32, i32* %18
%90 = call i32 @close(i32 %89)
store i32 -1, i32* %18
br label %91
91: ; preds = %88, %52
%92 = load %struct.addrinfo*, %struct.addrinfo** %15
%93 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %92, i32 0, i32 3
%94 = load %struct.addrinfo*, %struct.addrinfo** %93
store %struct.addrinfo* %94, %struct.addrinfo** %15
br label %49
95: ; preds = %75, %49
%96 = load i32, i32* %18
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %109
98: ; preds = %95
%99 = load %struct.addrinfo*, %struct.addrinfo** %16
%100 = call i32 @freeaddrinfo(%struct.addrinfo* %99)
%101 = load i32, i32* @stderr
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i8* %103)
%105 = load i32, i32* @LOG_ERR
%106 = load i32, i32* @errno
%107 = call i8* @strerror(i32 %106)
%108 = call i32 (i32, i8*, ...) @syslog(i32 %105, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i8* %107)
store i32 -1, i32* %7
br label %151
109: ; preds = %95
%110 = load %struct.addrinfo*, %struct.addrinfo** %15
%111 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %110, i32 0, i32 1
%112 = load i32, i32* %111
%113 = load i32*, i32** %13
store i32 %112, i32* %113
%114 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %12
%115 = load %struct.addrinfo*, %struct.addrinfo** %15
%116 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %115, i32 0, i32 2
%117 = load i32, i32* %116
%118 = load %struct.addrinfo*, %struct.addrinfo** %15
%119 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %118, i32 0, i32 1
%120 = load i32, i32* %119
%121 = call i32 @memcpy(%struct.sockaddr_storage* %114, i32 %117, i32 %120)
%122 = load %struct.addrinfo*, %struct.addrinfo** %16
%123 = call i32 @freeaddrinfo(%struct.addrinfo* %122)
%124 = load i32, i32* %11
%125 = icmp ugt i32 %124, 0
br i1 %125, label %126, label %149
126: ; preds = %109
%127 = call i64 (...) @geteuid()
%128 = icmp eq i64 %127, 0
br i1 %128, label %129, label %146
129: ; preds = %126
%130 = load i32, i32* %18
%131 = load i32, i32* @SOL_SOCKET
%132 = load i32, i32* @SO_SNDBUF
%133 = call i32 @setsockopt(i32 %130, i32 %131, i32 %132, i32* %11, i32 4)
%134 = load i32, i32* %18
%135 = load i32, i32* @SOL_SOCKET
%136 = load i32, i32* @SO_SNDBUF
%137 = call i32 @getsockopt(i32 %134, i32 %135, i32 %136, i32* %19, i32* %20)
%138 = load i32, i32* %11
%139 = load i32, i32* %19
%140 = icmp ne i32 %138, %139
br i1 %140, label %141, label %145
141: ; preds = %129
%142 = load i32, i32* %11
%143 = load i32, i32* %19
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 %142, i32 %143)
br label %145
145: ; preds = %141, %129
br label %148
146: ; preds = %126
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0))
br label %148
148: ; preds = %146, %145
br label %149
149: ; preds = %148, %109
%150 = load i32, i32* %18
store i32 %150, i32* %7
br label %151
151: ; preds = %149, %98, %42, %26
%152 = load i32, i32* %7
ret i32 %152
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.addrinfo = type { i32, i32, i32, %struct.addrinfo*, i32, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"hostname and listen port required!\0A\00"
@LOG_ERR = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [25 x i8] c"getaddrinfo error: [%s]\0A\00"
@errno = global i32 0
@.str.2 = [60 x i8] c"Send socket error: could not open the requested socket: %s\0A\00"
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@.str.3 = [57 x i8] c"Warning: Socket write buffer size requested: %u set: %u\0A\00"
@str = [57 x i8] c"Warning: Socket buffer size can only be changed by root!\00"
define i32 @Unicast_send_socket(i8* %0, i8* %1, i32 %2, i32 %3, %struct.sockaddr_storage* %4, i32* nocapture writeonly %5) {
%7 = alloca i32
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca i32
%11 = alloca i32
store i32 %3, i32* %7
%12 = bitcast %struct.addrinfo* %8 to i8*
%13 = bitcast %struct.addrinfo** %9 to i8*
%14 = bitcast i32* %10 to i8*
%15 = bitcast i32* %11 to i8*
%16 = icmp ne i8* %0, null
%17 = icmp ne i8* %1, null
%18 = and i1 %16, %17
br i1 %18, label %24, label %19
19: ; preds = %6
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @LOG_ERR
%23 = tail call i32 (i32, i8*, ...) @syslog(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %110
24: ; preds = %6
%25 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 32)
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i64 0, i32 0
store i32 %2, i32* %26
%27 = load i32, i32* @SOCK_DGRAM
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i64 0, i32 5
store i32 %27, i32* %28
%29 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %8, %struct.addrinfo** %9)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %110
36: ; preds = %24
%37 = load %struct.addrinfo*, %struct.addrinfo** %9
%38 = icmp eq %struct.addrinfo* %37, null
br i1 %38, label %73, label %39
39: ; preds = %36, %58
%40 = phi %struct.addrinfo* [ %61, %58 ], [ %37, %36 ]
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 5
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 4
%46 = load i32, i32* %45
%47 = call i32 @socket(i32 %42, i32 %44, i32 %46)
%48 = icmp slt i32 %47, 0
br i1 %48, label %58, label %49
49: ; preds = %39
%50 = load %struct.addrinfo*, %struct.addrinfo** %9
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i64 0, i32 2
%52 = load i32, i32* %51
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i64 0, i32 1
%54 = load i32, i32* %53
%55 = call i64 @connect(i32 %47, i32 %52, i32 %54)
%56 = icmp eq i64 %55, 0
%57 = call i32 @close(i32 %47)
br i1 %56, label %63, label %58
58: ; preds = %49, %39
%59 = load %struct.addrinfo*, %struct.addrinfo** %9
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i64 0, i32 3
%61 = load %struct.addrinfo*, %struct.addrinfo** %60
store %struct.addrinfo* %61, %struct.addrinfo** %9
%62 = icmp eq %struct.addrinfo* %61, null
br i1 %62, label %73, label %39
63: ; preds = %49
%64 = load %struct.addrinfo*, %struct.addrinfo** %9
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %64, i64 0, i32 0
%66 = load i32, i32* %65
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %64, i64 0, i32 5
%68 = load i32, i32* %67
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %64, i64 0, i32 4
%70 = load i32, i32* %69
%71 = call i32 @socket(i32 %66, i32 %68, i32 %70)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %83
73: ; preds = %58, %36, %63
%74 = call i32 @freeaddrinfo(%struct.addrinfo* %37)
%75 = load i32, i32* @stderr
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i8* %77)
%79 = load i32, i32* @LOG_ERR
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i32, i8*, ...) @syslog(i32 %79, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i8* %81)
br label %110
83: ; preds = %63
%84 = load %struct.addrinfo*, %struct.addrinfo** %9
%85 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %84, i64 0, i32 1
%86 = load i32, i32* %85
store i32 %86, i32* %5
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %84, i64 0, i32 2
%88 = load i32, i32* %87
%89 = load i32, i32* %85
%90 = call i32 @memcpy(%struct.sockaddr_storage* %4, i32 %88, i32 %89)
%91 = call i32 @freeaddrinfo(%struct.addrinfo* %37)
%92 = icmp eq i32 %3, 0
br i1 %92, label %110, label %93
93: ; preds = %83
%94 = call i64 (...) @geteuid()
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %108
96: ; preds = %93
%97 = load i32, i32* @SOL_SOCKET
%98 = load i32, i32* @SO_SNDBUF
%99 = call i32 @setsockopt(i32 %71, i32 %97, i32 %98, i32* %7, i32 4)
%100 = load i32, i32* @SOL_SOCKET
%101 = load i32, i32* @SO_SNDBUF
%102 = call i32 @getsockopt(i32 %71, i32 %100, i32 %101, i32* %10, i32* %11)
%103 = load i32, i32* %7
%104 = load i32, i32* %10
%105 = icmp eq i32 %103, %104
br i1 %105, label %110, label %106
106: ; preds = %96
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 %103, i32 %104)
br label %110
108: ; preds = %93
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %110
110: ; preds = %83, %96, %106, %108, %73, %31, %19
%111 = phi i32 [ -1, %31 ], [ -1, %73 ], [ -1, %19 ], [ %71, %108 ], [ %71, %106 ], [ %71, %96 ], [ %71, %83 ]
ret i32 %111
}