#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int getopt(int, char **, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
char *optarg;
char optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char **argv) {
  char *server_port = "80";
  char *server_ip = "google.com";
  int sockfd, rc;
  char *http_format_req;
  struct addrinfo hints, *server;
  char *message = "";
  int bytes_received = -1;
  char *recv_data = (char *)malloc(sizeof(char *) * 1000);
  int o;
  while ((o = getopt(argc, argv, "p:h:f:i:")) != -1) {
    switch (o) {
    case 'p':
      server_port = optarg;
      break;
    case 'h':
      server_ip = optarg;
      break;
    case 'f':
      message = optarg;
      break;
    case '?':
      if (optopt == 'p' || optopt == 'h') {
        fprintf(stderr, "Option %c requires an argument.\n", optopt);
      } else {
        fprintf(stderr, "Unknown argument: %c.\n", optopt);
      }
      break;
    }
  }
  http_format_req = (char *)malloc(
      sizeof(char *) * (strlen("GET / HTTP/1.1\n\n") + strlen(message)));
  sprintf(http_format_req, "GET ");
  sprintf(http_format_req + strlen(http_format_req), message);
  sprintf(http_format_req + strlen(http_format_req), " HTTP/1.0\n\n");
  printf("%s\n", http_format_req);
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  if ((rc = getaddrinfo(server_ip, server_port, &hints, &server)) != 0) {
    perror(gai_strerror(rc));
    exit(-1);
  }
  sockfd = socket(server->ai_family, server->ai_socktype, server->ai_protocol);
  if (sockfd == -1) {
    perror("ERROR opening socket");
    exit(-1);
  }
  rc = connect(sockfd, server->ai_addr, server->ai_addrlen);
  if (rc == -1) {
    perror("ERROR on connect");
    close(sockfd);
    exit(-1);
  }
  rc = send(sockfd, http_format_req, strlen(http_format_req), 0);
  if (rc < 0) {
    perror("ERROR on send");
    exit(-1);
  }
  bytes_received = recv(sockfd, recv_data, 1024, 0);
  while (bytes_received) {
    bytes_received = recv(sockfd, recv_data, 1024, 0);
    if (bytes_received == -1) {
      perror("recv");
      exit(1);
    }
    printf("%s\n", recv_data);
    if (bytes_received == 0) {
      break;
    }
    recv_data[bytes_received] = '\0';
  }
out:
  freeaddrinfo(server);
  close(sockfd);
  printf("Done.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdd0(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xdc8(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe2a(%rip),%rax
mov    %rax,-0x58(%rbp)
movl   $0xffffffff,-0x5c(%rbp)
mov    $0x1f40,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xda1(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x6c(%rbp)
cmp    $0xffffffff,%eax
je     1371 <main+0x161>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x70(%rbp)
sub    $0x3f,%eax
je     12fe <main+0xee>
jmp    1292 <main+0x82>
mov    -0x70(%rbp),%eax
sub    $0x66,%eax
je     12eb <main+0xdb>
jmp    12a3 <main+0x93>
mov    -0x70(%rbp),%eax
sub    $0x68,%eax
je     12d8 <main+0xc8>
jmp    12b4 <main+0xa4>
mov    -0x70(%rbp),%eax
sub    $0x70,%eax
jne    136c <main+0x15c>
jmp    12c5 <main+0xb5>
mov    0x2d2c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    136c <main+0x15c>
mov    0x2d19(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    136c <main+0x15c>
mov    0x2d06(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    136c <main+0x15c>
mov    0x2cd3(%rip),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
je     1324 <main+0x114>
mov    0x2cc0(%rip),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
jne    1348 <main+0x138>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
lea    0xce3(%rip),%rsi
mov    0x2c9d(%rip),%rax
movsbl (%rax),%edx
call   10a0 <fprintf@plt>
jmp    1367 <main+0x157>
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
lea    0xce0(%rip),%rsi
mov    0x2c79(%rip),%rax
movsbl (%rax),%edx
call   10a0 <fprintf@plt>
jmp    136c <main+0x15c>
jmp    125f <main+0x4f>
lea    0xcd7(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x84(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xcae(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x80(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x58(%rbp),%rsi
call   10e0 <sprintf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xc6a(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x30(%rbp),%rsi
lea    0xc66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1080 <memset@plt>
mov    0x2bb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2b8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1110 <getaddrinfo@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     1475 <main+0x265>
mov    -0x28(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edx
call   1130 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    14b2 <main+0x2a2>
lea    0xbd2(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   1100 <connect@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    14f2 <main+0x2e2>
lea    0xbaf(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1548 <main+0x338>
lea    0xb62(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     15d0 <main+0x3c0>
mov    -0x24(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    159e <main+0x38e>
lea    0xb1a(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x68(%rbp),%rsi
lea    0xac8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x5c(%rbp)
jne    15bf <main+0x3af>
jmp    15d0 <main+0x3c0>
mov    -0x68(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    155e <main+0x34e>
jmp    15d5 <main+0x3c5>
mov    -0x50(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
lea    0xac1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    $0x1f40,%edi
call   10b0 <malloc@plt>
mov    %rax,%r13
lea    0xdc9(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xdc0(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe21(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xdb3(%rip),%r14
mov    0x2d76(%rip),%r12
mov    0x2d5f(%rip),%r15
jmp    1282 <main+0x72>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
movsbl %al,%edx
lea    0xd9a(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10d0 <getopt@plt>
cmp    $0x65,%eax
jg     12c0 <main+0xb0>
cmp    $0x3f,%eax
jne    12e0 <main+0xd0>
movzbl (%r12),%eax
cmp    $0x70,%al
je     1270 <main+0x60>
cmp    $0x68,%al
je     1270 <main+0x60>
mov    (%r15),%edi
movsbl %al,%edx
lea    0xd85(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1282 <main+0x72>
nopw   0x0(%rax,%rax,1)
cmp    $0x66,%eax
je     12e7 <main+0xd7>
cmp    $0x68,%eax
je     12f8 <main+0xe8>
cmp    $0x70,%eax
jne    1282 <main+0x72>
mov    0x2d22(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
jmp    1282 <main+0x72>
cmp    $0xffffffff,%eax
jne    1282 <main+0x72>
jmp    130c <main+0xfc>
mov    0x2d0a(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    1282 <main+0x72>
mov    0x2cf9(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    1282 <main+0x72>
lea    0xd3c(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
add    %eax,%ebx
shl    $0x3,%ebx
mov    %ebx,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
movl   $0x20544547,(%rax)
movb   $0x0,0x4(%rax)
mov    %rax,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    %rbp,%rsi
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movabs $0x2e312f5054544820,%rcx
2f 31 2e
mov    %rcx,(%rbx,%rax,1)
movl   $0xa0a30,0x8(%rbx,%rax,1)
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1080 <memset@plt>
mov    0x2c47(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2c1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    %rsp,%rcx
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %rbp,%rdx
call   1110 <getaddrinfo@plt>
test   %eax,%eax
jne    14c0 <main+0x2b0>
mov    (%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     14cc <main+0x2bc>
mov    %eax,%ebp
mov    (%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   1100 <connect@plt>
cmp    $0xffffffff,%eax
je     14d5 <main+0x2c5>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     14f2 <main+0x2e2>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1493 <main+0x283>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     147d <main+0x26d>
mov    %eax,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <puts@plt>
test   %ebx,%ebx
je     1493 <main+0x283>
movslq %ebx,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1450 <main+0x240>
lea    0xc21(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    (%rsp),%rdi
call   1120 <freeaddrinfo@plt>
mov    %ebp,%edi
call   1090 <close@plt>
lea    0xc00(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
jmp    14f9 <main+0x2e9>
lea    0xb9e(%rip),%rdi
jmp    14f9 <main+0x2e9>
lea    0xbaa(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xb9e(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [3 x i8] c"80\00"
@.str.1 = [11 x i8] c"google.com\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [9 x i8] c"p:h:f:i:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.4 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.5 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.6 = [17 x i8] c"GET / HTTP/1.1\0A\0A\00"
@.str.7 = [5 x i8] c"GET \00"
@.str.8 = [12 x i8] c" HTTP/1.0\0A\0A\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.10 = [21 x i8] c"ERROR opening socket\00"
@.str.11 = [17 x i8] c"ERROR on connect\00"
@.str.12 = [14 x i8] c"ERROR on send\00"
@.str.13 = [5 x i8] c"recv\00"
@.str.14 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca %struct.addrinfo
%12 = alloca %struct.addrinfo*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %13
store i32 -1, i32* %14
%17 = call i64 @malloc(i32 8000)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %15
br label %19
19: ; preds = %49, %2
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 %22, i32* %16
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %50
24: ; preds = %19
%25 = load i32, i32* %16
switch i32 %25, label %49 [
i32 112, label %26
i32 104, label %28
i32 102, label %30
i32 63, label %32
]
26: ; preds = %24
%27 = load i8*, i8** @optarg
store i8* %27, i8** %6
br label %49
28: ; preds = %24
%29 = load i8*, i8** @optarg
store i8* %29, i8** %7
br label %49
30: ; preds = %24
%31 = load i8*, i8** @optarg
store i8* %31, i8** %13
br label %49
32: ; preds = %24
%33 = load i8, i8* @optopt
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 112
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i8, i8* @optopt
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 104
br i1 %39, label %40, label %44
40: ; preds = %36, %32
%41 = load i32, i32* @stderr
%42 = load i8, i8* @optopt
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8 signext %42)
br label %48
44: ; preds = %36
%45 = load i32, i32* @stderr
%46 = load i8, i8* @optopt
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8 signext %46)
br label %48
48: ; preds = %44, %40
br label %49
49: ; preds = %24, %48, %30, %28, %26
br label %19
50: ; preds = %19
%51 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%52 = load i8*, i8** %13
%53 = call i32 @strlen(i8* %52)
%54 = add nsw i32 %51, %53
%55 = sext i32 %54 to i64
%56 = mul i64 8, %55
%57 = trunc i64 %56 to i32
%58 = call i64 @malloc(i32 %57)
%59 = inttoptr i64 %58 to i8*
store i8* %59, i8** %10
%60 = load i8*, i8** %10
%61 = call i32 @sprintf(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%62 = load i8*, i8** %10
%63 = load i8*, i8** %10
%64 = call i32 @strlen(i8* %63)
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
%67 = load i8*, i8** %13
%68 = call i32 @sprintf(i8* %66, i8* %67)
%69 = load i8*, i8** %10
%70 = load i8*, i8** %10
%71 = call i32 @strlen(i8* %70)
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = call i32 @sprintf(i8* %73, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%75 = load i8*, i8** %10
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %75)
%77 = call i32 @memset(%struct.addrinfo* %11, i32 0, i32 20)
%78 = load i32, i32* @AF_INET
%79 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 4
store i32 %78, i32* %79
%80 = load i32, i32* @SOCK_STREAM
%81 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 3
store i32 %80, i32* %81
%82 = load i8*, i8** %7
%83 = load i8*, i8** %6
%84 = call i32 @getaddrinfo(i8* %82, i8* %83, %struct.addrinfo* %11, %struct.addrinfo** %12)
store i32 %84, i32* %9
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %50
%87 = load i32, i32* %9
%88 = call i8* @gai_strerror(i32 %87)
%89 = call i32 @perror(i8* %88)
%90 = call i32 @exit(i32 -1)
unreachable
91: ; preds = %50
%92 = load %struct.addrinfo*, %struct.addrinfo** %12
%93 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %92, i32 0, i32 4
%94 = load i32, i32* %93
%95 = load %struct.addrinfo*, %struct.addrinfo** %12
%96 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %95, i32 0, i32 3
%97 = load i32, i32* %96
%98 = load %struct.addrinfo*, %struct.addrinfo** %12
%99 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %98, i32 0, i32 2
%100 = load i32, i32* %99
%101 = call i32 @socket(i32 %94, i32 %97, i32 %100)
store i32 %101, i32* %8
%102 = load i32, i32* %8
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %107
104: ; preds = %91
%105 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%106 = call i32 @exit(i32 -1)
unreachable
107: ; preds = %91
%108 = load i32, i32* %8
%109 = load %struct.addrinfo*, %struct.addrinfo** %12
%110 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %109, i32 0, i32 1
%111 = load i32, i32* %110
%112 = load %struct.addrinfo*, %struct.addrinfo** %12
%113 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %112, i32 0, i32 0
%114 = load i32, i32* %113
%115 = call i32 @connect(i32 %108, i32 %111, i32 %114)
store i32 %115, i32* %9
%116 = load i32, i32* %9
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %123
118: ; preds = %107
%119 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%120 = load i32, i32* %8
%121 = call i32 @close(i32 %120)
%122 = call i32 @exit(i32 -1)
unreachable
123: ; preds = %107
%124 = load i32, i32* %8
%125 = load i8*, i8** %10
%126 = load i8*, i8** %10
%127 = call i32 @strlen(i8* %126)
%128 = call i32 @send(i32 %124, i8* %125, i32 %127, i32 0)
store i32 %128, i32* %9
%129 = load i32, i32* %9
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %134
131: ; preds = %123
%132 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
%133 = call i32 @exit(i32 -1)
unreachable
134: ; preds = %123
%135 = load i32, i32* %8
%136 = load i8*, i8** %15
%137 = call i32 @recv(i32 %135, i8* %136, i32 1024, i32 0)
store i32 %137, i32* %14
br label %138
138: ; preds = %156, %134
%139 = load i32, i32* %14
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %161
141: ; preds = %138
%142 = load i32, i32* %8
%143 = load i8*, i8** %15
%144 = call i32 @recv(i32 %142, i8* %143, i32 1024, i32 0)
store i32 %144, i32* %14
%145 = load i32, i32* %14
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %150
147: ; preds = %141
%148 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%149 = call i32 @exit(i32 1)
unreachable
150: ; preds = %141
%151 = load i8*, i8** %15
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %151)
%153 = load i32, i32* %14
%154 = icmp eq i32 %153, 0
br i1 %154, label %155, label %156
155: ; preds = %150
br label %161
156: ; preds = %150
%157 = load i8*, i8** %15
%158 = load i32, i32* %14
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds i8, i8* %157, i64 %159
store i8 0, i8* %160
br label %138
161: ; preds = %155, %138
br label %162
162: ; preds = %161
%163 = load %struct.addrinfo*, %struct.addrinfo** %12
%164 = call i32 @freeaddrinfo(%struct.addrinfo* %163)
%165 = load i32, i32* %8
%166 = call i32 @close(i32 %165)
%167 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [3 x i8] c"80\00"
@.str.1 = [11 x i8] c"google.com\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [9 x i8] c"p:h:f:i:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.4 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.5 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.6 = [17 x i8] c"GET / HTTP/1.1\0A\0A\00"
@.str.7 = [5 x i8] c"GET \00"
@.str.8 = [12 x i8] c" HTTP/1.0\0A\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.10 = [21 x i8] c"ERROR opening socket\00"
@.str.11 = [17 x i8] c"ERROR on connect\00"
@.str.12 = [14 x i8] c"ERROR on send\00"
@.str.13 = [5 x i8] c"recv\00"
@str = [6 x i8] c"Done.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = tail call i64 @malloc(i32 8000)
br label %8
8: ; preds = %24, %2
%9 = phi i8* [ %25, %24 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %2 ]
%10 = phi i8* [ %13, %24 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %2 ]
%11 = phi i8* [ %16, %24 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %2 ]
br label %12
12: ; preds = %8, %22
%13 = phi i8* [ %10, %8 ], [ %23, %22 ]
%14 = phi i8* [ %11, %8 ], [ %16, %22 ]
br label %15
15: ; preds = %12, %20
%16 = phi i8* [ %14, %12 ], [ %21, %20 ]
br label %17
17: ; preds = %19, %15
%18 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
switch i32 %18, label %19 [
i32 -1, label %34
i32 112, label %20
i32 104, label %22
i32 102, label %24
i32 63, label %26
]
19: ; preds = %17, %28, %31
br label %17
20: ; preds = %17
%21 = load i8*, i8** @optarg
br label %15
22: ; preds = %17
%23 = load i8*, i8** @optarg
br label %12
24: ; preds = %17
%25 = load i8*, i8** @optarg
br label %8
26: ; preds = %17
%27 = load i8, i8* @optopt
switch i8 %27, label %31 [
i8 112, label %28
i8 104, label %28
]
28: ; preds = %26, %26
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8 signext %27)
br label %19
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8 signext %27)
br label %19
34: ; preds = %17
%35 = inttoptr i64 %7 to i8*
%36 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%37 = tail call i32 @strlen(i8* %9)
%38 = add nsw i32 %37, %36
%39 = shl i32 %38, 3
%40 = tail call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %41, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 5, i1 false)
%42 = tail call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = tail call i32 @sprintf(i8* dereferenceable(1) %44, i8* dereferenceable(1) %9)
%46 = tail call i32 @strlen(i8* %41)
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %41, i64 %47
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(12) %48, i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i64 12, i1 false)
%49 = tail call i32 @puts(i8* dereferenceable(1) %41)
%50 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 20)
%51 = load i32, i32* @AF_INET
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %51, i32* %52
%53 = load i32, i32* @SOCK_STREAM
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %53, i32* %54
%55 = call i32 @getaddrinfo(i8* %13, i8* %16, %struct.addrinfo* %3, %struct.addrinfo** %4)
%56 = icmp eq i32 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %34
%58 = call i8* @gai_strerror(i32 %55)
%59 = call i32 @perror(i8* %58)
%60 = call i32 @exit(i32 -1)
unreachable
61: ; preds = %34
%62 = load %struct.addrinfo*, %struct.addrinfo** %4
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i64 0, i32 4
%64 = load i32, i32* %63
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i64 0, i32 3
%66 = load i32, i32* %65
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i64 0, i32 2
%68 = load i32, i32* %67
%69 = call i32 @socket(i32 %64, i32 %66, i32 %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %61
%72 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%73 = call i32 @exit(i32 -1)
unreachable
74: ; preds = %61
%75 = load %struct.addrinfo*, %struct.addrinfo** %4
%76 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %75, i64 0, i32 1
%77 = load i32, i32* %76
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %75, i64 0, i32 0
%79 = load i32, i32* %78
%80 = call i32 @connect(i32 %69, i32 %77, i32 %79)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %86
82: ; preds = %74
%83 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%84 = call i32 @close(i32 %69)
%85 = call i32 @exit(i32 -1)
unreachable
86: ; preds = %74
%87 = call i32 @strlen(i8* %41)
%88 = call i32 @send(i32 %69, i8* %41, i32 %87, i32 0)
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %86
%91 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
%92 = call i32 @exit(i32 -1)
unreachable
93: ; preds = %86
%94 = call i32 @recv(i32 %69, i8* %35, i32 1024, i32 0)
%95 = icmp eq i32 %94, 0
br i1 %95, label %111, label %96
96: ; preds = %93
%97 = call i32 @recv(i32 %69, i8* %35, i32 1024, i32 0)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %102
99: ; preds = %106, %96
%100 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %96, %106
%103 = phi i32 [ %109, %106 ], [ %97, %96 ]
%104 = call i32 @puts(i8* dereferenceable(1) %35)
%105 = icmp eq i32 %103, 0
br i1 %105, label %111, label %106
106: ; preds = %102
%107 = sext i32 %103 to i64
%108 = getelementptr inbounds i8, i8* %35, i64 %107
store i8 0, i8* %108
%109 = call i32 @recv(i32 %69, i8* %35, i32 1024, i32 0)
%110 = icmp eq i32 %109, -1
br i1 %110, label %99, label %102
111: ; preds = %102, %93
%112 = load %struct.addrinfo*, %struct.addrinfo** %4
%113 = call i32 @freeaddrinfo(%struct.addrinfo* %112)
%114 = call i32 @close(i32 %69)
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}