#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 */

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ ERANGE;
scalar_t__ errno;
char *http_header_str_val(char const *, char const *, int, char *, int);
long strtol(char *, int /*<<< orphan*/ *, int);
long int http_header_long_val(const char *response, const char *key,
                              int key_len) {
  long int len;
  char value[50];
  char *temp = http_header_str_val(response, key, key_len, value, 50);
  if (temp == NULL)
    return -1;
  len = strtol(temp, NULL, 10);
  if (errno == EINVAL || errno == ERANGE)
    return -1;
  return len;
}


x86 assembly (clang, -O0):
<http_header_long_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x60(%rbp),%rcx
mov    $0x32,%r8d
call   1040 <http_header_str_val@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1169 <http_header_long_val+0x49>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c8 <http_header_long_val+0xa8>
mov    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%rax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
je     11b3 <http_header_long_val+0x93>
mov    0x2e38(%rip),%rax
mov    (%rax),%rax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <http_header_long_val+0xa0>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c8 <http_header_long_val+0xa8>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_header_long_val>:
sub    $0x38,%rsp
mov    %rsp,%rcx
mov    $0x32,%r8d
call   1040 <http_header_str_val@plt>
test   %rax,%rax
je     1178 <http_header_long_val+0x58>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x2e8b(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e91(%rip),%rdx
cmp    (%rdx),%rcx
mov    0x2e6f(%rip),%rdx
mov    $0xffffffffffffffff,%rsi
cmove  %rsi,%rax
cmp    (%rdx),%rcx
cmove  %rsi,%rax
add    $0x38,%rsp
ret
mov    $0xffffffffffffffff,%rax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
define i64 @http_header_long_val(i8* %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca [50 x i8]
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%15 = call i8* @http_header_str_val(i8* %11, i8* %12, i32 %13, i8* %14, i32 50)
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %3
store i64 -1, i64* %4
br label %32
19: ; preds = %3
%20 = load i8*, i8** %10
%21 = call i64 @strtol(i8* %20, i32* null, i32 10)
store i64 %21, i64* %8
%22 = load i64, i64* @errno
%23 = load i64, i64* @EINVAL
%24 = icmp eq i64 %22, %23
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = load i64, i64* @errno
%27 = load i64, i64* @ERANGE
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25, %19
store i64 -1, i64* %4
br label %32
30: ; preds = %25
%31 = load i64, i64* %8
store i64 %31, i64* %4
br label %32
32: ; preds = %30, %29, %18
%33 = load i64, i64* %4
ret i64 %33
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
define i64 @http_header_long_val(i8* %0, i8* %1, i32 %2) {
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%6 = call i8* @http_header_str_val(i8* %0, i8* %1, i32 %2, i8* %5, i32 50)
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = call i64 @strtol(i8* nocapture %6, i32* null, i32 10)
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINVAL
%12 = icmp eq i64 %10, %11
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %10, %13
%15 = select i1 %12, i1 true, i1 %14
%16 = select i1 %15, i64 -1, i64 %9
br label %17
17: ; preds = %8, %3
%18 = phi i64 [ -1, %3 ], [ %16, %8 ]
ret i64 %18
}