#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 {
  int dummy;
};
struct pollfd {
  int fd;
  int events;
  int revents;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int POLLERR;
int POLLHUP;
int POLLIN;
int POLLOUT;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
scalar_t__ errno;
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ get_address(char *, char *, struct sockaddr *);
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int strnlen(char *, int);
int write(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 3 || strnlen(argv[1], 50) == 50) {
    fprintf(stderr, "Curl called but HOST or PORT not given or invalid\n");
    return 1;
  }
  struct sockaddr addr;
  int sock;
  if (strnlen(argv[2], 6) == 6) {
    fprintf(stderr, "Curl called but PORT malformed\n");
    return 1;
  }
  if (get_address(argv[1], argv[2], &addr) != 0) {
    fprintf(stderr, "Curl could not resolve hostname\n");
    return 1;
  }
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) {
    perror("Setting socket nonblocking");
    return 1;
  }
  if (connect(sock, &addr, 16) == -1) {
    if (errno != EINPROGRESS) {
      perror("Curl could not establish connection");
      return 1;
    }
  }
  struct pollfd fds[1];
  fds[0].fd = sock;
  fds[0].events = POLLOUT;
  int ret = poll(fds, 1, -1);
  if (ret < 1) {
    perror("Poll failed");
    return 1;
  }
  assert(fds[0].revents & POLLOUT);
  char str[512];
  snprintf(str, 512,
           "GET / HTTP/1.1\r\nHost: %s:%s\r\nConnection: close\r\n\r\n",
           argv[1], argv[2]);
  int len = strlen(str);
  if (write(sock, str, len) != len) {
    perror("Write error");
    return 1;
  }
  int rlen = 0;
  while (1) {
    fds[0].events = POLLIN;
    ret = poll(fds, 1, -1);
    if (ret < 0) {
      perror("Poll failed");
      return 1;
    }
    if (fds[0].revents & POLLIN) {
      char buf[4096] = {0};
      if ((rlen = read(sock, buf, 4096)) == -1) {
        perror("Read error");
        return 1;
      }
      if (rlen == 0) {
        break;
      }
      printf("%s", buf);
    }
    if (fds[0].revents & (POLLHUP | POLLERR)) {
      fprintf(stderr, "POLLHUP/ERR received %d\n", fds[0].revents);
      break;
    }
  }
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    123e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x32,%esi
call   10a0 <strnlen@plt>
cmp    $0x32,%eax
jne    1261 <main+0x61>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x6,%esi
call   10a0 <strnlen@plt>
cmp    $0x6,%eax
jne    129f <main+0x9f>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <get_address@plt>
cmp    $0x0,%rax
je     12e5 <main+0xe5>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    0x2ca3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c95(%rip),%rax
mov    (%rax),%esi
mov    0x2cbc(%rip),%rax
mov    (%rax),%edx
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    133c <main+0x13c>
lea    0xd49(%rip),%rdi
call   1100 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
jne    138d <main+0x18d>
mov    0x2c33(%rip),%rax
mov    (%rax),%rax
mov    0x2c61(%rip),%rcx
cmp    (%rcx),%rax
je     1388 <main+0x188>
lea    0xd18(%rip),%rdi
call   1100 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
jmp    138d <main+0x18d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10f0 <poll@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jge    13d7 <main+0x1d7>
lea    0xced(%rip),%rdi
call   1100 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
mov    -0x20(%rbp),%edi
mov    0x2c17(%rip),%rax
and    (%rax),%edi
call   10d0 <assert@plt>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
mov    $0x200,%esi
lea    0xcb4(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x230(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x234(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x234(%rbp),%edx
call   1050 <write@plt>
cmp    -0x234(%rbp),%eax
je     145b <main+0x25b>
lea    0xca8(%rip),%rdi
call   1100 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
movl   $0x0,-0x238(%rbp)
mov    0x2b4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10f0 <poll@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    14a9 <main+0x2a9>
lea    0xc1b(%rip),%rdi
call   1100 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
mov    -0x20(%rbp),%eax
mov    0x2b05(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1531 <main+0x331>
lea    -0x1240(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1090 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x1240(%rbp),%rsi
mov    $0x1000,%edx
call   10c0 <read@plt>
mov    %eax,-0x238(%rbp)
cmp    $0xffffffff,%eax
jne    150c <main+0x30c>
lea    0xc03(%rip),%rdi
call   1100 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    157d <main+0x37d>
cmpl   $0x0,-0x238(%rbp)
jne    151e <main+0x31e>
jmp    1575 <main+0x375>
lea    -0x1240(%rbp),%rsi
lea    0xbdd(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%eax
mov    0x2aa5(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2a7c(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1570 <main+0x370>
mov    0x2a50(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xba8(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    1575 <main+0x375>
jmp    1465 <main+0x265>
mov    -0x1c(%rbp),%edi
call   10b0 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x1240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1228,%rsp
cmp    $0x3,%edi
jne    122c <main+0x2c>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    $0x32,%esi
call   10a0 <strnlen@plt>
cmp    $0x32,%eax
jne    125c <main+0x5c>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x1228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rbx),%rdi
mov    $0x6,%esi
call   10a0 <strnlen@plt>
cmp    $0x6,%eax
jne    1281 <main+0x81>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
jmp    123c <main+0x3c>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    0x18(%rsp),%rdx
call   1030 <get_address@plt>
test   %rax,%rax
je     12aa <main+0xaa>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
jmp    123c <main+0x3c>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
mov    0x2cde(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%r14d
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
mov    0x2cfa(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1458 <main+0x258>
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0x10,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
jne    131a <main+0x11a>
mov    0x2c89(%rip),%rax
mov    (%rax),%rax
mov    0x2cb7(%rip),%rcx
cmp    (%rcx),%rax
jne    1484 <main+0x284>
mov    %r14d,0x8(%rsp)
mov    0x2cd2(%rip),%r15
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10f0 <poll@plt>
test   %eax,%eax
jle    1461 <main+0x261>
mov    (%r15),%edi
and    0x10(%rsp),%edi
call   10d0 <assert@plt>
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%r8
lea    0xd56(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %ebp,%eax
jne    1472 <main+0x272>
mov    0x2c17(%rip),%rbx
mov    (%rbx),%eax
lea    0x8(%rsp),%r12
mov    0x2c31(%rip),%r13
mov    0x2c0a(%rip),%r15
lea    0x220(%rsp),%rbp
jmp    13cb <main+0x1cb>
mov    (%r15),%ecx
or     0x0(%r13),%ecx
test   %edx,%ecx
jne    1432 <main+0x232>
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10f0 <poll@plt>
test   %eax,%eax
js     147b <main+0x27b>
mov    0x10(%rsp),%edx
mov    (%rbx),%eax
test   %edx,%eax
je     13c0 <main+0x1c0>
mov    $0x1000,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   10c0 <read@plt>
test   %eax,%eax
je     1449 <main+0x249>
cmp    $0xffffffff,%eax
je     148d <main+0x28d>
lea    0xce7(%rip),%rdi
mov    %rbp,%rsi
call   1070 <printf@plt>
mov    (%rbx),%eax
mov    0x10(%rsp),%edx
jmp    13c0 <main+0x1c0>
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
xor    %ebp,%ebp
jmp    1248 <main+0x48>
lea    0xc15(%rip),%rdi
jmp    1494 <main+0x294>
lea    0xc4b(%rip),%rdi
call   1100 <perror@plt>
jmp    1248 <main+0x48>
lea    0xc79(%rip),%rdi
jmp    1494 <main+0x294>
lea    0xc31(%rip),%rdi
jmp    1494 <main+0x294>
lea    0xc04(%rip),%rdi
jmp    1494 <main+0x294>
lea    0xc6a(%rip),%rdi
call   1100 <perror@plt>
jmp    1243 <main+0x43>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.pollfd = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [51 x i8] c"Curl called but HOST or PORT not given or invalid\0A\00"
@.str.1 = [32 x i8] c"Curl called but PORT malformed\0A\00"
@.str.2 = [33 x i8] c"Curl could not resolve hostname\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [27 x i8] c"Setting socket nonblocking\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.4 = [36 x i8] c"Curl could not establish connection\00"
@POLLOUT = global i32 0
@.str.5 = [12 x i8] c"Poll failed\00"
@.str.6 = [51 x i8] c"GET / HTTP/1.1\0D\0AHost: %s:%s\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.7 = [12 x i8] c"Write error\00"
@POLLIN = global i32 0
@.str.8 = [11 x i8] c"Read error\00"
@.str.9 = [3 x i8] c"%s\00"
@POLLHUP = global i32 0
@POLLERR = global i32 0
@.str.10 = [25 x i8] c"POLLHUP/ERR received %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr
%7 = alloca i32
%8 = alloca [1 x %struct.pollfd]
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %22, label %16
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strnlen(i8* %19, i32 50)
%21 = icmp eq i32 %20, 50
br i1 %21, label %22, label %25
22: ; preds = %16, %2
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %158
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @strnlen(i8* %28, i32 6)
%30 = icmp eq i32 %29, 6
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %158
34: ; preds = %25
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i64 @get_address(i8* %37, i8* %40, %struct.sockaddr* %6)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %34
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %158
46: ; preds = %34
%47 = load i32, i32* @AF_INET
%48 = load i32, i32* @SOCK_STREAM
%49 = call i32 @socket(i32 %47, i32 %48, i32 0)
store i32 %49, i32* %7
%50 = load i32, i32* %7
%51 = load i32, i32* @F_SETFL
%52 = load i32, i32* @O_NONBLOCK
%53 = call i32 @fcntl(i32 %50, i32 %51, i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %46
%56 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %158
57: ; preds = %46
%58 = load i32, i32* %7
%59 = call i32 @connect(i32 %58, %struct.sockaddr* %6, i32 16)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %68
61: ; preds = %57
%62 = load i64, i64* @errno
%63 = load i64, i64* @EINPROGRESS
%64 = icmp ne i64 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %158
67: ; preds = %61
br label %68
68: ; preds = %67, %57
%69 = load i32, i32* %7
%70 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%71 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %70, i32 0, i32 0
store i32 %69, i32* %71
%72 = load i32, i32* @POLLOUT
%73 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%74 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %73, i32 0, i32 1
store i32 %72, i32* %74
%75 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%76 = call i32 @poll(%struct.pollfd* %75, i32 1, i32 -1)
store i32 %76, i32* %9
%77 = load i32, i32* %9
%78 = icmp slt i32 %77, 1
br i1 %78, label %79, label %81
79: ; preds = %68
%80 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %158
81: ; preds = %68
%82 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%83 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %82, i32 0, i32 2
%84 = load i32, i32* %83
%85 = load i32, i32* @POLLOUT
%86 = and i32 %84, %85
%87 = call i32 @assert(i32 %86)
%88 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 2
%94 = load i8*, i8** %93
%95 = call i32 @snprintf(i8* %88, i32 512, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* %91, i8* %94)
%96 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%97 = call i32 @strlen(i8* %96)
store i32 %97, i32* %11
%98 = load i32, i32* %7
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%100 = load i32, i32* %11
%101 = call i32 @write(i32 %98, i8* %99, i32 %100)
%102 = load i32, i32* %11
%103 = icmp ne i32 %101, %102
br i1 %103, label %104, label %106
104: ; preds = %81
%105 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %158
106: ; preds = %81
store i32 0, i32* %12
br label %107
107: ; preds = %106, %154
%108 = load i32, i32* @POLLIN
%109 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%110 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %109, i32 0, i32 1
store i32 %108, i32* %110
%111 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%112 = call i32 @poll(%struct.pollfd* %111, i32 1, i32 -1)
store i32 %112, i32* %9
%113 = load i32, i32* %9
%114 = icmp slt i32 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %107
%116 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %158
117: ; preds = %107
%118 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%119 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %118, i32 0, i32 2
%120 = load i32, i32* %119
%121 = load i32, i32* @POLLIN
%122 = and i32 %120, %121
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %139
124: ; preds = %117
%125 = bitcast [4096 x i8]* %13 to i8*
%126 = load i32, i32* %7
%127 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%128 = call i32 @read(i32 %126, i8* %127, i32 4096)
store i32 %128, i32* %12
%129 = icmp eq i32 %128, -1
br i1 %129, label %130, label %132
130: ; preds = %124
%131 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %158
132: ; preds = %124
%133 = load i32, i32* %12
%134 = icmp eq i32 %133, 0
br i1 %134, label %135, label %136
135: ; preds = %132
br label %155
136: ; preds = %132
%137 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%138 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %137)
br label %139
139: ; preds = %136, %117
%140 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%141 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %140, i32 0, i32 2
%142 = load i32, i32* %141
%143 = load i32, i32* @POLLHUP
%144 = load i32, i32* @POLLERR
%145 = or i32 %143, %144
%146 = and i32 %142, %145
%147 = icmp ne i32 %146, 0
br i1 %147, label %148, label %154
148: ; preds = %139
%149 = load i32, i32* @stderr
%150 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %8, i64 0, i64 0
%151 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %150, i32 0, i32 2
%152 = load i32, i32* %151
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i32 %152)
br label %155
154: ; preds = %139
br label %107
155: ; preds = %148, %135
%156 = load i32, i32* %7
%157 = call i32 @close(i32 %156)
br label %158
158: ; preds = %155, %130, %115, %104, %79, %65, %55, %43, %31, %22
%159 = load i32, i32* %3
ret i32 %159
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.pollfd = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [51 x i8] c"Curl called but HOST or PORT not given or invalid\0A\00"
@.str.1 = [32 x i8] c"Curl called but PORT malformed\0A\00"
@.str.2 = [33 x i8] c"Curl could not resolve hostname\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [27 x i8] c"Setting socket nonblocking\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.4 = [36 x i8] c"Curl could not establish connection\00"
@POLLOUT = global i32 0
@.str.5 = [12 x i8] c"Poll failed\00"
@.str.6 = [51 x i8] c"GET / HTTP/1.1\0D\0AHost: %s:%s\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.7 = [12 x i8] c"Write error\00"
@POLLIN = global i32 0
@.str.8 = [11 x i8] c"Read error\00"
@.str.9 = [3 x i8] c"%s\00"
@POLLHUP = global i32 0
@POLLERR = global i32 0
@.str.10 = [25 x i8] c"POLLHUP/ERR received %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr
%4 = alloca [1 x %struct.pollfd]
%5 = alloca [512 x i8]
%6 = alloca [4096 x i8]
%7 = icmp eq i32 %0, 3
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strnlen(i8* %10, i32 50)
%12 = icmp eq i32 %11, 50
br i1 %12, label %13, label %16
13: ; preds = %8, %2
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %119
16: ; preds = %8
%17 = bitcast %struct.sockaddr* %3 to i8*
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @strnlen(i8* %19, i32 6)
%21 = icmp eq i32 %20, 6
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %117
25: ; preds = %16
%26 = load i8*, i8** %9
%27 = load i8*, i8** %18
%28 = call i64 @get_address(i8* %26, i8* %27, %struct.sockaddr* %3)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %117
33: ; preds = %25
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
%37 = load i32, i32* @F_SETFL
%38 = load i32, i32* @O_NONBLOCK
%39 = call i32 @fcntl(i32 %36, i32 %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %117
43: ; preds = %33
%44 = call i32 @connect(i32 %36, %struct.sockaddr* %3, i32 16)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %52
46: ; preds = %43
%47 = load i64, i64* @errno
%48 = load i64, i64* @EINPROGRESS
%49 = icmp eq i64 %47, %48
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
br label %117
52: ; preds = %46, %43
%53 = bitcast [1 x %struct.pollfd]* %4 to i8*
%54 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%55 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
store i32 %36, i32* %55
%56 = load i32, i32* @POLLOUT
%57 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0, i32 1
store i32 %56, i32* %57
%58 = call i32 @poll(%struct.pollfd* %54, i32 1, i32 -1)
%59 = icmp slt i32 %58, 1
br i1 %59, label %60, label %62
60: ; preds = %52
%61 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %115
62: ; preds = %52
%63 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0, i32 2
%64 = load i32, i32* %63
%65 = load i32, i32* @POLLOUT
%66 = and i32 %65, %64
%67 = call i32 @assert(i32 %66)
%68 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%69 = load i8*, i8** %9
%70 = load i8*, i8** %18
%71 = call i32 @snprintf(i8* %68, i32 512, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* %69, i8* %70)
%72 = call i32 @strlen(i8* %68)
%73 = call i32 @write(i32 %36, i8* %68, i32 %72)
%74 = icmp eq i32 %73, %72
br i1 %74, label %75, label %78
75: ; preds = %62
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%77 = load i32, i32* @POLLIN
br label %80
78: ; preds = %62
%79 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %113
80: ; preds = %75, %100
%81 = phi i32 [ %77, %75 ], [ %102, %100 ]
store i32 %81, i32* %57
%82 = call i32 @poll(%struct.pollfd* %54, i32 1, i32 -1)
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %113
86: ; preds = %80
%87 = load i32, i32* %63
%88 = load i32, i32* @POLLIN
%89 = and i32 %88, %87
%90 = icmp eq i32 %89, 0
br i1 %90, label %100, label %91
91: ; preds = %86
%92 = call i32 @read(i32 %36, i8* %76, i32 4096)
switch i32 %92, label %95 [
i32 -1, label %93
i32 0, label %99
]
93: ; preds = %91
%94 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %113
95: ; preds = %91
%96 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %76)
%97 = load i32, i32* @POLLIN
%98 = load i32, i32* %63
br label %100
99: ; preds = %91
br label %111
100: ; preds = %95, %86
%101 = phi i32 [ %98, %95 ], [ %87, %86 ]
%102 = phi i32 [ %97, %95 ], [ %88, %86 ]
%103 = load i32, i32* @POLLHUP
%104 = load i32, i32* @POLLERR
%105 = or i32 %104, %103
%106 = and i32 %105, %101
%107 = icmp eq i32 %106, 0
br i1 %107, label %80, label %108
108: ; preds = %100
%109 = load i32, i32* @stderr
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i32 %101)
br label %111
111: ; preds = %99, %108
%112 = call i32 @close(i32 %36)
br label %113
113: ; preds = %93, %84, %111, %78
%114 = phi i32 [ 1, %78 ], [ 1, %84 ], [ 0, %111 ], [ 1, %93 ]
br label %115
115: ; preds = %113, %60
%116 = phi i32 [ 1, %60 ], [ %114, %113 ]
br label %117
117: ; preds = %115, %50, %41, %30, %22
%118 = phi i32 [ 1, %22 ], [ 1, %30 ], [ 1, %41 ], [ 1, %50 ], [ %116, %115 ]
br label %119
119: ; preds = %117, %13
%120 = phi i32 [ 1, %13 ], [ %118, %117 ]
ret i32 %120
}