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

/* Variables and functions */
int /*<<< orphan*/ memset(struct tm *, int, int);
int mktime(struct tm *);
char *strchr(char *, char);
scalar_t__ strptime(char *, char *, struct tm *);
char *strstr(char const *, char *);
time_t parse_date_from_response_headers(const char *in) {
  char *date = NULL, *komma = NULL;
  if (in == NULL)
    return -1;
  date = strstr(in, "\nDate:");
  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))
      return mktime(&tm);
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_date_from_response_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <parse_date_from_response_headers+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <parse_date_from_response_headers+0xe1>
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b9 <parse_date_from_response_headers+0x69>
mov    -0x18(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
jmp    11c4 <parse_date_from_response_headers+0x74>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11c4 <parse_date_from_response_headers+0x74>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     122a <parse_date_from_response_headers+0xda>
cmpq   $0x0,-0x20(%rbp)
je     122a <parse_date_from_response_headers+0xda>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe06(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <strptime@plt>
cmp    $0x0,%rax
je     1225 <parse_date_from_response_headers+0xd5>
lea    -0x28(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x4(%rbp)
jmp    1231 <parse_date_from_response_headers+0xe1>
jmp    122a <parse_date_from_response_headers+0xda>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

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

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