#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  long s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
struct TYPE_4__ {
  int fd;
};
struct epoll_event {
  TYPE_2__ data;
  int /*<<< orphan*/ events;
};
typedef int /*<<< orphan*/ Address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int close(int);
int connect(int, struct sockaddr *, int);
int epoll_create(int);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(long *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int hSocket[20];
  struct hostent *pHostInfo;
  struct sockaddr_in Address;
  long nHostAddress;
  char pBuffer[10000];
  unsigned nReadAmount;
  char strHostName[255];
  int nHostPort;
  if (argc < 3) {
    printf("\nUsage: client host-name host-port\n");
    return 0;
  } else {
    strcpy(strHostName, argv[1]);
    nHostPort = atoi(argv[2]);
  }
  printf("\nMaking a socket");
  for (int i = 0; i < 20; i++) {
    hSocket[i] = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (hSocket[i] == -1) {
      printf("\nCould not make a socket\n");
      return 0;
    }
  }
  pHostInfo = gethostbyname(strHostName);
  memcpy(&nHostAddress, pHostInfo->h_addr, pHostInfo->h_length);
  Address.sin_addr.s_addr = nHostAddress;
  Address.sin_port = htons(nHostPort);
  Address.sin_family = AF_INET;
  int epollFD = epoll_create(1);
  for (int i = 0; i < 20; i++) {
    if (connect(hSocket[i], (struct sockaddr *)&Address, sizeof(Address)) ==
        -1) {
      printf("\nCould not connect to host\n");
      return 0;
    }
    char request[] = "GET /test.html HTTP/1.0\r\n\r\n";
    write(hSocket[i], request, strlen(request));
    struct epoll_event event;
    event.data.fd = hSocket[i];
    event.events = EPOLLIN;
    int ret = epoll_ctl(epollFD, EPOLL_CTL_ADD, hSocket[i], &event);
    if (ret)
      perror("epoll_ctl");
  }
  for (int i = 0; i < 20; i++) {
    struct epoll_event event;
    int rval = epoll_wait(epollFD, &event, 1, -1);
    if (rval < 0)
      perror("epoll_wait");
    read(event.data.fd, pBuffer, 10000);
    printf("\ngot from %d", event.data.fd);
    printf("\nClosing socket\n");
    if (close(hSocket[i]) == -1) {
      printf("\nCould not close socket\n");
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2900,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    123d <main+0x3d>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1570 <main+0x370>
lea    -0x28a0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x28a4(%rbp)
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x28a8(%rbp)
cmpl   $0x14,-0x28a8(%rbp)
jge    12fb <main+0xfb>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
call   1120 <socket@plt>
mov    %eax,%ecx
movslq -0x28a8(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
movslq -0x28a8(%rbp),%rax
cmpl   $0xffffffff,-0x60(%rbp,%rax,4)
jne    12e2 <main+0xe2>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1570 <main+0x370>
jmp    12e7 <main+0xe7>
mov    -0x28a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28a8(%rbp)
jmp    127c <main+0x7c>
lea    -0x28a0(%rbp),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x68(%rbp),%rax
mov    (%rax),%edx
lea    -0x80(%rbp),%rdi
call   10c0 <memcpy@plt>
mov    -0x80(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x28a4(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x74(%rbp)
mov    0x2caa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    $0x1,%edi
call   1100 <epoll_create@plt>
mov    %eax,-0x28ac(%rbp)
movl   $0x0,-0x28b0(%rbp)
cmpl   $0x14,-0x28b0(%rbp)
jge    1499 <main+0x299>
movslq -0x28b0(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
lea    -0x78(%rbp),%rsi
mov    $0x10,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
jne    13a6 <main+0x1a6>
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1570 <main+0x370>
mov    0xd13(%rip),%rax
mov    %rax,-0x28d0(%rbp)
mov    0xd0d(%rip),%rax
mov    %rax,-0x28c8(%rbp)
mov    0xd07(%rip),%rax
mov    %rax,-0x28c0(%rbp)
mov    0xd02(%rip),%eax
mov    %eax,-0x28b8(%rbp)
movslq -0x28b0(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
mov    %eax,-0x28fc(%rbp)
lea    -0x28d0(%rbp),%rax
mov    %rax,-0x28f8(%rbp)
lea    -0x28d0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28fc(%rbp),%edi
mov    -0x28f8(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
movslq -0x28b0(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
mov    %eax,-0x28d8(%rbp)
mov    0x2bad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28d4(%rbp)
mov    -0x28ac(%rbp),%edi
mov    0x2b90(%rip),%rax
mov    (%rax),%esi
movslq -0x28b0(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
lea    -0x28d8(%rbp),%rcx
call   1090 <epoll_ctl@plt>
mov    %eax,-0x28dc(%rbp)
cmpl   $0x0,-0x28dc(%rbp)
je     1480 <main+0x280>
lea    0xbf0(%rip),%rdi
call   10e0 <perror@plt>
jmp    1485 <main+0x285>
mov    -0x28b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28b0(%rbp)
jmp    135d <main+0x15d>
movl   $0x0,-0x28e0(%rbp)
cmpl   $0x14,-0x28e0(%rbp)
jge    1570 <main+0x370>
mov    -0x28ac(%rbp),%edi
lea    -0x28e8(%rbp),%rsi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
call   10d0 <epoll_wait@plt>
mov    %eax,-0x28ec(%rbp)
cmpl   $0x0,-0x28ec(%rbp)
jge    14eb <main+0x2eb>
lea    0xb8f(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x28e8(%rbp),%edi
lea    -0x2790(%rbp),%rsi
mov    $0x2710,%edx
call   10a0 <read@plt>
mov    -0x28e8(%rbp),%esi
lea    0xb71(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xb70(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movslq -0x28e0(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    1557 <main+0x357>
lea    0xb5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1570 <main+0x370>
jmp    155c <main+0x35c>
mov    -0x28e0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28e0(%rbp)
jmp    14a3 <main+0x2a3>
mov    -0x4(%rbp),%eax
add    $0x2900,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2888,%rsp
cmp    $0x2,%edi
jg     1232 <main+0x22>
lea    0xe62(%rip),%rdi
jmp    142e <main+0x21e>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0x70(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x10(%rbx),%rdi
call   1100 <atoi@plt>
mov    %eax,%r14d
lea    0xdaa(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d82(%rip),%r15
mov    0x2d53(%rip),%r12
mov    0x2d5c(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%edi
mov    (%r12),%esi
mov    0x0(%rbp),%edx
call   1130 <socket@plt>
mov    %eax,0x20(%rsp,%rbx,4)
cmp    $0xffffffff,%eax
je     138b <main+0x17b>
add    $0x1,%rbx
cmp    $0x14,%rbx
jne    1280 <main+0x70>
lea    0x70(%rsp),%rdi
call   10c0 <gethostbyname@plt>
mov    (%rax),%edx
mov    0x4(%rax),%esi
lea    0x8(%rsp),%rdi
call   10d0 <memcpy@plt>
mov    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    %r14d,%edi
call   1070 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    $0x1,%edi
call   1110 <epoll_create@plt>
mov    %eax,%r12d
xor    %r13d,%r13d
lea    0x170(%rsp),%rbx
mov    0x2cdd(%rip),%r14
mov    %rsp,%r15
xchg   %ax,%ax
mov    0x20(%rsp,%r13,4),%ebp
mov    %ebp,%edi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x187>
movups 0xdaa(%rip),%xmm0
movups %xmm0,0x17c(%rsp)
movaps 0xd8f(%rip),%xmm0
movaps %xmm0,0x170(%rsp)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %ebp,(%rsp)
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    (%r14),%esi
mov    %r12d,%edi
mov    %ebp,%edx
mov    %r15,%rcx
call   10a0 <epoll_ctl@plt>
test   %eax,%eax
jne    137d <main+0x16d>
add    $0x1,%r13
cmp    $0x14,%r13
jne    1300 <main+0xf0>
jmp    13a3 <main+0x193>
lea    0xc8d(%rip),%rdi
call   10f0 <perror@plt>
jmp    1371 <main+0x161>
lea    0xce4(%rip),%rdi
jmp    142e <main+0x21e>
lea    0xcbd(%rip),%rdi
jmp    142e <main+0x21e>
mov    %rsp,%r14
lea    0x170(%rsp),%rbp
lea    0xc71(%rip),%r13
lea    0xc77(%rip),%rbx
xor    %r15d,%r15d
nop
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
call   10e0 <epoll_wait@plt>
test   %eax,%eax
js     1419 <main+0x209>
mov    (%rsp),%edi
mov    %rbp,%rsi
mov    $0x2710,%edx
call   10b0 <read@plt>
mov    (%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    0x20(%rsp,%r15,4),%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
je     1427 <main+0x217>
add    $0x1,%r15
cmp    $0x14,%r15
jne    13c0 <main+0x1b0>
jmp    1433 <main+0x223>
lea    0xbfb(%rip),%rdi
call   10f0 <perror@plt>
jmp    13d9 <main+0x1c9>
lea    0xc15(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x2888,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i64 }
%struct.epoll_event = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"\0AUsage: client host-name host-port\0A\00"
@.str.1 = [17 x i8] c"\0AMaking a socket\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [26 x i8] c"\0ACould not make a socket\0A\00"
@.str.3 = [28 x i8] c"\0ACould not connect to host\0A\00"
@__const.main.request = [28 x i8] c"GET /test.html HTTP/1.0\0D\0A\0D\0A\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.4 = [10 x i8] c"epoll_ctl\00"
@.str.5 = [11 x i8] c"epoll_wait\00"
@.str.6 = [13 x i8] c"\0Agot from %d\00"
@.str.7 = [17 x i8] c"\0AClosing socket\0A\00"
@.str.8 = [25 x i8] c"\0ACould not close socket\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i32]
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca i64
%10 = alloca [10000 x i8]
%11 = alloca i32
%12 = alloca [255 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [28 x i8]
%18 = alloca %struct.epoll_event
%19 = alloca i32
%20 = alloca i32
%21 = alloca %struct.epoll_event
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 3
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %160
27: ; preds = %2
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %28, i8* %31)
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %13
br label %37
37: ; preds = %27
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %14
br label %39
39: ; preds = %58, %37
%40 = load i32, i32* %14
%41 = icmp slt i32 %40, 20
br i1 %41, label %42, label %61
42: ; preds = %39
%43 = load i32, i32* @AF_INET
%44 = load i32, i32* @SOCK_STREAM
%45 = load i32, i32* @IPPROTO_TCP
%46 = call i32 @socket(i32 %43, i32 %44, i32 %45)
%47 = load i32, i32* %14
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %48
store i32 %46, i32* %49
%50 = load i32, i32* %14
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %42
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %160
57: ; preds = %42
br label %58
58: ; preds = %57
%59 = load i32, i32* %14
%60 = add nsw i32 %59, 1
store i32 %60, i32* %14
br label %39
61: ; preds = %39
%62 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%63 = call %struct.hostent* @gethostbyname(i8* %62)
store %struct.hostent* %63, %struct.hostent** %7
%64 = load %struct.hostent*, %struct.hostent** %7
%65 = getelementptr inbounds %struct.hostent, %struct.hostent* %64, i32 0, i32 1
%66 = load i32, i32* %65
%67 = load %struct.hostent*, %struct.hostent** %7
%68 = getelementptr inbounds %struct.hostent, %struct.hostent* %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 @memcpy(i64* %9, i32 %66, i32 %69)
%71 = load i64, i64* %9
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
%73 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %72, i32 0, i32 0
store i64 %71, i64* %73
%74 = load i32, i32* %13
%75 = call i32 @htons(i32 %74)
%76 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %75, i32* %76
%77 = load i32, i32* @AF_INET
%78 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %77, i32* %78
%79 = call i32 @epoll_create(i32 1)
store i32 %79, i32* %15
store i32 0, i32* %16
br label %80
80: ; preds = %123, %61
%81 = load i32, i32* %16
%82 = icmp slt i32 %81, 20
br i1 %82, label %83, label %126
83: ; preds = %80
%84 = load i32, i32* %16
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %85
%87 = load i32, i32* %86
%88 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%89 = call i32 @connect(i32 %87, %struct.sockaddr* %88, i32 16)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %93
91: ; preds = %83
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %160
93: ; preds = %83
%94 = bitcast [28 x i8]* %17 to i8*
%95 = load i32, i32* %16
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %96
%98 = load i32, i32* %97
%99 = getelementptr inbounds [28 x i8], [28 x i8]* %17, i64 0, i64 0
%100 = getelementptr inbounds [28 x i8], [28 x i8]* %17, i64 0, i64 0
%101 = call i32 @strlen(i8* %100)
%102 = call i32 @write(i32 %98, i8* %99, i32 %101)
%103 = load i32, i32* %16
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %104
%106 = load i32, i32* %105
%107 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %18, i32 0, i32 0
%108 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %107, i32 0, i32 0
store i32 %106, i32* %108
%109 = load i32, i32* @EPOLLIN
%110 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %18, i32 0, i32 1
store i32 %109, i32* %110
%111 = load i32, i32* %15
%112 = load i32, i32* @EPOLL_CTL_ADD
%113 = load i32, i32* %16
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %114
%116 = load i32, i32* %115
%117 = call i32 @epoll_ctl(i32 %111, i32 %112, i32 %116, %struct.epoll_event* %18)
store i32 %117, i32* %19
%118 = load i32, i32* %19
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %93
%121 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %122
122: ; preds = %120, %93
br label %123
123: ; preds = %122
%124 = load i32, i32* %16
%125 = add nsw i32 %124, 1
store i32 %125, i32* %16
br label %80
126: ; preds = %80
store i32 0, i32* %20
br label %127
127: ; preds = %157, %126
%128 = load i32, i32* %20
%129 = icmp slt i32 %128, 20
br i1 %129, label %130, label %160
130: ; preds = %127
%131 = load i32, i32* %15
%132 = call i32 @epoll_wait(i32 %131, %struct.epoll_event* %21, i32 1, i32 -1)
store i32 %132, i32* %22
%133 = load i32, i32* %22
%134 = icmp slt i32 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %130
%136 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %137
137: ; preds = %135, %130
%138 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %21, i32 0, i32 0
%139 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %138, i32 0, i32 0
%140 = load i32, i32* %139
%141 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%142 = call i32 @read(i32 %140, i8* %141, i32 10000)
%143 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %21, i32 0, i32 0
%144 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %143, i32 0, i32 0
%145 = load i32, i32* %144
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %145)
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%148 = load i32, i32* %20
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %149
%151 = load i32, i32* %150
%152 = call i32 @close(i32 %151)
%153 = icmp eq i32 %152, -1
br i1 %153, label %154, label %156
154: ; preds = %137
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %160
156: ; preds = %137
br label %157
157: ; preds = %156
%158 = load i32, i32* %20
%159 = add nsw i32 %158, 1
store i32 %159, i32* %20
br label %127
160: ; preds = %25, %55, %91, %154, %127
%161 = load i32, i32* %3
ret i32 %161
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i64 }
%struct.epoll_event = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [17 x i8] c"\0AMaking a socket\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@__const.main.request = [28 x i8] c"GET /test.html HTTP/1.0\0D\0A\0D\0A\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.4 = [10 x i8] c"epoll_ctl\00"
@.str.5 = [11 x i8] c"epoll_wait\00"
@.str.6 = [13 x i8] c"\0Agot from %d\00"
@str = [16 x i8] c"\0AClosing socket\00"
@str.9 = [24 x i8] c"\0ACould not close socket\00"
@str.10 = [27 x i8] c"\0ACould not connect to host\00"
@str.11 = [25 x i8] c"\0ACould not make a socket\00"
@str.12 = [35 x i8] c"\0AUsage: client host-name host-port\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i32]
%4 = alloca %struct.sockaddr_in
%5 = alloca i64
%6 = alloca [10000 x i8]
%7 = alloca [255 x i8]
%8 = alloca [28 x i8]
%9 = alloca %struct.epoll_event
%10 = alloca %struct.epoll_event
%11 = bitcast [20 x i32]* %3 to i8*
%12 = bitcast %struct.sockaddr_in* %4 to i8*
%13 = bitcast i64* %5 to i8*
%14 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%16 = icmp slt i32 %0, 3
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.12, i64 0, i64 0))
br label %103
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strcpy(i8* %15, i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %30
27: ; preds = %30
%28 = add nuw nsw i64 %31, 1
%29 = icmp eq i64 %28, 20
br i1 %29, label %40, label %30
30: ; preds = %19, %27
%31 = phi i64 [ 0, %19 ], [ %28, %27 ]
%32 = load i32, i32* @AF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = load i32, i32* @IPPROTO_TCP
%35 = call i32 @socket(i32 %32, i32 %33, i32 %34)
%36 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %31
store i32 %35, i32* %36
%37 = icmp eq i32 %35, -1
br i1 %37, label %38, label %27
38: ; preds = %30
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
br label %103
40: ; preds = %27
%41 = call %struct.hostent* @gethostbyname(i8* %15)
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i64 0, i32 1
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i64 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @memcpy(i64* %5, i32 %43, i32 %45)
%47 = load i64, i64* %5
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2, i32 0
store i64 %47, i64* %48
%49 = call i32 @htons(i32 %25)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %49, i32* %50
%51 = load i32, i32* @AF_INET
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %51, i32* %52
%53 = call i32 @epoll_create(i32 1)
%54 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%55 = getelementptr inbounds [28 x i8], [28 x i8]* %8, i64 0, i64 0
%56 = bitcast %struct.epoll_event* %9 to i8*
%57 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i64 0, i32 0, i32 0
%58 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i64 0, i32 1
br label %62
59: ; preds = %79
%60 = bitcast %struct.epoll_event* %10 to i8*
%61 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i64 0, i32 0, i32 0
br label %82
62: ; preds = %40, %79
%63 = phi i64 [ 0, %40 ], [ %80, %79 ]
%64 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 @connect(i32 %65, %struct.sockaddr* %54, i32 16)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %62
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.10, i64 0, i64 0))
br label %103
70: ; preds = %62
%71 = call i32 @strlen(i8* %55)
%72 = call i32 @write(i32 %65, i8* %55, i32 %71)
store i32 %65, i32* %57
%73 = load i32, i32* @EPOLLIN
store i32 %73, i32* %58
%74 = load i32, i32* @EPOLL_CTL_ADD
%75 = call i32 @epoll_ctl(i32 %53, i32 %74, i32 %65, %struct.epoll_event* %9)
%76 = icmp eq i32 %75, 0
br i1 %76, label %79, label %77
77: ; preds = %70
%78 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %79
79: ; preds = %77, %70
%80 = add nuw nsw i64 %63, 1
%81 = icmp eq i64 %80, 20
br i1 %81, label %59, label %62
82: ; preds = %59, %100
%83 = phi i64 [ 0, %59 ], [ %101, %100 ]
%84 = call i32 @epoll_wait(i32 %53, %struct.epoll_event* %10, i32 1, i32 -1)
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %82
%87 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %88
88: ; preds = %86, %82
%89 = load i32, i32* %61
%90 = call i32 @read(i32 %89, i8* %14, i32 10000)
%91 = load i32, i32* %61
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %91)
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%94 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %83
%95 = load i32, i32* %94
%96 = call i32 @close(i32 %95)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %100
98: ; preds = %88
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.9, i64 0, i64 0))
br label %103
100: ; preds = %88
%101 = add nuw nsw i64 %83, 1
%102 = icmp eq i64 %101, 20
br i1 %102, label %103, label %82
103: ; preds = %100, %68, %38, %98, %17
ret i32 0
}