#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:m:i:")) != -1) {
    switch (o) {
    case 'p':
      server_port = optarg;
      break;
    case 'h':
      server_ip = optarg;
      break;
    case 'm':
      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 / 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    $0x90,%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    $0x68,%eax
je     12d8 <main+0xc8>
jmp    12a3 <main+0x93>
mov    -0x70(%rbp),%eax
sub    $0x6d,%eax
je     12eb <main+0xdb>
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,-0x74(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x74(%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    0xcb4(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x30(%rbp),%rsi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1080 <memset@plt>
mov    0x2c06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2bda(%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     1426 <main+0x216>
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    1463 <main+0x253>
lea    0xc21(%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    14a3 <main+0x293>
lea    0xbfe(%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,-0x84(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    14f3 <main+0x2e3>
lea    0xbb7(%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     157b <main+0x36b>
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    1549 <main+0x339>
lea    0xb6f(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x68(%rbp),%rsi
lea    0xb1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x5c(%rbp)
jne    156a <main+0x35a>
jmp    157b <main+0x36b>
mov    -0x68(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1509 <main+0x2f9>
jmp    1580 <main+0x370>
mov    -0x50(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
lea    0xb16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x90,%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,%r12
lea    0xdd9(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xdd0(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe31(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xdc3(%rip),%r14
mov    0x2d86(%rip),%r13
mov    0x2d6f(%rip),%r15
jmp    1272 <main+0x72>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
movsbl %al,%edx
lea    0xdaa(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10d0 <getopt@plt>
cmp    $0x67,%eax
jg     12b0 <main+0xb0>
cmp    $0x3f,%eax
jne    12d0 <main+0xd0>
movzbl 0x0(%r13),%eax
cmp    $0x70,%al
je     1260 <main+0x60>
cmp    $0x68,%al
je     1260 <main+0x60>
mov    (%r15),%edi
movsbl %al,%edx
lea    0xd95(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1272 <main+0x72>
nopw   0x0(%rax,%rax,1)
cmp    $0x68,%eax
je     12d7 <main+0xd7>
cmp    $0x6d,%eax
je     12e8 <main+0xe8>
cmp    $0x70,%eax
jne    1272 <main+0x72>
mov    0x2d32(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
jmp    1272 <main+0x72>
cmp    $0xffffffff,%eax
jne    1272 <main+0x72>
jmp    12fc <main+0xfc>
mov    0x2d1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    1272 <main+0x72>
mov    0x2d09(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    1272 <main+0x72>
lea    0xd4c(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1050 <strlen@plt>
add    %eax,%ebx
shl    $0x3,%ebx
mov    %ebx,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
movups 0xd36(%rip),%xmm0
movups %xmm0,(%rax)
movb   $0x0,0x10(%rax)
mov    %rax,%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1080 <memset@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    %rsp,%rcx
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %rbp,%rdx
call   1100 <getaddrinfo@plt>
test   %eax,%eax
jne    147f <main+0x27f>
mov    (%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     148b <main+0x28b>
mov    %eax,%ebp
mov    (%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
je     1494 <main+0x294>
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     14b1 <main+0x2b1>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1452 <main+0x252>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     143c <main+0x23c>
mov    %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1040 <puts@plt>
test   %ebx,%ebx
je     1452 <main+0x252>
movslq %ebx,%rax
movb   $0x0,(%r12,%rax,1)
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1410 <main+0x210>
lea    0xc62(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    (%rsp),%rdi
call   1110 <freeaddrinfo@plt>
mov    %ebp,%edi
call   1090 <close@plt>
lea    0xc41(%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    14b8 <main+0x2b8>
lea    0xbdf(%rip),%rdi
jmp    14b8 <main+0x2b8>
lea    0xbeb(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    0xbdf(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <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:m: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 = [17 x i8] c"GET / HTTP/1.0\0A\0A\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.9 = [21 x i8] c"ERROR opening socket\00"
@.str.10 = [17 x i8] c"ERROR on connect\00"
@.str.11 = [14 x i8] c"ERROR on send\00"
@.str.12 = [5 x i8] c"recv\00"
@.str.13 = [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 109, 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 ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%62 = load i8*, i8** %10
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %62)
%64 = call i32 @memset(%struct.addrinfo* %11, i32 0, i32 20)
%65 = load i32, i32* @AF_INET
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 4
store i32 %65, i32* %66
%67 = load i32, i32* @SOCK_STREAM
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 3
store i32 %67, i32* %68
%69 = load i8*, i8** %7
%70 = load i8*, i8** %6
%71 = call i32 @getaddrinfo(i8* %69, i8* %70, %struct.addrinfo* %11, %struct.addrinfo** %12)
store i32 %71, i32* %9
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %50
%74 = load i32, i32* %9
%75 = call i8* @gai_strerror(i32 %74)
%76 = call i32 @perror(i8* %75)
%77 = call i32 @exit(i32 -1)
unreachable
78: ; preds = %50
%79 = load %struct.addrinfo*, %struct.addrinfo** %12
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %79, i32 0, i32 4
%81 = load i32, i32* %80
%82 = load %struct.addrinfo*, %struct.addrinfo** %12
%83 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %82, i32 0, i32 3
%84 = load i32, i32* %83
%85 = load %struct.addrinfo*, %struct.addrinfo** %12
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i32 0, i32 2
%87 = load i32, i32* %86
%88 = call i32 @socket(i32 %81, i32 %84, i32 %87)
store i32 %88, i32* %8
%89 = load i32, i32* %8
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %78
%92 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%93 = call i32 @exit(i32 -1)
unreachable
94: ; preds = %78
%95 = load i32, i32* %8
%96 = load %struct.addrinfo*, %struct.addrinfo** %12
%97 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %96, i32 0, i32 1
%98 = load i32, i32* %97
%99 = load %struct.addrinfo*, %struct.addrinfo** %12
%100 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %99, i32 0, i32 0
%101 = load i32, i32* %100
%102 = call i32 @connect(i32 %95, i32 %98, i32 %101)
store i32 %102, i32* %9
%103 = load i32, i32* %9
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %110
105: ; preds = %94
%106 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
%107 = load i32, i32* %8
%108 = call i32 @close(i32 %107)
%109 = call i32 @exit(i32 -1)
unreachable
110: ; preds = %94
%111 = load i32, i32* %8
%112 = load i8*, i8** %10
%113 = load i8*, i8** %10
%114 = call i32 @strlen(i8* %113)
%115 = call i32 @send(i32 %111, i8* %112, i32 %114, i32 0)
store i32 %115, i32* %9
%116 = load i32, i32* %9
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %121
118: ; preds = %110
%119 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%120 = call i32 @exit(i32 -1)
unreachable
121: ; preds = %110
%122 = load i32, i32* %8
%123 = load i8*, i8** %15
%124 = call i32 @recv(i32 %122, i8* %123, i32 1024, i32 0)
store i32 %124, i32* %14
br label %125
125: ; preds = %143, %121
%126 = load i32, i32* %14
%127 = icmp ne i32 %126, 0
br i1 %127, label %128, label %148
128: ; preds = %125
%129 = load i32, i32* %8
%130 = load i8*, i8** %15
%131 = call i32 @recv(i32 %129, i8* %130, i32 1024, i32 0)
store i32 %131, i32* %14
%132 = load i32, i32* %14
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %137
134: ; preds = %128
%135 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%136 = call i32 @exit(i32 1)
unreachable
137: ; preds = %128
%138 = load i8*, i8** %15
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %138)
%140 = load i32, i32* %14
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %143
142: ; preds = %137
br label %148
143: ; preds = %137
%144 = load i8*, i8** %15
%145 = load i32, i32* %14
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i8, i8* %144, i64 %146
store i8 0, i8* %147
br label %125
148: ; preds = %142, %125
br label %149
149: ; preds = %148
%150 = load %struct.addrinfo*, %struct.addrinfo** %12
%151 = call i32 @freeaddrinfo(%struct.addrinfo* %150)
%152 = load i32, i32* %8
%153 = call i32 @close(i32 %152)
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, 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:m: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 = [17 x i8] c"GET / HTTP/1.0\0A\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.9 = [21 x i8] c"ERROR opening socket\00"
@.str.10 = [17 x i8] c"ERROR on connect\00"
@.str.11 = [14 x i8] c"ERROR on send\00"
@.str.12 = [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 109, 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(17) %41, i8* align 1 dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i64 17, i1 false)
%42 = tail call i32 @puts(i8* dereferenceable(1) %41)
%43 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 20)
%44 = load i32, i32* @AF_INET
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %44, i32* %45
%46 = load i32, i32* @SOCK_STREAM
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %46, i32* %47
%48 = call i32 @getaddrinfo(i8* %13, i8* %16, %struct.addrinfo* %3, %struct.addrinfo** %4)
%49 = icmp eq i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %34
%51 = call i8* @gai_strerror(i32 %48)
%52 = call i32 @perror(i8* %51)
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %34
%55 = load %struct.addrinfo*, %struct.addrinfo** %4
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i64 0, i32 4
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i64 0, i32 3
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i64 0, i32 2
%61 = load i32, i32* %60
%62 = call i32 @socket(i32 %57, i32 %59, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %67
64: ; preds = %54
%65 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%66 = call i32 @exit(i32 -1)
unreachable
67: ; preds = %54
%68 = load %struct.addrinfo*, %struct.addrinfo** %4
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i64 0, i32 1
%70 = load i32, i32* %69
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i64 0, i32 0
%72 = load i32, i32* %71
%73 = call i32 @connect(i32 %62, i32 %70, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %79
75: ; preds = %67
%76 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
%77 = call i32 @close(i32 %62)
%78 = call i32 @exit(i32 -1)
unreachable
79: ; preds = %67
%80 = call i32 @strlen(i8* %41)
%81 = call i32 @send(i32 %62, i8* %41, i32 %80, i32 0)
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %79
%84 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%85 = call i32 @exit(i32 -1)
unreachable
86: ; preds = %79
%87 = call i32 @recv(i32 %62, i8* %35, i32 1024, i32 0)
%88 = icmp eq i32 %87, 0
br i1 %88, label %104, label %89
89: ; preds = %86
%90 = call i32 @recv(i32 %62, i8* %35, i32 1024, i32 0)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %95
92: ; preds = %99, %89
%93 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %89, %99
%96 = phi i32 [ %102, %99 ], [ %90, %89 ]
%97 = call i32 @puts(i8* dereferenceable(1) %35)
%98 = icmp eq i32 %96, 0
br i1 %98, label %104, label %99
99: ; preds = %95
%100 = sext i32 %96 to i64
%101 = getelementptr inbounds i8, i8* %35, i64 %100
store i8 0, i8* %101
%102 = call i32 @recv(i32 %62, i8* %35, i32 1024, i32 0)
%103 = icmp eq i32 %102, -1
br i1 %103, label %92, label %95
104: ; preds = %95, %86
%105 = load %struct.addrinfo*, %struct.addrinfo** %4
%106 = call i32 @freeaddrinfo(%struct.addrinfo* %105)
%107 = call i32 @close(i32 %62)
%108 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}