#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;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ siz;
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ SO_SNDBUF;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, TYPE_1__ *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              void *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int do_connect(char *host, int port) {
  int sock, siz;
  struct hostent *he;
  struct sockaddr_in sa;
  int salen;
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    fprintf(stderr, "socket: %s\n", strerror(errno));
    exit(1);
  }
  siz = 64 * 1024;
  (void)setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void *)&siz, sizeof(siz));
  (void)setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void *)&siz, sizeof(siz));
  siz = 1;
  (void)setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&siz, sizeof(siz));
  sa.sin_family = AF_INET;
  sa.sin_port = htons(port);
  if (host == NULL) {
    int ear;
    sa.sin_addr.s_addr = INADDR_ANY;
    if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
      fprintf(stderr, "bind: %s\n", strerror(errno));
      exit(1);
    }
    listen(sock, 1);
    salen = sizeof(struct sockaddr_in);
    ear = accept(sock, (struct sockaddr *)&sa, &salen);
    if (ear < 0) {
      fprintf(stderr, "accept: %s\n", strerror(errno));
      exit(1);
    }
    close(sock);
    sock = ear;
  } else {
    if (!(inet_aton(host, &sa.sin_addr))) {
      if ((he = gethostbyname(host)) == NULL) {
        fprintf(stderr, "gethostbyname: %s\n", strerror(errno));
        exit(1);
      }
      bcopy((char *)he->h_addr, (char *)&sa.sin_addr, he->h_length);
    }
    if ((connect(sock, (struct sockaddr *)&sa, sizeof sa)) < 0) {
      fprintf(stderr, "connect: %s\n", strerror(errno));
      exit(1);
    }
  }
  return sock;
}


