#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 hash {
  int dummy;
};
typedef int /*<<< orphan*/ rangeUrl;

/* Variables and functions */
long long atoll(char *);
int /*<<< orphan*/ freeHash(struct hash **);
char *hashFindValUpperCase(struct hash *, char *);
int netUrlHeadExt(char *, char *, struct hash *);
struct hash *newHashExt(int /*<<< orphan*/, int);
int /*<<< orphan*/ safef(char *, int, char *, char *);
char *strchr(char *, char);
long long netUrlSizeByRangeResponse(char *url) {
  long long retVal = -1;
  char rangeUrl[2048];
  safef(rangeUrl, sizeof(rangeUrl), "%s;byterange=0-0", url);
  struct hash *hash = newHashExt(0, 1);
  int status = netUrlHeadExt(rangeUrl, "GET", hash);
  if (status == 206) {
    char *rangeString = hashFindValUpperCase(hash, "Content-Range:");
    if (rangeString) {
      char *slash = strchr(rangeString, '/');
      if (slash) {
        retVal = atoll(slash + 1);
      }
    }
  }
  freeHash(&hash);
  return retVal;
}


x86 assembly (clang, -O0):
<netUrlSizeByRangeResponse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x800,%esi
lea    0xe62(%rip),%rdx
call   1090 <safef@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <newHashExt@plt>
mov    %rax,-0x818(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x818(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1030 <netUrlHeadExt@plt>
mov    %eax,-0x81c(%rbp)
cmpl   $0xce,-0x81c(%rbp)
jne    1252 <netUrlSizeByRangeResponse+0xe2>
mov    -0x818(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1040 <hashFindValUpperCase@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
je     124d <netUrlSizeByRangeResponse+0xdd>
mov    -0x828(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x830(%rbp)
je     1248 <netUrlSizeByRangeResponse+0xd8>
mov    -0x830(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoll@plt>
mov    %rax,-0x10(%rbp)
jmp    124d <netUrlSizeByRangeResponse+0xdd>
jmp    1252 <netUrlSizeByRangeResponse+0xe2>
lea    -0x818(%rbp),%rdi
call   1070 <freeHash@plt>
mov    -0x10(%rbp),%rax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netUrlSizeByRangeResponse>:
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%rcx
lea    0xe7c(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x800,%esi
call   1090 <safef@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <newHashExt@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
lea    0xe60(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1030 <netUrlHeadExt@plt>
mov    $0xffffffffffffffff,%r14
cmp    $0xce,%eax
jne    11ff <netUrlSizeByRangeResponse+0x8f>
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
call   1040 <hashFindValUpperCase@plt>
test   %rax,%rax
je     11ff <netUrlSizeByRangeResponse+0x8f>
mov    %rax,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11ff <netUrlSizeByRangeResponse+0x8f>
add    $0x1,%rax
mov    %rax,%rdi
call   1080 <atoll@plt>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
call   1070 <freeHash@plt>
mov    %r14,%rax
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.hash = type { i32 }
@.str = [17 x i8] c"%s;byterange=0-0\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [15 x i8] c"Content-Range:\00"
define i64 @netUrlSizeByRangeResponse(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [2048 x i8]
%5 = alloca %struct.hash*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %2
store i64 -1, i64* %3
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%10 = load i8*, i8** %2
%11 = call i32 @safef(i8* %9, i32 2048, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call %struct.hash* @newHashExt(i32 0, i32 1)
store %struct.hash* %12, %struct.hash** %5
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%14 = load %struct.hash*, %struct.hash** %5
%15 = call i32 @netUrlHeadExt(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %struct.hash* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 206
br i1 %17, label %18, label %34
18: ; preds = %1
%19 = load %struct.hash*, %struct.hash** %5
%20 = call i8* @hashFindValUpperCase(%struct.hash* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = load i8*, i8** %7
%25 = call i8* @strchr(i8* %24, i8 signext 47)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i64 @atoll(i8* %30)
store i64 %31, i64* %3
br label %32
32: ; preds = %28, %23
br label %33
33: ; preds = %32, %18
br label %34
34: ; preds = %33, %1
%35 = call i32 @freeHash(%struct.hash** %5)
%36 = load i64, i64* %3
ret i64 %36
}

LLVM IR (-O2):
%struct.hash = type { i32 }
@.str = [17 x i8] c"%s;byterange=0-0\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [15 x i8] c"Content-Range:\00"
define i64 @netUrlSizeByRangeResponse(i8* %0) {
%2 = alloca [2048 x i8]
%3 = alloca %struct.hash*
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = call i32 @safef(i8* %4, i32 2048, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = bitcast %struct.hash** %3 to i8*
%7 = call %struct.hash* @newHashExt(i32 0, i32 1)
store %struct.hash* %7, %struct.hash** %3
%8 = call i32 @netUrlHeadExt(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %struct.hash* %7)
%9 = icmp eq i32 %8, 206
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = call i8* @hashFindValUpperCase(%struct.hash* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = call i8* @strchr(i8* %11, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = call i64 @atoll(i8* %17)
br label %19
19: ; preds = %10, %16, %13, %1
%20 = phi i64 [ -1, %1 ], [ -1, %10 ], [ %18, %16 ], [ -1, %13 ]
%21 = call i32 @freeHash(%struct.hash** %3)
ret i64 %20
}