#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;
size_t strtoul(char const *, char **, int);
int parse_content_length(const char *s, size_t *len) {
  size_t tmp_len;
  char *endptr;
  const char *nptr = s;
  if (!s) {
    errno = EINVAL;
    return -1;
  }
  errno = 0;
  tmp_len = strtoul(nptr, &endptr, 10);
  if ((errno == ERANGE) || (errno != 0 && tmp_len == 0)) {
    errno = EINVAL;
    return -1;
  }
  if (endptr == nptr) {
    errno = EINVAL;
    return -1;
  }
  *len = tmp_len;
  return 0;
}


x86 assembly (clang, -O0):
<parse_content_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <parse_content_length+0x43>
mov    0x2e96(%rip),%rax
mov    (%rax),%rcx
mov    0x2e94(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <parse_content_length+0xfd>
mov    0x2e7e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%rax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
je     11ad <parse_content_length+0x9d>
mov    0x2e40(%rip),%rax
cmpq   $0x0,(%rax)
je     11cd <parse_content_length+0xbd>
cmpq   $0x0,-0x20(%rbp)
jne    11cd <parse_content_length+0xbd>
mov    0x2e1c(%rip),%rax
mov    (%rax),%rcx
mov    0x2e1a(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <parse_content_length+0xfd>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    11fb <parse_content_length+0xeb>
mov    0x2dee(%rip),%rax
mov    (%rax),%rcx
mov    0x2dec(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <parse_content_length+0xfd>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_content_length>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1177 <parse_content_length+0x67>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ead(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    (%r15),%rcx
mov    0x2e9d(%rip),%rdx
cmp    (%rdx),%rcx
je     1168 <parse_content_length+0x58>
test   %rcx,%rcx
je     115a <parse_content_length+0x4a>
test   %rax,%rax
je     1168 <parse_content_length+0x58>
cmp    %rbx,0x8(%rsp)
je     1168 <parse_content_length+0x58>
mov    %rax,(%r14)
xor    %eax,%eax
jmp    1190 <parse_content_length+0x80>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r15)
jmp    118b <parse_content_length+0x7b>
mov    0x2e52(%rip),%rax
mov    (%rax),%rax
mov    0x2e50(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EINVAL = global i64 0
@errno = global i64 0
@ERANGE = global i64 0
define i32 @parse_content_length(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i64, i64* @EINVAL
store i64 %7, i64* @errno
br label %25
8: ; preds = %2
store i64 0, i64* @errno
%9 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
%10 = load i64, i64* @errno
%11 = load i64, i64* @ERANGE
%12 = icmp eq i64 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = icmp ne i64 %10, 0
%15 = icmp eq i64 %9, 0
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %17, label %19
17: ; preds = %13, %8
%18 = load i64, i64* @EINVAL
store i64 %18, i64* @errno
br label %25
19: ; preds = %13
%20 = load i8*, i8** %3
%21 = icmp eq i8* %20, %0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i64, i64* @EINVAL
store i64 %23, i64* @errno
br label %25
24: ; preds = %19
store i64 %9, i64* %1
br label %25
25: ; preds = %24, %22, %17, %6
%26 = phi i32 [ -1, %17 ], [ -1, %22 ], [ 0, %24 ], [ -1, %6 ]
ret i32 %26
}