#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 int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
char *gai_strerror(int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, long *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
int write(int, char *, int);
long queryResourceSize(int socket, char *path, char *host, int useWindowStyle) {
  long retValue = 0;
  char *windowsNewLine = "\r\n";
  char *linuxNewLine = "\n";
  char *newLine = useWindowStyle ? windowsNewLine : linuxNewLine;
  if (path != NULL && host != NULL && socket >= 0) {
    int size = 8192;
    char buffer[8192];
    char *cursor = buffer;
    int offset = 0;
    offset = sprintf(cursor, "HEAD %s HTTP/1.1%s", path, newLine);
    cursor += offset;
    offset = sprintf(cursor,
                     "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows "
                     "NT 6.0; Trident/4.0)%s",
                     newLine);
    cursor += offset;
    offset = sprintf(cursor, "Connection: close%s", newLine);
    cursor += offset;
    offset = sprintf(cursor, "Host: %s%s", host, newLine);
    cursor += offset;
    offset = sprintf(cursor, "%s", newLine);
    cursor += offset;
    *cursor = '\0';
    if (socket >= 0) {
      printf("\nprobing...");
      int count = write(socket, buffer, (cursor - buffer));
      if (count < 0) {
        fprintf(stderr, "write: %d : %s\n", count, gai_strerror(count));
      }
      cursor = buffer;
      do {
        fd_set read_set;
        struct timeval timeout;
        timeout.tv_sec = 10;
        timeout.tv_usec = 0;
        FD_ZERO(&read_set);
        FD_SET(socket, &read_set);
        int r = select(socket + 1, &read_set, NULL, NULL, &timeout);
        if (r < 0) {
          fprintf(stderr, "poll errorrom socket %d \n", socket);
        }
        if (r == 0) {
          fprintf(stderr, "tiemout rom socket %d \n", socket);
        }
        if (r > 0) {
          if (size > 0) {
            count = read(socket, cursor, size);
            if (count > 0) {
              cursor += count;
              size -= count;
            }
            if (count == 0) {
              *cursor = '\0';
              break;
            }
          }
        }
      } while (0);
      char *contentLengthLine = strstr(buffer, "Content-Length:");
      if (contentLengthLine != NULL) {
        long contentLength = 0;
        sscanf(contentLengthLine, "Content-Length: %ld\n*", &contentLength);
        if (contentLength > 0) {
          retValue = contentLength;
        }
      }
    }
  }
  return retValue;
}


x86 assembly (clang, -O0):
<queryResourceSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20a0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe28(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe1e(%rip),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1201 <queryResourceSize+0x51>
mov    -0x30(%rbp),%rax
mov    %rax,-0x2098(%rbp)
jmp    120c <queryResourceSize+0x5c>
mov    -0x38(%rbp),%rax
mov    %rax,-0x2098(%rbp)
mov    -0x2098(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     15c9 <queryResourceSize+0x419>
cmpq   $0x0,-0x18(%rbp)
je     15c9 <queryResourceSize+0x419>
cmpl   $0x0,-0x4(%rbp)
jl     15c9 <queryResourceSize+0x419>
movl   $0x2000,-0x44(%rbp)
lea    -0x2050(%rbp),%rax
mov    %rax,-0x2058(%rbp)
movl   $0x0,-0x205c(%rbp)
mov    -0x2058(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    %eax,-0x205c(%rbp)
mov    -0x205c(%rbp),%ecx
mov    -0x2058(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x2058(%rbp)
mov    -0x2058(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    %eax,-0x205c(%rbp)
mov    -0x205c(%rbp),%ecx
mov    -0x2058(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x2058(%rbp)
mov    -0x2058(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    %eax,-0x205c(%rbp)
mov    -0x205c(%rbp),%ecx
mov    -0x2058(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x2058(%rbp)
mov    -0x2058(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    %eax,-0x205c(%rbp)
mov    -0x205c(%rbp),%ecx
mov    -0x2058(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x2058(%rbp)
mov    -0x2058(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    %eax,-0x205c(%rbp)
mov    -0x205c(%rbp),%ecx
mov    -0x2058(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x2058(%rbp)
mov    -0x2058(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x4(%rbp)
jl     15c4 <queryResourceSize+0x414>
lea    0xced(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x2050(%rbp),%rsi
mov    -0x2058(%rbp),%rax
lea    -0x2050(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x2060(%rbp)
cmpl   $0x0,-0x2060(%rbp)
jge    1413 <queryResourceSize+0x263>
mov    0x2c09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20a0(%rbp)
mov    -0x2060(%rbp),%eax
mov    %eax,-0x209c(%rbp)
mov    -0x2060(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x20a0(%rbp),%edi
mov    -0x209c(%rbp),%edx
mov    %rax,%rcx
lea    0xc83(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    -0x2050(%rbp),%rax
mov    %rax,-0x2058(%rbp)
movl   $0xa,-0x2078(%rbp)
movq   $0x0,-0x2070(%rbp)
lea    -0x2064(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x2064(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x2064(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x2078(%rbp),%r8
mov    %rcx,%rdx
call   1090 <select@plt>
mov    %eax,-0x207c(%rbp)
cmpl   $0x0,-0x207c(%rbp)
jge    149e <queryResourceSize+0x2ee>
mov    0x2b55(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xc08(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x0,-0x207c(%rbp)
jne    14c5 <queryResourceSize+0x315>
mov    0x2b2e(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xbfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x0,-0x207c(%rbp)
jle    154f <queryResourceSize+0x39f>
cmpl   $0x0,-0x44(%rbp)
jle    154a <queryResourceSize+0x39a>
mov    -0x4(%rbp),%edi
mov    -0x2058(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x2060(%rbp)
cmpl   $0x0,-0x2060(%rbp)
jle    1529 <queryResourceSize+0x379>
mov    -0x2060(%rbp),%ecx
mov    -0x2058(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x2058(%rbp)
mov    -0x2060(%rbp),%ecx
mov    -0x44(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x2060(%rbp)
jne    1545 <queryResourceSize+0x395>
mov    -0x2058(%rbp),%rax
movb   $0x0,(%rax)
jmp    1554 <queryResourceSize+0x3a4>
jmp    154a <queryResourceSize+0x39a>
jmp    154f <queryResourceSize+0x39f>
jmp    1554 <queryResourceSize+0x3a4>
lea    -0x2050(%rbp),%rdi
lea    0xb6f(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x2088(%rbp)
cmpq   $0x0,-0x2088(%rbp)
je     15bf <queryResourceSize+0x40f>
movq   $0x0,-0x2090(%rbp)
mov    -0x2088(%rbp),%rdi
lea    0xb4c(%rip),%rsi
lea    -0x2090(%rbp),%rdx
call   10a0 <sscanf@plt>
cmpq   $0x0,-0x2090(%rbp)
jle    15ba <queryResourceSize+0x40a>
mov    -0x2090(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    15bf <queryResourceSize+0x40f>
jmp    15c4 <queryResourceSize+0x414>
jmp    15c9 <queryResourceSize+0x419>
mov    -0x28(%rbp),%rax
add    $0x20a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<queryResourceSize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2028,%rsp
test   %ecx,%ecx
lea    0xe27(%rip),%rax
lea    0xe1f(%rip),%r14
cmove  %rax,%r14
xor    %eax,%eax
test   %edi,%edi
js     13ac <queryResourceSize+0x1ec>
mov    %rdx,%r12
mov    %rsi,%rdx
test   %rsi,%rsi
je     13ac <queryResourceSize+0x1ec>
test   %r12,%r12
je     13ac <queryResourceSize+0x1ec>
mov    %edi,%r15d
lea    0xdf2(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <sprintf@plt>
cltq
lea    (%rsp,%rax,1),%r13
add    $0x20,%r13
lea    0xde5(%rip),%rsi
mov    %r13,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
movslq %eax,%rbp
add    %r13,%rbp
lea    0xe19(%rip),%rsi
mov    %rbp,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
movslq %eax,%rbx
add    %rbp,%rbx
lea    0xe13(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <sprintf@plt>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <stpcpy@plt>
sub    %ebp,%eax
cltq
lea    (%rax,%rbp,1),%rbx
movb   $0x0,(%rax,%rbp,1)
lea    0xdea(%rip),%rdi
call   1050 <printf@plt>
lea    0x20(%rsp),%rsi
sub    %esi,%ebx
mov    %r15d,%edi
mov    %ebx,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    12da <queryResourceSize+0x11a>
mov    %eax,%ebx
mov    0x2d24(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1060 <gai_strerror@plt>
lea    0xdc3(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
movl   $0xa,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10d0 <FD_SET@plt>
lea    0x1(%r15),%edi
lea    0x8(%rsp),%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10a0 <select@plt>
test   %eax,%eax
js     133b <queryResourceSize+0x17b>
je     134d <queryResourceSize+0x18d>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x2000,%edx
call   1070 <read@plt>
test   %eax,%eax
jne    1367 <queryResourceSize+0x1a7>
movb   $0x0,0x20(%rsp)
jmp    1367 <queryResourceSize+0x1a7>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
jmp    135d <queryResourceSize+0x19d>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xd63(%rip),%rsi
lea    0x20(%rsp),%rdi
call   10e0 <strstr@plt>
test   %rax,%rax
je     13aa <queryResourceSize+0x1ea>
movq   $0x0,0x8(%rsp)
lea    0xd54(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   10b0 <sscanf@plt>
mov    0x8(%rsp),%rcx
xor    %eax,%eax
test   %rcx,%rcx
cmovns %rcx,%rax
jmp    13ac <queryResourceSize+0x1ec>
xor    %eax,%eax
add    $0x2028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [19 x i8] c"HEAD %s HTTP/1.1%s\00"
@.str.3 = [78 x i8] c"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)%s\00"
@.str.4 = [20 x i8] c"Connection: close%s\00"
@.str.5 = [11 x i8] c"Host: %s%s\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [12 x i8] c"\0Aprobing...\00"
@stderr = global i32 0
@.str.8 = [16 x i8] c"write: %d : %s\0A\00"
@.str.9 = [26 x i8] c"poll errorrom socket %d \0A\00"
@.str.10 = [24 x i8] c"tiemout rom socket %d \0A\00"
@.str.11 = [16 x i8] c"Content-Length:\00"
@.str.12 = [22 x i8] c"Content-Length: %ld\0A*\00"
define i64 @queryResourceSize(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca [8192 x i8]
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca %struct.timeval
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i64 0, i64* %9
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %11
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = load i8*, i8** %10
br label %29
27: ; preds = %4
%28 = load i8*, i8** %11
br label %29
29: ; preds = %27, %25
%30 = phi i8* [ %26, %25 ], [ %28, %27 ]
store i8* %30, i8** %12
%31 = load i8*, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %168
33: ; preds = %29
%34 = load i8*, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %168
36: ; preds = %33
%37 = load i32, i32* %5
%38 = icmp sge i32 %37, 0
br i1 %38, label %39, label %168
39: ; preds = %36
store i32 8192, i32* %13
%40 = getelementptr inbounds [8192 x i8], [8192 x i8]* %14, i64 0, i64 0
store i8* %40, i8** %15
store i32 0, i32* %16
%41 = load i8*, i8** %15
%42 = load i8*, i8** %6
%43 = load i8*, i8** %12
%44 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %43)
store i32 %44, i32* %16
%45 = load i32, i32* %16
%46 = load i8*, i8** %15
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %15
%49 = load i8*, i8** %15
%50 = load i8*, i8** %12
%51 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.3, i64 0, i64 0), i8* %50)
store i32 %51, i32* %16
%52 = load i32, i32* %16
%53 = load i8*, i8** %15
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8, i8* %53, i64 %54
store i8* %55, i8** %15
%56 = load i8*, i8** %15
%57 = load i8*, i8** %12
%58 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %56, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %57)
store i32 %58, i32* %16
%59 = load i32, i32* %16
%60 = load i8*, i8** %15
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8* %62, i8** %15
%63 = load i8*, i8** %15
%64 = load i8*, i8** %7
%65 = load i8*, i8** %12
%66 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %63, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %64, i8* %65)
store i32 %66, i32* %16
%67 = load i32, i32* %16
%68 = load i8*, i8** %15
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds i8, i8* %68, i64 %69
store i8* %70, i8** %15
%71 = load i8*, i8** %15
%72 = load i8*, i8** %12
%73 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %72)
store i32 %73, i32* %16
%74 = load i32, i32* %16
%75 = load i8*, i8** %15
%76 = sext i32 %74 to i64
%77 = getelementptr inbounds i8, i8* %75, i64 %76
store i8* %77, i8** %15
%78 = load i8*, i8** %15
store i8 0, i8* %78
%79 = load i32, i32* %5
%80 = icmp sge i32 %79, 0
br i1 %80, label %81, label %167
81: ; preds = %39
%82 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%83 = load i32, i32* %5
%84 = getelementptr inbounds [8192 x i8], [8192 x i8]* %14, i64 0, i64 0
%85 = load i8*, i8** %15
%86 = getelementptr inbounds [8192 x i8], [8192 x i8]* %14, i64 0, i64 0
%87 = ptrtoint i8* %85 to i64
%88 = ptrtoint i8* %86 to i64
%89 = sub i64 %87, %88
%90 = trunc i64 %89 to i32
%91 = call i32 @write(i32 %83, i8* %84, i32 %90)
store i32 %91, i32* %17
%92 = load i32, i32* %17
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %100
94: ; preds = %81
%95 = load i32, i32* @stderr
%96 = load i32, i32* %17
%97 = load i32, i32* %17
%98 = call i8* @gai_strerror(i32 %97)
%99 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %96, i8* %98)
br label %100
100: ; preds = %94, %81
%101 = getelementptr inbounds [8192 x i8], [8192 x i8]* %14, i64 0, i64 0
store i8* %101, i8** %15
br label %102
102: ; preds = %100
%103 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
store i32 10, i32* %103
%104 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
store i64 0, i64* %104
%105 = call i32 @FD_ZERO(i32* %18)
%106 = load i32, i32* %5
%107 = call i32 @FD_SET(i32 %106, i32* %18)
%108 = load i32, i32* %5
%109 = add nsw i32 %108, 1
%110 = call i32 @select(i32 %109, i32* %18, i32* null, i32* null, %struct.timeval* %19)
store i32 %110, i32* %20
%111 = load i32, i32* %20
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %117
113: ; preds = %102
%114 = load i32, i32* @stderr
%115 = load i32, i32* %5
%116 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %115)
br label %117
117: ; preds = %113, %102
%118 = load i32, i32* %20
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %124
120: ; preds = %117
%121 = load i32, i32* @stderr
%122 = load i32, i32* %5
%123 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i32 %122)
br label %124
124: ; preds = %120, %117
%125 = load i32, i32* %20
%126 = icmp sgt i32 %125, 0
br i1 %126, label %127, label %152
127: ; preds = %124
%128 = load i32, i32* %13
%129 = icmp sgt i32 %128, 0
br i1 %129, label %130, label %151
130: ; preds = %127
%131 = load i32, i32* %5
%132 = load i8*, i8** %15
%133 = load i32, i32* %13
%134 = call i32 @read(i32 %131, i8* %132, i32 %133)
store i32 %134, i32* %17
%135 = load i32, i32* %17
%136 = icmp sgt i32 %135, 0
br i1 %136, label %137, label %145
137: ; preds = %130
%138 = load i32, i32* %17
%139 = load i8*, i8** %15
%140 = sext i32 %138 to i64
%141 = getelementptr inbounds i8, i8* %139, i64 %140
store i8* %141, i8** %15
%142 = load i32, i32* %17
%143 = load i32, i32* %13
%144 = sub nsw i32 %143, %142
store i32 %144, i32* %13
br label %145
145: ; preds = %137, %130
%146 = load i32, i32* %17
%147 = icmp eq i32 %146, 0
br i1 %147, label %148, label %150
148: ; preds = %145
%149 = load i8*, i8** %15
store i8 0, i8* %149
br label %153
150: ; preds = %145
br label %151
151: ; preds = %150, %127
br label %152
152: ; preds = %151, %124
br label %153
153: ; preds = %152, %148
%154 = getelementptr inbounds [8192 x i8], [8192 x i8]* %14, i64 0, i64 0
%155 = call i8* @strstr(i8* %154, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
store i8* %155, i8** %21
%156 = load i8*, i8** %21
%157 = icmp ne i8* %156, null
br i1 %157, label %158, label %166
158: ; preds = %153
store i64 0, i64* %22
%159 = load i8*, i8** %21
%160 = call i32 @sscanf(i8* %159, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i64* %22)
%161 = load i64, i64* %22
%162 = icmp sgt i64 %161, 0
br i1 %162, label %163, label %165
163: ; preds = %158
%164 = load i64, i64* %22
store i64 %164, i64* %9
br label %165
165: ; preds = %163, %158
br label %166
166: ; preds = %165, %153
br label %167
167: ; preds = %166, %39
br label %168
168: ; preds = %167, %36, %33, %29
%169 = load i64, i64* %9
ret i64 %169
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [19 x i8] c"HEAD %s HTTP/1.1%s\00"
@.str.3 = [78 x i8] c"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)%s\00"
@.str.4 = [20 x i8] c"Connection: close%s\00"
@.str.5 = [11 x i8] c"Host: %s%s\00"
@.str.7 = [12 x i8] c"\0Aprobing...\00"
@stderr = global i32 0
@.str.8 = [16 x i8] c"write: %d : %s\0A\00"
@.str.9 = [26 x i8] c"poll errorrom socket %d \0A\00"
@.str.10 = [24 x i8] c"tiemout rom socket %d \0A\00"
@.str.11 = [16 x i8] c"Content-Length:\00"
@.str.12 = [22 x i8] c"Content-Length: %ld\0A*\00"
define i64 @queryResourceSize(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [8192 x i8]
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca i64
%9 = icmp eq i32 %3, 0
%10 = select i1 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%11 = icmp ne i8* %1, null
%12 = icmp ne i8* %2, null
%13 = and i1 %11, %12
%14 = icmp sgt i32 %0, -1
%15 = and i1 %14, %13
br i1 %15, label %16, label %81
16: ; preds = %4
%17 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %10)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 %19
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %26, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %10)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = call i8* @stpcpy(i8* %29, i8* %10)
%31 = ptrtoint i8* %30 to i64
%32 = ptrtoint i8* %29 to i64
%33 = sub i64 %31, %32
%34 = shl i64 %33, 32
%35 = ashr exact i64 %34, 32
%36 = getelementptr inbounds i8, i8* %29, i64 %35
store i8 0, i8* %36
%37 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint [8192 x i8]* %5 to i64
%40 = sub i64 %38, %39
%41 = trunc i64 %40 to i32
%42 = call i32 @write(i32 %0, i8* %17, i32 %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %16
%45 = load i32, i32* @stderr
%46 = call i8* @gai_strerror(i32 %42)
%47 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %42, i8* %46)
br label %48
48: ; preds = %44, %16
%49 = bitcast i32* %6 to i8*
%50 = bitcast %struct.timeval* %7 to i8*
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 10, i32* %51
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
store i64 0, i64* %52
%53 = call i32 @FD_ZERO(i32* %6)
%54 = call i32 @FD_SET(i32 %0, i32* %6)
%55 = add nuw nsw i32 %0, 1
%56 = call i32 @select(i32 %55, i32* %6, i32* null, i32* null, %struct.timeval* %7)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %48
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %0)
br label %70
61: ; preds = %48
%62 = icmp eq i32 %56, 0
br i1 %62, label %63, label %66
63: ; preds = %61
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i32 %0)
br label %70
66: ; preds = %61
%67 = call i32 @read(i32 %0, i8* %17, i32 8192)
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %66
store i8 0, i8* %17
br label %70
70: ; preds = %63, %58, %66, %69
%71 = call i8* @strstr(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%72 = icmp eq i8* %71, null
br i1 %72, label %79, label %73
73: ; preds = %70
%74 = bitcast i64* %8 to i8*
store i64 0, i64* %8
%75 = call i32 @sscanf(i8* %71, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i64* %8)
%76 = load i64, i64* %8
%77 = icmp sgt i64 %76, 0
%78 = select i1 %77, i64 %76, i64 0
br label %79
79: ; preds = %70, %73
%80 = phi i64 [ %78, %73 ], [ 0, %70 ]
br label %81
81: ; preds = %79, %4
%82 = phi i64 [ %80, %79 ], [ 0, %4 ]
ret i64 %82
}