#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 /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
};

/* Variables and functions */
scalar_t__ _date_do(char const *, char *, struct tm *);
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
time_t mailer_helper_get_date(char const *date, struct tm *tm) {
  time_t t;
  if (date != NULL)
    if (_date_do(date, "%a, %d %b %Y %T %z (%z)", tm) == 0 ||
        _date_do(date, "%a, %d %b %Y %T %z", tm) == 0 ||
        _date_do(date, "%d %b %Y %T %z", tm) == 0 ||
        _date_do(date, "%d/%m/%Y %T %z", tm) == 0 ||
        _date_do(date, "%d/%m/%Y %T", tm) == 0 ||
        _date_do(date, "%FT%TZ", tm) == 0) {
      if (tm->tm_year >= -1830 && tm->tm_year < -1800)
        tm->tm_year += 1900;
      else if (tm->tm_year >= -1900 && tm->tm_year < -1830)
        tm->tm_year += 2000;
      return mktime(tm);
    }
  t = time(NULL);
  gmtime_r(&t, tm);
  return t;
}


x86 assembly (clang, -O0):
<mailer_helper_get_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     128b <mailer_helper_get_date+0x14b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe96(%rip),%rsi
call   1040 <_date_do@plt>
cmp    $0x0,%rax
je     120f <mailer_helper_get_date+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe90(%rip),%rsi
call   1040 <_date_do@plt>
cmp    $0x0,%rax
je     120f <mailer_helper_get_date+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1040 <_date_do@plt>
cmp    $0x0,%rax
je     120f <mailer_helper_get_date+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1040 <_date_do@plt>
cmp    $0x0,%rax
je     120f <mailer_helper_get_date+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe58(%rip),%rsi
call   1040 <_date_do@plt>
cmp    $0x0,%rax
je     120f <mailer_helper_get_date+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1040 <_date_do@plt>
cmp    $0x0,%rax
jne    1286 <mailer_helper_get_date+0x146>
mov    -0x18(%rbp),%rax
cmpl   $0xfffff8da,(%rax)
jl     1242 <mailer_helper_get_date+0x102>
mov    -0x18(%rbp),%rax
cmpl   $0xfffff8f8,(%rax)
jge    1242 <mailer_helper_get_date+0x102>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    %ecx,(%rax)
jmp    1275 <mailer_helper_get_date+0x135>
mov    -0x18(%rbp),%rax
cmpl   $0xfffff894,(%rax)
jl     1270 <mailer_helper_get_date+0x130>
mov    -0x18(%rbp),%rax
cmpl   $0xfffff8da,(%rax)
jge    1270 <mailer_helper_get_date+0x130>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x7d0,%ecx
mov    %ecx,(%rax)
jmp    1275 <mailer_helper_get_date+0x135>
mov    -0x18(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x4(%rbp)
jmp    12aa <mailer_helper_get_date+0x16a>
jmp    128b <mailer_helper_get_date+0x14b>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
call   1030 <gmtime_r@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mailer_helper_get_date>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     11e2 <mailer_helper_get_date+0xa2>
mov    %rdi,%rbx
lea    0xea6(%rip),%rsi
mov    %r14,%rdx
call   1040 <_date_do@plt>
test   %rax,%rax
je     1206 <mailer_helper_get_date+0xc6>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <_date_do@plt>
test   %rax,%rax
je     1206 <mailer_helper_get_date+0xc6>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <_date_do@plt>
test   %rax,%rax
je     1206 <mailer_helper_get_date+0xc6>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <_date_do@plt>
test   %rax,%rax
je     1206 <mailer_helper_get_date+0xc6>
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <_date_do@plt>
test   %rax,%rax
je     1206 <mailer_helper_get_date+0xc6>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <_date_do@plt>
test   %rax,%rax
je     1206 <mailer_helper_get_date+0xc6>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
call   1030 <gmtime_r@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%r14),%eax
lea    0x726(%rax),%edx
lea    0x76c(%rax),%ecx
cmp    $0x1e,%edx
jb     1226 <mailer_helper_get_date+0xe6>
cmp    $0x45,%ecx
ja     1229 <mailer_helper_get_date+0xe9>
add    $0x7d0,%eax
mov    %eax,%ecx
mov    %ecx,(%r14)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <mktime@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [24 x i8] c"%a, %d %b %Y %T %z (%z)\00"
@.str.1 = [19 x i8] c"%a, %d %b %Y %T %z\00"
@.str.2 = [15 x i8] c"%d %b %Y %T %z\00"
@.str.3 = [15 x i8] c"%d/%m/%Y %T %z\00"
@.str.4 = [12 x i8] c"%d/%m/%Y %T\00"
@.str.5 = [7 x i8] c"%FT%TZ\00"
define i32 @mailer_helper_get_date(i8* %0, %struct.tm* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.tm*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.tm* %1, %struct.tm** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %74
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = load %struct.tm*, %struct.tm** %5
%12 = call i64 @_date_do(i8* %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %struct.tm* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %39, label %14
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = load %struct.tm*, %struct.tm** %5
%17 = call i64 @_date_do(i8* %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %39, label %19
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load %struct.tm*, %struct.tm** %5
%22 = call i64 @_date_do(i8* %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %39, label %24
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load %struct.tm*, %struct.tm** %5
%27 = call i64 @_date_do(i8* %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %39, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load %struct.tm*, %struct.tm** %5
%32 = call i64 @_date_do(i8* %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %struct.tm* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load %struct.tm*, %struct.tm** %5
%37 = call i64 @_date_do(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %struct.tm* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %73
39: ; preds = %34, %29, %24, %19, %14, %9
%40 = load %struct.tm*, %struct.tm** %5
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = icmp sge i32 %42, -1830
br i1 %43, label %44, label %54
44: ; preds = %39
%45 = load %struct.tm*, %struct.tm** %5
%46 = getelementptr inbounds %struct.tm, %struct.tm* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = icmp slt i32 %47, -1800
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load %struct.tm*, %struct.tm** %5
%51 = getelementptr inbounds %struct.tm, %struct.tm* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = add nsw i32 %52, 1900
store i32 %53, i32* %51
br label %70
54: ; preds = %44, %39
%55 = load %struct.tm*, %struct.tm** %5
%56 = getelementptr inbounds %struct.tm, %struct.tm* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = icmp sge i32 %57, -1900
br i1 %58, label %59, label %69
59: ; preds = %54
%60 = load %struct.tm*, %struct.tm** %5
%61 = getelementptr inbounds %struct.tm, %struct.tm* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = icmp slt i32 %62, -1830
br i1 %63, label %64, label %69
64: ; preds = %59
%65 = load %struct.tm*, %struct.tm** %5
%66 = getelementptr inbounds %struct.tm, %struct.tm* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = add nsw i32 %67, 2000
store i32 %68, i32* %66
br label %69
69: ; preds = %64, %59, %54
br label %70
70: ; preds = %69, %49
%71 = load %struct.tm*, %struct.tm** %5
%72 = call i32 @mktime(%struct.tm* %71)
store i32 %72, i32* %3
br label %79
73: ; preds = %34
br label %74
74: ; preds = %73, %2
%75 = call i32 @time(i32* null)
store i32 %75, i32* %6
%76 = load %struct.tm*, %struct.tm** %5
%77 = call i32 @gmtime_r(i32* %6, %struct.tm* %76)
%78 = load i32, i32* %6
store i32 %78, i32* %3
br label %79
79: ; preds = %74, %70
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [24 x i8] c"%a, %d %b %Y %T %z (%z)\00"
@.str.1 = [19 x i8] c"%a, %d %b %Y %T %z\00"
@.str.2 = [15 x i8] c"%d %b %Y %T %z\00"
@.str.3 = [15 x i8] c"%d/%m/%Y %T %z\00"
@.str.4 = [12 x i8] c"%d/%m/%Y %T\00"
@.str.5 = [7 x i8] c"%FT%TZ\00"
define i32 @mailer_helper_get_date(i8* %0, %struct.tm* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %38, label %6
6: ; preds = %2
%7 = tail call i64 @_date_do(i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %struct.tm* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %6
%10 = tail call i64 @_date_do(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = tail call i64 @_date_do(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %12
%16 = tail call i64 @_date_do(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = tail call i64 @_date_do(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %struct.tm* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i64 @_date_do(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %struct.tm* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %21, %18, %15, %12, %9, %6
%25 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%26 = load i32, i32* %25
%27 = add i32 %26, 1830
%28 = icmp ult i32 %27, 30
%29 = add i32 %26, 1900
br i1 %28, label %34, label %30
30: ; preds = %24
%31 = icmp ult i32 %29, 70
br i1 %31, label %32, label %36
32: ; preds = %30
%33 = add nsw i32 %26, 2000
br label %34
34: ; preds = %24, %32
%35 = phi i32 [ %33, %32 ], [ %29, %24 ]
store i32 %35, i32* %25
br label %36
36: ; preds = %34, %30
%37 = tail call i32 @mktime(%struct.tm* %1)
br label %42
38: ; preds = %21, %2
%39 = tail call i32 @time(i32* null)
store i32 %39, i32* %3
%40 = call i32 @gmtime_r(i32* %3, %struct.tm* %1)
%41 = load i32, i32* %3
br label %42
42: ; preds = %38, %36
%43 = phi i32 [ %37, %36 ], [ %41, %38 ]
ret i32 %43
}