#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_INET;
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 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_INET;
  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 %ld bytes from %s:%s\n", (long)nread, host, service);
      printf("Received bytes: %s\n", buf);
    } 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    0xd51(%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    0xcb4(%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    149d <main+0x2cd>
mov    -0x298(%rbp),%rcx
mov    -0x2a0(%rbp),%rdx
movslq -0x70(%rbp),%rsi
lea    0xbb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x270(%rbp),%rsi
lea    0xbc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    14cb <main+0x2fb>
mov    0x2b14(%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    0xba1(%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     1507 <main+0x337>
mov    0x2ac1(%rip),%rax
mov    (%rax),%edi
lea    0xb76(%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    1414 <main+0x244>
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    1429 <main+0x259>
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     13ef <main+0x21f>
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),%r12
lea    -0x30(%rbp),%rbx
jmp    12c4 <main+0xf4>
cs nopw 0x0(%rax,%rax,1)
mov    -0x40(%rbp),%rsp
movl   $0x4,-0x2c(%rbp)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x1f4,%edx
xor    %ecx,%ecx
mov    %rbx,%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    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2cbf(%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    0x2cb4(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %rbx,%rdi
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    0xcfb(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    -0x270(%rbp),%r12
jmp    13af <main+0x1df>
nopl   (%rax)
movslq %r13d,%rsi
lea    0xca8(%rip),%rdi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xcb3(%rip),%rdi
lea    -0x270(%rbp),%r12
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x2c(%rbp),%r9d
mov    %r15d,%edi
mov    %r12,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
lea    -0x30(%rbp),%rbx
mov    %rbx,%r8
call   1060 <sendto@plt>
cmp    %r13d,%eax
je     12c0 <main+0xf0>
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
lea    0xc93(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12c0 <main+0xf0>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
lea    0xc23(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2ba3(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xbd9(%rip),%rsi
jmp    1445 <main+0x275>
mov    0x2b88(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xbd1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1406 <main+0x236>

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 = [17 x i8] c"Usage: %s port \0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = 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 %ld bytes from %s:%s\0A\00"
@.str.4 = [20 x i8] c"Received bytes: %s\0A\00"
@.str.5 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.6 = [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 ([17 x i8], [17 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_INET
%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 = %148, %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 %131
125: ; preds = %109
%126 = load i32, i32* %13
%127 = sext i32 %126 to i64
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %127, i8* %113, i8* %116)
%129 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %129)
br label %136
131: ; preds = %109
%132 = load i32, i32* @stderr
%133 = load i32, i32* %10
%134 = call i8* @gai_strerror(i32 %133)
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %134)
br label %136
136: ; preds = %131, %125
%137 = load i32, i32* %9
%138 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%139 = load i32, i32* %13
%140 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr*
%141 = load i32, i32* %12
%142 = call i32 @sendto(i32 %137, i8* %138, i32 %139, i32 0, %struct.sockaddr* %140, i32 %141)
%143 = load i32, i32* %13
%144 = icmp ne i32 %142, %143
br i1 %144, label %145, label %148
145: ; preds = %136
%146 = load i32, i32* @stderr
%147 = call i32 (i32, i8*, ...) @fprintf(i32 %146, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %148
148: ; preds = %145, %136
%149 = 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 = [17 x i8] c"Usage: %s port \0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = 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 %ld bytes from %s:%s\0A\00"
@.str.4 = [20 x i8] c"Received bytes: %s\0A\00"
@.str.5 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.6 = [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 ([17 x i8], [17 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_INET
%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 = %109, %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 %109, 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 %97
93: ; preds = %80
%94 = sext i32 %78 to i64
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %94, i8* %84, i8* %87)
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %101
97: ; preds = %80
%98 = load i32, i32* @stderr
%99 = call i8* @gai_strerror(i32 %91)
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %99)
br label %101
101: ; preds = %97, %93
%102 = load i32, i32* %6
%103 = call i32 @sendto(i32 %53, i8* %12, i32 %78, i32 0, %struct.sockaddr* %76, i32 %102)
%104 = icmp eq i32 %103, %78
br i1 %104, label %108, label %105
105: ; preds = %101
%106 = load i32, i32* @stderr
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %108
108: ; preds = %105, %101
br label %109
109: ; preds = %108, %77
br label %77
}