#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__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct protoent {
  int /*<<< orphan*/ p_proto;
};
struct in_addr {
  int dummy;
};
struct hostent {
  char **h_addr_list;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ sockaddr_in;
typedef scalar_t__ in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
struct protoent *getprotobyname(char *);
int /*<<< orphan*/ htons(unsigned short);
scalar_t__ inet_addr(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
unsigned short strtoul(char *, int /*<<< orphan*/ *, int);
int write(int, char *, int);
int main(int argc, char **argv) {
  char buffer[BUFSIZ];
  enum CONSTEXPR { MAX_REQUEST_LEN = 1024 };
  char request[MAX_REQUEST_LEN];
  char request_template[] = "GET / HTTP/1.1\r\nHost: %s\r\n\r\n";
  struct protoent *protoent;
  char *hostname = "example.com";
  in_addr_t in_addr;
  int request_len;
  int socket_file_descriptor;
  ssize_t nbytes_total, nbytes_last;
  struct hostent *hostent;
  struct sockaddr_in sockaddr_in;
  unsigned short server_port = 80;
  if (argc > 1)
    hostname = argv[1];
  if (argc > 2)
    server_port = strtoul(argv[2], NULL, 10);
  request_len = snprintf(request, MAX_REQUEST_LEN, request_template, hostname);
  if (request_len >= MAX_REQUEST_LEN) {
    fprintf(stderr, "request length large: %d\n", request_len);
    exit(EXIT_FAILURE);
  }
  protoent = getprotobyname("tcp");
  if (protoent == NULL) {
    perror("getprotobyname");
    exit(EXIT_FAILURE);
  }
  socket_file_descriptor = socket(AF_INET, SOCK_STREAM, protoent->p_proto);
  if (socket_file_descriptor == -1) {
    perror("socket");
    exit(EXIT_FAILURE);
  }
  hostent = gethostbyname(hostname);
  if (hostent == NULL) {
    fprintf(stderr, "error: gethostbyname(\"%s\")\n", hostname);
    exit(EXIT_FAILURE);
  }
  in_addr = inet_addr(inet_ntoa(*(struct in_addr *)*(hostent->h_addr_list)));
  if (in_addr == (in_addr_t)-1) {
    fprintf(stderr, "error: inet_addr(\"%s\")\n", *(hostent->h_addr_list));
    exit(EXIT_FAILURE);
  }
  sockaddr_in.sin_addr.s_addr = in_addr;
  sockaddr_in.sin_family = AF_INET;
  sockaddr_in.sin_port = htons(server_port);
  if (connect(socket_file_descriptor, (struct sockaddr *)&sockaddr_in,
              sizeof(sockaddr_in)) == -1) {
    perror("connect");
    exit(EXIT_FAILURE);
  }
  nbytes_total = 0;
  while (nbytes_total < request_len) {
    nbytes_last = write(socket_file_descriptor, request + nbytes_total,
                        request_len - nbytes_total);
    if (nbytes_last == -1) {
      perror("write");
      exit(EXIT_FAILURE);
    }
    nbytes_total += nbytes_last;
  }
  fprintf(stderr, "debug: before first read\n");
  while ((nbytes_total = read(socket_file_descriptor, buffer, BUFSIZ)) > 0) {
    fprintf(stderr, "debug: after a read\n");
    write(STDOUT_FILENO, buffer, nbytes_total);
  }
  fprintf(stderr, "debug: after last read\n");
  if (nbytes_total == -1) {
    perror("read");
    exit(EXIT_FAILURE);
  }
  close(socket_file_descriptor);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x490(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    0xdc1(%rip),%rax
mov    %rax,-0x440(%rbp)
mov    0xdbb(%rip),%rax
mov    %rax,-0x438(%rbp)
mov    0xdb5(%rip),%rax
mov    %rax,-0x430(%rbp)
mov    0xdb0(%rip),%eax
mov    %eax,-0x428(%rbp)
mov    0xda8(%rip),%al
mov    %al,-0x424(%rbp)
lea    0xd9c(%rip),%rax
mov    %rax,-0x450(%rbp)
movw   $0x50,-0x482(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    12aa <main+0xba>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x450(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    12d1 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %ax,-0x482(%rbp)
lea    -0x420(%rbp),%rdi
lea    -0x440(%rbp),%rdx
mov    -0x450(%rbp),%rcx
mov    $0x400,%esi
call   1060 <snprintf@plt>
mov    %eax,-0x45c(%rbp)
cmpl   $0x400,-0x45c(%rbp)
jl     1331 <main+0x141>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
mov    -0x45c(%rbp),%edx
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xd0b(%rip),%rdi
call   10c0 <getprotobyname@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
jne    136c <main+0x17c>
lea    0xcee(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c53(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
mov    0x2c4c(%rip),%rax
mov    (%rax),%esi
mov    -0x448(%rbp),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x460(%rbp)
cmpl   $0xffffffff,-0x460(%rbp)
jne    13b9 <main+0x1c9>
lea    0xcb0(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c06(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x450(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x470(%rbp)
cmpq   $0x0,-0x470(%rbp)
jne    1406 <main+0x216>
mov    0x2bef(%rip),%rax
mov    (%rax),%edi
mov    -0x450(%rbp),%rdx
lea    0xc6c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2bb9(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x470(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %eax,%edi
call   1090 <inet_addr@plt>
mov    %rax,-0x458(%rbp)
cmpq   $0xffffffffffffffff,-0x458(%rbp)
ff
jne    1468 <main+0x278>
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
mov    -0x470(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdx
lea    0xc26(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2b57(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x458(%rbp),%rax
mov    %rax,-0x478(%rbp)
mov    0x2b63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x47c(%rbp)
movzwl -0x482(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x480(%rbp)
mov    -0x460(%rbp),%edi
lea    -0x480(%rbp),%rsi
mov    $0x10,%edx
call   1100 <connect@plt>
cmp    $0xffffffff,%eax
jne    14d1 <main+0x2e1>
lea    0xbd3(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2aee(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movl   $0x0,-0x464(%rbp)
mov    -0x464(%rbp),%eax
cmp    -0x45c(%rbp),%eax
jge    1559 <main+0x369>
mov    -0x460(%rbp),%edi
lea    -0x420(%rbp),%rsi
movslq -0x464(%rbp),%rax
add    %rax,%rsi
mov    -0x45c(%rbp),%edx
sub    -0x464(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x468(%rbp)
cmpl   $0xffffffff,-0x468(%rbp)
jne    1542 <main+0x352>
lea    0xb6a(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2a7d(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x468(%rbp),%eax
add    -0x464(%rbp),%eax
mov    %eax,-0x464(%rbp)
jmp    14db <main+0x2eb>
mov    0x2a70(%rip),%rax
mov    (%rax),%edi
lea    0xb36(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x490(%rbp),%rsi
mov    -0x460(%rbp),%edi
mov    0x2a3c(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    %eax,-0x464(%rbp)
cmp    $0x0,%eax
jle    15d1 <main+0x3e1>
mov    0x2a2f(%rip),%rax
mov    (%rax),%edi
lea    0xb0f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x490(%rbp),%rsi
mov    0x2a31(%rip),%rax
mov    (%rax),%edi
mov    -0x464(%rbp),%edx
call   1030 <write@plt>
jmp    1570 <main+0x380>
mov    0x29f8(%rip),%rax
mov    (%rax),%edi
lea    0xaed(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
cmpl   $0xffffffff,-0x464(%rbp)
jne    160f <main+0x41f>
lea    0xaea(%rip),%rdi
call   10d0 <perror@plt>
mov    0x29b0(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x460(%rbp),%edi
call   1070 <close@plt>
mov    0x298f(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
movups 0xde8(%rip),%xmm0
movups %xmm0,-0x53(%rbp)
movaps 0xdd0(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
mov    $0x50,%bx
cmp    $0x2,%edi
jl     1257 <main+0x67>
mov    0x8(%rsi),%r12
je     125e <main+0x6e>
mov    0x10(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,%ebx
jmp    125e <main+0x6e>
lea    0xdbf(%rip),%r12
lea    -0x460(%rbp),%rdi
lea    -0x60(%rbp),%rdx
mov    $0x400,%esi
mov    %r12,%rcx
call   1060 <snprintf@plt>
mov    %eax,%r13d
cmp    $0x400,%eax
jl     129c <main+0xac>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    12e0 <main+0xf0>
lea    0xda0(%rip),%rdi
call   10c0 <getprotobyname@plt>
test   %rax,%rax
jne    12b6 <main+0xc6>
lea    0xd93(%rip),%rdi
jmp    12db <main+0xeb>
mov    0x2d23(%rip),%rcx
mov    (%rcx),%edi
mov    0x2d02(%rip),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
jne    12ee <main+0xfe>
lea    0xd7b(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
jne    1313 <main+0x123>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
lea    0xd4f(%rip),%rsi
mov    %r12,%rdx
jmp    1347 <main+0x157>
mov    %rax,%r12
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %eax,%edi
call   1090 <inet_addr@plt>
cmp    $0xffffffffffffffff,%rax
jne    1350 <main+0x160>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rax
mov    (%rax),%rdx
lea    0xd32(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    12e0 <main+0xf0>
mov    %rax,-0x30(%rbp)
mov    0x2c85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
movzwl %bx,%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
lea    -0x38(%rbp),%rsi
mov    %r15d,%edi
mov    $0x10,%edx
call   1100 <connect@plt>
cmp    $0xffffffff,%eax
jne    138d <main+0x19d>
lea    0xd09(%rip),%rdi
jmp    12db <main+0xeb>
test   %r13d,%r13d
jle    13cb <main+0x1db>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebx,%rax
lea    (%rax,%rbp,1),%rsi
add    $0xfffffffffffffba0,%rsi
mov    %r13d,%edx
sub    %eax,%edx
mov    %r15d,%edi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     149b <main+0x2ab>
add    %eax,%ebx
cmp    %ebx,%r13d
jg     13a0 <main+0x1b0>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
lea    0xcc4(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x2bd7(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   1080 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    145d <main+0x26d>
lea    0xcb6(%rip),%r12
mov    0x2be6(%rip),%r13
mov    0x2bbf(%rip),%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rax),%edi
mov    %r12,%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   1080 <read@plt>
mov    %eax,%ebx
mov    0x2b79(%rip),%rax
test   %ebx,%ebx
jg     1420 <main+0x230>
jmp    1464 <main+0x274>
mov    0x2b6c(%rip),%rax
mov    (%rax),%edi
lea    0xc61(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
cmp    $0xffffffff,%ebx
jne    1485 <main+0x295>
lea    0xc66(%rip),%rdi
jmp    12db <main+0xeb>
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xbf7(%rip),%rdi
jmp    12db <main+0xeb>

LLVM IR (-O0):
%struct.protoent = type { i32 }
%struct.hostent = type { i8** }
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@__const.main.request_template = [29 x i8] c"GET / HTTP/1.1\0D\0AHost: %s\0D\0A\0D\0A\00"
@.str = [12 x i8] c"example.com\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"request length large: %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"tcp\00"
@.str.3 = [15 x i8] c"getprotobyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [7 x i8] c"socket\00"
@.str.5 = [28 x i8] c"error: gethostbyname(\22%s\22)\0A\00"
@.str.6 = [24 x i8] c"error: inet_addr(\22%s\22)\0A\00"
@.str.7 = [8 x i8] c"connect\00"
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [26 x i8] c"debug: before first read\0A\00"
@.str.10 = [21 x i8] c"debug: after a read\0A\00"
@STDOUT_FILENO = global i32 0
@.str.11 = [24 x i8] c"debug: after last read\0A\00"
@.str.12 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [1024 x i8]
%9 = alloca [29 x i8]
%10 = alloca %struct.protoent*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.hostent*
%18 = alloca %struct.sockaddr_in
%19 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* @BUFSIZ
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %6
%23 = alloca i8, i64 %21
store i64 %21, i64* %7
%24 = bitcast [29 x i8]* %9 to i8*
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %11
store i16 80, i16* %19
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
store i8* %30, i8** %11
br label %31
31: ; preds = %27, %2
%32 = load i32, i32* %4
%33 = icmp sgt i32 %32, 2
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call zeroext i16 @strtoul(i8* %37, i32* null, i32 10)
store i16 %38, i16* %19
br label %39
39: ; preds = %34, %31
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [29 x i8], [29 x i8]* %9, i64 0, i64 0
%42 = load i8*, i8** %11
%43 = call i32 @snprintf(i8* %40, i32 1024, i8* %41, i8* %42)
store i32 %43, i32* %13
%44 = load i32, i32* %13
%45 = icmp sge i32 %44, 1024
br i1 %45, label %46, label %52
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = load i32, i32* %13
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %39
%53 = call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store %struct.protoent* %53, %struct.protoent** %10
%54 = load %struct.protoent*, %struct.protoent** %10
%55 = icmp eq %struct.protoent* %54, null
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %52
%61 = load i32, i32* @AF_INET
%62 = load i32, i32* @SOCK_STREAM
%63 = load %struct.protoent*, %struct.protoent** %10
%64 = getelementptr inbounds %struct.protoent, %struct.protoent* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 @socket(i32 %61, i32 %62, i32 %65)
store i32 %66, i32* %14
%67 = load i32, i32* %14
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %73
69: ; preds = %60
%70 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %60
%74 = load i8*, i8** %11
%75 = call %struct.hostent* @gethostbyname(i8* %74)
store %struct.hostent* %75, %struct.hostent** %17
%76 = load %struct.hostent*, %struct.hostent** %17
%77 = icmp eq %struct.hostent* %76, null
br i1 %77, label %78, label %84
78: ; preds = %73
%79 = load i32, i32* @stderr
%80 = load i8*, i8** %11
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %80)
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %73
%85 = load %struct.hostent*, %struct.hostent** %17
%86 = getelementptr inbounds %struct.hostent, %struct.hostent* %85, i32 0, i32 0
%87 = load i8**, i8*** %86
%88 = load i8*, i8** %87
%89 = bitcast i8* %88 to %struct.in_addr*
%90 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %89, i32 0, i32 0
%91 = load i32, i32* %90
%92 = call i32 @inet_ntoa(i32 %91)
%93 = call i64 @inet_addr(i32 %92)
store i64 %93, i64* %12
%94 = load i64, i64* %12
%95 = icmp eq i64 %94, -1
br i1 %95, label %96, label %105
96: ; preds = %84
%97 = load i32, i32* @stderr
%98 = load %struct.hostent*, %struct.hostent** %17
%99 = getelementptr inbounds %struct.hostent, %struct.hostent* %98, i32 0, i32 0
%100 = load i8**, i8*** %99
%101 = load i8*, i8** %100
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %101)
%103 = load i32, i32* @EXIT_FAILURE
%104 = call i32 @exit(i32 %103)
unreachable
105: ; preds = %84
%106 = load i64, i64* %12
%107 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 2
%108 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %107, i32 0, i32 0
store i64 %106, i64* %108
%109 = load i32, i32* @AF_INET
%110 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
store i32 %109, i32* %110
%111 = load i16, i16* %19
%112 = call i32 @htons(i16 zeroext %111)
%113 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
store i32 %112, i32* %113
%114 = load i32, i32* %14
%115 = bitcast %struct.sockaddr_in* %18 to %struct.sockaddr*
%116 = call i32 @connect(i32 %114, %struct.sockaddr* %115, i32 16)
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %122
118: ; preds = %105
%119 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%120 = load i32, i32* @EXIT_FAILURE
%121 = call i32 @exit(i32 %120)
unreachable
122: ; preds = %105
store i32 0, i32* %15
br label %123
123: ; preds = %143, %122
%124 = load i32, i32* %15
%125 = load i32, i32* %13
%126 = icmp slt i32 %124, %125
br i1 %126, label %127, label %147
127: ; preds = %123
%128 = load i32, i32* %14
%129 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%130 = load i32, i32* %15
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i8, i8* %129, i64 %131
%133 = load i32, i32* %13
%134 = load i32, i32* %15
%135 = sub nsw i32 %133, %134
%136 = call i32 @write(i32 %128, i8* %132, i32 %135)
store i32 %136, i32* %16
%137 = load i32, i32* %16
%138 = icmp eq i32 %137, -1
br i1 %138, label %139, label %143
139: ; preds = %127
%140 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%141 = load i32, i32* @EXIT_FAILURE
%142 = call i32 @exit(i32 %141)
unreachable
143: ; preds = %127
%144 = load i32, i32* %16
%145 = load i32, i32* %15
%146 = add nsw i32 %145, %144
store i32 %146, i32* %15
br label %123
147: ; preds = %123
%148 = load i32, i32* @stderr
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %150
150: ; preds = %155, %147
%151 = load i32, i32* %14
%152 = load i32, i32* @BUFSIZ
%153 = call i32 @read(i32 %151, i8* %23, i32 %152)
store i32 %153, i32* %15
%154 = icmp sgt i32 %153, 0
br i1 %154, label %155, label %161
155: ; preds = %150
%156 = load i32, i32* @stderr
%157 = call i32 (i32, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%158 = load i32, i32* @STDOUT_FILENO
%159 = load i32, i32* %15
%160 = call i32 @write(i32 %158, i8* %23, i32 %159)
br label %150
161: ; preds = %150
%162 = load i32, i32* @stderr
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
%164 = load i32, i32* %15
%165 = icmp eq i32 %164, -1
br i1 %165, label %166, label %170
166: ; preds = %161
%167 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%168 = load i32, i32* @EXIT_FAILURE
%169 = call i32 @exit(i32 %168)
unreachable
170: ; preds = %161
%171 = load i32, i32* %14
%172 = call i32 @close(i32 %171)
%173 = load i32, i32* @EXIT_SUCCESS
%174 = call i32 @exit(i32 %173)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.protoent = type { i32 }
%struct.hostent = type { i8** }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@__const.main.request_template = [29 x i8] c"GET / HTTP/1.1\0D\0AHost: %s\0D\0A\0D\0A\00"
@.str = [12 x i8] c"example.com\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"request length large: %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"tcp\00"
@.str.3 = [15 x i8] c"getprotobyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [7 x i8] c"socket\00"
@.str.5 = [28 x i8] c"error: gethostbyname(\22%s\22)\0A\00"
@.str.6 = [24 x i8] c"error: inet_addr(\22%s\22)\0A\00"
@.str.7 = [8 x i8] c"connect\00"
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [26 x i8] c"debug: before first read\0A\00"
@.str.10 = [21 x i8] c"debug: after a read\0A\00"
@STDOUT_FILENO = global i32 0
@.str.11 = [24 x i8] c"debug: after last read\0A\00"
@.str.12 = [5 x i8] c"read\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [29 x i8]
%5 = alloca %struct.sockaddr_in
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [29 x i8], [29 x i8]* %4, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = icmp sgt i32 %0, 1
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = icmp eq i32 %0, 2
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call zeroext i16 @strtoul(i8* nocapture %19, i32* null, i32 10)
br label %21
21: ; preds = %2, %17, %13
%22 = phi i8* [ %15, %17 ], [ %15, %13 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %2 ]
%23 = phi i16 [ %20, %17 ], [ 80, %13 ], [ 80, %2 ]
%24 = call i32 @snprintf(i8* %9, i32 1024, i8* %10, i8* %22)
%25 = icmp sgt i32 %24, 1023
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %21
%32 = call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq %struct.protoent* %32, null
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %31
%39 = load i32, i32* @AF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = getelementptr inbounds %struct.protoent, %struct.protoent* %32, i64 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @socket(i32 %39, i32 %40, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %38
%50 = call %struct.hostent* @gethostbyname(i8* %22)
%51 = icmp eq %struct.hostent* %50, null
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %49
%58 = bitcast %struct.hostent* %50 to %struct.in_addr***
%59 = load %struct.in_addr**, %struct.in_addr*** %58
%60 = load %struct.in_addr*, %struct.in_addr** %59
%61 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %60, i64 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @inet_ntoa(i32 %62)
%64 = call i64 @inet_addr(i32 %63)
%65 = icmp eq i64 %64, -1
br i1 %65, label %66, label %74
66: ; preds = %57
%67 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i64 0, i32 0
%68 = load i32, i32* @stderr
%69 = load i8**, i8*** %67
%70 = load i8*, i8** %69
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %70)
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %57
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2, i32 0
store i64 %64, i64* %75
%76 = load i32, i32* @AF_INET
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %76, i32* %77
%78 = call i32 @htons(i16 zeroext %23)
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %78, i32* %79
%80 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%81 = call i32 @connect(i32 %43, %struct.sockaddr* %80, i32 16)
%82 = icmp eq i32 %81, -1
br i1 %82, label %85, label %83
83: ; preds = %74
%84 = icmp sgt i32 %24, 0
br i1 %84, label %91, label %103
85: ; preds = %74
%86 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %91
%90 = icmp sgt i32 %24, %98
br i1 %90, label %91, label %103
91: ; preds = %83, %89
%92 = phi i32 [ %98, %89 ], [ 0, %83 ]
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %93
%95 = sub nsw i32 %24, %92
%96 = call i32 @write(i32 %43, i8* %94, i32 %95)
%97 = icmp eq i32 %96, -1
%98 = add nsw i32 %96, %92
br i1 %97, label %99, label %89
99: ; preds = %91
%100 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%101 = load i32, i32* @EXIT_FAILURE
%102 = call i32 @exit(i32 %101)
unreachable
103: ; preds = %89, %83
%104 = load i32, i32* @stderr
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%106 = load i32, i32* @BUFSIZ
%107 = call i32 @read(i32 %43, i8* %8, i32 %106)
%108 = icmp sgt i32 %107, 0
br i1 %108, label %109, label %118
109: ; preds = %103, %109
%110 = phi i32 [ %116, %109 ], [ %107, %103 ]
%111 = load i32, i32* @stderr
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%113 = load i32, i32* @STDOUT_FILENO
%114 = call i32 @write(i32 %113, i8* %8, i32 %110)
%115 = load i32, i32* @BUFSIZ
%116 = call i32 @read(i32 %43, i8* %8, i32 %115)
%117 = icmp sgt i32 %116, 0
br i1 %117, label %109, label %118
118: ; preds = %109, %103
%119 = phi i32 [ %107, %103 ], [ %116, %109 ]
%120 = load i32, i32* @stderr
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
%122 = icmp eq i32 %119, -1
br i1 %122, label %123, label %127
123: ; preds = %118
%124 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %118
%128 = call i32 @close(i32 %43)
%129 = load i32, i32* @EXIT_SUCCESS
%130 = call i32 @exit(i32 %129)
unreachable
}