#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_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ sockaddr;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int SOCK_NONBLOCK;
int SOCK_STREAM;
scalar_t__ accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int atoi(char *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ listen(int, int);
int *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argc < 2 || !strcmp(argv[1], "-h")) {
    fprintf(stderr, "usage: %s ARGUMENTS...\n", argv[0]);
    return EXIT_FAILURE;
  }
  int nsocks = argc - 1;
  int *sockets = malloc(nsocks * sizeof(int));
  int *ports = malloc(nsocks * sizeof(int));
  fd_set set;
  struct sockaddr_in sockaddr;
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_addr.s_addr = INADDR_ANY;
  socklen_t socklen;
  for (int i = 0; i < nsocks; ++i) {
    int port = atoi(argv[i + 1]);
    ports[i] = port;
    sockaddr.sin_port = htons(port);
    sockets[i] = socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
    bind(sockets[i], (struct sockaddr *)&sockaddr, sizeof(sockaddr));
    listen(sockets[i], 10);
    FD_SET(sockets[i], &set);
  }
  FILE *cxlog = fopen("cxlog", "w");
  for (;;) {
    fd_set s = set;
    select(sockets[nsocks - 1] + 1, &s, NULL, NULL, NULL);
    for (int i = 0; i < nsocks; ++i) {
      if (FD_ISSET(sockets[i], &s)) {
        if (accept(sockets[i], (struct sockaddr *)&sockaddr, &socklen) >= 0) {
          fprintf(cxlog, "connection established with %s on port %d\n",
                  inet_ntoa(sockaddr.sin_addr), ports[i]);
          fflush(cxlog);
        } else {
          perror("failure\n");
          exit(1);
        }
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     124d <main+0x3d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc1(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    127b <main+0x6b>
mov    0x2d74(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1386 <main+0x176>
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x44(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
mov    0x2ca9(%rip),%rax
mov    (%rax),%esi
mov    0x2cb0(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x2c(%rbp),%rsi
call   1120 <FD_SET@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12c9 <main+0xb9>
lea    0xc8e(%rip),%rdi
lea    0xc8d(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
add    $0x1,%edi
lea    -0x54(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1080 <select@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1489 <main+0x279>
mov    -0x20(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x54(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1476 <main+0x266>
mov    -0x20(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10f0 <accept@plt>
cmp    $0x0,%rax
jl     145b <main+0x24b>
mov    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xbdd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x50(%rbp),%rdi
call   10a0 <fflush@plt>
jmp    1471 <main+0x261>
lea    0xbec(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
jmp    1489 <main+0x279>
jmp    147b <main+0x26b>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    13d1 <main+0x1c1>
jmp    139d <main+0x18d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r12
cmp    $0x2,%edi
jl     123d <main+0x2d>
mov    %edi,%ebx
mov    0x8(%r12),%rdi
lea    0xdcc(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1271 <main+0x61>
mov    0x2d84(%rip),%rax
movslq (%rax),%rdi
mov    (%r12),%rdx
lea    0xdb1(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    -0x1(%rbx),%r14d
mov    %rbx,0x20(%rsp)
lea    -0x4(,%rbx,4),%ebp
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbp),%r15
mov    0x8(%r12,%rbp,8),%rdi
call   1100 <atoi@plt>
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx,%rbp,4)
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
mov    0x2cc6(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%r13d
mov    %eax,(%rbx,%rbp,4)
mov    %eax,%edi
mov    %rsp,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    %r13d,%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
mov    %r13d,%edi
lea    0x14(%rsp),%rsi
call   1120 <FD_SET@plt>
mov    %r15,%rbp
cmp    %r15,%r14
jne    12c0 <main+0xb0>
lea    0xcda(%rip),%rdi
lea    0xcd9(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,0x28(%rsp)
mov    0x20(%rsp),%rax
add    $0xfffffffe,%eax
mov    (%rbx,%rax,4),%r15d
add    $0x1,%r15d
lea    0x10(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    0x14(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <select@plt>
xor    %r12d,%r12d
nopl   (%rax)
mov    (%rbx,%r12,4),%r13d
mov    %r13d,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
jne    13b0 <main+0x1a0>
add    $0x1,%r12
cmp    %r12,%r14
jne    1390 <main+0x180>
jmp    1370 <main+0x160>
nop
mov    %r13d,%edi
mov    %rsp,%rsi
lea    0x34(%rsp),%rdx
call   10f0 <accept@plt>
test   %rax,%rax
js     13fc <main+0x1ec>
mov    (%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    0x18(%rsp),%rcx
mov    (%rcx,%r12,4),%ecx
mov    0x28(%rsp),%r12
mov    %r12,%rdi
lea    0xc3e(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r12,%rdi
call   10a0 <fflush@plt>
jmp    1370 <main+0x160>
lea    0xc4b(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"-h\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"usage: %s ARGUMENTS...\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str.2 = [6 x i8] c"cxlog\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [43 x i8] c"connection established with %s on port %d\0A\00"
@.str.5 = [9 x i8] c"failure\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 %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %25, label %19
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %34, label %25
25: ; preds = %19, %2
%26 = load i32, i32* @stderr
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i32*
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
ret i32 %33
34: ; preds = %19
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 4
%40 = trunc i64 %39 to i32
%41 = call i32* @malloc(i32 %40)
store i32* %41, i32** %7
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 4
%45 = trunc i64 %44 to i32
%46 = call i32* @malloc(i32 %45)
store i32* %46, i32** %8
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %47, i32* %48
%49 = load i32, i32* @INADDR_ANY
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
store i32 %49, i32* %51
store i32 0, i32* %12
br label %52
52: ; preds = %100, %34
%53 = load i32, i32* %12
%54 = load i32, i32* %6
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %103
56: ; preds = %52
%57 = load i8**, i8*** %5
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %57, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @atoi(i8* %62)
store i32 %63, i32* %13
%64 = load i32, i32* %13
%65 = load i32*, i32** %8
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
store i32 %64, i32* %68
%69 = load i32, i32* %13
%70 = call i32 @htons(i32 %69)
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %70, i32* %71
%72 = load i32, i32* @PF_INET
%73 = load i32, i32* @SOCK_STREAM
%74 = load i32, i32* @SOCK_NONBLOCK
%75 = or i32 %73, %74
%76 = call i32 @socket(i32 %72, i32 %75, i32 0)
%77 = load i32*, i32** %7
%78 = load i32, i32* %12
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
store i32 %76, i32* %80
%81 = load i32*, i32** %7
%82 = load i32, i32* %12
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %81, i64 %83
%85 = load i32, i32* %84
%86 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%87 = call i32 @bind(i32 %85, %struct.sockaddr* %86, i32 12)
%88 = load i32*, i32** %7
%89 = load i32, i32* %12
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
%92 = load i32, i32* %91
%93 = call i32 @listen(i32 %92, i32 10)
%94 = load i32*, i32** %7
%95 = load i32, i32* %12
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i32, i32* %94, i64 %96
%98 = load i32, i32* %97
%99 = call i32 @FD_SET(i32 %98, i32* %9)
br label %100
100: ; preds = %56
%101 = load i32, i32* %12
%102 = add nsw i32 %101, 1
store i32 %102, i32* %12
br label %52
103: ; preds = %52
%104 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %104, i32** %14
br label %105
105: ; preds = %158, %103
%106 = load i32, i32* %9
store i32 %106, i32* %15
%107 = load i32*, i32** %7
%108 = load i32, i32* %6
%109 = sub nsw i32 %108, 1
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i32, i32* %107, i64 %110
%112 = load i32, i32* %111
%113 = add nsw i32 %112, 1
%114 = call i32 @select(i32 %113, i32* %15, i32* null, i32* null, i32* null)
store i32 0, i32* %16
br label %115
115: ; preds = %155, %105
%116 = load i32, i32* %16
%117 = load i32, i32* %6
%118 = icmp slt i32 %116, %117
br i1 %118, label %119, label %158
119: ; preds = %115
%120 = load i32*, i32** %7
%121 = load i32, i32* %16
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i32, i32* %120, i64 %122
%124 = load i32, i32* %123
%125 = call i64 @FD_ISSET(i32 %124, i32* %15)
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %154
127: ; preds = %119
%128 = load i32*, i32** %7
%129 = load i32, i32* %16
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i32, i32* %128, i64 %130
%132 = load i32, i32* %131
%133 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%134 = call i64 @accept(i32 %132, %struct.sockaddr* %133, i32* %11)
%135 = icmp sge i64 %134, 0
br i1 %135, label %136, label %150
136: ; preds = %127
%137 = load i32*, i32** %14
%138 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%139 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %138, i32 0, i32 0
%140 = load i32, i32* %139
%141 = call i8* @inet_ntoa(i32 %140)
%142 = load i32*, i32** %8
%143 = load i32, i32* %16
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds i32, i32* %142, i64 %144
%146 = load i32, i32* %145
%147 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %137, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %141, i32 %146)
%148 = load i32*, i32** %14
%149 = call i32 @fflush(i32* %148)
br label %153
150: ; preds = %127
%151 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%152 = call i32 @exit(i32 1)
unreachable
153: ; preds = %136
br label %158
154: ; preds = %119
br label %155
155: ; preds = %154
%156 = load i32, i32* %16
%157 = add nsw i32 %156, 1
store i32 %157, i32* %16
br label %115
158: ; preds = %153, %115
br label %105
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"-h\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"usage: %s ARGUMENTS...\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str.2 = [6 x i8] c"cxlog\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [43 x i8] c"connection established with %s on port %d\0A\00"
@.str.5 = [9 x i8] c"failure\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = icmp slt i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %8, %2
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = load i8*, i8** %1
%18 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
ret i32 %19
20: ; preds = %8
%21 = add nsw i32 %0, -1
%22 = shl i32 %21, 2
%23 = tail call i32* @malloc(i32 %22)
%24 = tail call i32* @malloc(i32 %22)
%25 = bitcast i32* %3 to i8*
%26 = bitcast %struct.sockaddr_in* %4 to i8*
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %29, i32* %30
%31 = bitcast i32* %5 to i8*
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = zext i32 %21 to i64
br label %45
35: ; preds = %45
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%37 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = bitcast i32* %6 to i8*
%39 = add nsw i32 %0, -2
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %23, i64 %40
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
%44 = zext i32 %21 to i64
br label %63
45: ; preds = %45, %20
%46 = phi i64 [ 0, %20 ], [ %47, %45 ]
%47 = add nuw nsw i64 %46, 1
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
%51 = getelementptr inbounds i32, i32* %24, i64 %46
store i32 %50, i32* %51
%52 = call i32 @htons(i32 %50)
store i32 %52, i32* %32
%53 = load i32, i32* @PF_INET
%54 = load i32, i32* @SOCK_STREAM
%55 = load i32, i32* @SOCK_NONBLOCK
%56 = or i32 %55, %54
%57 = call i32 @socket(i32 %53, i32 %56, i32 0)
%58 = getelementptr inbounds i32, i32* %23, i64 %46
store i32 %57, i32* %58
%59 = call i32 @bind(i32 %57, %struct.sockaddr* %33, i32 12)
%60 = call i32 @listen(i32 %57, i32 10)
%61 = call i32 @FD_SET(i32 %57, i32* %3)
%62 = icmp eq i64 %47, %34
br i1 %62, label %35, label %45
63: ; preds = %35, %89
%64 = load i32, i32* %3
store i32 %64, i32* %6
%65 = call i32 @select(i32 %43, i32* %6, i32* null, i32* null, i32* null)
br label %66
66: ; preds = %63, %86
%67 = phi i64 [ 0, %63 ], [ %87, %86 ]
%68 = getelementptr inbounds i32, i32* %23, i64 %67
%69 = load i32, i32* %68
%70 = call i64 @FD_ISSET(i32 %69, i32* %6)
%71 = icmp eq i64 %70, 0
br i1 %71, label %86, label %72
72: ; preds = %66
%73 = call i64 @accept(i32 %69, %struct.sockaddr* %36, i32* %5)
%74 = icmp sgt i64 %73, -1
br i1 %74, label %75, label %83
75: ; preds = %72
%76 = and i64 %67, 4294967295
%77 = load i32, i32* %30
%78 = call i8* @inet_ntoa(i32 %77)
%79 = getelementptr inbounds i32, i32* %24, i64 %76
%80 = load i32, i32* %79
%81 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %78, i32 %80)
%82 = call i32 @fflush(i32* %37)
br label %89
83: ; preds = %72
%84 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %66
%87 = add nuw nsw i64 %67, 1
%88 = icmp eq i64 %87, %44
br i1 %88, label %89, label %66
89: ; preds = %86, %75
br label %63
}