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

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
scalar_t__ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_V6ONLY;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
char *inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  int sockfd;
  struct addrinfo hints, *servinfo, *p;
  int rv;
  int numbytes;
  struct sockaddr_storage their_addr;
  char buf[100];
  socklen_t addr_len;
  char s[INET6_ADDRSTRLEN];
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = AI_PASSIVE;
  if ((rv = getaddrinfo(NULL, "4950", &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
    return 1;
  }
  int haveBound = 0;
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if (p->ai_family != AF_INET6)
      continue;
    sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
    if (sockfd == -1) {
      perror("socket");
      continue;
    }
    int no = 0;
    if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof(int)) == -1) {
      close(sockfd);
      perror("setsockopt");
    }
    if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
      close(sockfd);
      perror("bind");
      continue;
    }
    haveBound = 1;
    break;
  }
  if (!haveBound) {
    for (p = servinfo; p != NULL; p = p->ai_next) {
      if (p->ai_family != AF_INET)
        continue;
      if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) ==
          -1) {
        perror("socket");
        continue;
      }
      if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
        close(sockfd);
        perror("bind");
        continue;
      }
      haveBound = 1;
      break;
    }
  }
  if (p == NULL) {
    fprintf(stderr, "failed to bind socket\n");
    return 2;
  }
  freeaddrinfo(servinfo);
  printf("waiting to recvfrom...\n");
  addr_len = sizeof their_addr;
  if ((numbytes = recvfrom(sockfd, buf, 100 - 1, 0,
                           (struct sockaddr *)&their_addr, &addr_len)) == -1) {
    perror("recvfrom");
    exit(1);
  }
  printf("got packet from %s\n",
         inet_ntop(their_addr.ss_family,
                   get_in_addr((struct sockaddr *)&their_addr), s, sizeof s));
  printf("packet is %d bytes long\n", numbytes);
  buf[numbytes] = '\0';
  printf("packet contains \"%s\"\n", buf);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xf8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xf0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xd8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd81(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     12dc <main+0xec>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xfc(%rbp)
mov    -0x44(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    -0xfc(%rbp),%edi
mov    %rax,%rdx
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0xdc(%rbp)
jmp    15ea <main+0x3fa>
movl   $0x0,-0xe0(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     13f3 <main+0x203>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2cb9(%rip),%rcx
cmp    (%rcx),%rax
je     1315 <main+0x125>
jmp    13e2 <main+0x1f2>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    134d <main+0x15d>
lea    0xcd3(%rip),%rdi
call   10d0 <perror@plt>
jmp    13e2 <main+0x1f2>
movl   $0x0,-0xe4(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2c3f(%rip),%rax
mov    (%rax),%esi
mov    0x2c3e(%rip),%rax
mov    (%rax),%edx
lea    -0xe4(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    139b <main+0x1ab>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
lea    0xc87(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x8(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    13d3 <main+0x1e3>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
lea    0xc5f(%rip),%rdi
call   10d0 <perror@plt>
jmp    13e2 <main+0x1f2>
movl   $0x1,-0xe0(%rbp)
jmp    13f3 <main+0x203>
mov    -0x40(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    12ee <main+0xfe>
cmpl   $0x0,-0xe0(%rbp)
jne    14c3 <main+0x2d3>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     14be <main+0x2ce>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2bb7(%rip),%rcx
cmp    (%rcx),%rax
je     142f <main+0x23f>
jmp    14ad <main+0x2bd>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1466 <main+0x276>
lea    0xbba(%rip),%rdi
call   10d0 <perror@plt>
jmp    14ad <main+0x2bd>
mov    -0x8(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    149e <main+0x2ae>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
lea    0xb94(%rip),%rdi
call   10d0 <perror@plt>
jmp    14ad <main+0x2bd>
movl   $0x1,-0xe0(%rbp)
jmp    14be <main+0x2ce>
mov    -0x40(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1408 <main+0x218>
jmp    14c3 <main+0x2d3>
cmpq   $0x0,-0x40(%rbp)
jne    14fb <main+0x30b>
mov    0x2adb(%rip),%rax
mov    (%rax),%edi
lea    0xb4f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0xdc(%rbp)
jmp    15ea <main+0x3fa>
mov    -0x38(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
lea    0xb39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x4,-0xc4(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
lea    -0x50(%rbp),%r8
mov    $0x63,%edx
xor    %ecx,%ecx
lea    -0xc4(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,-0x48(%rbp)
cmp    $0xffffffff,%eax
jne    155f <main+0x36f>
lea    0xb0c(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x100(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <get_in_addr@plt>
mov    -0x100(%rbp),%edi
mov    -0xf0(%rbp),%rdx
mov    %eax,%esi
mov    -0xf8(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xacd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%esi
lea    0xad0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movslq -0x48(%rbp),%rax
movb   $0x0,-0xc0(%rbp,%rax,1)
lea    -0xc0(%rbp),%rsi
lea    0xac8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xdc(%rbp)
mov    -0xd0(%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    $0xb8,%rsp
mov    %rsp,%r15
mov    0x2dca(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r12
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x78(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1090 <memset@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x78(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
lea    0xd8f(%rip),%rsi
lea    -0x38(%rbp),%rcx
xor    %edi,%edi
mov    %r14,%rdx
call   1100 <getaddrinfo@plt>
test   %eax,%eax
je     12b0 <main+0xb0>
mov    0x2d26(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1080 <gai_strerror@plt>
lea    0xd6b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebx
jmp    14c1 <main+0x2c1>
mov    %rbx,-0x50(%rbp)
mov    -0x38(%rbp),%rbx
test   %rbx,%rbx
je     14a5 <main+0x2a5>
mov    %r15,-0x48(%rbp)
mov    0x2cf4(%rip),%r14
lea    -0xe0(%rbp),%r15
jmp    12f2 <main+0xf2>
lea    0xd3a(%rip),%rdi
nopl   0x0(%rax)
call   10e0 <perror@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     1380 <main+0x180>
mov    (%rbx),%rdi
cmp    (%r14),%rdi
jne    12e5 <main+0xe5>
mov    0x10(%rbx),%edx
mov    0x14(%rbx),%esi
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     12d5 <main+0xd5>
mov    %eax,%r13d
movl   $0x0,-0xe0(%rbp)
mov    0x2c82(%rip),%rax
mov    (%rax),%esi
mov    0x2c81(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    %r15,%rcx
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     136a <main+0x16a>
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
mov    %r13d,%edi
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
jne    13ef <main+0x1ef>
mov    %r13d,%edi
call   10a0 <close@plt>
lea    0xcc3(%rip),%rdi
jmp    12e0 <main+0xe0>
mov    %r13d,%edi
call   10a0 <close@plt>
lea    0xca4(%rip),%rdi
call   10e0 <perror@plt>
jmp    133f <main+0x13f>
mov    -0x38(%rbp),%rbx
test   %rbx,%rbx
mov    -0x48(%rbp),%r15
je     14a5 <main+0x2a5>
mov    0x2c40(%rip),%r14
jmp    13bb <main+0x1bb>
mov    %r13d,%edi
call   10a0 <close@plt>
lea    0xc7f(%rip),%rdi
call   10e0 <perror@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     14a5 <main+0x2a5>
mov    (%rbx),%rdi
cmp    (%r14),%rdi
jne    13ae <main+0x1ae>
mov    0x10(%rbx),%edx
mov    0x14(%rbx),%esi
call   1120 <socket@plt>
lea    0xc41(%rip),%rdi
cmp    $0xffffffff,%eax
je     13a9 <main+0x1a9>
mov    %eax,%r13d
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
mov    %eax,%edi
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
je     139a <main+0x19a>
mov    -0x38(%rbp),%rdi
call   1110 <freeaddrinfo@plt>
lea    0xc91(%rip),%rdi
call   1050 <puts@plt>
movl   $0x4,-0x3c(%rbp)
lea    -0xe0(%rbp),%rsi
xor    %ebx,%ebx
lea    -0x30(%rbp),%r8
lea    -0x3c(%rbp),%r9
mov    %r13d,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     14d5 <main+0x2d5>
mov    %eax,%r15d
mov    -0x30(%rbp),%r14d
lea    -0x30(%rbp),%rdi
call   1040 <get_in_addr@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    %r12,%rdx
mov    -0x50(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xbf1(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xbf4(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movslq %r15d,%rax
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    0xbf1(%rip),%rdi
lea    -0xe0(%rbp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
mov    -0x48(%rbp),%r15
jmp    14c1 <main+0x2c1>
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
lea    0xb78(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x2,%ebx
mov    %r15,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb68(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i64 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"4950\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@AF_INET6 = global i64 0
@.str.2 = [7 x i8] c"socket\00"
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
@.str.3 = [11 x i8] c"setsockopt\00"
@.str.4 = [5 x i8] c"bind\00"
@AF_INET = global i64 0
@.str.5 = [23 x i8] c"failed to bind socket\0A\00"
@.str.6 = [24 x i8] c"waiting to recvfrom...\0A\00"
@.str.7 = [9 x i8] c"recvfrom\00"
@.str.8 = [20 x i8] c"got packet from %s\0A\00"
@.str.9 = [25 x i8] c"packet is %d bytes long\0A\00"
@.str.10 = [22 x i8] c"packet contains \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.addrinfo*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_storage
%9 = alloca [100 x i8]
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %1
%16 = load i32, i32* @INET6_ADDRSTRLEN
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %11
%19 = alloca i8, i64 %17
store i64 %17, i64* %12
%20 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%21 = load i64, i64* @AF_UNSPEC
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 0
store i64 %21, i64* %22
%23 = load i32, i32* @SOCK_DGRAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @AI_PASSIVE
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 6
store i32 %25, i32* %26
%27 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
store i32 %27, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %0
%30 = load i32, i32* @stderr
%31 = load i32, i32* %6
%32 = call i8* @gai_strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 1, i32* %1
store i32 1, i32* %13
br label %174
34: ; preds = %0
store i32 0, i32* %14
%35 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %35, %struct.addrinfo** %5
br label %36
36: ; preds = %86, %34
%37 = load %struct.addrinfo*, %struct.addrinfo** %5
%38 = icmp ne %struct.addrinfo* %37, null
br i1 %38, label %39, label %90
39: ; preds = %36
%40 = load %struct.addrinfo*, %struct.addrinfo** %5
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = load i64, i64* @AF_INET6
%44 = icmp ne i64 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %39
br label %86
46: ; preds = %39
%47 = load %struct.addrinfo*, %struct.addrinfo** %5
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = load %struct.addrinfo*, %struct.addrinfo** %5
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 4
%52 = load i32, i32* %51
%53 = load %struct.addrinfo*, %struct.addrinfo** %5
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 3
%55 = load i32, i32* %54
%56 = call i32 @socket(i64 %49, i32 %52, i32 %55)
store i32 %56, i32* %2
%57 = load i32, i32* %2
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %46
%60 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %86
61: ; preds = %46
store i32 0, i32* %15
%62 = load i32, i32* %2
%63 = load i32, i32* @IPPROTO_IPV6
%64 = load i32, i32* @IPV6_V6ONLY
%65 = call i32 @setsockopt(i32 %62, i32 %63, i32 %64, i32* %15, i32 4)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %71
67: ; preds = %61
%68 = load i32, i32* %2
%69 = call i32 @close(i32 %68)
%70 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %71
71: ; preds = %67, %61
%72 = load i32, i32* %2
%73 = load %struct.addrinfo*, %struct.addrinfo** %5
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 2
%75 = load i32, i32* %74
%76 = load %struct.addrinfo*, %struct.addrinfo** %5
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i32 0, i32 1
%78 = load i32, i32* %77
%79 = call i32 @bind(i32 %72, i32 %75, i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %85
81: ; preds = %71
%82 = load i32, i32* %2
%83 = call i32 @close(i32 %82)
%84 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %86
85: ; preds = %71
store i32 1, i32* %14
br label %90
86: ; preds = %81, %59, %45
%87 = load %struct.addrinfo*, %struct.addrinfo** %5
%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** %5
br label %36
90: ; preds = %85, %36
%91 = load i32, i32* %14
%92 = icmp ne i32 %91, 0
br i1 %92, label %139, label %93
93: ; preds = %90
%94 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %94, %struct.addrinfo** %5
br label %95
95: ; preds = %134, %93
%96 = load %struct.addrinfo*, %struct.addrinfo** %5
%97 = icmp ne %struct.addrinfo* %96, null
br i1 %97, label %98, label %138
98: ; preds = %95
%99 = load %struct.addrinfo*, %struct.addrinfo** %5
%100 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %99, i32 0, i32 0
%101 = load i64, i64* %100
%102 = load i64, i64* @AF_INET
%103 = icmp ne i64 %101, %102
br i1 %103, label %104, label %105
104: ; preds = %98
br label %134
105: ; preds = %98
%106 = load %struct.addrinfo*, %struct.addrinfo** %5
%107 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %106, i32 0, i32 0
%108 = load i64, i64* %107
%109 = load %struct.addrinfo*, %struct.addrinfo** %5
%110 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %109, i32 0, i32 4
%111 = load i32, i32* %110
%112 = load %struct.addrinfo*, %struct.addrinfo** %5
%113 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %112, i32 0, i32 3
%114 = load i32, i32* %113
%115 = call i32 @socket(i64 %108, i32 %111, i32 %114)
store i32 %115, i32* %2
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %119
117: ; preds = %105
%118 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %134
119: ; preds = %105
%120 = load i32, i32* %2
%121 = load %struct.addrinfo*, %struct.addrinfo** %5
%122 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %121, i32 0, i32 2
%123 = load i32, i32* %122
%124 = load %struct.addrinfo*, %struct.addrinfo** %5
%125 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %124, i32 0, i32 1
%126 = load i32, i32* %125
%127 = call i32 @bind(i32 %120, i32 %123, i32 %126)
%128 = icmp eq i32 %127, -1
br i1 %128, label %129, label %133
129: ; preds = %119
%130 = load i32, i32* %2
%131 = call i32 @close(i32 %130)
%132 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %134
133: ; preds = %119
store i32 1, i32* %14
br label %138
134: ; preds = %129, %117, %104
%135 = load %struct.addrinfo*, %struct.addrinfo** %5
%136 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i32 0, i32 5
%137 = load %struct.addrinfo*, %struct.addrinfo** %136
store %struct.addrinfo* %137, %struct.addrinfo** %5
br label %95
138: ; preds = %133, %95
br label %139
139: ; preds = %138, %90
%140 = load %struct.addrinfo*, %struct.addrinfo** %5
%141 = icmp eq %struct.addrinfo* %140, null
br i1 %141, label %142, label %145
142: ; preds = %139
%143 = load i32, i32* @stderr
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %1
store i32 1, i32* %13
br label %174
145: ; preds = %139
%146 = load %struct.addrinfo*, %struct.addrinfo** %4
%147 = call i32 @freeaddrinfo(%struct.addrinfo* %146)
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
store i32 4, i32* %10
%149 = load i32, i32* %2
%150 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%151 = bitcast %struct.sockaddr_storage* %8 to %struct.sockaddr*
%152 = call i32 @recvfrom(i32 %149, i8* %150, i32 99, i32 0, %struct.sockaddr* %151, i32* %10)
store i32 %152, i32* %7
%153 = icmp eq i32 %152, -1
br i1 %153, label %154, label %157
154: ; preds = %145
%155 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%156 = call i32 @exit(i32 1)
unreachable
157: ; preds = %145
%158 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %8, i32 0, i32 0
%159 = load i32, i32* %158
%160 = bitcast %struct.sockaddr_storage* %8 to %struct.sockaddr*
%161 = call i32 @get_in_addr(%struct.sockaddr* %160)
%162 = trunc i64 %17 to i32
%163 = call i8* @inet_ntop(i32 %159, i32 %161, i8* %19, i32 %162)
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %163)
%165 = load i32, i32* %7
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %165)
%167 = load i32, i32* %7
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %168
store i8 0, i8* %169
%170 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %170)
%172 = load i32, i32* %2
%173 = call i32 @close(i32 %172)
store i32 0, i32* %1
store i32 1, i32* %13
br label %174
174: ; preds = %157, %142, %29
%175 = load i8*, i8** %11
%176 = load i32, i32* %1
ret i32 %176
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i64 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"4950\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@AF_INET6 = global i64 0
@.str.2 = [7 x i8] c"socket\00"
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
@.str.3 = [11 x i8] c"setsockopt\00"
@.str.4 = [5 x i8] c"bind\00"
@AF_INET = global i64 0
@.str.5 = [23 x i8] c"failed to bind socket\0A\00"
@.str.7 = [9 x i8] c"recvfrom\00"
@.str.8 = [20 x i8] c"got packet from %s\0A\00"
@.str.9 = [25 x i8] c"packet is %d bytes long\0A\00"
@.str.10 = [22 x i8] c"packet contains \22%s\22\0A\00"
@str = [23 x i8] c"waiting to recvfrom...\00"
define i32 @main() {
%1 = alloca %struct.addrinfo
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.sockaddr_storage
%4 = alloca [100 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = bitcast %struct.addrinfo* %1 to i8*
%8 = bitcast %struct.addrinfo** %2 to i8*
%9 = bitcast %struct.sockaddr_storage* %3 to i8*
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = bitcast i32* %5 to i8*
%12 = load i32, i32* @INET6_ADDRSTRLEN
%13 = zext i32 %12 to i64
%14 = tail call i8* @llvm.stacksave()
%15 = alloca i8, i64 %13
%16 = call i32 @memset(%struct.addrinfo* %1, i32 0, i32 40)
%17 = load i64, i64* @AF_UNSPEC
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
store i64 %17, i64* %18
%19 = load i32, i32* @SOCK_DGRAM
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 4
store i32 %19, i32* %20
%21 = load i32, i32* @AI_PASSIVE
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 6
store i32 %21, i32* %22
%23 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %1, %struct.addrinfo** %2)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %0
%26 = load %struct.addrinfo*, %struct.addrinfo** %2
%27 = icmp eq %struct.addrinfo* %26, null
br i1 %27, label %104, label %28
28: ; preds = %25
%29 = bitcast i32* %6 to i8*
br label %37
30: ; preds = %0
%31 = load i32, i32* @stderr
%32 = call i8* @gai_strerror(i32 %23)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %129
34: ; preds = %71
%35 = load %struct.addrinfo*, %struct.addrinfo** %2
%36 = icmp eq %struct.addrinfo* %35, null
br i1 %36, label %104, label %75
37: ; preds = %28, %71
%38 = phi %struct.addrinfo* [ %26, %28 ], [ %73, %71 ]
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 0
%40 = load i64, i64* %39
%41 = load i64, i64* @AF_INET6
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %71
43: ; preds = %37
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 4
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 3
%47 = load i32, i32* %46
%48 = call i32 @socket(i64 %40, i32 %45, i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %71
52: ; preds = %43
store i32 0, i32* %6
%53 = load i32, i32* @IPPROTO_IPV6
%54 = load i32, i32* @IPV6_V6ONLY
%55 = call i32 @setsockopt(i32 %48, i32 %53, i32 %54, i32* %6, i32 4)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 @close(i32 %48)
%59 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %57, %52
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 2
%62 = load i32, i32* %61
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 1
%64 = load i32, i32* %63
%65 = call i32 @bind(i32 %48, i32 %62, i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = call i32 @close(i32 %48)
%69 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %71
70: ; preds = %60
br label %107
71: ; preds = %67, %37, %50
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 5
%73 = load %struct.addrinfo*, %struct.addrinfo** %72
%74 = icmp eq %struct.addrinfo* %73, null
br i1 %74, label %34, label %37
75: ; preds = %34, %100
%76 = phi %struct.addrinfo* [ %102, %100 ], [ %35, %34 ]
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i64 0, i32 0
%78 = load i64, i64* %77
%79 = load i64, i64* @AF_INET
%80 = icmp eq i64 %78, %79
br i1 %80, label %81, label %100
81: ; preds = %75
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i64 0, i32 4
%83 = load i32, i32* %82
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i64 0, i32 3
%85 = load i32, i32* %84
%86 = call i32 @socket(i64 %78, i32 %83, i32 %85)
%87 = icmp eq i32 %86, -1
br i1 %87, label %97, label %88
88: ; preds = %81
%89 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i64 0, i32 2
%90 = load i32, i32* %89
%91 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i64 0, i32 1
%92 = load i32, i32* %91
%93 = call i32 @bind(i32 %86, i32 %90, i32 %92)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %107
95: ; preds = %88
%96 = call i32 @close(i32 %86)
br label %97
97: ; preds = %81, %95
%98 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %95 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %81 ]
%99 = call i32 @perror(i8* %98)
br label %100
100: ; preds = %97, %75
%101 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i64 0, i32 5
%102 = load %struct.addrinfo*, %struct.addrinfo** %101
%103 = icmp eq %struct.addrinfo* %102, null
br i1 %103, label %104, label %75
104: ; preds = %100, %25, %34
%105 = load i32, i32* @stderr
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %129
107: ; preds = %88, %70
%108 = phi i32 [ %48, %70 ], [ %86, %88 ]
%109 = load %struct.addrinfo*, %struct.addrinfo** %2
%110 = call i32 @freeaddrinfo(%struct.addrinfo* %109)
%111 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
store i32 4, i32* %5
%112 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%113 = call i32 @recvfrom(i32 %108, i8* %10, i32 99, i32 0, %struct.sockaddr* %112, i32* %5)
%114 = icmp eq i32 %113, -1
br i1 %114, label %115, label %118
115: ; preds = %107
%116 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %107
%119 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 0, i32 0
%120 = load i32, i32* %119
%121 = call i32 @get_in_addr(%struct.sockaddr* %112)
%122 = call i8* @inet_ntop(i32 %120, i32 %121, i8* %15, i32 %12)
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %122)
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %113)
%125 = sext i32 %113 to i64
%126 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %125
store i8 0, i8* %126
%127 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %10)
%128 = call i32 @close(i32 %108)
br label %129
129: ; preds = %104, %118, %30
%130 = phi i32 [ 1, %30 ], [ 2, %104 ], [ 0, %118 ]
ret i32 %130
}