#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_storage {
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef size_t ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ peerAddr;
typedef int /*<<< orphan*/ addrCriteria;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct sockaddr_storage *);
char *gai_strerror(int);
int /*<<< orphan*/ getSockName(int);
int getaddrinfo(char const *, char const *, struct sockaddr_storage *,
                struct sockaddr_storage **);
int /*<<< orphan*/ memset(struct sockaddr_storage *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printSocketAddress(struct sockaddr *);
size_t recvfrom(int, char *, size_t, int /*<<< orphan*/, struct sockaddr *,
                int *);
size_t sendto(int, char const *, size_t, int /*<<< orphan*/, struct sockaddr *,
              int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
size_t strlen(char const *);
int /*<<< orphan*/ sysError(char *);
int /*<<< orphan*/ usrError(char *);
int main(int argc, char **argv) {
  if (argc != 4)
    usrError("Usage:\t<Address> <Port> <String>");
  const char *address = argv[1];
  const char *port = argv[2];
  const char *string = argv[3];
  struct addrinfo addrCriteria;
  memset(&addrCriteria, 0, sizeof(addrCriteria));
  addrCriteria.ai_family = AF_UNSPEC;
  addrCriteria.ai_socktype = SOCK_DGRAM;
  addrCriteria.ai_protocol = IPPROTO_UDP;
  struct addrinfo *servAddr;
  int ret = getaddrinfo(address, port, &addrCriteria, &servAddr);
  if (ret != 0)
    sysError(gai_strerror(ret));
  int servSock =
      socket(servAddr->ai_family, servAddr->ai_socktype, servAddr->ai_protocol);
  if (servSock < 0)
    sysError("failed to create server");
  getSockName(servSock);
  size_t stringLen = strlen(string);
  ssize_t bytesSent = 0;
  bytesSent =
      sendto(servSock, string, stringLen, 0,
             (struct sockaddr *)servAddr->ai_addr, servAddr->ai_addrlen);
  if (bytesSent < 0)
    sysError("failed to send string");
  else if (bytesSent != stringLen)
    sysError("sent unexpected amount of data");
  fprintf(stdout, "sent %d bytes of data\n", bytesSent);
  fprintf(stdout, "string: %s\n", string);
  struct sockaddr_storage peerAddr;
  socklen_t peerLen = sizeof(peerAddr);
  memset(&peerAddr, 0, peerLen);
  char buff[stringLen];
  ssize_t bytesRcvd = 0;
  bytesRcvd = recvfrom(servSock, buff, stringLen, 0,
                       (struct sockaddr *)&peerAddr, &peerLen);
  if (bytesRcvd < 0)
    sysError("failed to get string");
  else if (bytesRcvd == 0)
    sysError("connection died prematurely");
  buff[bytesRcvd] = '\0';
  fprintf(stdout, "received %d bytes of data from ", bytesRcvd);
  printSocketAddress((struct sockaddr *)&peerAddr);
  freeaddrinfo(servAddr);
  close(servSock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     120f <main+0x2f>
lea    0xdf6(%rip),%rdi
call   1050 <usrError@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1299 <main+0xb9>
mov    -0x54(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    %rax,%rdi
call   1030 <sysError@plt>
mov    -0x50(%rbp),%rax
mov    0x18(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    12cc <main+0xec>
lea    0xd5a(%rip),%rdi
call   1030 <sysError@plt>
mov    -0x58(%rbp),%edi
call   10b0 <getSockName@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x58(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%r8
mov    -0x50(%rbp),%rax
mov    (%rax),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jae    132a <main+0x14a>
lea    0xd19(%rip),%rdi
call   1030 <sysError@plt>
jmp    1349 <main+0x169>
mov    -0x68(%rbp),%rax
cmp    -0x60(%rbp),%rax
je     1344 <main+0x164>
lea    0xd10(%rip),%rdi
call   1030 <sysError@plt>
jmp    1349 <main+0x169>
mov    0x2c80(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    (%rax),%edi
mov    -0x68(%rbp),%rdx
lea    0xd0a(%rip),%rsi
xor    %eax,%eax
mov    %eax,-0xb4(%rbp)
mov    %al,-0xb5(%rbp)
call   10a0 <fprintf@plt>
mov    -0xc0(%rbp),%rcx
mov    -0xb5(%rbp),%al
mov    (%rcx),%edi
mov    -0x28(%rbp),%rdx
lea    0xcf4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0xb4(%rbp),%esi
movl   $0x20,-0x8c(%rbp)
mov    -0x8c(%rbp),%edx
lea    -0x88(%rbp),%rdi
call   1070 <memset@plt>
mov    -0x60(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0xb0(%rbp)
mov    %rsi,%rsp
mov    %rax,-0xa0(%rbp)
movq   $0x0,-0xa8(%rbp)
mov    -0x58(%rbp),%edi
mov    -0x60(%rbp),%rdx
lea    -0x88(%rbp),%r8
xor    %ecx,%ecx
lea    -0x8c(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jae    1435 <main+0x255>
lea    0xc66(%rip),%rdi
call   1030 <sysError@plt>
jmp    1454 <main+0x274>
cmpq   $0x0,-0xa8(%rbp)
jne    144f <main+0x26f>
lea    0xc5c(%rip),%rdi
call   1030 <sysError@plt>
jmp    1454 <main+0x274>
mov    -0xb0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%rdx
lea    0xc45(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    -0x88(%rbp),%rdi
call   10d0 <printSocketAddress@plt>
mov    -0x50(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    -0x58(%rbp),%edi
call   1090 <close@plt>
mov    -0x98(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
je     1205 <main+0x25>
lea    0xe00(%rip),%rdi
call   1050 <usrError@plt>
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%r12
mov    0x18(%rbx),%r14
lea    -0x58(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
lea    -0x30(%rbp),%rcx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
je     126d <main+0x8d>
mov    %eax,%edi
call   1060 <gai_strerror@plt>
mov    %rax,%rdi
call   1030 <sysError@plt>
mov    -0x30(%rbp),%rax
mov    0x18(%rax),%edi
mov    0x10(%rax),%edx
mov    0x14(%rax),%esi
call   1100 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    1292 <main+0xb2>
lea    0xd94(%rip),%rdi
call   1030 <sysError@plt>
mov    %r15d,%edi
call   10b0 <getSockName@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%r8
mov    (%rax),%r9d
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %rax,%rbx
cmp    %r12,%rax
je     12d4 <main+0xf4>
lea    0xd6a(%rip),%rdi
call   1030 <sysError@plt>
mov    0x2cf5(%rip),%r13
mov    0x0(%r13),%edi
lea    0xd72(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xd74(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
movl   $0x20,-0x34(%rbp)
lea    -0x78(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    %rsp,%r13
mov    %rsp,%rbx
mov    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x34(%rbp),%r9
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
mov    %r14,%r8
call   10c0 <recvfrom@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1361 <main+0x181>
lea    0xd1f(%rip),%rdi
call   1030 <sysError@plt>
movb   $0x0,(%rbx,%r14,1)
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
lea    0xd21(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    -0x78(%rbp),%rdi
call   10d0 <printSocketAddress@plt>
mov    -0x30(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    %r15d,%edi
call   1090 <close@plt>
mov    %r13,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
%struct.sockaddr_storage = type { i32, i64, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [33 x i8] c"Usage:\09<Address> <Port> <String>\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [24 x i8] c"failed to create server\00"
@.str.2 = [22 x i8] c"failed to send string\00"
@.str.3 = [31 x i8] c"sent unexpected amount of data\00"
@stdout = global i32 0
@.str.4 = [23 x i8] c"sent %d bytes of data\0A\00"
@.str.5 = [12 x i8] c"string: %s\0A\00"
@.str.6 = [21 x i8] c"failed to get string\00"
@.str.7 = [28 x i8] c"connection died prematurely\00"
@.str.8 = [32 x i8] c"received %d bytes of data from \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca %struct.sockaddr_storage
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 4
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @usrError(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
store i8* %27, i8** %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
store i8* %30, i8** %7
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
store i8* %33, i8** %8
%34 = bitcast %struct.addrinfo* %9 to %struct.sockaddr_storage*
%35 = call i32 @memset(%struct.sockaddr_storage* %34, i32 0, i32 32)
%36 = load i32, i32* @AF_UNSPEC
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 4
store i32 %36, i32* %37
%38 = load i32, i32* @SOCK_DGRAM
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 3
store i32 %38, i32* %39
%40 = load i32, i32* @IPPROTO_UDP
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 2
store i32 %40, i32* %41
%42 = load i8*, i8** %6
%43 = load i8*, i8** %7
%44 = bitcast %struct.addrinfo* %9 to %struct.sockaddr_storage*
%45 = bitcast %struct.addrinfo** %10 to %struct.sockaddr_storage**
%46 = call i32 @getaddrinfo(i8* %42, i8* %43, %struct.sockaddr_storage* %44, %struct.sockaddr_storage** %45)
store i32 %46, i32* %11
%47 = load i32, i32* %11
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %24
%50 = load i32, i32* %11
%51 = call i8* @gai_strerror(i32 %50)
%52 = call i32 @sysError(i8* %51)
br label %53
53: ; preds = %49, %24
%54 = load %struct.addrinfo*, %struct.addrinfo** %10
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 4
%56 = load i32, i32* %55
%57 = load %struct.addrinfo*, %struct.addrinfo** %10
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 3
%59 = load i32, i32* %58
%60 = load %struct.addrinfo*, %struct.addrinfo** %10
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i32 0, i32 2
%62 = load i32, i32* %61
%63 = call i32 @socket(i32 %56, i32 %59, i32 %62)
store i32 %63, i32* %12
%64 = load i32, i32* %12
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %53
%67 = call i32 @sysError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %68
68: ; preds = %66, %53
%69 = load i32, i32* %12
%70 = call i32 @getSockName(i32 %69)
%71 = load i8*, i8** %8
%72 = call i64 @strlen(i8* %71)
store i64 %72, i64* %13
store i64 0, i64* %14
%73 = load i32, i32* %12
%74 = load i8*, i8** %8
%75 = load i64, i64* %13
%76 = load %struct.addrinfo*, %struct.addrinfo** %10
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i32 0, i32 1
%78 = load i64, i64* %77
%79 = inttoptr i64 %78 to %struct.sockaddr*
%80 = load %struct.addrinfo*, %struct.addrinfo** %10
%81 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %80, i32 0, i32 0
%82 = load i32, i32* %81
%83 = call i64 @sendto(i32 %73, i8* %74, i64 %75, i32 0, %struct.sockaddr* %79, i32 %82)
store i64 %83, i64* %14
%84 = load i64, i64* %14
%85 = icmp ult i64 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %68
%87 = call i32 @sysError(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %95
88: ; preds = %68
%89 = load i64, i64* %14
%90 = load i64, i64* %13
%91 = icmp ne i64 %89, %90
br i1 %91, label %92, label %94
92: ; preds = %88
%93 = call i32 @sysError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %94
94: ; preds = %92, %88
br label %95
95: ; preds = %94, %86
%96 = load i32, i32* @stdout
%97 = load i64, i64* %14
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i64 %97)
%99 = load i32, i32* @stdout
%100 = load i8*, i8** %8
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %100)
store i32 32, i32* %16
%102 = load i32, i32* %16
%103 = call i32 @memset(%struct.sockaddr_storage* %15, i32 0, i32 %102)
%104 = load i64, i64* %13
%105 = call i8* @llvm.stacksave()
store i8* %105, i8** %17
%106 = alloca i8, i64 %104
store i64 %104, i64* %18
store i64 0, i64* %19
%107 = load i32, i32* %12
%108 = load i64, i64* %13
%109 = bitcast %struct.sockaddr_storage* %15 to %struct.sockaddr*
%110 = call i64 @recvfrom(i32 %107, i8* %106, i64 %108, i32 0, %struct.sockaddr* %109, i32* %16)
store i64 %110, i64* %19
%111 = load i64, i64* %19
%112 = icmp ult i64 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %95
%114 = call i32 @sysError(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %121
115: ; preds = %95
%116 = load i64, i64* %19
%117 = icmp eq i64 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %115
%119 = call i32 @sysError(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %120
120: ; preds = %118, %115
br label %121
121: ; preds = %120, %113
%122 = load i64, i64* %19
%123 = getelementptr inbounds i8, i8* %106, i64 %122
store i8 0, i8* %123
%124 = load i32, i32* @stdout
%125 = load i64, i64* %19
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i64 %125)
%127 = bitcast %struct.sockaddr_storage* %15 to %struct.sockaddr*
%128 = call i32 @printSocketAddress(%struct.sockaddr* %127)
%129 = load %struct.addrinfo*, %struct.addrinfo** %10
%130 = bitcast %struct.addrinfo* %129 to %struct.sockaddr_storage*
%131 = call i32 @freeaddrinfo(%struct.sockaddr_storage* %130)
%132 = load i32, i32* %12
%133 = call i32 @close(i32 %132)
%134 = load i8*, i8** %17
%135 = load i32, i32* %3
ret i32 %135
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
%struct.sockaddr_storage = type { i32, i64, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [33 x i8] c"Usage:\09<Address> <Port> <String>\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [24 x i8] c"failed to create server\00"
@.str.3 = [31 x i8] c"sent unexpected amount of data\00"
@stdout = global i32 0
@.str.4 = [23 x i8] c"sent %d bytes of data\0A\00"
@.str.5 = [12 x i8] c"string: %s\0A\00"
@.str.7 = [28 x i8] c"connection died prematurely\00"
@.str.8 = [32 x i8] c"received %d bytes of data from \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
%7 = icmp eq i32 %0, 4
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @usrError(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = bitcast %struct.addrinfo* %3 to i8*
%18 = bitcast %struct.addrinfo* %3 to %struct.sockaddr_storage*
%19 = call i32 @memset(%struct.sockaddr_storage* %18, i32 0, i32 32)
%20 = load i32, i32* @AF_UNSPEC
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %20, i32* %21
%22 = load i32, i32* @SOCK_DGRAM
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %22, i32* %23
%24 = load i32, i32* @IPPROTO_UDP
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %24, i32* %25
%26 = bitcast %struct.addrinfo** %4 to i8*
%27 = bitcast %struct.addrinfo** %4 to %struct.sockaddr_storage**
%28 = call i32 @getaddrinfo(i8* %12, i8* %14, %struct.sockaddr_storage* %18, %struct.sockaddr_storage** %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %10
%31 = call i8* @gai_strerror(i32 %28)
%32 = call i32 @sysError(i8* %31)
br label %33
33: ; preds = %30, %10
%34 = load %struct.addrinfo*, %struct.addrinfo** %4
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 4
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 3
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 2
%40 = load i32, i32* %39
%41 = call i32 @socket(i32 %36, i32 %38, i32 %40)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %33
%44 = call i32 @sysError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %43, %33
%46 = call i32 @getSockName(i32 %41)
%47 = call i64 @strlen(i8* dereferenceable(1) %16)
%48 = load %struct.addrinfo*, %struct.addrinfo** %4
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i64 0, i32 1
%50 = load i64, i64* %49
%51 = inttoptr i64 %50 to %struct.sockaddr*
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i64 0, i32 0
%53 = load i32, i32* %52
%54 = call i64 @sendto(i32 %41, i8* %16, i64 %47, i32 0, %struct.sockaddr* %51, i32 %53)
%55 = icmp eq i64 %54, %47
br i1 %55, label %58, label %56
56: ; preds = %45
%57 = call i32 @sysError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %45, %56
%59 = load i32, i32* @stdout
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i64 %54)
%61 = load i32, i32* @stdout
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%63 = bitcast %struct.sockaddr_storage* %5 to i8*
%64 = bitcast i32* %6 to i8*
store i32 32, i32* %6
%65 = call i32 @memset(%struct.sockaddr_storage* %5, i32 0, i32 32)
%66 = call i8* @llvm.stacksave()
%67 = alloca i8, i64 %47
%68 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
%69 = call i64 @recvfrom(i32 %41, i8* %67, i64 %47, i32 0, %struct.sockaddr* %68, i32* %6)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %58
%72 = call i32 @sysError(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %73
73: ; preds = %58, %71
%74 = getelementptr inbounds i8, i8* %67, i64 %69
store i8 0, i8* %74
%75 = load i32, i32* @stdout
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i64 %69)
%77 = call i32 @printSocketAddress(%struct.sockaddr* %68)
%78 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %27
%79 = call i32 @freeaddrinfo(%struct.sockaddr_storage* %78)
%80 = call i32 @close(i32 %41)
ret i32 0
}