#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 *nre_strcasestr(char *, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int http_get_maxage(char *cache_ctl, int len) {
  if (!*cache_ctl)
    return -1;
  char *temp = NULL;
  temp = nre_strcasestr(cache_ctl, "max-age=");
  if (temp) {
    len = strtol(temp + sizeof("max-age="), NULL, 10);
    if (errno == EINVAL || errno == ERANGE)
      return -1;
    return len;
  }
  temp = nre_strcasestr(cache_ctl, "s-maxage=");
  if (temp) {
    len = strtol(temp + sizeof("s-maxage="), NULL, 10);
    if (errno == EINVAL || errno == ERANGE)
      return -1;
    return len;
  }
  return -1;
}


x86 assembly (clang, -O0):
<http_get_maxage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1148 <http_get_maxage+0x28>
movl   $0xffffffff,-0x4(%rbp)
jmp    125d <http_get_maxage+0x13d>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <nre_strcasestr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d3 <http_get_maxage+0xb3>
mov    -0x20(%rbp),%rdi
add    $0x9,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
je     11bc <http_get_maxage+0x9c>
mov    0x2e2f(%rip),%rax
mov    (%rax),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jne    11c8 <http_get_maxage+0xa8>
movl   $0xffffffff,-0x4(%rbp)
jmp    125d <http_get_maxage+0x13d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <http_get_maxage+0x13d>
mov    -0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1030 <nre_strcasestr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1256 <http_get_maxage+0x136>
mov    -0x20(%rbp),%rdi
add    $0xa,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%rax
mov    0x2db4(%rip),%rcx
cmp    (%rcx),%rax
je     123f <http_get_maxage+0x11f>
mov    0x2dac(%rip),%rax
mov    (%rax),%rax
mov    0x2db2(%rip),%rcx
cmp    (%rcx),%rax
jne    124b <http_get_maxage+0x12b>
movl   $0xffffffff,-0x4(%rbp)
jmp    125d <http_get_maxage+0x13d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <http_get_maxage+0x13d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_get_maxage>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
cmpb   $0x0,(%rdi)
je     1199 <http_get_maxage+0x79>
mov    %rdi,%rbx
lea    0xec9(%rip),%rsi
call   1030 <nre_strcasestr@plt>
test   %rax,%rax
je     1147 <http_get_maxage+0x27>
add    $0x9,%rax
jmp    115f <http_get_maxage+0x3f>
lea    0xebb(%rip),%rsi
mov    %rbx,%rdi
call   1030 <nre_strcasestr@plt>
test   %rax,%rax
je     1199 <http_get_maxage+0x79>
add    $0xa,%rax
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ebp
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
mov    0x2e45(%rip),%rcx
mov    $0xffffffff,%edx
cmove  %edx,%ebp
cmp    (%rcx),%rax
cmove  %edx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"max-age=\00"
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@.str.1 = [10 x i8] c"s-maxage=\00"
define i32 @http_get_maxage(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 -1, i32* %3
br label %50
11: ; preds = %2
store i8* null, i8** %6
%12 = load i8*, i8** %4
%13 = call i8* @nre_strcasestr(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 9
%19 = call i32 @strtol(i8* %18, i32* null, i32 10)
store i32 %19, i32* %5
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINVAL
%22 = icmp eq i64 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %16
%24 = load i64, i64* @errno
%25 = load i64, i64* @ERANGE
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23, %16
store i32 -1, i32* %3
br label %50
28: ; preds = %23
%29 = load i32, i32* %5
store i32 %29, i32* %3
br label %50
30: ; preds = %11
%31 = load i8*, i8** %4
%32 = call i8* @nre_strcasestr(i8* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %49
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 10
%38 = call i32 @strtol(i8* %37, i32* null, i32 10)
store i32 %38, i32* %5
%39 = load i64, i64* @errno
%40 = load i64, i64* @EINVAL
%41 = icmp eq i64 %39, %40
br i1 %41, label %46, label %42
42: ; preds = %35
%43 = load i64, i64* @errno
%44 = load i64, i64* @ERANGE
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42, %35
store i32 -1, i32* %3
br label %50
47: ; preds = %42
%48 = load i32, i32* %5
store i32 %48, i32* %3
br label %50
49: ; preds = %30
store i32 -1, i32* %3
br label %50
50: ; preds = %49, %47, %46, %28, %27, %10
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [9 x i8] c"max-age=\00"
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@.str.1 = [10 x i8] c"s-maxage=\00"
define i32 @http_get_maxage(i8* %0, i32 %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %31, label %5
5: ; preds = %2
%6 = tail call i8* @nre_strcasestr(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %6, i64 9
%10 = tail call i32 @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINVAL
%13 = icmp eq i64 %11, %12
%14 = load i64, i64* @ERANGE
%15 = icmp eq i64 %11, %14
%16 = select i1 %13, i1 true, i1 %15
%17 = select i1 %16, i32 -1, i32 %10
br label %31
18: ; preds = %5
%19 = tail call i8* @nre_strcasestr(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %31, label %21
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %19, i64 10
%23 = tail call i32 @strtol(i8* nocapture %22, i32* null, i32 10)
%24 = load i64, i64* @errno
%25 = load i64, i64* @EINVAL
%26 = icmp eq i64 %24, %25
%27 = load i64, i64* @ERANGE
%28 = icmp eq i64 %24, %27
%29 = select i1 %26, i1 true, i1 %28
%30 = select i1 %29, i32 -1, i32 %23
br label %31
31: ; preds = %21, %8, %18, %2
%32 = phi i32 [ -1, %2 ], [ -1, %18 ], [ %17, %8 ], [ %30, %21 ]
ret i32 %32
}