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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
scalar_t__ getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                       struct addrinfo **);
int getopt(int, char **, char *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
char *optarg;
char optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *server_port = "1234";
  int sockfd, rc;
  int yes = 1;
  struct addrinfo hints, *server;
  char message[256];
  int o;
  while ((o = getopt(argc, argv, "p:")) != -1) {
    switch (o) {
    case 'p':
      server_port = optarg;
      break;
    case '?':
      if (optopt == 'p') {
        fprintf(stderr, "Option %c requires an argument.\n", optopt);
      } else {
        fprintf(stderr, "Unknown argument: %c.\n", optopt);
      }
      break;
    }
  }
  printf("listening on port: %s\n", server_port);
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  if (rc = getaddrinfo(NULL, server_port, &hints, &server) != 0) {
    perror(gai_strerror(rc));
    exit(-1);
  }
  sockfd = socket(server->ai_family, server->ai_socktype, server->ai_protocol);
  if (sockfd == -1) {
    perror("ERROR opening socket");
    exit(-1);
  }
  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
    perror("setsockopt");
    exit(-1);
  }
  rc = bind(sockfd, server->ai_addr, server->ai_addrlen);
  if (rc == -1) {
    perror("ERROR on connect");
    close(sockfd);
    exit(-1);
  }
  listen(sockfd, 10);
  int imindex;
  while (1) {
    struct sockaddr_storage client_addr;
    socklen_t addr_size;
    int clientfd;
    int bytes_read;
    addr_size = sizeof client_addr;
    clientfd = accept(sockfd, (struct sockaddr *)&client_addr, &addr_size);
    bytes_read = read(clientfd, message, sizeof message);
    printf("client ip= ");
    int ipaddr;
    for (imindex = 2; imindex < 6; imindex++) {
      ipaddr = (int)(((struct sockaddr *)&client_addr)->sa_data[imindex]);
      ipaddr = (ipaddr + 256) % 256;
      printf("%d.", ipaddr);
    }
    printf("\n");
    if (bytes_read < 0) {
      perror("ERROR reading socket");
    }
    close(clientfd);
    printf("Read: %s\n", message);
  }
