#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ readBytes;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
scalar_t__ read(int, char *, int);
char *realloc(char *, size_t);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
char *grabDataWithURL(int sockfd, const char *URL, const char *ip,
                      size_t *inlen) {
  fd_set rset, wset;
  FD_ZERO(&rset);
  FD_SET(sockfd, &rset);
  wset = rset;
  int n = 0;
  struct timeval tval;
  tval.tv_sec = 1;
  tval.tv_usec = 0;
  if ((n = select(sockfd + 1, NULL, &wset, NULL, &tval)) == 0) {
    fprintf(stderr, "Failed to get socket ready!\n");
    return NULL;
  }
  if (FD_ISSET(sockfd, &wset)) {
    char writeData[1024] = {0};
    sprintf(writeData,
            "GET %s HTTP/1.1\r\nUser-Agent: DKR/1.0\r\nHost: %s\r\nAccept: "
            "*/*\r\n\r\n",
            URL, ip);
    write(sockfd, writeData, strlen(writeData));
  }
  char *outBuf = calloc(4096, sizeof(char));
  size_t walker = 0;
  size_t curBufLength = 4096;
  while (1) {
    FD_ZERO(&rset);
    FD_SET(sockfd, &rset);
    tval.tv_sec = 1;
    tval.tv_usec = 0;
    if ((n = select(sockfd + 1, &rset, NULL, NULL, &tval)) == 0) {
      fprintf(stderr, "Failed to get a response for %s on %s!\n", URL, ip);
      close(sockfd);
      return NULL;
    }
    char readBytes[4096] = {0};
    ssize_t slen = read(sockfd, readBytes, sizeof(readBytes));
    if (slen <= 0) {
      close(sockfd);
      if (inlen)
        *inlen = walker;
      return outBuf;
    } else {
      size_t len = (size_t)slen;
      if ((walker + len) > curBufLength) {
        while (curBufLength < (walker + len)) {
          curBufLength *= 2;
        }
        char *newBuf = realloc(outBuf, curBufLength);
        if (!newBuf) {
          fprintf(stderr, "Failed to reallocate to size %zu\n", curBufLength);
          free(outBuf);
          return NULL;
        }
        outBuf = newBuf;
      }
      memcpy(outBuf + walker, readBytes, len);
      walker += len;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<grabDataWithURL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x14a0,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x2c(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    -0xc(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1110 <FD_SET@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x1,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%rdx
lea    -0x48(%rbp),%r8
mov    %rcx,%rsi
call   10e0 <select@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    1285 <grabDataWithURL+0x95>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1522 <grabDataWithURL+0x332>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1300 <grabDataWithURL+0x110>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x450(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd59(%rip),%rsi
call   1100 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1494(%rbp)
lea    -0x450(%rbp),%rax
mov    %rax,-0x1490(%rbp)
lea    -0x450(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x1494(%rbp),%edi
mov    -0x1490(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x1000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x458(%rbp)
movq   $0x0,-0x460(%rbp)
movq   $0x1000,-0x468(%rbp)
lea    -0x2c(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    -0xc(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1110 <FD_SET@plt>
movl   $0x1,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x48(%rbp),%r8
mov    %rcx,%rdx
call   10e0 <select@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    13aa <grabDataWithURL+0x1ba>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xccf(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1522 <grabDataWithURL+0x332>
lea    -0x1470(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x1470(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %rax,-0x1478(%rbp)
cmpq   $0x0,-0x1478(%rbp)
jg     1417 <grabDataWithURL+0x227>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
cmpq   $0x0,-0x28(%rbp)
je     1407 <grabDataWithURL+0x217>
mov    -0x460(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x458(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1522 <grabDataWithURL+0x332>
mov    -0x1478(%rbp),%rax
mov    %rax,-0x1480(%rbp)
mov    -0x460(%rbp),%rax
add    -0x1480(%rbp),%rax
cmp    -0x468(%rbp),%rax
jbe    14e7 <grabDataWithURL+0x2f7>
jmp    1445 <grabDataWithURL+0x255>
mov    -0x468(%rbp),%rax
mov    -0x460(%rbp),%rcx
add    -0x1480(%rbp),%rcx
cmp    %rcx,%rax
jae    147a <grabDataWithURL+0x28a>
mov    -0x468(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x468(%rbp)
jmp    1445 <grabDataWithURL+0x255>
mov    -0x458(%rbp),%rdi
mov    -0x468(%rbp),%rsi
call   10f0 <realloc@plt>
mov    %rax,-0x1488(%rbp)
cmpq   $0x0,-0x1488(%rbp)
jne    14d9 <grabDataWithURL+0x2e9>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
mov    -0x468(%rbp),%rdx
lea    0xbcc(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x458(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1522 <grabDataWithURL+0x332>
mov    -0x1488(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x458(%rbp),%rdi
add    -0x460(%rbp),%rdi
lea    -0x1470(%rbp),%rsi
mov    -0x1480(%rbp),%rdx
call   10c0 <memcpy@plt>
mov    -0x1480(%rbp),%rax
add    -0x460(%rbp),%rax
mov    %rax,-0x460(%rbp)
jmp    132c <grabDataWithURL+0x13c>
mov    -0x8(%rbp),%rax
add    $0x14a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grabDataWithURL>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1058,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%ebx
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   10d0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1110 <FD_SET@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x1c(%rsp)
movl   $0x1,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x1(%rbx),%edi
lea    0x1c(%rsp),%rdx
lea    0x20(%rsp),%r8
mov    %edi,0x18(%rsp)
xor    %esi,%esi
xor    %ecx,%ecx
call   10e0 <select@plt>
test   %eax,%eax
je     1438 <grabDataWithURL+0x248>
mov    %r15,0x30(%rsp)
lea    0x1c(%rsp),%rsi
mov    %ebx,%edi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
mov    %rbx,%r15
je     12b5 <grabDataWithURL+0xc5>
lea    0x50(%rsp),%rbp
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xd8b(%rip),%rsi
mov    %rbp,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
call   1100 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r12,0x38(%rsp)
mov    %r14,0x40(%rsp)
mov    $0x1000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,0x10(%rsp)
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   10d0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1110 <FD_SET@plt>
movl   $0x1,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x20(%rsp),%r8
mov    0x18(%rsp),%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10e0 <select@plt>
test   %eax,%eax
je     140b <grabDataWithURL+0x21b>
mov    $0x1000,%ebx
xor    %r14d,%r14d
lea    0x50(%rsp),%rbp
mov    %r15,0x48(%rsp)
jmp    1395 <grabDataWithURL+0x1a5>
nopl   (%rax)
mov    0x10(%rsp),%rax
mov    %rax,0x10(%rsp)
add    %rax,%r14
mov    %r14,%rdi
lea    0x50(%rsp),%rbp
mov    %rbp,%rsi
mov    %r13,%rdx
call   10c0 <memcpy@plt>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   10d0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1110 <FD_SET@plt>
movl   $0x1,0x20(%rsp)
movq   $0x0,0x28(%rsp)
mov    0x18(%rsp),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
call   10e0 <select@plt>
mov    %r12,%r14
test   %eax,%eax
je     140b <grabDataWithURL+0x21b>
mov    $0x1000,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
test   %rax,%rax
jle    1453 <grabDataWithURL+0x263>
mov    %rax,%r13
lea    (%rax,%r14,1),%r12
cmp    %rbx,%r12
jbe    1330 <grabDataWithURL+0x140>
mov    0x10(%rsp),%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rbp
add    %rbx,%rbx
cmp    %r12,%rbp
jb     13e0 <grabDataWithURL+0x1f0>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   10f0 <realloc@plt>
test   %rax,%rax
je     146f <grabDataWithURL+0x27f>
mov    %rbp,%rbx
mov    0x48(%rsp),%r15
jmp    1335 <grabDataWithURL+0x145>
mov    0x2bce(%rip),%rax
mov    (%rax),%edi
lea    0xc42(%rip),%rsi
xor    %ebx,%ebx
mov    0x38(%rsp),%rdx
mov    0x40(%rsp),%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r15d,%edi
call   1080 <close@plt>
jmp    1493 <grabDataWithURL+0x2a3>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
lea    0xbb8(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1493 <grabDataWithURL+0x2a3>
mov    %r15d,%edi
call   1080 <close@plt>
mov    0x30(%rsp),%rax
test   %rax,%rax
je     1468 <grabDataWithURL+0x278>
mov    %r14,(%rax)
mov    0x10(%rsp),%rbx
jmp    1493 <grabDataWithURL+0x2a3>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
lea    0xc06(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x1058,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Failed to get socket ready!\0A\00"
@.str.1 = [64 x i8] c"GET %s HTTP/1.1\0D\0AUser-Agent: DKR/1.0\0D\0AHost: %s\0D\0AAccept: */*\0D\0A\0D\0A\00"
@.str.2 = [40 x i8] c"Failed to get a response for %s on %s!\0A\00"
@.str.3 = [34 x i8] c"Failed to reallocate to size %zu\0A\00"
define i8* @grabDataWithURL(i32 %0, i8* %1, i8* %2, i64* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.timeval
%14 = alloca [1024 x i8]
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
%18 = alloca [4096 x i8]
%19 = alloca i64
%20 = alloca i64
%21 = alloca i8*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64* %3, i64** %9
%22 = call i32 @FD_ZERO(i32* %10)
%23 = load i32, i32* %6
%24 = call i32 @FD_SET(i32 %23, i32* %10)
%25 = load i32, i32* %10
store i32 %25, i32* %11
store i32 0, i32* %12
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 1, i32* %26
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i64 0, i64* %27
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
%30 = call i32 @select(i32 %29, i32* null, i32* %11, i32* null, %struct.timeval* %13)
store i32 %30, i32* %12
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %4
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
br label %128
35: ; preds = %4
%36 = load i32, i32* %6
%37 = call i64 @FD_ISSET(i32 %36, i32* %11)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = bitcast [1024 x i8]* %14 to i8*
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%42 = load i8*, i8** %7
%43 = load i8*, i8** %8
%44 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43)
%45 = load i32, i32* %6
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = call i32 @write(i32 %45, i8* %46, i32 %48)
br label %50
50: ; preds = %39, %35
%51 = call i8* @calloc(i32 4096, i32 1)
store i8* %51, i8** %15
store i64 0, i64* %16
store i64 4096, i64* %17
br label %52
52: ; preds = %50, %127
%53 = call i32 @FD_ZERO(i32* %10)
%54 = load i32, i32* %6
%55 = call i32 @FD_SET(i32 %54, i32* %10)
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 1, i32* %56
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i64 0, i64* %57
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
%60 = call i32 @select(i32 %59, i32* %10, i32* null, i32* null, %struct.timeval* %13)
store i32 %60, i32* %12
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %69
62: ; preds = %52
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %7
%65 = load i8*, i8** %8
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %64, i8* %65)
%67 = load i32, i32* %6
%68 = call i32 @close(i32 %67)
store i8* null, i8** %5
br label %128
69: ; preds = %52
%70 = bitcast [4096 x i8]* %18 to i8*
%71 = load i32, i32* %6
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %18, i64 0, i64 0
%73 = call i64 @read(i32 %71, i8* %72, i32 4096)
store i64 %73, i64* %19
%74 = load i64, i64* %19
%75 = icmp sle i64 %74, 0
br i1 %75, label %76, label %86
76: ; preds = %69
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
%79 = load i64*, i64** %9
%80 = icmp ne i64* %79, null
br i1 %80, label %81, label %84
81: ; preds = %76
%82 = load i64, i64* %16
%83 = load i64*, i64** %9
store i64 %82, i64* %83
br label %84
84: ; preds = %81, %76
%85 = load i8*, i8** %15
store i8* %85, i8** %5
br label %128
86: ; preds = %69
%87 = load i64, i64* %19
store i64 %87, i64* %20
%88 = load i64, i64* %16
%89 = load i64, i64* %20
%90 = add i64 %88, %89
%91 = load i64, i64* %17
%92 = icmp ugt i64 %90, %91
br i1 %92, label %93, label %117
93: ; preds = %86
br label %94
94: ; preds = %100, %93
%95 = load i64, i64* %17
%96 = load i64, i64* %16
%97 = load i64, i64* %20
%98 = add i64 %96, %97
%99 = icmp ult i64 %95, %98
br i1 %99, label %100, label %103
100: ; preds = %94
%101 = load i64, i64* %17
%102 = mul i64 %101, 2
store i64 %102, i64* %17
br label %94
103: ; preds = %94
%104 = load i8*, i8** %15
%105 = load i64, i64* %17
%106 = call i8* @realloc(i8* %104, i64 %105)
store i8* %106, i8** %21
%107 = load i8*, i8** %21
%108 = icmp ne i8* %107, null
br i1 %108, label %115, label %109
109: ; preds = %103
%110 = load i32, i32* @stderr
%111 = load i64, i64* %17
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %111)
%113 = load i8*, i8** %15
%114 = call i32 @free(i8* %113)
store i8* null, i8** %5
br label %128
115: ; preds = %103
%116 = load i8*, i8** %21
store i8* %116, i8** %15
br label %117
117: ; preds = %115, %86
%118 = load i8*, i8** %15
%119 = load i64, i64* %16
%120 = getelementptr inbounds i8, i8* %118, i64 %119
%121 = getelementptr inbounds [4096 x i8], [4096 x i8]* %18, i64 0, i64 0
%122 = load i64, i64* %20
%123 = call i32 @memcpy(i8* %120, i8* %121, i64 %122)
%124 = load i64, i64* %20
%125 = load i64, i64* %16
%126 = add i64 %125, %124
store i64 %126, i64* %16
br label %127
127: ; preds = %117
br label %52
128: ; preds = %109, %84, %62, %32
%129 = load i8*, i8** %5
ret i8* %129
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Failed to get socket ready!\0A\00"
@.str.1 = [64 x i8] c"GET %s HTTP/1.1\0D\0AUser-Agent: DKR/1.0\0D\0AHost: %s\0D\0AAccept: */*\0D\0A\0D\0A\00"
@.str.2 = [40 x i8] c"Failed to get a response for %s on %s!\0A\00"
@.str.3 = [34 x i8] c"Failed to reallocate to size %zu\0A\00"
define i8* @grabDataWithURL(i32 %0, i8* %1, i8* %2, i64* writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca [1024 x i8]
%9 = alloca [4096 x i8]
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = call i32 @FD_ZERO(i32* %5)
%13 = call i32 @FD_SET(i32 %0, i32* %5)
%14 = load i32, i32* %5
store i32 %14, i32* %6
%15 = bitcast %struct.timeval* %7 to i8*
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 1, i32* %16
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
store i64 0, i64* %17
%18 = add nsw i32 %0, 1
%19 = call i32 @select(i32 %18, i32* null, i32* %6, i32* null, %struct.timeval* %7)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %4
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %79
24: ; preds = %4
%25 = call i64 @FD_ISSET(i32 %0, i32* %6)
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = call i32 @sprintf(i8* %28, i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
%30 = call i32 @strlen(i8* %28)
%31 = call i32 @write(i32 %0, i8* %28, i32 %30)
br label %32
32: ; preds = %27, %24
%33 = call dereferenceable_or_null(4096) i8* @calloc(i32 4096, i32 1)
%34 = call i32 @FD_ZERO(i32* %5)
%35 = call i32 @FD_SET(i32 %0, i32* %5)
store i32 1, i32* %16
store i64 0, i64* %17
%36 = call i32 @select(i32 %18, i32* %5, i32* null, i32* null, %struct.timeval* %7)
%37 = icmp eq i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %32
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
br label %44
40: ; preds = %70, %32
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
%43 = call i32 @close(i32 %0)
br label %79
44: ; preds = %38, %70
%45 = phi i64 [ 4096, %38 ], [ %72, %70 ]
%46 = phi i64 [ 0, %38 ], [ %55, %70 ]
%47 = phi i8* [ %33, %38 ], [ %71, %70 ]
%48 = call i64 @read(i32 %0, i8* %39, i32 4096)
%49 = icmp slt i64 %48, 1
br i1 %49, label %50, label %54
50: ; preds = %44
%51 = call i32 @close(i32 %0)
%52 = icmp eq i64* %3, null
br i1 %52, label %68, label %53
53: ; preds = %50
store i64 %46, i64* %3
br label %68
54: ; preds = %44
%55 = add i64 %48, %46
%56 = icmp ugt i64 %55, %45
br i1 %56, label %57, label %70
57: ; preds = %54, %57
%58 = phi i64 [ %60, %57 ], [ %45, %54 ]
%59 = icmp ult i64 %58, %55
%60 = shl i64 %58, 1
br i1 %59, label %57, label %61
61: ; preds = %57
%62 = call i8* @realloc(i8* %47, i64 %58)
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %70
64: ; preds = %61
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %58)
%67 = call i32 @free(i8* %47)
br label %68
68: ; preds = %53, %50, %64
%69 = phi i8* [ null, %64 ], [ %47, %50 ], [ %47, %53 ]
br label %79
70: ; preds = %54, %61
%71 = phi i8* [ %47, %54 ], [ %62, %61 ]
%72 = phi i64 [ %45, %54 ], [ %58, %61 ]
%73 = getelementptr inbounds i8, i8* %71, i64 %46
%74 = call i32 @memcpy(i8* %73, i8* %39, i64 %48)
%75 = call i32 @FD_ZERO(i32* %5)
%76 = call i32 @FD_SET(i32 %0, i32* %5)
store i32 1, i32* %16
store i64 0, i64* %17
%77 = call i32 @select(i32 %18, i32* %5, i32* null, i32* null, %struct.timeval* %7)
%78 = icmp eq i32 %77, 0
br i1 %78, label %40, label %44
79: ; preds = %68, %40, %21
%80 = phi i8* [ null, %21 ], [ null, %40 ], [ %69, %68 ]
ret i8* %80
}