#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 */
typedef int /*<<< orphan*/ v;
typedef int u_short;
struct td_desc {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char const *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ main_thread(struct td_desc **, int, int);
struct td_desc **make_threads(int *, int, int);
char *malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ printf(char *, int, int, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strtoul(char *, char **, int);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  struct addrinfo hints, *res, *res0;
  char *dummy, *packet;
  int port;
  int error, v, nthreads = 1;
  struct td_desc **tp;
  const char *cause = NULL;
  int s[20];
  int nsock;
  if (argc < 2)
    usage();
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = AI_PASSIVE;
  port = strtoul(argv[1], &dummy, 10);
  if (port < 1 || port > 65535 || *dummy != '\0')
    usage();
  if (argc > 2)
    nthreads = strtoul(argv[2], &dummy, 10);
  if (nthreads < 1 || nthreads > 64)
    usage();
  packet = malloc(65536);
  if (packet == NULL) {
    perror("malloc");
    return (-1);
  }
  bzero(packet, 65536);
  error = getaddrinfo(NULL, argv[1], &hints, &res0);
  if (error) {
    perror(gai_strerror(error));
    return (-1);
  }
  nsock = 0;
  for (res = res0; res && nsock < 20; res = res->ai_next) {
    s[nsock] = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (s[nsock] < 0) {
      cause = "socket";
      continue;
    }
    v = 128 * 1024;
    if (setsockopt(s[nsock], SOL_SOCKET, SO_RCVBUF, &v, sizeof(v)) < 0) {
      cause = "SO_RCVBUF";
      close(s[nsock]);
      continue;
    }
    if (bind(s[nsock], res->ai_addr, res->ai_addrlen) < 0) {
      cause = "bind";
      close(s[nsock]);
      continue;
    }
    (void)listen(s[nsock], 5);
    nsock++;
  }
  if (nsock == 0) {
    perror(cause);
    return (-1);
  }
  printf("netreceive %d sockets x %d threads listening on UDP port %d\n", nsock,
         nthreads, (u_short)port);
  tp = make_threads(s, nsock, nthreads);
  main_thread(tp, nsock, nthreads);
  freeaddrinfo(res0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x68(%rbp)
movq   $0x0,-0x78(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1249 <main+0x39>
mov    $0x0,%al
call   10c0 <usage@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x50(%rbp),%rsi
mov    $0xa,%edx
call   1100 <strtoul@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x1,-0x5c(%rbp)
jl     12bd <main+0xad>
cmpl   $0xffff,-0x5c(%rbp)
jg     12bd <main+0xad>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12c4 <main+0xb4>
mov    $0x0,%al
call   10c0 <usage@plt>
cmpl   $0x2,-0x8(%rbp)
jle    12e7 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x50(%rbp),%rsi
mov    $0xa,%edx
call   1100 <strtoul@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x1,-0x68(%rbp)
jl     12fb <main+0xeb>
cmpl   $0x40,-0x68(%rbp)
jle    1302 <main+0xf2>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    $0x10000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1333 <main+0x123>
lea    0xcde(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1570 <main+0x360>
mov    -0x58(%rbp),%rdi
mov    $0x10000,%esi
call   10f0 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x38(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1110 <getaddrinfo@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
je     1383 <main+0x173>
mov    -0x60(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1570 <main+0x360>
movl   $0x0,-0xd4(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x40(%rbp)
mov    %al,-0xd5(%rbp)
je     13b8 <main+0x1a8>
cmpl   $0x14,-0xd4(%rbp)
setl   %al
mov    %al,-0xd5(%rbp)
mov    -0xd5(%rbp),%al
test   $0x1,%al
jne    13cb <main+0x1bb>
jmp    1502 <main+0x2f2>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   1130 <socket@plt>
mov    %eax,%ecx
movslq -0xd4(%rbp),%rax
mov    %ecx,-0xd0(%rbp,%rax,4)
movslq -0xd4(%rbp),%rax
cmpl   $0x0,-0xd0(%rbp,%rax,4)
jge    141a <main+0x20a>
lea    0xbf6(%rip),%rax
mov    %rax,-0x78(%rbp)
jmp    14f1 <main+0x2e1>
movl   $0x20000,-0x64(%rbp)
movslq -0xd4(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%edi
mov    0x2bb2(%rip),%rax
mov    (%rax),%esi
mov    0x2b81(%rip),%rax
mov    (%rax),%edx
lea    -0x64(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    147d <main+0x26d>
lea    0xbad(%rip),%rax
mov    %rax,-0x78(%rbp)
movslq -0xd4(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%edi
call   1090 <close@plt>
jmp    14f1 <main+0x2e1>
movslq -0xd4(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    14ca <main+0x2ba>
lea    0xb6a(%rip),%rax
mov    %rax,-0x78(%rbp)
movslq -0xd4(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%edi
call   1090 <close@plt>
jmp    14f1 <main+0x2e1>
movslq -0xd4(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
mov    -0x40(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1395 <main+0x185>
cmpl   $0x0,-0xd4(%rbp)
jne    1524 <main+0x314>
mov    -0x78(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1570 <main+0x360>
mov    -0xd4(%rbp),%esi
mov    -0x68(%rbp),%edx
mov    -0x5c(%rbp),%ecx
lea    0xae6(%rip),%rdi
call   1060 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
mov    -0x68(%rbp),%edx
call   1030 <make_threads@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0xd4(%rbp),%esi
mov    -0x68(%rbp),%edx
call   1050 <main_thread@plt>
mov    -0x48(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
cmp    $0x1,%edi
jg     1212 <main+0x22>
xor    %eax,%eax
call   10b0 <usage@plt>
lea    0x28(%rsp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
mov    0x8(%r14),%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,%r15d
lea    -0x10000(%r15),%eax
cmp    $0xffff0001,%eax
jb     1278 <main+0x88>
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
je     127f <main+0x8f>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    $0x1,%ebp
cmp    $0x3,%ebx
jl     12ad <main+0xbd>
mov    0x10(%r14),%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,%ebp
add    $0xffffffbf,%eax
cmp    $0xffffffbf,%eax
ja     12ad <main+0xbd>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x8(%r14),%rsi
lea    0x28(%rsp),%rdx
lea    0x18(%rsp),%rcx
xor    %edi,%edi
call   10f0 <getaddrinfo@plt>
test   %eax,%eax
jne    1407 <main+0x217>
mov    0x18(%rsp),%r14
xor    %ebx,%ebx
test   %r14,%r14
je     1413 <main+0x223>
mov    %ebp,0x8(%rsp)
mov    %r15,0x20(%rsp)
mov    0x2cd6(%rip),%r15
lea    0xc(%rsp),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%r14),%edi
mov    0x8(%r14),%edx
mov    0xc(%r14),%esi
call   1110 <socket@plt>
mov    %eax,%ebp
movslq %ebx,%rax
mov    %ebp,0x50(%rsp,%rax,4)
test   %ebp,%ebp
js     1370 <main+0x180>
movl   $0x20000,0xc(%rsp)
mov    0x2cbb(%rip),%rax
mov    (%rax),%esi
mov    (%r15),%edx
mov    %ebp,%edi
mov    %r12,%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1380 <main+0x190>
mov    (%r14),%edx
mov    0x4(%r14),%esi
mov    %ebp,%edi
call   10c0 <bind@plt>
mov    %ebp,%edi
test   %rax,%rax
js     1390 <main+0x1a0>
mov    $0x5,%esi
call   10a0 <listen@plt>
add    $0x1,%ebx
jmp    13a0 <main+0x1b0>
nopl   0x0(%rax,%rax,1)
lea    0xc89(%rip),%r13
jmp    13a0 <main+0x1b0>
nopl   0x0(%rax)
mov    %ebp,%edi
call   1090 <close@plt>
lea    0xc79(%rip),%r13
jmp    13a0 <main+0x1b0>
call   1090 <close@plt>
lea    0xc75(%rip),%r13
nopl   0x0(%rax)
mov    0x18(%r14),%r14
test   %r14,%r14
je     13b2 <main+0x1c2>
cmp    $0x14,%ebx
jl     1300 <main+0x110>
test   %ebx,%ebx
je     1416 <main+0x226>
lea    0xc59(%rip),%rdi
mov    %ebx,%esi
mov    0x8(%rsp),%ebp
mov    %ebp,%edx
mov    0x20(%rsp),%rcx
call   1060 <printf@plt>
lea    0x50(%rsp),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <make_threads@plt>
mov    %rax,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <main_thread@plt>
mov    0x18(%rsp),%rdi
call   1100 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
jmp    1419 <main+0x229>
xor    %r13d,%r13d
mov    %r13,%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%eax
jmp    13f5 <main+0x205>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.td_desc = type { i32 }
@PF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [7 x i8] c"malloc\00"
@.str.1 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str.2 = [10 x i8] c"SO_RCVBUF\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [61 x i8] c"netreceive %d sockets x %d threads listening on UDP port %d\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 i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.td_desc**
%16 = alloca i8*
%17 = alloca [20 x i32]
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %14
store i8* null, i8** %16
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 (...) @usage()
br label %23
23: ; preds = %21, %2
%24 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 40)
%25 = load i32, i32* @PF_UNSPEC
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %25, i32* %26
%27 = load i32, i32* @SOCK_DGRAM
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %27, i32* %28
%29 = load i32, i32* @AI_PASSIVE
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i32 %29, i32* %30
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strtoul(i8* %33, i8** %9, i32 10)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = icmp slt i32 %35, 1
br i1 %36, label %45, label %37
37: ; preds = %23
%38 = load i32, i32* %11
%39 = icmp sgt i32 %38, 65535
br i1 %39, label %45, label %40
40: ; preds = %37
%41 = load i8*, i8** %9
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %40, %37, %23
%46 = call i32 (...) @usage()
br label %47
47: ; preds = %45, %40
%48 = load i32, i32* %4
%49 = icmp sgt i32 %48, 2
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @strtoul(i8* %53, i8** %9, i32 10)
store i32 %54, i32* %14
br label %55
55: ; preds = %50, %47
%56 = load i32, i32* %14
%57 = icmp slt i32 %56, 1
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = load i32, i32* %14
%60 = icmp sgt i32 %59, 64
br i1 %60, label %61, label %63
61: ; preds = %58, %55
%62 = call i32 (...) @usage()
br label %63
63: ; preds = %61, %58
%64 = call i8* @malloc(i32 65536)
store i8* %64, i8** %10
%65 = load i8*, i8** %10
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %179
69: ; preds = %63
%70 = load i8*, i8** %10
%71 = call i32 @bzero(i8* %70, i32 65536)
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = call i32 @getaddrinfo(i32* null, i8* %74, %struct.addrinfo* %6, %struct.addrinfo** %8)
store i32 %75, i32* %12
%76 = load i32, i32* %12
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %69
%79 = load i32, i32* %12
%80 = call i8* @gai_strerror(i32 %79)
%81 = call i32 @perror(i8* %80)
store i32 -1, i32* %3
br label %179
82: ; preds = %69
store i32 0, i32* %18
%83 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %83, %struct.addrinfo** %7
br label %84
84: ; preds = %154, %82
%85 = load %struct.addrinfo*, %struct.addrinfo** %7
%86 = icmp ne %struct.addrinfo* %85, null
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i32, i32* %18
%89 = icmp slt i32 %88, 20
br label %90
90: ; preds = %87, %84
%91 = phi i1 [ false, %84 ], [ %89, %87 ]
br i1 %91, label %92, label %158
92: ; preds = %90
%93 = load %struct.addrinfo*, %struct.addrinfo** %7
%94 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %93, i32 0, i32 4
%95 = load i32, i32* %94
%96 = load %struct.addrinfo*, %struct.addrinfo** %7
%97 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %96, i32 0, i32 3
%98 = load i32, i32* %97
%99 = load %struct.addrinfo*, %struct.addrinfo** %7
%100 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %99, i32 0, i32 2
%101 = load i32, i32* %100
%102 = call i32 @socket(i32 %95, i32 %98, i32 %101)
%103 = load i32, i32* %18
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %104
store i32 %102, i32* %105
%106 = load i32, i32* %18
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %107
%109 = load i32, i32* %108
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %112
111: ; preds = %92
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %16
br label %154
112: ; preds = %92
store i32 131072, i32* %13
%113 = load i32, i32* %18
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %114
%116 = load i32, i32* %115
%117 = load i32, i32* @SOL_SOCKET
%118 = load i32, i32* @SO_RCVBUF
%119 = call i64 @setsockopt(i32 %116, i32 %117, i32 %118, i32* %13, i32 4)
%120 = icmp slt i64 %119, 0
br i1 %120, label %121, label %127
121: ; preds = %112
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %16
%122 = load i32, i32* %18
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %123
%125 = load i32, i32* %124
%126 = call i32 @close(i32 %125)
br label %154
127: ; preds = %112
%128 = load i32, i32* %18
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %129
%131 = load i32, i32* %130
%132 = load %struct.addrinfo*, %struct.addrinfo** %7
%133 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %132, i32 0, i32 1
%134 = load i32, i32* %133
%135 = load %struct.addrinfo*, %struct.addrinfo** %7
%136 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %135, i32 0, i32 0
%137 = load i32, i32* %136
%138 = call i64 @bind(i32 %131, i32 %134, i32 %137)
%139 = icmp slt i64 %138, 0
br i1 %139, label %140, label %146
140: ; preds = %127
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %16
%141 = load i32, i32* %18
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %142
%144 = load i32, i32* %143
%145 = call i32 @close(i32 %144)
br label %154
146: ; preds = %127
%147 = load i32, i32* %18
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 %148
%150 = load i32, i32* %149
%151 = call i32 @listen(i32 %150, i32 5)
%152 = load i32, i32* %18
%153 = add nsw i32 %152, 1
store i32 %153, i32* %18
br label %154
154: ; preds = %146, %140, %121, %111
%155 = load %struct.addrinfo*, %struct.addrinfo** %7
%156 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %155, i32 0, i32 5
%157 = load %struct.addrinfo*, %struct.addrinfo** %156
store %struct.addrinfo* %157, %struct.addrinfo** %7
br label %84
158: ; preds = %90
%159 = load i32, i32* %18
%160 = icmp eq i32 %159, 0
br i1 %160, label %161, label %164
161: ; preds = %158
%162 = load i8*, i8** %16
%163 = call i32 @perror(i8* %162)
store i32 -1, i32* %3
br label %179
164: ; preds = %158
%165 = load i32, i32* %18
%166 = load i32, i32* %14
%167 = load i32, i32* %11
%168 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %165, i32 %166, i32 %167)
%169 = getelementptr inbounds [20 x i32], [20 x i32]* %17, i64 0, i64 0
%170 = load i32, i32* %18
%171 = load i32, i32* %14
%172 = call %struct.td_desc** @make_threads(i32* %169, i32 %170, i32 %171)
store %struct.td_desc** %172, %struct.td_desc*** %15
%173 = load %struct.td_desc**, %struct.td_desc*** %15
%174 = load i32, i32* %18
%175 = load i32, i32* %14
%176 = call i32 @main_thread(%struct.td_desc** %173, i32 %174, i32 %175)
%177 = load %struct.addrinfo*, %struct.addrinfo** %8
%178 = call i32 @freeaddrinfo(%struct.addrinfo* %177)
br label %179
179: ; preds = %164, %161, %78, %67
%180 = load i32, i32* %3
ret i32 %180
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.td_desc = type { i32 }
@PF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str.2 = [10 x i8] c"SO_RCVBUF\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [61 x i8] c"netreceive %d sockets x %d threads listening on UDP port %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [20 x i32]
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = bitcast i8** %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast [20 x i32]* %7 to i8*
%13 = icmp slt i32 %0, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 (...) @usage()
br label %16
16: ; preds = %14, %2
%17 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%18 = load i32, i32* @PF_UNSPEC
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %18, i32* %19
%20 = load i32, i32* @SOCK_DGRAM
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %20, i32* %21
%22 = load i32, i32* @AI_PASSIVE
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strtoul(i8* %25, i8** %5, i32 10)
%27 = add i32 %26, -65536
%28 = icmp ult i32 %27, -65535
br i1 %28, label %33, label %29
29: ; preds = %16
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29, %16
%34 = call i32 (...) @usage()
br label %35
35: ; preds = %33, %29
%36 = icmp sgt i32 %0, 2
br i1 %36, label %37, label %45
37: ; preds = %35
%38 = getelementptr inbounds i8*, i8** %1, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @strtoul(i8* %39, i8** %5, i32 10)
%41 = add i32 %40, -65
%42 = icmp ult i32 %41, -64
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (...) @usage()
br label %45
45: ; preds = %35, %43, %37
%46 = phi i32 [ %40, %43 ], [ %40, %37 ], [ 1, %35 ]
%47 = load i8*, i8** %24
%48 = call i32 @getaddrinfo(i32* null, i8* %47, %struct.addrinfo* %3, %struct.addrinfo** %4)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load %struct.addrinfo*, %struct.addrinfo** %4
%52 = icmp eq %struct.addrinfo* %51, null
br i1 %52, label %99, label %56
53: ; preds = %45
%54 = call i8* @gai_strerror(i32 %48)
%55 = call i32 @perror(i8* %54)
br label %109
56: ; preds = %50, %89
%57 = phi %struct.addrinfo* [ %93, %89 ], [ %51, %50 ]
%58 = phi i32 [ %91, %89 ], [ 0, %50 ]
%59 = phi i8* [ %90, %89 ], [ null, %50 ]
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 4
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 3
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 2
%65 = load i32, i32* %64
%66 = call i32 @socket(i32 %61, i32 %63, i32 %65)
%67 = sext i32 %58 to i64
%68 = getelementptr inbounds [20 x i32], [20 x i32]* %7, i64 0, i64 %67
store i32 %66, i32* %68
%69 = icmp slt i32 %66, 0
br i1 %69, label %89, label %70
70: ; preds = %56
store i32 131072, i32* %6
%71 = load i32, i32* @SOL_SOCKET
%72 = load i32, i32* @SO_RCVBUF
%73 = call i64 @setsockopt(i32 %66, i32 %71, i32 %72, i32* %6, i32 4)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %70
%76 = call i32 @close(i32 %66)
br label %89
77: ; preds = %70
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 1
%79 = load i32, i32* %78
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 0
%81 = load i32, i32* %80
%82 = call i64 @bind(i32 %66, i32 %79, i32 %81)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %77
%85 = call i32 @close(i32 %66)
br label %89
86: ; preds = %77
%87 = call i32 @listen(i32 %66, i32 5)
%88 = add nsw i32 %58, 1
br label %89
89: ; preds = %56, %86, %84, %75
%90 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %75 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %84 ], [ %59, %86 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %56 ]
%91 = phi i32 [ %58, %75 ], [ %58, %84 ], [ %88, %86 ], [ %58, %56 ]
%92 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 5
%93 = load %struct.addrinfo*, %struct.addrinfo** %92
%94 = icmp ne %struct.addrinfo* %93, null
%95 = icmp slt i32 %91, 20
%96 = select i1 %94, i1 %95, i1 false
br i1 %96, label %56, label %97
97: ; preds = %89
%98 = icmp eq i32 %91, 0
br i1 %98, label %99, label %102
99: ; preds = %50, %97
%100 = phi i8* [ %90, %97 ], [ null, %50 ]
%101 = call i32 @perror(i8* %100)
br label %109
102: ; preds = %97
%103 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %91, i32 %46, i32 %26)
%104 = getelementptr inbounds [20 x i32], [20 x i32]* %7, i64 0, i64 0
%105 = call %struct.td_desc** @make_threads(i32* %104, i32 %91, i32 %46)
%106 = call i32 @main_thread(%struct.td_desc** %105, i32 %91, i32 %46)
%107 = load %struct.addrinfo*, %struct.addrinfo** %4
%108 = call i32 @freeaddrinfo(%struct.addrinfo* %107)
br label %109
109: ; preds = %102, %99, %53
%110 = phi i32 [ -1, %53 ], [ -1, %99 ], [ 0, %102 ]
ret i32 %110
}