#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__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serveraddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
char *getRequest(char *host, char *path) {
  char *request = malloc(sizeof(char) * 15000);
  if (request == NULL) {
    printf("MALLOC FAILED!\r\n");
    return NULL;
  }
  struct hostent *server;
  struct sockaddr_in serveraddr;
  int port = 80;
  int tcpSocket = socket(AF_INET, SOCK_STREAM, 0);
  if (tcpSocket < 0) {
    printf("Error opening socket\r\n");
    return NULL;
  }
  server = gethostbyname(host);
  if (server == NULL) {
    printf("gethostbyname() failed\r\n");
  }
  bzero((char *)&serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serveraddr.sin_addr.s_addr,
        server->h_length);
  serveraddr.sin_port = htons(port);
  if (connect(tcpSocket, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) <
      0)
    printf("Error Connecting\r\n");
  bzero(request, 15000);
  sprintf(request, "Get %s HTTP/1.1\r\nHost:%s\r\n\r\n", path, host);
  if (send(tcpSocket, request, strlen(request), 0) < 0)
    printf("Error with send()\r\n");
  bzero(request, 15000);
  int total = 0;
  int incoming = 0;
  int incoming_parsed = 0;
  int read = 1000;
  char *contentLength = NULL;
  while ((read == 1000 && total < 15000) ||
         (incoming_parsed && total < incoming)) {
    if (incoming_parsed) {
      read = recv(tcpSocket, request, (incoming - total), MSG_WAITALL);
    } else {
      read = recv(tcpSocket, request, 1000, MSG_WAITALL);
    }
    total += read;
    request += read;
    if (!incoming_parsed &&
        (contentLength = strstr((request - total), "Content-Length: ")) !=
            NULL) {
      sscanf(contentLength + 16, "%d", &incoming);
      if (incoming)
        incoming_parsed = 1;
    }
  }
  request -= total;
  close(tcpSocket);
  return request;
}


