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

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ EXIT_FAILURE;
int NI_MAXHOST;
int NI_MAXSERV;
int /*<<< orphan*/ NI_NUMERICSERV;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int getnameinfo(struct sockaddr *, int, char *, int, char *, int,
                int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int sfd, s;
  struct sockaddr_storage peer_addr;
  socklen_t peer_addr_len;
  ssize_t nread;
  char buf[500];
  if (argc != 2) {
    fprintf(stderr, "Usage: %s port\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_protocol = 0;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  s = getaddrinfo(NULL, argv[1], &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    exit(EXIT_FAILURE);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
    if (sfd == -1)
      continue;
    if (bind(sfd, rp->ai_addr, rp->ai_addrlen) == 0)
      break;
    close(sfd);
  }
  if (rp == NULL) {
    fprintf(stderr, "Could not bind\n");
    exit(EXIT_FAILURE);
  }
  freeaddrinfo(result);
  for (;;) {
    peer_addr_len = sizeof(struct sockaddr_storage);
    nread = recvfrom(sfd, buf, 500, 0, (struct sockaddr *)&peer_addr,
                     &peer_addr_len);
    if (nread == -1)
      continue;
    char host[NI_MAXHOST], service[NI_MAXSERV];
    s = getnameinfo((struct sockaddr *)&peer_addr, peer_addr_len, host,
                    NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICSERV);
    if (s == 0)
      printf("Received %zd bytes from %s:%s\n", nread, host, service);
    else
      fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
    if (sendto(sfd, buf, nread, 0, (struct sockaddr *)&peer_addr,
               peer_addr_len) != nread)
      fprintf(stderr, "Error sending response\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     121f <main+0x4f>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1050 <memset@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
je     12d5 <main+0x105>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28c(%rbp)
mov    -0x60(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x28c(%rbp),%edi
mov    %rax,%rdx
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1353 <main+0x183>
mov    -0x58(%rbp),%rax
mov    0x1c(%rax),%edi
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%rdx
call   10f0 <socket@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    1315 <main+0x145>
jmp    1342 <main+0x172>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jne    133a <main+0x16a>
jmp    1353 <main+0x183>
mov    -0x5c(%rbp),%edi
call   1070 <close@plt>
mov    -0x58(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    12dd <main+0x10d>
cmpq   $0x0,-0x58(%rbp)
jne    1383 <main+0x1b3>
mov    0x2c53(%rip),%rax
mov    (%rax),%edi
lea    0xcb3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x50(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
movl   $0x4,-0x6c(%rbp)
mov    -0x5c(%rbp),%edi
lea    -0x270(%rbp),%rsi
lea    -0x68(%rbp),%r8
mov    $0x1f4,%edx
xor    %ecx,%ecx
lea    -0x6c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0xffffffff,-0x70(%rbp)
jne    13c3 <main+0x1f3>
jmp    138c <main+0x1bc>
mov    0x2bde(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x278(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x2a0(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x280(%rbp)
mov    0x2bd1(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r8
sub    %rcx,%r8
mov    %r8,-0x298(%rbp)
mov    %r8,%rsp
mov    %rax,-0x288(%rbp)
lea    -0x68(%rbp),%rdi
mov    -0x6c(%rbp),%esi
mov    0x2b77(%rip),%rax
mov    (%rax),%ecx
mov    0x2b96(%rip),%rax
mov    (%rax),%r9d
mov    0x2ba4(%rip),%rax
mov    (%rax),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1080 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
jne    1485 <main+0x2b5>
mov    -0x298(%rbp),%rcx
mov    -0x2a0(%rbp),%rdx
mov    -0x70(%rbp),%esi
lea    0xbb6(%rip),%rdi
call   1030 <printf@plt>
jmp    14b3 <main+0x2e3>
mov    0x2b2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2a4(%rbp)
mov    -0x60(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x2a4(%rbp),%edi
mov    %rax,%rdx
lea    0xba4(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x5c(%rbp),%edi
lea    -0x270(%rbp),%rsi
mov    -0x70(%rbp),%edx
lea    -0x68(%rbp),%r8
mov    -0x6c(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    -0x70(%rbp),%eax
je     14ef <main+0x31f>
mov    0x2ad9(%rip),%rax
mov    (%rax),%edi
lea    0xb79(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x278(%rbp),%rax
mov    %rax,%rsp
jmp    138c <main+0x1bc>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x248,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1401 <main+0x231>
lea    -0x78(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1050 <memset@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
xorps  %xmm0,%xmm0
movups %xmm0,-0x70(%rbp)
movups %xmm0,-0x58(%rbp)
mov    0x8(%rbx),%rsi
lea    -0x38(%rbp),%rcx
xor    %edi,%edi
mov    %r14,%rdx
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
jne    1416 <main+0x246>
mov    -0x38(%rbp),%rbx
jmp    1264 <main+0x94>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x20(%rbx),%rbx
test   %rbx,%rbx
je     13dc <main+0x20c>
mov    0x1c(%rbx),%edi
mov    0x18(%rbx),%esi
mov    0x10(%rbx),%rdx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0x90>
mov    %eax,%r15d
mov    0x8(%rbx),%rsi
mov    (%rbx),%edx
mov    %eax,%edi
call   10b0 <bind@plt>
test   %rax,%rax
je     12a0 <main+0xd0>
mov    %r15d,%edi
call   1070 <close@plt>
jmp    1260 <main+0x90>
mov    -0x38(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
lea    -0x270(%rbp),%rbx
lea    -0x30(%rbp),%r12
jmp    12c4 <main+0xf4>
cs nopw 0x0(%rax,%rax,1)
mov    -0x40(%rbp),%rsp
movl   $0x4,-0x2c(%rbp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1f4,%edx
xor    %ecx,%ecx
mov    %r12,%r8
lea    -0x2c(%rbp),%r9
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     12c4 <main+0xf4>
mov    %eax,%r13d
mov    %rsp,-0x40(%rbp)
mov    0x2cb1(%rip),%rcx
mov    (%rcx),%eax
mov    %r12,%rdi
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2cbc(%rip),%rax
mov    (%rax),%r9d
mov    %rsp,%r14
mov    %r9,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%esi
mov    (%rcx),%ecx
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %r12,%rdx
mov    %r14,%r8
push   %rax
call   1080 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
je     1380 <main+0x1b0>
mov    0x2c60(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
mov    %ebx,%edi
lea    0xce6(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1395 <main+0x1c5>
cs nopw 0x0(%rax,%rax,1)
lea    0xcaa(%rip),%rdi
mov    %r13d,%esi
mov    %r12,%rdx
mov    %r14,%rcx
call   1030 <printf@plt>
mov    -0x2c(%rbp),%r9d
mov    %r15d,%edi
lea    -0x270(%rbp),%rbx
mov    %rbx,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
lea    -0x30(%rbp),%r12
mov    %r12,%r8
call   1060 <sendto@plt>
cmp    %r13d,%eax
je     12c0 <main+0xf0>
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
lea    0xc91(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12c0 <main+0xf0>
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
lea    0xc35(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2bb0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xbec(%rip),%rsi
jmp    1432 <main+0x262>
mov    0x2b9b(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xbe3(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    13f3 <main+0x223>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32*, i64, i32, i32, %struct.addrinfo*, i32*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s port\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [16 x i8] c"Could not bind\0A\00"
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.3 = [31 x i8] c"Received %zd bytes from %s:%s\0A\00"
@.str.4 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.5 = [24 x i8] c"Error sending response\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_storage
%12 = alloca i32
%13 = alloca i32
%14 = alloca [500 x i8]
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %28
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %2
%29 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 56)
%30 = load i32, i32* @AF_UNSPEC
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %30, i32* %31
%32 = load i32, i32* @SOCK_DGRAM
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %32, i32* %33
%34 = load i32, i32* @AI_PASSIVE
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 7
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i64 0, i64* %36
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i32* null, i32** %37
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32* null, i32** %38
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store %struct.addrinfo* null, %struct.addrinfo** %39
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @getaddrinfo(i32* null, i8* %42, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %28
%47 = load i32, i32* @stderr
%48 = load i32, i32* %10
%49 = call i8* @gai_strerror(i32 %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %28
%54 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %54, %struct.addrinfo** %8
br label %55
55: ; preds = %86, %53
%56 = load %struct.addrinfo*, %struct.addrinfo** %8
%57 = icmp ne %struct.addrinfo* %56, null
br i1 %57, label %58, label %90
58: ; preds = %55
%59 = load %struct.addrinfo*, %struct.addrinfo** %8
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 4
%61 = load i32, i32* %60
%62 = load %struct.addrinfo*, %struct.addrinfo** %8
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i32 0, i32 3
%64 = load i32, i32* %63
%65 = load %struct.addrinfo*, %struct.addrinfo** %8
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 2
%67 = load i64, i64* %66
%68 = call i32 @socket(i32 %61, i32 %64, i64 %67)
store i32 %68, i32* %9
%69 = load i32, i32* %9
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %72
71: ; preds = %58
br label %86
72: ; preds = %58
%73 = load i32, i32* %9
%74 = load %struct.addrinfo*, %struct.addrinfo** %8
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i32 0, i32 1
%76 = load i32*, i32** %75
%77 = load %struct.addrinfo*, %struct.addrinfo** %8
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i64 @bind(i32 %73, i32* %76, i32 %79)
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %72
br label %90
83: ; preds = %72
%84 = load i32, i32* %9
%85 = call i32 @close(i32 %84)
br label %86
86: ; preds = %83, %71
%87 = load %struct.addrinfo*, %struct.addrinfo** %8
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %87, i32 0, i32 5
%89 = load %struct.addrinfo*, %struct.addrinfo** %88
store %struct.addrinfo* %89, %struct.addrinfo** %8
br label %55
90: ; preds = %82, %55
%91 = load %struct.addrinfo*, %struct.addrinfo** %8
%92 = icmp eq %struct.addrinfo* %91, null
br i1 %92, label %93, label %98
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%96 = load i32, i32* @EXIT_FAILURE
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %90
%99 = load %struct.addrinfo*, %struct.addrinfo** %7
%100 = call i32 @freeaddrinfo(%struct.addrinfo* %99)
br label %101
101: ; preds = %145, %108, %98
store i32 4, i32* %12
%102 = load i32, i32* %9
%103 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%104 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr*
%105 = call i32 @recvfrom(i32 %102, i8* %103, i32 500, i32 0, %struct.sockaddr* %104, i32* %12)
store i32 %105, i32* %13
%106 = load i32, i32* %13
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %109
108: ; preds = %101
br label %101
109: ; preds = %101
%110 = load i32, i32* @NI_MAXHOST
%111 = zext i32 %110 to i64
%112 = call i8* @llvm.stacksave()
store i8* %112, i8** %15
%113 = alloca i8, i64 %111
store i64 %111, i64* %16
%114 = load i32, i32* @NI_MAXSERV
%115 = zext i32 %114 to i64
%116 = alloca i8, i64 %115
store i64 %115, i64* %17
%117 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr*
%118 = load i32, i32* %12
%119 = load i32, i32* @NI_MAXHOST
%120 = load i32, i32* @NI_MAXSERV
%121 = load i32, i32* @NI_NUMERICSERV
%122 = call i32 @getnameinfo(%struct.sockaddr* %117, i32 %118, i8* %113, i32 %119, i8* %116, i32 %120, i32 %121)
store i32 %122, i32* %10
%123 = load i32, i32* %10
%124 = icmp eq i32 %123, 0
br i1 %124, label %125, label %128
125: ; preds = %109
%126 = load i32, i32* %13
%127 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %126, i8* %113, i8* %116)
br label %133
128: ; preds = %109
%129 = load i32, i32* @stderr
%130 = load i32, i32* %10
%131 = call i8* @gai_strerror(i32 %130)
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %131)
br label %133
133: ; preds = %128, %125
%134 = load i32, i32* %9
%135 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%136 = load i32, i32* %13
%137 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr*
%138 = load i32, i32* %12
%139 = call i32 @sendto(i32 %134, i8* %135, i32 %136, i32 0, %struct.sockaddr* %137, i32 %138)
%140 = load i32, i32* %13
%141 = icmp ne i32 %139, %140
br i1 %141, label %142, label %145
142: ; preds = %133
%143 = load i32, i32* @stderr
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %145
145: ; preds = %142, %133
%146 = load i8*, i8** %15
br label %101
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32*, i64, i32, i32, %struct.addrinfo*, i32*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s port\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [16 x i8] c"Could not bind\0A\00"
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.3 = [31 x i8] c"Received %zd bytes from %s:%s\0A\00"
@.str.4 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.5 = [24 x i8] c"Error sending response\0A\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 = alloca [500 x i8]
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = bitcast %struct.sockaddr_storage* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%13 = icmp eq i32 %0, 2
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 56)
%22 = load i32, i32* @AF_UNSPEC
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %22, i32* %23
%24 = load i32, i32* @SOCK_DGRAM
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %24, i32* %25
%26 = load i32, i32* @AI_PASSIVE
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 7
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = bitcast i32** %28 to i8*
%32 = bitcast %struct.addrinfo** %29 to i8*
%33 = load i8*, i8** %30
%34 = call i32 @getaddrinfo(i32* null, i8* %33, %struct.addrinfo* %3, %struct.addrinfo** %4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %20
%37 = load %struct.addrinfo*, %struct.addrinfo** %4
%38 = icmp eq %struct.addrinfo* %37, null
br i1 %38, label %68, label %45
39: ; preds = %20
%40 = load i32, i32* @stderr
%41 = call i8* @gai_strerror(i32 %34)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %36, %64
%46 = phi %struct.addrinfo* [ %66, %64 ], [ %37, %36 ]
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 4
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 3
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 2
%52 = load i64, i64* %51
%53 = call i32 @socket(i32 %48, i32 %50, i64 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %64, label %55
55: ; preds = %45
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 1
%57 = load i32*, i32** %56
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 0
%59 = load i32, i32* %58
%60 = call i64 @bind(i32 %53, i32* %57, i32 %59)
%61 = icmp eq i64 %60, 0
br i1 %61, label %73, label %62
62: ; preds = %55
%63 = call i32 @close(i32 %53)
br label %64
64: ; preds = %45, %62
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 5
%66 = load %struct.addrinfo*, %struct.addrinfo** %65
%67 = icmp eq %struct.addrinfo* %66, null
br i1 %67, label %68, label %45
68: ; preds = %64, %36
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %55
%74 = load %struct.addrinfo*, %struct.addrinfo** %4
%75 = call i32 @freeaddrinfo(%struct.addrinfo* %74)
%76 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
br label %77
77: ; preds = %107, %73
store i32 4, i32* %6
%78 = call i32 @recvfrom(i32 %53, i8* %12, i32 500, i32 0, %struct.sockaddr* %76, i32* %6)
%79 = icmp eq i32 %78, -1
br i1 %79, label %107, label %80
80: ; preds = %77
%81 = load i32, i32* @NI_MAXHOST
%82 = zext i32 %81 to i64
%83 = call i8* @llvm.stacksave()
%84 = alloca i8, i64 %82
%85 = load i32, i32* @NI_MAXSERV
%86 = zext i32 %85 to i64
%87 = alloca i8, i64 %86
%88 = load i32, i32* %6
%89 = load i32, i32* @NI_MAXHOST
%90 = load i32, i32* @NI_NUMERICSERV
%91 = call i32 @getnameinfo(%struct.sockaddr* %76, i32 %88, i8* %84, i32 %89, i8* %87, i32 %85, i32 %90)
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %80
%94 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %78, i8* %84, i8* %87)
br label %99
95: ; preds = %80
%96 = load i32, i32* @stderr
%97 = call i8* @gai_strerror(i32 %91)
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %97)
br label %99
99: ; preds = %95, %93
%100 = load i32, i32* %6
%101 = call i32 @sendto(i32 %53, i8* %12, i32 %78, i32 0, %struct.sockaddr* %76, i32 %100)
%102 = icmp eq i32 %101, %78
br i1 %102, label %106, label %103
103: ; preds = %99
%104 = load i32, i32* @stderr
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %106
106: ; preds = %103, %99
br label %107
107: ; preds = %106, %77
br label %77
}