#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 tm_isdst;
};

/* Variables and functions */
int mktime(struct tm *);
struct tm *parse_date(char const *);
time_t parse_rfc1123(const char *str) {
  struct tm *tm;
  time_t t;
  if (NULL == str)
    return -1;
  tm = parse_date(str);
  if (!tm)
    return -1;
  tm->tm_isdst = -1;
  t = mktime(tm);
  if (t != -1) {
    time_t dst = 0;
    extern long timezone;
    if (tm->tm_isdst > 0)
      dst = -3600;
    t -= (timezone + dst);
  }
  return t;
}


x86 assembly (clang, -O0):
<parse_rfc1123>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1144 <parse_rfc1123+0x24>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <parse_rfc1123+0xa4>
mov    -0x10(%rbp),%rdi
call   1030 <parse_date@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <parse_rfc1123+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <parse_rfc1123+0xa4>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <mktime@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     11be <parse_rfc1123+0x9e>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11a3 <parse_rfc1123+0x83>
movl   $0xfffff1f0,-0x20(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%rcx
movslq -0x20(%rbp),%rax
add    %rax,%rcx
movslq -0x1c(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_rfc1123>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1166 <parse_rfc1123+0x46>
call   1030 <parse_date@plt>
test   %rax,%rax
je     1166 <parse_rfc1123+0x46>
mov    %rax,%rbx
movl   $0xffffffff,(%rax)
mov    %rax,%rdi
call   1040 <mktime@plt>
cmp    $0xffffffff,%eax
je     1166 <parse_rfc1123+0x46>
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%ecx
cmpl   $0x0,(%rbx)
lea    -0xe10(%rcx),%edx
cmovle %ecx,%edx
sub    %edx,%eax
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@timezone = external global i64
define i32 @parse_rfc1123(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.tm*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* null, %7
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %40
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call %struct.tm* @parse_date(i8* %11)
store %struct.tm* %12, %struct.tm** %4
%13 = load %struct.tm*, %struct.tm** %4
%14 = icmp ne %struct.tm* %13, null
br i1 %14, label %16, label %15
15: ; preds = %10
store i32 -1, i32* %2
br label %40
16: ; preds = %10
%17 = load %struct.tm*, %struct.tm** %4
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 0
store i32 -1, i32* %18
%19 = load %struct.tm*, %struct.tm** %4
%20 = call i32 @mktime(%struct.tm* %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %38
23: ; preds = %16
store i32 0, i32* %6
%24 = load %struct.tm*, %struct.tm** %4
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -3600, i32* %6
br label %29
29: ; preds = %28, %23
%30 = load i64, i64* @timezone
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = add nsw i64 %30, %32
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = sub nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %5
br label %38
38: ; preds = %29, %16
%39 = load i32, i32* %5
store i32 %39, i32* %2
br label %40
40: ; preds = %38, %15, %9
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@timezone = external global i64
define i32 @parse_rfc1123(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = tail call %struct.tm* @parse_date(i8* %0)
%5 = icmp eq %struct.tm* %4, null
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
store i32 -1, i32* %7
%8 = tail call i32 @mktime(%struct.tm* %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %18, label %10
10: ; preds = %6
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
%13 = select i1 %12, i64 4294963696, i64 0
%14 = load i64, i64* @timezone
%15 = add i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = sub i32 %8, %16
br label %18
18: ; preds = %6, %10, %3, %1
%19 = phi i32 [ -1, %1 ], [ -1, %3 ], [ %17, %10 ], [ -1, %6 ]
ret i32 %19
}