#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 */
typedef int /*<<< orphan*/ svaddr;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int NI_MAXHOST;
int NI_MAXSERV;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int getnameinfo(struct sockaddr *, int, char *, int, char *, int,
                int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int inet_pton(int /*<<< orphan*/, char *, TYPE_1__ *);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char *argv[]) {
  int sockfd;
  int clifd[65536];
  int nbytes;
  struct sockaddr_in svaddr, cliaddr;
  socklen_t addr_len;
  char buf[] = "hello, world";
  char host[NI_MAXHOST];
  char service[NI_MAXSERV];
  int ret, i;
  if (argc != 2 && argc != 3) {
    fprintf(stderr, "Usage: %s <port> [ip]\n", argv[0]);
    exit(-1);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket() failed");
    exit(errno);
  }
  memset(&svaddr, 0, sizeof(svaddr));
  svaddr.sin_family = AF_INET;
  svaddr.sin_port = htons(atoi(argv[1]));
  if (argv[2]) {
    if (inet_pton(AF_INET, argv[2], &(svaddr.sin_addr)) != 1) {
      fprintf(stderr, "inet_pton() convert %s failed: %s\n", argv[2],
              strerror(errno));
      exit(errno);
    }
  } else {
    svaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  }
  if (bind(sockfd, (struct sockaddr *)&svaddr, sizeof(svaddr)) == -1) {
    perror("bind() failed");
    exit(errno);
  }
  if (listen(sockfd, 5) == -1) {
    perror("listen() failed");
    exit(errno);
  }
  i = 0;
  while (1) {
    addr_len = sizeof(cliaddr);
    clifd[i] = accept(sockfd, (struct sockaddr *)&cliaddr, &addr_len);
    if (clifd[i] == -1) {
      perror("accept() failed");
      exit(errno);
    }
    ret = getnameinfo((struct sockaddr *)&cliaddr, addr_len, host, NI_MAXHOST,
                      service, NI_MAXSERV, 0);
    if (ret == 0)
      printf("Client %d connection from: %s (%s)\n", ++i, host, service);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x646c726f77202c,%rax
mov    %rax,-0x40053(%rbp)
movabs $0x77202c6f6c6c6568,%rax
2c 20 77
mov    %rax,-0x40058(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40060(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40088(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40068(%rbp)
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40080(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40070(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     12c7 <main+0xd7>
cmpl   $0x3,-0x8(%rbp)
je     12c7 <main+0xd7>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1306 <main+0x116>
lea    0xd31(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x40030(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40028(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x4002c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     13d4 <main+0x1e4>
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x40030(%rbp),%rdx
call   1090 <inet_pton@plt>
cmp    $0x1,%eax
je     13cf <main+0x1df>
mov    0x2c4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40094(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40090(%rbp)
mov    0x2c1c(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x40094(%rbp),%edi
mov    -0x40090(%rbp),%rdx
mov    %rax,%rcx
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2bf0(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    13e8 <main+0x1f8>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x40030(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40030(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    141f <main+0x22f>
lea    0xc4b(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    144f <main+0x25f>
lea    0xc29(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2b70(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movl   $0x0,-0x40078(%rbp)
jmp    145e <main+0x26e>
movl   $0xc,-0x40044(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40040(%rbp),%rsi
lea    -0x40044(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,%ecx
movslq -0x40078(%rbp),%rax
mov    %ecx,-0x40020(%rbp,%rax,4)
movslq -0x40078(%rbp),%rax
cmpl   $0xffffffff,-0x40020(%rbp,%rax,4)
ff
jne    14bd <main+0x2cd>
lea    0xbcb(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2b02(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x40080(%rbp),%r8
mov    -0x40088(%rbp),%rdx
lea    -0x40040(%rbp),%rdi
mov    -0x40044(%rbp),%esi
mov    0x2ad1(%rip),%rax
mov    (%rax),%ecx
mov    0x2af8(%rip),%rax
mov    (%rax),%r9d
xor    %eax,%eax
sub    $0x10,%rsp
movl   $0x0,(%rsp)
call   1070 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x40074(%rbp)
cmpl   $0x0,-0x40074(%rbp)
jne    153d <main+0x34d>
mov    -0x40080(%rbp),%rcx
mov    -0x40088(%rbp),%rdx
mov    -0x40078(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x40078(%rbp)
lea    0xb4d(%rip),%rdi
call   1040 <printf@plt>
jmp    1459 <main+0x269>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r12
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
and    $0xfffffffe,%edi
cmp    $0x2,%edi
jne    126b <main+0x7b>
mov    0x2da1(%rip),%r14
mov    (%r14),%edi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
jne    1290 <main+0xa0>
lea    0xdb1(%rip),%rdi
jmp    1391 <main+0x1a1>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xd81(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    %eax,%r15d
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r14),%eax
mov    %eax,-0x30(%rbp)
mov    0x8(%r12),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    0x10(%r12),%rsi
test   %rsi,%rsi
jne    12da <main+0xea>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x38(%rbp)
jmp    12eb <main+0xfb>
mov    (%r14),%edi
lea    -0x38(%rbp),%rdx
call   1090 <inet_pton@plt>
cmp    $0x1,%eax
jne    1328 <main+0x138>
lea    -0x38(%rbp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    130d <main+0x11d>
lea    0xd42(%rip),%rdi
jmp    1391 <main+0x1a1>
mov    %r15d,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1363 <main+0x173>
lea    0xd32(%rip),%rdi
jmp    1391 <main+0x1a1>
mov    0x2c99(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%r12),%r14
mov    0x2c7b(%rip),%r15
mov    (%r15),%edi
call   1100 <strerror@plt>
lea    0xcdb(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r15),%edi
call   10f0 <exit@plt>
mov    %rbx,-0x40(%rbp)
mov    %r13,-0x48(%rbp)
movl   $0xc,-0x2c(%rbp)
lea    -0x58(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %r15d,%r14d
mov    %r15d,%edi
call   10d0 <accept@plt>
cmp    $0xffffffff,%eax
jne    13a4 <main+0x1b4>
lea    0xcd7(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c1b(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
xor    %ebx,%ebx
lea    -0x58(%rbp),%r12
mov    -0x48(%rbp),%r15
mov    -0x40(%rbp),%r13
jmp    13db <main+0x1eb>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0xc,-0x2c(%rbp)
mov    %r14d,%edi
mov    %r12,%rsi
lea    -0x2c(%rbp),%rdx
call   10d0 <accept@plt>
cmp    $0xffffffff,%eax
je     138a <main+0x19a>
mov    -0x2c(%rbp),%esi
mov    0x2bcb(%rip),%rax
mov    (%rax),%ecx
mov    0x2bf2(%rip),%rax
mov    (%rax),%r9d
sub    $0x8,%rsp
mov    %r12,%rdi
mov    %r15,%rdx
mov    %r13,%r8
push   $0x0
call   1070 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    13c0 <main+0x1d0>
add    $0x1,%ebx
lea    0xc61(%rip),%rdi
mov    %ebx,%esi
mov    %r15,%rdx
mov    %r13,%rcx
call   1040 <printf@plt>
jmp    13c0 <main+0x1d0>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [13 x i8] c"hello, world\00"
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s <port> [ip]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@errno = global i32 0
@.str.2 = [35 x i8] c"inet_pton() convert %s failed: %s\0A\00"
@INADDR_ANY = global i32 0
@.str.3 = [14 x i8] c"bind() failed\00"
@.str.4 = [16 x i8] c"listen() failed\00"
@.str.5 = [16 x i8] c"accept() failed\00"
@.str.6 = [36 x i8] c"Client %d connection from: %s (%s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [65536 x i32]
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [13 x i8]
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = bitcast [13 x i8]* %12 to i8*
%19 = load i32, i32* @NI_MAXHOST
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %13
%22 = alloca i8, i64 %20
store i64 %20, i64* %14
%23 = load i32, i32* @NI_MAXSERV
%24 = zext i32 %23 to i64
%25 = alloca i8, i64 %24
store i64 %24, i64* %15
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 2
br i1 %27, label %28, label %38
28: ; preds = %2
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 3
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %28, %2
%39 = load i32, i32* @AF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %6
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %38
%44 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32, i32* @errno
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %38
%48 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%49 = load i32, i32* @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %49, i32* %50
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
%55 = call i32 @htons(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %55, i32* %56
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %80
61: ; preds = %47
%62 = load i32, i32* @AF_INET
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%67 = call i32 @inet_pton(i32 %62, i8* %65, %struct.TYPE_2__* %66)
%68 = icmp ne i32 %67, 1
br i1 %68, label %69, label %79
69: ; preds = %61
%70 = load i32, i32* @stderr
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %73, i8* %75)
%77 = load i32, i32* @errno
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %61
br label %85
80: ; preds = %47
%81 = load i32, i32* @INADDR_ANY
%82 = call i32 @htonl(i32 %81)
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%84 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %83, i32 0, i32 0
store i32 %82, i32* %84
br label %85
85: ; preds = %80, %79
%86 = load i32, i32* %6
%87 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%88 = call i32 @bind(i32 %86, %struct.sockaddr* %87, i32 12)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %94
90: ; preds = %85
%91 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%92 = load i32, i32* @errno
%93 = call i32 @exit(i32 %92)
unreachable
94: ; preds = %85
%95 = load i32, i32* %6
%96 = call i32 @listen(i32 %95, i32 5)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %102
98: ; preds = %94
%99 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%100 = load i32, i32* @errno
%101 = call i32 @exit(i32 %100)
unreachable
102: ; preds = %94
store i32 0, i32* %17
br label %103
103: ; preds = %132, %102
br label %104
104: ; preds = %103
store i32 12, i32* %11
%105 = load i32, i32* %6
%106 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%107 = call i32 @accept(i32 %105, %struct.sockaddr* %106, i32* %11)
%108 = load i32, i32* %17
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [65536 x i32], [65536 x i32]* %7, i64 0, i64 %109
store i32 %107, i32* %110
%111 = load i32, i32* %17
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [65536 x i32], [65536 x i32]* %7, i64 0, i64 %112
%114 = load i32, i32* %113
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %120
116: ; preds = %104
%117 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%118 = load i32, i32* @errno
%119 = call i32 @exit(i32 %118)
unreachable
120: ; preds = %104
%121 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%122 = load i32, i32* %11
%123 = load i32, i32* @NI_MAXHOST
%124 = load i32, i32* @NI_MAXSERV
%125 = call i32 @getnameinfo(%struct.sockaddr* %121, i32 %122, i8* %22, i32 %123, i8* %25, i32 %124, i32 0)
store i32 %125, i32* %16
%126 = load i32, i32* %16
%127 = icmp eq i32 %126, 0
br i1 %127, label %128, label %132
128: ; preds = %120
%129 = load i32, i32* %17
%130 = add nsw i32 %129, 1
store i32 %130, i32* %17
%131 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %130, i8* %22, i8* %25)
br label %132
132: ; preds = %128, %120
br label %103
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s <port> [ip]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@errno = global i32 0
@.str.2 = [35 x i8] c"inet_pton() convert %s failed: %s\0A\00"
@INADDR_ANY = global i32 0
@.str.3 = [14 x i8] c"bind() failed\00"
@.str.4 = [16 x i8] c"listen() failed\00"
@.str.5 = [16 x i8] c"accept() failed\00"
@.str.6 = [36 x i8] c"Client %d connection from: %s (%s)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @NI_MAXHOST
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = load i32, i32* @NI_MAXSERV
%13 = zext i32 %12 to i64
%14 = alloca i8, i64 %13
%15 = and i32 %0, -2
%16 = icmp eq i32 %15, 2
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @errno
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %22
%32 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %33, i32* %34
%35 = getelementptr inbounds i8*, i8** %1, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %38, i32* %39
%40 = getelementptr inbounds i8*, i8** %1, i64 2
%41 = load i8*, i8** %40
%42 = icmp eq i8* %41, null
br i1 %42, label %56, label %43
43: ; preds = %31
%44 = load i32, i32* @AF_INET
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%46 = call i32 @inet_pton(i32 %44, i8* %41, %struct.TYPE_2__* %45)
%47 = icmp eq i32 %46, 1
br i1 %47, label %60, label %48
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %40
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %50, i8* %52)
%54 = load i32, i32* @errno
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %31
%57 = load i32, i32* @INADDR_ANY
%58 = call i32 @htonl(i32 %57)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %58, i32* %59
br label %60
60: ; preds = %43, %56
%61 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%62 = call i32 @bind(i32 %25, %struct.sockaddr* %61, i32 12)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %60
%65 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%66 = load i32, i32* @errno
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %60
%69 = call i32 @listen(i32 %25, i32 5)
%70 = icmp eq i32 %69, -1
br i1 %70, label %75, label %71
71: ; preds = %68
%72 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
store i32 12, i32* %5
%73 = call i32 @accept(i32 %25, %struct.sockaddr* %72, i32* %5)
%74 = icmp eq i32 %73, -1
br i1 %74, label %79, label %83
75: ; preds = %68
%76 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32, i32* @errno
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %93, %71
%80 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%81 = load i32, i32* @errno
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %71, %93
%84 = phi i32 [ %94, %93 ], [ 0, %71 ]
%85 = load i32, i32* %5
%86 = load i32, i32* @NI_MAXHOST
%87 = load i32, i32* @NI_MAXSERV
%88 = call i32 @getnameinfo(%struct.sockaddr* %72, i32 %85, i8* %11, i32 %86, i8* %14, i32 %87, i32 0)
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %83
%91 = add nsw i32 %84, 1
%92 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %91, i8* %11, i8* %14)
br label %93
93: ; preds = %90, %83
%94 = phi i32 [ %91, %90 ], [ %84, %83 ]
store i32 12, i32* %5
%95 = call i32 @accept(i32 %25, %struct.sockaddr* %72, i32* %5)
%96 = icmp eq i32 %95, -1
br i1 %96, label %79, label %83
}