x86 assembly (clang, -O0):
<getRequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x3a98,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1232 <getRequest+0x42>
lea    0xde0(%rip),%rdi
call   1070 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    14d9 <getRequest+0x2e9>
movl   $0x50,-0x3c(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1278 <getRequest+0x88>
lea    0xdab(%rip),%rdi
call   1070 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    14d9 <getRequest+0x2e9>
mov    -0x10(%rbp),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    129c <getRequest+0xac>
lea    0xd91(%rip),%rdi
call   1070 <printf@plt>
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x38(%rbp),%rsi
add    $0x4,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bcopy@plt>
mov    -0x3c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    1303 <getRequest+0x113>
lea    0xd43(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x3a98,%esi
call   10d0 <bzero@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd30(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x0,%rax
jge    1366 <getRequest+0x176>
lea    0xd10(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x3a98,%esi
call   10d0 <bzero@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x3e8,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
cmpl   $0x3e8,-0x50(%rbp)
jne    13b7 <getRequest+0x1c7>
mov    $0x1,%al
cmpl   $0x3a98,-0x44(%rbp)
mov    %al,-0x65(%rbp)
jl     13d8 <getRequest+0x1e8>
xor    %eax,%eax
cmpl   $0x0,-0x4c(%rbp)
mov    %al,-0x66(%rbp)
je     13d2 <getRequest+0x1e2>
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
setl   %al
mov    %al,-0x66(%rbp)
mov    -0x66(%rbp),%al
mov    %al,-0x65(%rbp)
mov    -0x65(%rbp),%al
test   $0x1,%al
jne    13e8 <getRequest+0x1f8>
jmp    14b3 <getRequest+0x2c3>
cmpl   $0x0,-0x4c(%rbp)
je     1415 <getRequest+0x225>
mov    -0x40(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x48(%rbp),%edx
sub    -0x44(%rbp),%edx
mov    0x2bc2(%rip),%rax
mov    (%rax),%ecx
call   1030 <recv@plt>
mov    %eax,-0x50(%rbp)
jmp    1432 <getRequest+0x242>
mov    -0x40(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2ba5(%rip),%rax
mov    (%rax),%ecx
mov    $0x3e8,%edx
call   1030 <recv@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x50(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    14ae <getRequest+0x2be>
mov    -0x20(%rbp),%rdi
movslq -0x44(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
lea    0xc18(%rip),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
je     14ae <getRequest+0x2be>
mov    -0x58(%rbp),%rdi
add    $0x10,%rdi
lea    0xc07(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   10b0 <sscanf@plt>
cmpl   $0x0,-0x48(%rbp)
je     14a9 <getRequest+0x2b9>
movl   $0x1,-0x4c(%rbp)
jmp    14ae <getRequest+0x2be>
jmp    1398 <getRequest+0x1a8>
mov    -0x44(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRequest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
mov    $0x3a98,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1401 <getRequest+0x211>
mov    %rax,%rbx
mov    0x2dc7(%rip),%r15
mov    (%r15),%edi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
js     140a <getRequest+0x21a>
mov    %eax,%r13d
mov    %rbp,0x20(%rsp)
mov    %r14,%rdi
call   1090 <gethostbyname@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1260 <getRequest+0x70>
lea    0xdfb(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbp),%rsi
lea    0x14(%rsp),%rdi
mov    0x0(%rbp),%edx
call   10c0 <memmove@plt>
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
jns    12b9 <getRequest+0xc9>
lea    0xd90(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3a98,%esi
call   10d0 <bzero@plt>
lea    0xd33(%rip),%rsi
mov    %rbx,%rdi
mov    0x20(%rsp),%rdx
mov    %r14,%rcx
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %r15d,%r15d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
jns    1308 <getRequest+0x118>
lea    0xd2e(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3a98,%esi
call   10d0 <bzero@plt>
movl   $0x0,0xc(%rsp)
mov    $0x3e8,%ebp
mov    0x2c9f(%rip),%r12
lea    0xced(%rip),%r14
xor    %ecx,%ecx
jmp    1365 <getRequest+0x175>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rsp),%edx
sub    %r15d,%edx
mov    (%r12),%ecx
mov    %r13d,%edi
mov    %rbx,%rsi
call   1030 <recv@plt>
mov    %eax,%ebp
add    %eax,%r15d
cltq
add    %rax,%rbx
mov    $0x1,%ecx
cmp    $0x3e8,%ebp
jne    13e0 <getRequest+0x1f0>
cmp    $0x3a98,%r15d
jge    13e0 <getRequest+0x1f0>
test   %ecx,%ecx
jne    1340 <getRequest+0x150>
mov    (%r12),%ecx
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1030 <recv@plt>
mov    %eax,%ebp
add    %eax,%r15d
cltq
add    %rax,%rbx
movslq %r15d,%rax
mov    %rbx,%rdi
sub    %rax,%rdi
mov    %r14,%rsi
call   1100 <strstr@plt>
mov    $0x0,%ecx
test   %rax,%rax
je     1365 <getRequest+0x175>
add    $0x10,%rax
mov    %rax,%rdi
lea    0xc6d(%rip),%rsi
lea    0xc(%rsp),%rdx
call   10b0 <sscanf@plt>
xor    %ecx,%ecx
cmpl   $0x0,0xc(%rsp)
setne  %cl
jmp    1365 <getRequest+0x175>
nopw   0x0(%rax,%rax,1)
test   %ecx,%ecx
je     13f1 <getRequest+0x201>
mov    0xc(%rsp),%edx
cmp    %edx,%r15d
jl     1344 <getRequest+0x154>
movslq %r15d,%rax
sub    %rax,%rbx
mov    %r13d,%edi
call   1080 <close@plt>
jmp    1418 <getRequest+0x228>
lea    0xc7c(%rip),%rdi
jmp    1411 <getRequest+0x221>
lea    0xc5d(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32, i64 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"MALLOC FAILED!\0D\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [23 x i8] c"Error opening socket\0D\0A\00"
@.str.2 = [25 x i8] c"gethostbyname() failed\0D\0A\00"
@.str.3 = [19 x i8] c"Error Connecting\0D\0A\00"
@.str.4 = [29 x i8] c"Get %s HTTP/1.1\0D\0AHost:%s\0D\0A\0D\0A\00"
@.str.5 = [20 x i8] c"Error with send()\0D\0A\00"
@MSG_WAITALL = global i32 0
@.str.6 = [17 x i8] c"Content-Length: \00"
@.str.7 = [3 x i8] c"%d\00"
define i8* @getRequest(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%16 = call i8* @malloc(i32 15000)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %148
21: ; preds = %2
store i32 80, i32* %9
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %148
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = call %struct.hostent* @gethostbyname(i8* %30)
store %struct.hostent* %31, %struct.hostent** %7
%32 = load %struct.hostent*, %struct.hostent** %7
%33 = icmp eq %struct.hostent* %32, null
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = bitcast %struct.sockaddr_in* %8 to i8*
%38 = call i32 @bzero(i8* %37, i32 12)
%39 = load i32, i32* @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %39, i32* %40
%41 = load %struct.hostent*, %struct.hostent** %7
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i32 0, i32 1
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to i8*
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
%47 = bitcast i32* %46 to i8*
%48 = load %struct.hostent*, %struct.hostent** %7
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @bcopy(i8* %44, i8* %47, i32 %50)
%52 = load i32, i32* %9
%53 = call i32 @htons(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %53, i32* %54
%55 = load i32, i32* %10
%56 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%57 = call i64 @connect(i32 %55, %struct.sockaddr* %56, i32 12)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %36
%60 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %36
%62 = load i8*, i8** %6
%63 = call i32 @bzero(i8* %62, i32 15000)
%64 = load i8*, i8** %6
%65 = load i8*, i8** %5
%66 = load i8*, i8** %4
%67 = call i32 @sprintf(i8* %64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %65, i8* %66)
%68 = load i32, i32* %10
%69 = load i8*, i8** %6
%70 = load i8*, i8** %6
%71 = call i32 @strlen(i8* %70)
%72 = call i64 @send(i32 %68, i8* %69, i32 %71, i32 0)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %61
%75 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %76
76: ; preds = %74, %61
%77 = load i8*, i8** %6
%78 = call i32 @bzero(i8* %77, i32 15000)
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 1000, i32* %14
store i8* null, i8** %15
br label %79
79: ; preds = %138, %76
%80 = load i32, i32* %14
%81 = icmp eq i32 %80, 1000
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i32, i32* %11
%84 = icmp slt i32 %83, 15000
br i1 %84, label %94, label %85
85: ; preds = %82, %79
%86 = load i32, i32* %13
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %85
%89 = load i32, i32* %11
%90 = load i32, i32* %12
%91 = icmp slt i32 %89, %90
br label %92
92: ; preds = %88, %85
%93 = phi i1 [ false, %85 ], [ %91, %88 ]
br label %94
94: ; preds = %92, %82
%95 = phi i1 [ true, %82 ], [ %93, %92 ]
br i1 %95, label %96, label %139
96: ; preds = %94
%97 = load i32, i32* %13
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %107
99: ; preds = %96
%100 = load i32, i32* %10
%101 = load i8*, i8** %6
%102 = load i32, i32* %12
%103 = load i32, i32* %11
%104 = sub nsw i32 %102, %103
%105 = load i32, i32* @MSG_WAITALL
%106 = call i32 @recv(i32 %100, i8* %101, i32 %104, i32 %105)
store i32 %106, i32* %14
br label %112
107: ; preds = %96
%108 = load i32, i32* %10
%109 = load i8*, i8** %6
%110 = load i32, i32* @MSG_WAITALL
%111 = call i32 @recv(i32 %108, i8* %109, i32 1000, i32 %110)
store i32 %111, i32* %14
br label %112
112: ; preds = %107, %99
%113 = load i32, i32* %14
%114 = load i32, i32* %11
%115 = add nsw i32 %114, %113
store i32 %115, i32* %11
%116 = load i32, i32* %14
%117 = load i8*, i8** %6
%118 = sext i32 %116 to i64
%119 = getelementptr inbounds i8, i8* %117, i64 %118
store i8* %119, i8** %6
%120 = load i32, i32* %13
%121 = icmp ne i32 %120, 0
br i1 %121, label %138, label %122
122: ; preds = %112
%123 = load i8*, i8** %6
%124 = load i32, i32* %11
%125 = sext i32 %124 to i64
%126 = sub i64 0, %125
%127 = getelementptr inbounds i8, i8* %123, i64 %126
%128 = call i8* @strstr(i8* %127, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
store i8* %128, i8** %15
%129 = icmp ne i8* %128, null
br i1 %129, label %130, label %138
130: ; preds = %122
%131 = load i8*, i8** %15
%132 = getelementptr inbounds i8, i8* %131, i64 16
%133 = call i32 @sscanf(i8* %132, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %12)
%134 = load i32, i32* %12
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %137
136: ; preds = %130
store i32 1, i32* %13
br label %137
137: ; preds = %136, %130
br label %138
138: ; preds = %137, %122, %112
br label %79
139: ; preds = %94
%140 = load i32, i32* %11
%141 = load i8*, i8** %6
%142 = sext i32 %140 to i64
%143 = sub i64 0, %142
%144 = getelementptr inbounds i8, i8* %141, i64 %143
store i8* %144, i8** %6
%145 = load i32, i32* %10
%146 = call i32 @close(i32 %145)
%147 = load i8*, i8** %6
store i8* %147, i8** %3
br label %148
148: ; preds = %139, %27, %19
%149 = load i8*, i8** %3
ret i8* %149
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [29 x i8] c"Get %s HTTP/1.1\0D\0AHost:%s\0D\0A\0D\0A\00"
@MSG_WAITALL = global i32 0
@.str.6 = [17 x i8] c"Content-Length: \00"
@.str.7 = [3 x i8] c"%d\00"
@str = [19 x i8] c"Error with send()\0D\00"
@str.8 = [18 x i8] c"Error Connecting\0D\00"
@str.9 = [24 x i8] c"gethostbyname() failed\0D\00"
@str.10 = [22 x i8] c"Error opening socket\0D\00"
@str.11 = [16 x i8] c"MALLOC FAILED!\0D\00"
define i8* @getRequest(i8* %0, i8* %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = tail call dereferenceable_or_null(15000) i8* @malloc(i32 15000)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
br label %105
9: ; preds = %2
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
br label %103
17: ; preds = %9
%18 = tail call %struct.hostent* @gethostbyname(i8* %0)
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.9, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = call i32 @bzero(i8* %10, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i64 0, i32 1
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%30 = bitcast i32* %29 to i8*
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i64 0, i32 0
%32 = load i32, i32* %31
%33 = tail call i32 @htons(i32 80)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %33, i32* %34
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i64 @connect(i32 %13, %struct.sockaddr* %35, i32 12)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %22
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %40
40: ; preds = %38, %22
%41 = call i32 @bzero(i8* %5, i32 15000)
%42 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %0)
%43 = call i32 @strlen(i8* %5)
%44 = call i64 @send(i32 %13, i8* %5, i32 %43, i32 0)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %40
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %46, %40
%49 = call i32 @bzero(i8* %5, i32 15000)
%50 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %51
51: ; preds = %87, %48
%52 = phi i8* [ %5, %48 ], [ %88, %87 ]
%53 = phi i32 [ 0, %48 ], [ %89, %87 ]
%54 = phi i32 [ 0, %48 ], [ %90, %87 ]
%55 = phi i32 [ 1000, %48 ], [ %91, %87 ]
%56 = icmp eq i32 %55, 1000
%57 = icmp slt i32 %53, 15000
%58 = select i1 %56, i1 %57, i1 false
br i1 %58, label %64, label %59
59: ; preds = %51
%60 = icmp ne i32 %54, 0
%61 = load i32, i32* %4
%62 = icmp slt i32 %53, %61
%63 = select i1 %60, i1 %62, i1 false
br i1 %63, label %79, label %98
64: ; preds = %51
%65 = icmp eq i32 %54, 0
br i1 %65, label %68, label %66
66: ; preds = %64
%67 = load i32, i32* %4
br label %79
68: ; preds = %64
%69 = load i32, i32* @MSG_WAITALL
%70 = call i32 @recv(i32 %13, i8* %52, i32 1000, i32 %69)
%71 = add nsw i32 %70, %53
%72 = sext i32 %70 to i64
%73 = getelementptr inbounds i8, i8* %52, i64 %72
%74 = sext i32 %71 to i64
%75 = sub nsw i64 0, %74
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = call i8* @strstr(i8* dereferenceable(1) %76, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%78 = icmp eq i8* %77, null
br i1 %78, label %87, label %92
79: ; preds = %66, %59
%80 = phi i32 [ %67, %66 ], [ %61, %59 ]
%81 = sub nsw i32 %80, %53
%82 = load i32, i32* @MSG_WAITALL
%83 = call i32 @recv(i32 %13, i8* %52, i32 %81, i32 %82)
%84 = add nsw i32 %83, %53
%85 = sext i32 %83 to i64
%86 = getelementptr inbounds i8, i8* %52, i64 %85
br label %87
87: ; preds = %79, %92, %68
%88 = phi i8* [ %86, %79 ], [ %73, %68 ], [ %73, %92 ]
%89 = phi i32 [ %84, %79 ], [ %71, %68 ], [ %71, %92 ]
%90 = phi i32 [ 1, %79 ], [ 0, %68 ], [ %97, %92 ]
%91 = phi i32 [ %83, %79 ], [ %70, %68 ], [ %70, %92 ]
br label %51
92: ; preds = %68
%93 = getelementptr inbounds i8, i8* %77, i64 16
%94 = call i32 @sscanf(i8* %93, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %4)
%95 = load i32, i32* %4
%96 = icmp ne i32 %95, 0
%97 = zext i1 %96 to i32
br label %87
98: ; preds = %59
%99 = sext i32 %53 to i64
%100 = sub nsw i64 0, %99
%101 = getelementptr inbounds i8, i8* %52, i64 %100
%102 = call i32 @close(i32 %13)
br label %103
103: ; preds = %98, %15
%104 = phi i8* [ null, %15 ], [ %101, %98 ]
br label %105
105: ; preds = %103, %7
%106 = phi i8* [ null, %7 ], [ %104, %103 ]
ret i8* %106
}