#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 */
char *header_value(char *, char *);
scalar_t__ isspace(char);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int get_content_length(char *headers) {
  char *cp = header_value(headers, "Content-Length: ");
  int len;
  if (!cp)
    return -1;
  if (cp[0] == '0' && isspace(cp[1]))
    return 0;
  len = strtol(cp, NULL, 0);
  return len ? len : -1;
}


x86 assembly (clang, -O0):
<get_content_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <header_value@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1167 <get_content_length+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <get_content_length+0xa4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    119a <get_content_length+0x6a>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     119a <get_content_length+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <get_content_length+0xa4>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11c1 <get_content_length+0x91>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11ce <get_content_length+0x9e>
mov    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11ce <get_content_length+0x9e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_content_length>:
push   %rbx
lea    0xec8(%rip),%rsi
call   1050 <header_value@plt>
test   %rax,%rax
je     1176 <get_content_length+0x46>
mov    %rax,%rbx
cmpb   $0x30,(%rax)
jne    115f <get_content_length+0x2f>
movsbl 0x1(%rbx),%edi
call   1030 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     115f <get_content_length+0x2f>
pop    %rbx
ret
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
cmp    $0x1,%eax
sbb    %eax,%eax
or     %ecx,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Content-Length: \00"
define i32 @get_content_length(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @header_value(i8* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 -1, i32* %2
br label %34
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 48
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = call i64 @isspace(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 0, i32* %2
br label %34
24: ; preds = %17, %11
%25 = load i8*, i8** %4
%26 = call i32 @strtol(i8* %25, i32* null, i32 0)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32, i32* %5
br label %32
31: ; preds = %24
br label %32
32: ; preds = %31, %29
%33 = phi i32 [ %30, %29 ], [ -1, %31 ]
store i32 %33, i32* %2
br label %34
34: ; preds = %32, %23, %10
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [17 x i8] c"Content-Length: \00"
define i32 @get_content_length(i8* %0) {
%2 = tail call i8* @header_value(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 48
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %2, i64 1
%9 = load i8, i8* %8
%10 = tail call i64 @isspace(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7, %4
%13 = tail call i32 @strtol(i8* nocapture %2, i32* null, i32 0)
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i32 -1, i32 %13
br label %16
16: ; preds = %7, %1, %12
%17 = phi i32 [ %15, %12 ], [ -1, %1 ], [ 0, %7 ]
ret i32 %17
}