x86 assembly (clang, -O0):
<do_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    124b <do_connect+0x6b>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xdc4(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x10000,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x10(%rbp),%edi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
mov    0x2d4f(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
mov    0x2cec(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    13be <do_connect+0x1de>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    1344 <do_connect+0x164>
mov    0x2ca3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xcd7(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1090 <listen@plt>
movl   $0xc,-0x34(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    13ab <do_connect+0x1cb>
mov    0x2c3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c20(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xc7a(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    148e <do_connect+0x2ae>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <inet_aton@plt>
cmp    $0x0,%eax
jne    1438 <do_connect+0x258>
mov    -0x8(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1421 <do_connect+0x241>
mov    0x2bc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2baa(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xc10(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bcopy@plt>
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    1489 <do_connect+0x2a9>
mov    0x2b5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xbbb(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    148e <do_connect+0x2ae>
mov    -0x10(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_connect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
mov    0x2de5(%rip),%r12
mov    (%r12),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1375 <do_connect+0x195>
mov    %eax,%ebx
movl   $0x10000,0x4(%rsp)
mov    0x2dc0(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%r13
mov    %ebx,%edi
mov    %r13,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x0(%rbp),%esi
mov    0x2d85(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r13,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0x1,0x4(%rsp)
mov    0x0(%rbp),%esi
mov    0x2d29(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r13,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    %r15d,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
test   %r14,%r14
je     130d <do_connect+0x12d>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1080 <inet_aton@plt>
test   %eax,%eax
jne    12d4 <do_connect+0xf4>
mov    %r14,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     13d5 <do_connect+0x1f5>
mov    0x8(%rax),%rsi
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
call   10b0 <memmove@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
jns    1364 <do_connect+0x184>
mov    0x2cc7(%rip),%rax
mov    (%rax),%ebx
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd2d(%rip),%rsi
jmp    13f3 <do_connect+0x213>
mov    0x2cbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
js     1395 <do_connect+0x1b5>
mov    %ebx,%edi
mov    $0x1,%esi
call   1090 <listen@plt>
movl   $0xc,0x14(%rsp)
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
mov    %ebx,%edi
call   10c0 <accept@plt>
test   %eax,%eax
js     13b5 <do_connect+0x1d5>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c3c(%rip),%rax
mov    (%rax),%ebx
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc6d(%rip),%rsi
jmp    13f3 <do_connect+0x213>
mov    0x2c1c(%rip),%rax
mov    (%rax),%ebx
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc59(%rip),%rsi
jmp    13f3 <do_connect+0x213>
mov    0x2bfc(%rip),%rax
mov    (%rax),%ebx
mov    0x2be3(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc43(%rip),%rsi
jmp    13f3 <do_connect+0x213>
mov    0x2bdc(%rip),%rax
mov    (%rax),%ebx
mov    0x2bc3(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc2f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i64 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@SO_SNDBUF = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [10 x i8] c"bind: %s\0A\00"
@.str.2 = [12 x i8] c"accept: %s\0A\00"
@.str.3 = [19 x i8] c"gethostbyname: %s\0A\00"
@.str.4 = [13 x i8] c"connect: %s\0A\00"
define i32 @do_connect(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
store i32 65536, i32* %6
%23 = load i32, i32* %5
%24 = load i32, i32* @SOL_SOCKET
%25 = load i32, i32* @SO_RCVBUF
%26 = bitcast i32* %6 to i8*
%27 = call i32 @setsockopt(i32 %23, i32 %24, i32 %25, i8* %26, i32 4)
%28 = load i32, i32* %5
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_SNDBUF
%31 = bitcast i32* %6 to i8*
%32 = call i32 @setsockopt(i32 %28, i32 %29, i32 %30, i8* %31, i32 4)
store i32 1, i32* %6
%33 = load i32, i32* %5
%34 = load i32, i32* @SOL_SOCKET
%35 = load i32, i32* @SO_REUSEADDR
%36 = bitcast i32* %6 to i8*
%37 = call i32 @setsockopt(i32 %33, i32 %34, i32 %35, i8* %36, i32 4)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %38, i32* %39
%40 = load i32, i32* %4
%41 = call i32 @htons(i32 %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %41, i32* %42
%43 = load i8*, i8** %3
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %77
45: ; preds = %22
%46 = load i32, i32* @INADDR_ANY
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
store i32 %46, i32* %48
%49 = load i32, i32* %5
%50 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%51 = call i64 @bind(i32 %49, %struct.sockaddr* %50, i32 12)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %45
%60 = load i32, i32* %5
%61 = call i32 @listen(i32 %60, i32 1)
store i32 12, i32* %9
%62 = load i32, i32* %5
%63 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%64 = call i32 @accept(i32 %62, %struct.sockaddr* %63, i32* %9)
store i32 %64, i32* %10
%65 = load i32, i32* %10
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %73
67: ; preds = %59
%68 = load i32, i32* @stderr
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %70)
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %59
%74 = load i32, i32* %5
%75 = call i32 @close(i32 %74)
%76 = load i32, i32* %10
store i32 %76, i32* %5
br label %115
77: ; preds = %22
%78 = load i8*, i8** %3
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%80 = call i32 @inet_aton(i8* %78, %struct.TYPE_2__* %79)
%81 = icmp ne i32 %80, 0
br i1 %81, label %103, label %82
82: ; preds = %77
%83 = load i8*, i8** %3
%84 = call %struct.hostent* @gethostbyname(i8* %83)
store %struct.hostent* %84, %struct.hostent** %7
%85 = icmp eq %struct.hostent* %84, null
br i1 %85, label %86, label %92
86: ; preds = %82
%87 = load i32, i32* @stderr
%88 = load i32, i32* @errno
%89 = call i8* @strerror(i32 %88)
%90 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %89)
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %82
%93 = load %struct.hostent*, %struct.hostent** %7
%94 = getelementptr inbounds %struct.hostent, %struct.hostent* %93, i32 0, i32 1
%95 = load i64, i64* %94
%96 = inttoptr i64 %95 to i8*
%97 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%98 = bitcast %struct.TYPE_2__* %97 to i8*
%99 = load %struct.hostent*, %struct.hostent** %7
%100 = getelementptr inbounds %struct.hostent, %struct.hostent* %99, i32 0, i32 0
%101 = load i32, i32* %100
%102 = call i32 @bcopy(i8* %96, i8* %98, i32 %101)
br label %103
103: ; preds = %92, %77
%104 = load i32, i32* %5
%105 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%106 = call i64 @connect(i32 %104, %struct.sockaddr* %105, i32 12)
%107 = icmp slt i64 %106, 0
br i1 %107, label %108, label %114
108: ; preds = %103
%109 = load i32, i32* @stderr
%110 = load i32, i32* @errno
%111 = call i8* @strerror(i32 %110)
%112 = call i32 @fprintf(i32 %109, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %103
br label %115
115: ; preds = %114, %73
%116 = load i32, i32* %5
ret i32 %116
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@SO_SNDBUF = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [10 x i8] c"bind: %s\0A\00"
@.str.2 = [12 x i8] c"accept: %s\0A\00"
@.str.3 = [19 x i8] c"gethostbyname: %s\0A\00"
@.str.4 = [13 x i8] c"connect: %s\0A\00"
define i32 @do_connect(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
store i32 65536, i32* %3
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_RCVBUF
%22 = call i32 @setsockopt(i32 %11, i32 %20, i32 %21, i8* %6, i32 4)
%23 = load i32, i32* @SOL_SOCKET
%24 = load i32, i32* @SO_SNDBUF
%25 = call i32 @setsockopt(i32 %11, i32 %23, i32 %24, i8* %6, i32 4)
store i32 1, i32* %3
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_REUSEADDR
%28 = call i32 @setsockopt(i32 %11, i32 %26, i32 %27, i8* %6, i32 4)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %29, i32* %30
%31 = call i32 @htons(i32 %1)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %31, i32* %32
%33 = icmp eq i8* %0, null
br i1 %33, label %34, label %58
34: ; preds = %19
%35 = load i32, i32* @INADDR_ANY
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %35, i32* %36
%37 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%38 = call i64 @bind(i32 %11, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %34
%47 = call i32 @listen(i32 %11, i32 1)
store i32 12, i32* %5
%48 = call i32 @accept(i32 %11, %struct.sockaddr* %37, i32* %5)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %46
%57 = call i32 @close(i32 %11)
br label %87
58: ; preds = %19
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%60 = call i32 @inet_aton(i8* %0, %struct.TYPE_2__* %59)
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %77
62: ; preds = %58
%63 = call %struct.hostent* @gethostbyname(i8* %0)
%64 = icmp eq %struct.hostent* %63, null
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %68)
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %62
%72 = getelementptr inbounds %struct.hostent, %struct.hostent* %63, i64 0, i32 1
%73 = load i64, i64* %72
%74 = inttoptr i64 %73 to i8*
%75 = getelementptr inbounds %struct.hostent, %struct.hostent* %63, i64 0, i32 0
%76 = load i32, i32* %75
br label %77
77: ; preds = %71, %58
%78 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%79 = call i64 @connect(i32 %11, %struct.sockaddr* %78, i32 12)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %87
81: ; preds = %77
%82 = load i32, i32* @stderr
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %84)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %77, %56
%88 = phi i32 [ %48, %56 ], [ %11, %77 ]
ret i32 %88
}