#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in6 {
  int sin_family;
  void *sin6_port;
  int /*<<< orphan*/ sin6_addr;
  void *sin6_family;
  void *sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr_in {
  int sin_family;
  void *sin6_port;
  int /*<<< orphan*/ sin6_addr;
  void *sin6_family;
  void *sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct sigaction {
  int /*<<< orphan*/ sa_flags;
  int /*<<< orphan*/ sa_handler;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr6;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ cliaddr6;
typedef int /*<<< orphan*/ cliaddr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int AF_INET;
void *AF_INET6;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SA_NOCLDWAIT;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_DFL;
int SOCK_DGRAM;
int SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in6 *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char getopt(int, char **, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ in6addr_any;
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int socket(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int family = AF_INET6;
  int port = 30080;
  int listenfd, connfd;
  pid_t childpid;
  socklen_t clilen;
  struct sockaddr_in cliaddr, servaddr;
  struct sockaddr_in6 cliaddr6, servaddr6;
  char opt;
  int sock_type = SOCK_STREAM;
  int n;
  char buf[128];
  struct sigaction sa;
  bool silent = false;
  while ((opt = getopt(argc, argv, "46p:su")) != -1) {
    switch (opt) {
    case '4':
      family = AF_INET;
      break;
    case '6':
      family = AF_INET6;
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 's':
      silent = true;
      break;
    case 'u':
      sock_type = SOCK_DGRAM;
      break;
    default:
      fprintf(stderr, "Usage: %s [-p port] [-4] [-6] [-s] [-u]\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  listenfd = socket(family, sock_type, 0);
  if (family == AF_INET) {
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(port);
    bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  } else {
    bzero(&servaddr6, sizeof(servaddr6));
    servaddr6.sin6_family = AF_INET6;
    servaddr6.sin6_addr = in6addr_any;
    servaddr6.sin6_port = htons(port);
    bind(listenfd, (struct sockaddr *)&servaddr6, sizeof(servaddr6));
  }
  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = SIG_DFL;
  sa.sa_flags = SA_NOCLDWAIT;
  sigaction(SIGCHLD, &sa, NULL);
  if (sock_type == SOCK_STREAM) {
    listen(listenfd, 4);
    for (;;) {
      if (family == AF_INET) {
        clilen = sizeof(cliaddr);
        connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen);
      } else {
        clilen = sizeof(cliaddr6);
        connfd = accept(listenfd, (struct sockaddr *)&cliaddr6, &clilen);
      }
      if (!silent)
        printf("Received connection\n");
      if ((childpid = fork()) == 0) {
        close(listenfd);
        sleep(1);
        exit(0);
      }
      close(connfd);
    }
  } else {
    for (;;) {
      clilen = sizeof(cliaddr);
      if (family == AF_INET) {
        clilen = sizeof(cliaddr);
        n = recvfrom(listenfd, buf, sizeof(buf), 0, (struct sockaddr *)&cliaddr,
                     &clilen);
        sendto(listenfd, buf, n, 0, (struct sockaddr *)&cliaddr, clilen);
      } else {
        clilen = sizeof(cliaddr6);
        sendto(listenfd, buf, n, 0, (struct sockaddr *)&cliaddr6, clilen);
      }
      if (!silent)
        printf("Received %d bytes\n", n);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x14(%rbp)
movl   $0x7580,-0x18(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf0(%rbp)
movl   $0x0,-0x18c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd7c(%rip),%rdx
call   10f0 <getopt@plt>
mov    %al,-0xe9(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1391 <main+0x161>
movsbl -0xe9(%rbp),%eax
mov    %eax,-0x190(%rbp)
sub    $0x34,%eax
je     1306 <main+0xd6>
jmp    12b6 <main+0x86>
mov    -0x190(%rbp),%eax
sub    $0x36,%eax
je     1317 <main+0xe7>
jmp    12ca <main+0x9a>
mov    -0x190(%rbp),%eax
sub    $0x70,%eax
je     1329 <main+0xf9>
jmp    12de <main+0xae>
mov    -0x190(%rbp),%eax
sub    $0x73,%eax
je     133f <main+0x10f>
jmp    12f2 <main+0xc2>
mov    -0x190(%rbp),%eax
sub    $0x75,%eax
je     134e <main+0x11e>
jmp    1362 <main+0x132>
mov    0x2cc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    138c <main+0x15c>
mov    0x2c92(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x14(%rbp)
jmp    138c <main+0x15c>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   1110 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    138c <main+0x15c>
movl   $0x1,-0x18c(%rbp)
jmp    138c <main+0x15c>
mov    0x2c63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf0(%rbp)
jmp    138c <main+0x15c>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc8e(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    1276 <main+0x46>
mov    -0x14(%rbp),%edi
mov    -0xf0(%rbp),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2c22(%rip),%rcx
cmp    (%rcx),%eax
jne    140c <main+0x1dc>
lea    -0x88(%rbp),%rdi
mov    $0x30,%esi
call   10e0 <bzero@plt>
mov    0x2c02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2beb(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x60(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x68(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x88(%rbp),%rsi
mov    $0x30,%edx
call   10d0 <bind@plt>
jmp    1460 <main+0x230>
lea    -0xe8(%rbp),%rdi
mov    $0x30,%esi
call   10e0 <bzero@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xd0(%rbp)
mov    0x2bb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd8(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0xe0(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0xe8(%rbp),%rsi
mov    $0x30,%edx
call   10d0 <bind@plt>
lea    -0x188(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2b0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x184(%rbp)
mov    0x2b4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x188(%rbp)
mov    0x2b28(%rip),%rax
mov    (%rax),%edi
lea    -0x188(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    -0xf0(%rbp),%eax
mov    0x2ae1(%rip),%rcx
cmp    (%rcx),%eax
jne    156e <main+0x33e>
mov    -0x1c(%rbp),%edi
mov    $0x4,%esi
call   10b0 <listen@plt>
mov    -0x14(%rbp),%eax
mov    0x2afa(%rip),%rcx
cmp    (%rcx),%eax
jne    14fd <main+0x2cd>
movl   $0x30,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x58(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x20(%rbp)
jmp    151a <main+0x2ea>
movl   $0x30,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0xb8(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x18c(%rbp)
jne    1535 <main+0x305>
lea    0xb02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1140 <fork@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    1561 <main+0x331>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1130 <sleep@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
jmp    14cc <main+0x29c>
jmp    1573 <main+0x343>
movl   $0x30,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2a4c(%rip),%rcx
cmp    (%rcx),%eax
jne    15db <main+0x3ab>
movl   $0x30,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x180(%rbp),%rsi
lea    -0x58(%rbp),%r8
mov    $0x80,%edx
xor    %ecx,%ecx
lea    -0x28(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,-0xf4(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x180(%rbp),%rsi
mov    -0xf4(%rbp),%edx
lea    -0x58(%rbp),%r8
mov    -0x28(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
jmp    1604 <main+0x3d4>
movl   $0x30,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x180(%rbp),%rsi
mov    -0xf4(%rbp),%edx
lea    -0xb8(%rbp),%r8
mov    -0x28(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmpl   $0x0,-0x18c(%rbp)
jne    1625 <main+0x3f5>
mov    -0xf4(%rbp),%esi
lea    0xa27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1573 <main+0x343>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%r14d
lea    0xd8c(%rip),%rdx
call   1100 <getopt@plt>
cmp    $0xff,%al
je     1320 <main+0xe0>
mov    $0x7580,%r15d
movl   $0x0,0x10(%rsp)
lea    0xd6a(%rip),%r13
mov    0x2d1b(%rip),%rbx
jmp    12c1 <main+0x81>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   1120 <atoi@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1100 <getopt@plt>
cmp    $0xff,%al
je     132e <main+0xee>
movsbl %al,%eax
cmp    $0x6f,%eax
jle    12f0 <main+0xb0>
cmp    $0x70,%eax
je     129f <main+0x5f>
cmp    $0x73,%eax
je     1307 <main+0xc7>
cmp    $0x75,%eax
jne    14c5 <main+0x285>
mov    (%rbx),%r14d
jmp    12b0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x34,%eax
je     1311 <main+0xd1>
cmp    $0x36,%eax
jne    14c5 <main+0x285>
mov    0x2cab(%rip),%rax
jmp    1318 <main+0xd8>
movl   $0x1,0x10(%rsp)
jmp    12b0 <main+0x70>
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
jmp    12b0 <main+0x70>
movl   $0x0,0x10(%rsp)
mov    $0x7580,%r15d
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
mov    %r14d,%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%ebp
mov    0x2c89(%rip),%rax
cmp    (%rax),%ebx
jne    1382 <main+0x142>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    $0x30,%esi
call   10f0 <bzero@plt>
mov    %ebx,0x20(%rsp)
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x48(%rsp)
mov    %r15d,%edi
call   1050 <htons@plt>
mov    %rax,0x40(%rsp)
jmp    13bd <main+0x17d>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    $0x30,%esi
call   10f0 <bzero@plt>
mov    0x2c15(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x38(%rsp)
mov    0x2c3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    %r15d,%edi
call   1050 <htons@plt>
mov    %rax,0x28(%rsp)
mov    0x2bd4(%rip),%r15
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x30,%edx
call   10e0 <bind@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    0x2b9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2bdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2bb8(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
cmp    (%r15),%r14d
je     14ec <main+0x2ac>
lea    0xb0(%rsp),%rbx
lea    0x80(%rsp),%r15
lea    0x14(%rsp),%r12
lea    0x50(%rsp),%r13
nopw   0x0(%rax,%rax,1)
movl   $0x30,0x14(%rsp)
mov    0xc(%rsp),%eax
mov    0x2b7d(%rip),%rcx
cmp    (%rcx),%eax
jne    1490 <main+0x250>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   10d0 <recvfrom@plt>
mov    %eax,%r14d
mov    0x14(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
jmp    14a3 <main+0x263>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %r13,%r8
mov    $0x30,%r9d
call   1090 <sendto@plt>
cmpl   $0x0,0x10(%rsp)
jne    1440 <main+0x200>
lea    0xb7a(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1440 <main+0x200>
mov    0x2ad4(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xb2e(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2aab(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
mov    %ebp,%edi
mov    $0x4,%esi
call   10c0 <listen@plt>
lea    0x80(%rsp),%r12
lea    0x50(%rsp),%r13
lea    0x14(%rsp),%r15
lea    0xb32(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0x30,0x14(%rsp)
mov    %r12,%rsi
mov    0xc(%rsp),%eax
mov    0x2a9a(%rip),%rcx
cmp    (%rcx),%eax
je     153d <main+0x2fd>
mov    %r13,%rsi
mov    %ebp,%edi
mov    %r15,%rdx
call   1110 <accept@plt>
mov    %eax,%ebx
cmpl   $0x0,0x10(%rsp)
jne    1558 <main+0x318>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1150 <fork@plt>
test   %eax,%eax
je     156c <main+0x32c>
mov    %ebx,%edi
call   10a0 <close@plt>
jmp    1520 <main+0x2e0>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1140 <sleep@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i8*, i32, i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32, i8*, i32, i8*, i8*, %struct.TYPE_2__ }
%struct.sigaction = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i8* null
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"46p:su\00"
@AF_INET = global i32 0
@optarg = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Usage: %s [-p port] [-4] [-6] [-s] [-u]\0A\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@in6addr_any = global i32 0
@SIG_DFL = global i32 0
@SA_NOCLDWAIT = global i32 0
@SIGCHLD = global i32 0
@.str.2 = [21 x i8] c"Received connection\0A\00"
@.str.3 = [19 x i8] c"Received %d bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.sockaddr_in
%14 = alloca %struct.sockaddr_in6
%15 = alloca %struct.sockaddr_in6
%16 = alloca i8
%17 = alloca i32
%18 = alloca i32
%19 = alloca [128 x i8]
%20 = alloca %struct.sigaction
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = load i8*, i8** @AF_INET6
%23 = ptrtoint i8* %22 to i32
store i32 %23, i32* %6
store i32 30080, i32* %7
%24 = load i32, i32* @SOCK_STREAM
store i32 %24, i32* %17
store i32 0, i32* %21
br label %25
25: ; preds = %53, %2
%26 = load i32, i32* %4
%27 = load i8**, i8*** %5
%28 = call signext i8 @getopt(i32 %26, i8** %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8 %28, i8* %16
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %54
31: ; preds = %25
%32 = load i8, i8* %16
%33 = sext i8 %32 to i32
switch i32 %33, label %45 [
i32 52, label %34
i32 54, label %36
i32 112, label %39
i32 115, label %42
i32 117, label %43
]
34: ; preds = %31
%35 = load i32, i32* @AF_INET
store i32 %35, i32* %6
br label %53
36: ; preds = %31
%37 = load i8*, i8** @AF_INET6
%38 = ptrtoint i8* %37 to i32
store i32 %38, i32* %6
br label %53
39: ; preds = %31
%40 = load i32, i32* @optarg
%41 = call i32 @atoi(i32 %40)
store i32 %41, i32* %7
br label %53
42: ; preds = %31
store i32 1, i32* %21
br label %53
43: ; preds = %31
%44 = load i32, i32* @SOCK_DGRAM
store i32 %44, i32* %17
br label %53
45: ; preds = %31
%46 = load i32, i32* @stderr
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([41 x i8], [41 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 = %43, %42, %39, %36, %34
br label %25
54: ; preds = %25
%55 = load i32, i32* %6
%56 = load i32, i32* %17
%57 = call i32 @socket(i32 %55, i32 %56, i32 0)
store i32 %57, i32* %8
%58 = load i32, i32* %6
%59 = load i32, i32* @AF_INET
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %76
61: ; preds = %54
%62 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr_in6*
%63 = call i32 @bzero(%struct.sockaddr_in6* %62, i32 48)
%64 = load i32, i32* @AF_INET
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
store i32 %64, i32* %65
%66 = load i32, i32* @INADDR_ANY
%67 = call i32 @htonl(i32 %66)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 5
%69 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %68, i32 0, i32 0
store i32 %67, i32* %69
%70 = load i32, i32* %7
%71 = call i8* @htons(i32 %70)
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 4
store i8* %71, i8** %72
%73 = load i32, i32* %8
%74 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%75 = call i32 @bind(i32 %73, %struct.sockaddr* %74, i32 48)
br label %88
76: ; preds = %54
%77 = call i32 @bzero(%struct.sockaddr_in6* %15, i32 48)
%78 = load i8*, i8** @AF_INET6
%79 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %15, i32 0, i32 3
store i8* %78, i8** %79
%80 = load i32, i32* @in6addr_any
%81 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %15, i32 0, i32 2
store i32 %80, i32* %81
%82 = load i32, i32* %7
%83 = call i8* @htons(i32 %82)
%84 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %15, i32 0, i32 1
store i8* %83, i8** %84
%85 = load i32, i32* %8
%86 = bitcast %struct.sockaddr_in6* %15 to %struct.sockaddr*
%87 = call i32 @bind(i32 %85, %struct.sockaddr* %86, i32 48)
br label %88
88: ; preds = %76, %61
%89 = call i32 @memset(%struct.sigaction* %20, i32 0, i32 8)
%90 = load i32, i32* @SIG_DFL
%91 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %20, i32 0, i32 1
store i32 %90, i32* %91
%92 = load i32, i32* @SA_NOCLDWAIT
%93 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %20, i32 0, i32 0
store i32 %92, i32* %93
%94 = load i32, i32* @SIGCHLD
%95 = call i32 @sigaction(i32 %94, %struct.sigaction* %20, i32* null)
%96 = load i32, i32* %17
%97 = load i32, i32* @SOCK_STREAM
%98 = icmp eq i32 %96, %97
br i1 %98, label %99, label %130
99: ; preds = %88
%100 = load i32, i32* %8
%101 = call i32 @listen(i32 %100, i32 4)
br label %102
102: ; preds = %127, %99
%103 = load i32, i32* %6
%104 = load i32, i32* @AF_INET
%105 = icmp eq i32 %103, %104
br i1 %105, label %106, label %110
106: ; preds = %102
store i32 48, i32* %11
%107 = load i32, i32* %8
%108 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%109 = call i32 @accept(i32 %107, %struct.sockaddr* %108, i32* %11)
store i32 %109, i32* %9
br label %114
110: ; preds = %102
store i32 48, i32* %11
%111 = load i32, i32* %8
%112 = bitcast %struct.sockaddr_in6* %14 to %struct.sockaddr*
%113 = call i32 @accept(i32 %111, %struct.sockaddr* %112, i32* %11)
store i32 %113, i32* %9
br label %114
114: ; preds = %110, %106
%115 = load i32, i32* %21
%116 = icmp ne i32 %115, 0
br i1 %116, label %119, label %117
117: ; preds = %114
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %119
119: ; preds = %117, %114
%120 = call i32 (...) @fork()
store i32 %120, i32* %10
%121 = icmp eq i32 %120, 0
br i1 %121, label %122, label %127
122: ; preds = %119
%123 = load i32, i32* %8
%124 = call i32 @close(i32 %123)
%125 = call i32 @sleep(i32 1)
%126 = call i32 @exit(i32 0)
unreachable
127: ; preds = %119
%128 = load i32, i32* %9
%129 = call i32 @close(i32 %128)
br label %102
130: ; preds = %88
br label %131
131: ; preds = %159, %130
store i32 48, i32* %11
%132 = load i32, i32* %6
%133 = load i32, i32* @AF_INET
%134 = icmp eq i32 %132, %133
br i1 %134, label %135, label %146
135: ; preds = %131
store i32 48, i32* %11
%136 = load i32, i32* %8
%137 = getelementptr inbounds [128 x i8], [128 x i8]* %19, i64 0, i64 0
%138 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%139 = call i32 @recvfrom(i32 %136, i8* %137, i32 128, i32 0, %struct.sockaddr* %138, i32* %11)
store i32 %139, i32* %18
%140 = load i32, i32* %8
%141 = getelementptr inbounds [128 x i8], [128 x i8]* %19, i64 0, i64 0
%142 = load i32, i32* %18
%143 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%144 = load i32, i32* %11
%145 = call i32 @sendto(i32 %140, i8* %141, i32 %142, i32 0, %struct.sockaddr* %143, i32 %144)
br label %153
146: ; preds = %131
store i32 48, i32* %11
%147 = load i32, i32* %8
%148 = getelementptr inbounds [128 x i8], [128 x i8]* %19, i64 0, i64 0
%149 = load i32, i32* %18
%150 = bitcast %struct.sockaddr_in6* %14 to %struct.sockaddr*
%151 = load i32, i32* %11
%152 = call i32 @sendto(i32 %147, i8* %148, i32 %149, i32 0, %struct.sockaddr* %150, i32 %151)
br label %153
153: ; preds = %146, %135
%154 = load i32, i32* %21
%155 = icmp ne i32 %154, 0
br i1 %155, label %159, label %156
156: ; preds = %153
%157 = load i32, i32* %18
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %157)
br label %159
159: ; preds = %156, %153
br label %131
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i8*, i32, i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32, i8*, i32, i8*, i8*, %struct.TYPE_2__ }
%struct.sigaction = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i8* null
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"46p:su\00"
@AF_INET = global i32 0
@optarg = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Usage: %s [-p port] [-4] [-6] [-s] [-u]\0A\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@in6addr_any = global i32 0
@SIG_DFL = global i32 0
@SA_NOCLDWAIT = global i32 0
@SIGCHLD = global i32 0
@.str.3 = [19 x i8] c"Received %d bytes\0A\00"
@str = [20 x i8] c"Received connection\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in6
%7 = alloca %struct.sockaddr_in6
%8 = alloca [128 x i8]
%9 = alloca %struct.sigaction
%10 = load i8*, i8** @AF_INET6
%11 = ptrtoint i8* %10 to i64
%12 = trunc i64 %11 to i32
%13 = bitcast i32* %3 to i8*
%14 = bitcast %struct.sockaddr_in* %4 to i8*
%15 = bitcast %struct.sockaddr_in* %5 to i8*
%16 = bitcast %struct.sockaddr_in6* %6 to i8*
%17 = bitcast %struct.sockaddr_in6* %7 to i8*
%18 = load i32, i32* @SOCK_STREAM
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%20 = bitcast %struct.sigaction* %9 to i8*
%21 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i8 %21, -1
br i1 %22, label %54, label %23
23: ; preds = %2, %47
%24 = phi i8 [ %52, %47 ], [ %21, %2 ]
%25 = phi i32 [ %51, %47 ], [ 0, %2 ]
%26 = phi i32 [ %50, %47 ], [ %18, %2 ]
%27 = phi i32 [ %49, %47 ], [ %12, %2 ]
%28 = phi i32 [ %48, %47 ], [ 30080, %2 ]
%29 = sext i8 %24 to i32
switch i32 %29, label %41 [
i32 52, label %30
i32 54, label %32
i32 112, label %36
i32 115, label %47
i32 117, label %39
]
30: ; preds = %23
%31 = load i32, i32* @AF_INET
br label %47
32: ; preds = %23
%33 = load i8*, i8** @AF_INET6
%34 = ptrtoint i8* %33 to i64
%35 = trunc i64 %34 to i32
br label %47
36: ; preds = %23
%37 = load i32, i32* @optarg
%38 = tail call i32 @atoi(i32 %37)
br label %47
39: ; preds = %23
%40 = load i32, i32* @SOCK_DGRAM
br label %47
41: ; preds = %23
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %1
%44 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %23, %39, %36, %32, %30
%48 = phi i32 [ %28, %39 ], [ %38, %36 ], [ %28, %32 ], [ %28, %30 ], [ %28, %23 ]
%49 = phi i32 [ %27, %39 ], [ %27, %36 ], [ %35, %32 ], [ %31, %30 ], [ %27, %23 ]
%50 = phi i32 [ %40, %39 ], [ %26, %36 ], [ %26, %32 ], [ %26, %30 ], [ %26, %23 ]
%51 = phi i32 [ %25, %39 ], [ %25, %36 ], [ %25, %32 ], [ %25, %30 ], [ 1, %23 ]
%52 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%53 = icmp eq i8 %52, -1
br i1 %53, label %54, label %23
54: ; preds = %47, %2
%55 = phi i32 [ 30080, %2 ], [ %48, %47 ]
%56 = phi i32 [ %12, %2 ], [ %49, %47 ]
%57 = phi i32 [ %18, %2 ], [ %50, %47 ]
%58 = phi i32 [ 0, %2 ], [ %51, %47 ]
%59 = tail call i32 @socket(i32 %56, i32 %57, i32 0)
%60 = load i32, i32* @AF_INET
%61 = icmp eq i32 %56, %60
br i1 %61, label %62, label %72
62: ; preds = %54
%63 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr_in6*
%64 = call i32 @bzero(%struct.sockaddr_in6* %63, i32 48)
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %56, i32* %65
%66 = load i32, i32* @INADDR_ANY
%67 = tail call i32 @htonl(i32 %66)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 5, i32 0
store i32 %67, i32* %68
%69 = tail call i8* @htons(i32 %55)
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 4
store i8* %69, i8** %70
%71 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %81
72: ; preds = %54
%73 = call i32 @bzero(%struct.sockaddr_in6* %7, i32 48)
%74 = load i8*, i8** @AF_INET6
%75 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %7, i64 0, i32 3
store i8* %74, i8** %75
%76 = load i32, i32* @in6addr_any
%77 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %7, i64 0, i32 2
store i32 %76, i32* %77
%78 = tail call i8* @htons(i32 %55)
%79 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %7, i64 0, i32 1
store i8* %78, i8** %79
%80 = bitcast %struct.sockaddr_in6* %7 to %struct.sockaddr*
br label %81
81: ; preds = %72, %62
%82 = phi %struct.sockaddr* [ %80, %72 ], [ %71, %62 ]
%83 = call i32 @bind(i32 %59, %struct.sockaddr* %82, i32 48)
%84 = call i32 @memset(%struct.sigaction* %9, i32 0, i32 8)
%85 = load i32, i32* @SIG_DFL
%86 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i64 0, i32 1
store i32 %85, i32* %86
%87 = load i32, i32* @SA_NOCLDWAIT
%88 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i64 0, i32 0
store i32 %87, i32* %88
%89 = load i32, i32* @SIGCHLD
%90 = call i32 @sigaction(i32 %89, %struct.sigaction* %9, i32* null)
%91 = load i32, i32* @SOCK_STREAM
%92 = icmp eq i32 %57, %91
br i1 %92, label %97, label %93
93: ; preds = %81
%94 = bitcast %struct.sockaddr_in6* %6 to %struct.sockaddr*
%95 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%96 = icmp eq i32 %58, 0
br label %118
97: ; preds = %81
%98 = call i32 @listen(i32 %59, i32 4)
%99 = bitcast %struct.sockaddr_in6* %6 to %struct.sockaddr*
%100 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%101 = icmp eq i32 %58, 0
br label %102
102: ; preds = %116, %97
%103 = load i32, i32* @AF_INET
%104 = icmp eq i32 %56, %103
store i32 48, i32* %3
%105 = select i1 %104, %struct.sockaddr* %100, %struct.sockaddr* %99
%106 = call i32 @accept(i32 %59, %struct.sockaddr* %105, i32* %3)
br i1 %101, label %107, label %109
107: ; preds = %102
%108 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %109
109: ; preds = %107, %102
%110 = call i32 (...) @fork()
%111 = icmp eq i32 %110, 0
br i1 %111, label %112, label %116
112: ; preds = %109
%113 = call i32 @close(i32 %59)
%114 = call i32 @sleep(i32 1)
%115 = call i32 @exit(i32 0)
unreachable
116: ; preds = %109
%117 = call i32 @close(i32 %106)
br label %102
118: ; preds = %132, %93
%119 = phi i32 [ undef, %93 ], [ %129, %132 ]
%120 = load i32, i32* @AF_INET
%121 = icmp eq i32 %56, %120
store i32 48, i32* %3
br i1 %121, label %122, label %126
122: ; preds = %118
%123 = call i32 @recvfrom(i32 %59, i8* %19, i32 128, i32 0, %struct.sockaddr* %95, i32* %3)
%124 = load i32, i32* %3
%125 = call i32 @sendto(i32 %59, i8* %19, i32 %123, i32 0, %struct.sockaddr* %95, i32 %124)
br label %128
126: ; preds = %118
%127 = call i32 @sendto(i32 %59, i8* %19, i32 %119, i32 0, %struct.sockaddr* %94, i32 48)
br label %128
128: ; preds = %126, %122
%129 = phi i32 [ %123, %122 ], [ %119, %126 ]
br i1 %96, label %130, label %132
130: ; preds = %128
%131 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %129)
br label %132
132: ; preds = %130, %128
br label %118
}