out:
  freeaddrinfo(server);
  close(sockfd);
  printf("Done.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdf0(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xddc(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x154(%rbp)
cmp    $0xffffffff,%eax
je     12de <main+0xee>
mov    -0x154(%rbp),%eax
mov    %eax,-0x174(%rbp)
sub    $0x3f,%eax
je     127e <main+0x8e>
jmp    1257 <main+0x67>
mov    -0x174(%rbp),%eax
sub    $0x70,%eax
jne    12d9 <main+0xe9>
jmp    126b <main+0x7b>
mov    0x2d86(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12d9 <main+0xe9>
mov    0x2d43(%rip),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
jne    12b5 <main+0xc5>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
mov    0x2d20(%rip),%rax
movsbl (%rax),%edx
call   1090 <fprintf@plt>
jmp    12d4 <main+0xe4>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
mov    0x2cfc(%rip),%rax
movsbl (%rax),%edx
call   1090 <fprintf@plt>
jmp    12d9 <main+0xe9>
jmp    121b <main+0x2b>
mov    -0x18(%rbp),%rsi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1100 <getaddrinfo@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x20(%rbp)
test   $0x1,%al
jne    1358 <main+0x168>
jmp    1372 <main+0x182>
mov    -0x20(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    %rax,%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x48(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    13af <main+0x1bf>
lea    0xcb7(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2c27(%rip),%rax
mov    (%rax),%esi
mov    0x2be6(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    13f2 <main+0x202>
lea    0xc89(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bind@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1432 <main+0x242>
lea    0xc5c(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
movl   $0x4,-0x164(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x160(%rbp),%rsi
lea    -0x164(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x168(%rbp)
mov    -0x168(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,-0x16c(%rbp)
lea    0xbff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x158(%rbp)
cmpl   $0x6,-0x158(%rbp)
jge    1500 <main+0x310>
mov    -0x160(%rbp),%rax
movslq -0x158(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %eax,-0x170(%rbp)
mov    -0x170(%rbp),%eax
add    $0x100,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x170(%rbp)
mov    -0x170(%rbp),%esi
lea    0xbaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x158(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x158(%rbp)
jmp    149a <main+0x2aa>
lea    0xb37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x16c(%rbp)
jge    1527 <main+0x337>
lea    0xb76(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x168(%rbp),%edi
call   1070 <close@plt>
lea    -0x150(%rbp),%rsi
lea    0xb6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    143f <main+0x24f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
movl   $0x1,0x14(%rsp)
lea    0xddb(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xdd4(%rip),%r15
mov    0x2d90(%rip),%r14
mov    0x2d79(%rip),%r12
lea    0xde3(%rip),%r13
jmp    125b <main+0x5b>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edx
mov    %r13,%rsi
call   10a0 <fprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10e0 <getopt@plt>
cmp    $0x3f,%eax
je     1290 <main+0x90>
cmp    $0xffffffff,%eax
je     12af <main+0xaf>
cmp    $0x70,%eax
jne    125b <main+0x5b>
mov    0x2d7a(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
jmp    125b <main+0x5b>
nopl   0x0(%rax,%rax,1)
movzbl (%r14),%eax
mov    (%r12),%edi
cmp    $0x70,%al
jne    1250 <main+0x50>
lea    0xd65(%rip),%rsi
mov    $0x70,%edx
call   10a0 <fprintf@plt>
jmp    125b <main+0x5b>
lea    0xd8a(%rip),%rdi
mov    0x18(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x28(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
mov    0x2cc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x3c(%rsp)
lea    0x20(%rsp),%rcx
xor    %edi,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1110 <getaddrinfo@plt>
test   %rax,%rax
jne    14f6 <main+0x2f6>
mov    0x20(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     1505 <main+0x305>
mov    %eax,%r13d
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
mov    0x2c5e(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    %r13d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     150e <main+0x30e>
mov    0x20(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r13d,%edi
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     1524 <main+0x324>
mov    %r13d,%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
lea    0x40(%rsp),%rbx
lea    0xcf8(%rip),%rbp
lea    0xd0a(%rip),%r14
jmp    13c5 <main+0x1c5>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
call   1080 <close@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x4,0x10(%rsp)
mov    %r13d,%edi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   10f0 <accept@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1090 <read@plt>
mov    %eax,%r12d
lea    0xc8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    0x10(%rax),%eax
lea    0x100(%rax),%ecx
lea    0x1ff(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xffffff00,%edx
neg    %edx
lea    (%rax,%rdx,1),%esi
add    $0x100,%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    0x18(%rax),%eax
lea    0x100(%rax),%ecx
lea    0x1ff(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xffffff00,%edx
neg    %edx
lea    (%rax,%rdx,1),%esi
add    $0x100,%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    0x20(%rax),%eax
lea    0x100(%rax),%ecx
lea    0x1ff(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xffffff00,%edx
neg    %edx
lea    (%rax,%rdx,1),%esi
add    $0x100,%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    0x28(%rax),%eax
lea    0x100(%rax),%ecx
lea    0x1ff(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xffffff00,%edx
neg    %edx
lea    (%rax,%rdx,1),%esi
add    $0x100,%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r12d,%r12d
jns    13b0 <main+0x1b0>
lea    0xbac(%rip),%rdi
call   10d0 <perror@plt>
jmp    13b0 <main+0x1b0>
mov    $0x1,%edi
call   1060 <gai_strerror@plt>
mov    %rax,%rdi
jmp    1515 <main+0x315>
lea    0xb4b(%rip),%rdi
jmp    1515 <main+0x315>
lea    0xb57(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
lea    0xb4c(%rip),%rdi
call   10d0 <perror@plt>
mov    %r13d,%edi
call   1080 <close@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i64* }
@.str = [5 x i8] c"1234\00"
@.str.1 = [3 x i8] c"p:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.2 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.3 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.4 = [23 x i8] c"listening on port: %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.5 = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.6 = [11 x i8] c"setsockopt\00"
@.str.7 = [17 x i8] c"ERROR on connect\00"
@.str.8 = [12 x i8] c"client ip= \00"
@.str.9 = [4 x i8] c"%d.\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [21 x i8] c"ERROR reading socket\00"
@.str.12 = [10 x i8] c"Read: %s\0A\00"
@.str.13 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca [256 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.sockaddr_storage
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 1, i32* %9
br label %20
20: ; preds = %42, %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %23, i32* %13
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %43
25: ; preds = %20
%26 = load i32, i32* %13
switch i32 %26, label %42 [
i32 112, label %27
i32 63, label %29
]
27: ; preds = %25
%28 = load i8*, i8** @optarg
store i8* %28, i8** %6
br label %42
29: ; preds = %25
%30 = load i8, i8* @optopt
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 112
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i8, i8* @optopt
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8 signext %35)
br label %41
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = load i8, i8* @optopt
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8 signext %39)
br label %41
41: ; preds = %37, %33
br label %42
42: ; preds = %25, %41, %27
br label %20
43: ; preds = %20
%44 = load i8*, i8** %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 24)
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %47, i32* %48
%49 = load i32, i32* @SOCK_STREAM
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %49, i32* %50
%51 = load i32, i32* @AI_PASSIVE
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 5
store i32 %51, i32* %52
%53 = load i8*, i8** %6
%54 = call i64 @getaddrinfo(i32* null, i8* %53, %struct.addrinfo* %10, %struct.addrinfo** %11)
%55 = icmp ne i64 %54, 0
%56 = zext i1 %55 to i32
store i32 %56, i32* %8
br i1 %55, label %57, label %62
57: ; preds = %43
%58 = load i32, i32* %8
%59 = call i8* @gai_strerror(i32 %58)
%60 = call i32 @perror(i8* %59)
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %43
%63 = load %struct.addrinfo*, %struct.addrinfo** %11
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i32 0, i32 4
%65 = load i32, i32* %64
%66 = load %struct.addrinfo*, %struct.addrinfo** %11
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i32 0, i32 3
%68 = load i32, i32* %67
%69 = load %struct.addrinfo*, %struct.addrinfo** %11
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 2
%71 = load i32, i32* %70
%72 = call i32 @socket(i32 %65, i32 %68, i32 %71)
store i32 %72, i32* %7
%73 = load i32, i32* %7
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %78
75: ; preds = %62
%76 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%77 = call i32 @exit(i32 -1)
unreachable
78: ; preds = %62
%79 = load i32, i32* %7
%80 = load i32, i32* @SOL_SOCKET
%81 = load i32, i32* @SO_REUSEADDR
%82 = call i32 @setsockopt(i32 %79, i32 %80, i32 %81, i32* %9, i32 4)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %87
84: ; preds = %78
%85 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%86 = call i32 @exit(i32 -1)
unreachable
87: ; preds = %78
%88 = load i32, i32* %7
%89 = load %struct.addrinfo*, %struct.addrinfo** %11
%90 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %89, i32 0, i32 1
%91 = load i32, i32* %90
%92 = load %struct.addrinfo*, %struct.addrinfo** %11
%93 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %92, i32 0, i32 0
%94 = load i32, i32* %93
%95 = call i32 @bind(i32 %88, i32 %91, i32 %94)
store i32 %95, i32* %8
%96 = load i32, i32* %8
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %103
98: ; preds = %87
%99 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%100 = load i32, i32* %7
%101 = call i32 @close(i32 %100)
%102 = call i32 @exit(i32 -1)
unreachable
103: ; preds = %87
%104 = load i32, i32* %7
%105 = call i32 @listen(i32 %104, i32 10)
br label %106
106: ; preds = %103, %140
store i32 4, i32* %16
%107 = load i32, i32* %7
%108 = bitcast %struct.sockaddr_storage* %15 to %struct.sockaddr*
%109 = call i32 @accept(i32 %107, %struct.sockaddr* %108, i32* %16)
store i32 %109, i32* %17
%110 = load i32, i32* %17
%111 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%112 = call i32 @read(i32 %110, i8* %111, i32 256)
store i32 %112, i32* %18
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
store i32 2, i32* %14
br label %114
114: ; preds = %131, %106
%115 = load i32, i32* %14
%116 = icmp slt i32 %115, 6
br i1 %116, label %117, label %134
117: ; preds = %114
%118 = bitcast %struct.sockaddr_storage* %15 to %struct.sockaddr*
%119 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %118, i32 0, i32 0
%120 = load i64*, i64** %119
%121 = load i32, i32* %14
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i64, i64* %120, i64 %122
%124 = load i64, i64* %123
%125 = trunc i64 %124 to i32
store i32 %125, i32* %19
%126 = load i32, i32* %19
%127 = add nsw i32 %126, 256
%128 = srem i32 %127, 256
store i32 %128, i32* %19
%129 = load i32, i32* %19
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %129)
br label %131
131: ; preds = %117
%132 = load i32, i32* %14
%133 = add nsw i32 %132, 1
store i32 %133, i32* %14
br label %114
134: ; preds = %114
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%136 = load i32, i32* %18
%137 = icmp slt i32 %136, 0
br i1 %137, label %138, label %140
138: ; preds = %134
%139 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
br label %140
140: ; preds = %138, %134
%141 = load i32, i32* %17
%142 = call i32 @close(i32 %141)
%143 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), i8* %143)
br label %106
145: ; No predecessors!
%146 = load %struct.addrinfo*, %struct.addrinfo** %11
%147 = call i32 @freeaddrinfo(%struct.addrinfo* %146)
%148 = load i32, i32* %7
%149 = call i32 @close(i32 %148)
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i64* }
@.str = [5 x i8] c"1234\00"
@.str.1 = [3 x i8] c"p:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.2 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.3 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.4 = [23 x i8] c"listening on port: %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.5 = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.6 = [11 x i8] c"setsockopt\00"
@.str.7 = [17 x i8] c"ERROR on connect\00"
@.str.8 = [12 x i8] c"client ip= \00"
@.str.9 = [4 x i8] c"%d.\00"
@.str.11 = [21 x i8] c"ERROR reading socket\00"
@.str.12 = [10 x i8] c"Read: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca [256 x i8]
%7 = alloca %struct.sockaddr_storage
%8 = alloca i32
%9 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%10 = bitcast %struct.addrinfo* %4 to i8*
%11 = bitcast %struct.addrinfo** %5 to i8*
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
br label %13
13: ; preds = %18, %2
%14 = phi i8* [ %19, %18 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
br label %15
15: ; preds = %17, %13
%16 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %16, label %17 [
i32 -1, label %28
i32 112, label %18
i32 63, label %20
]
17: ; preds = %15, %24, %26
br label %15
18: ; preds = %15
%19 = load i8*, i8** @optarg
br label %13
20: ; preds = %15
%21 = load i8, i8* @optopt
%22 = icmp eq i8 %21, 112
%23 = load i32, i32* @stderr
br i1 %22, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8 signext 112)
br label %17
26: ; preds = %20
%27 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8 signext %21)
br label %17
28: ; preds = %15
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%30 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 24)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %31, i32* %32
%33 = load i32, i32* @SOCK_STREAM
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %33, i32* %34
%35 = load i32, i32* @AI_PASSIVE
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i32 %35, i32* %36
%37 = call i64 @getaddrinfo(i32* null, i8* %14, %struct.addrinfo* %4, %struct.addrinfo** %5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %28
%40 = call i8* @gai_strerror(i32 1)
%41 = call i32 @perror(i8* %40)
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %28
%44 = load %struct.addrinfo*, %struct.addrinfo** %5
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i64 0, i32 4
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i64 0, i32 3
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i64 0, i32 2
%50 = load i32, i32* %49
%51 = call i32 @socket(i32 %46, i32 %48, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %43
%54 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%55 = call i32 @exit(i32 -1)
unreachable
56: ; preds = %43
%57 = load i32, i32* @SOL_SOCKET
%58 = load i32, i32* @SO_REUSEADDR
%59 = call i32 @setsockopt(i32 %51, i32 %57, i32 %58, i32* %3, i32 4)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %56
%65 = load %struct.addrinfo*, %struct.addrinfo** %5
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 1
%67 = load i32, i32* %66
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i64 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 @bind(i32 %51, i32 %67, i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %76
72: ; preds = %64
%73 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%74 = call i32 @close(i32 %51)
%75 = call i32 @exit(i32 -1)
unreachable
76: ; preds = %64
%77 = call i32 @listen(i32 %51, i32 10)
%78 = bitcast %struct.sockaddr_storage* %7 to i8*
%79 = bitcast i32* %8 to i8*
%80 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%81 = bitcast %struct.sockaddr_storage* %7 to i64**
br label %82
82: ; preds = %118, %76
store i32 4, i32* %8
%83 = call i32 @accept(i32 %51, %struct.sockaddr* %80, i32* %8)
%84 = call i32 @read(i32 %83, i8* %12, i32 256)
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%86 = load i64*, i64** %81
%87 = getelementptr inbounds i64, i64* %86, i64 2
%88 = load i64, i64* %87
%89 = trunc i64 %88 to i32
%90 = add nsw i32 %89, 256
%91 = srem i32 %90, 256
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %91)
%93 = load i64*, i64** %81
%94 = getelementptr inbounds i64, i64* %93, i64 3
%95 = load i64, i64* %94
%96 = trunc i64 %95 to i32
%97 = add nsw i32 %96, 256
%98 = srem i32 %97, 256
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %98)
%100 = load i64*, i64** %81
%101 = getelementptr inbounds i64, i64* %100, i64 4
%102 = load i64, i64* %101
%103 = trunc i64 %102 to i32
%104 = add nsw i32 %103, 256
%105 = srem i32 %104, 256
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %105)
%107 = load i64*, i64** %81
%108 = getelementptr inbounds i64, i64* %107, i64 5
%109 = load i64, i64* %108
%110 = trunc i64 %109 to i32
%111 = add nsw i32 %110, 256
%112 = srem i32 %111, 256
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %112)
%114 = call i32 @putchar(i32 10)
%115 = icmp slt i32 %84, 0
br i1 %115, label %116, label %118
116: ; preds = %82
%117 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
br label %118
118: ; preds = %116, %82
%119 = call i32 @close(i32 %83)
%120 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), i8* %12)
br label %82
}