#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 */
typedef scalar_t__ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memset(struct tm *, int, int);
scalar_t__ const mktime(struct tm *);
char *strchr(char *, char);
scalar_t__ strptime(char *, char *, struct tm *);
char *strstr(char const *, char *);
int calc_page_age(const char *in, const time_t their_ts) {
  int age = -1;
  if (in != NULL && their_ts > 0) {
    char *date = strstr(in, "\nLast-Modified:");
    char *komma = date ? strchr(date, ',') : NULL;
    if (date && komma) {
      struct tm tm;
      memset(&tm, 0x00, sizeof tm);
      if (strptime(komma + 1, "%d %b %Y %H:%M:%S %Z", &tm))
        age = their_ts - mktime(&tm);
    }
  }
  return age;
}


x86 assembly (clang, -O0):
<calc_page_age>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1236 <calc_page_age+0xe6>
cmpq   $0x0,-0x10(%rbp)
jle    1236 <calc_page_age+0xe6>
mov    -0x8(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b3 <calc_page_age+0x63>
mov    -0x20(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
jmp    11be <calc_page_age+0x6e>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    11be <calc_page_age+0x6e>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1231 <calc_page_age+0xe1>
cmpq   $0x0,-0x28(%rbp)
je     1231 <calc_page_age+0xe1>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
lea    0xe15(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <strptime@plt>
cmp    $0x0,%rax
je     122c <calc_page_age+0xdc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <mktime@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    1231 <calc_page_age+0xe1>
jmp    1236 <calc_page_age+0xe6>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_page_age>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     11d6 <calc_page_age+0x86>
mov    %rsi,%r14
test   %rsi,%rsi
jle    11d6 <calc_page_age+0x86>
lea    0xe8f(%rip),%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11d6 <calc_page_age+0x86>
mov    %rax,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11d6 <calc_page_age+0x86>
mov    %rax,%rbx
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
add    $0x1,%rbx
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1060 <strptime@plt>
test   %rax,%rax
je     11d1 <calc_page_age+0x81>
lea    0x8(%rsp),%rdi
call   1050 <mktime@plt>
sub    %eax,%r14d
mov    %r14d,%ebp
jmp    11d6 <calc_page_age+0x86>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [16 x i8] c"\0ALast-Modified:\00"
@.str.1 = [21 x i8] c"%d %b %Y %H:%M:%S %Z\00"
define i32 @calc_page_age(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.tm
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 -1, i32* %5
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %43
11: ; preds = %2
%12 = load i64, i64* %4
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %43
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = call i8* @strstr(i8* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = call i8* @strchr(i8* %20, i8 signext 44)
br label %23
22: ; preds = %14
br label %23
23: ; preds = %22, %19
%24 = phi i8* [ %21, %19 ], [ null, %22 ]
store i8* %24, i8** %7
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %42
27: ; preds = %23
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = call i32 @memset(%struct.tm* %8, i32 0, i32 4)
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = call i64 @strptime(i8* %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %8)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i64, i64* %4
%38 = call i64 @mktime(%struct.tm* %8)
%39 = sub nsw i64 %37, %38
%40 = trunc i64 %39 to i32
store i32 %40, i32* %5
br label %41
41: ; preds = %36, %30
br label %42
42: ; preds = %41, %27, %23
br label %43
43: ; preds = %42, %11, %2
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [16 x i8] c"\0ALast-Modified:\00"
@.str.1 = [21 x i8] c"%d %b %Y %H:%M:%S %Z\00"
define i32 @calc_page_age(i8* %0, i64 %1) {
%3 = alloca %struct.tm
%4 = icmp ne i8* %0, null
%5 = icmp sgt i64 %1, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %25
7: ; preds = %2
%8 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %25, label %10
10: ; preds = %7
%11 = tail call i8* @strchr(i8* %8, i8 signext 44)
%12 = icmp eq i8* %11, null
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = bitcast %struct.tm* %3 to i8*
%15 = call i32 @memset(%struct.tm* %3, i32 0, i32 4)
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = call i64 @strptime(i8* %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = call i64 @mktime(%struct.tm* %3)
%21 = sub nsw i64 %1, %20
%22 = trunc i64 %21 to i32
br label %23
23: ; preds = %19, %13
%24 = phi i32 [ %22, %19 ], [ -1, %13 ]
br label %25
25: ; preds = %7, %10, %23, %2
%26 = phi i32 [ -1, %2 ], [ %24, %23 ], [ -1, %10 ], [ -1, %7 ]
ret i32 %26
}