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

/* Variables and functions */
int mg_get_month_index(char *);
int mg_num_leap_years(int);
int sscanf(char const *, char *, int *, char *, int *, int *, int *, int *);
time_t mg_parse_date_string(const char *datetime) {
  static const unsigned short days_before_month[] = {
      0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
  char month_str[32];
  int second, minute, hour, day, month, year, leap_days, days;
  time_t result = (time_t)0;
  if (((sscanf(datetime, "%d/%3s/%d %d:%d:%d", &day, month_str, &year, &hour,
               &minute, &second) == 6) ||
       (sscanf(datetime, "%d %3s %d %d:%d:%d", &day, month_str, &year, &hour,
               &minute, &second) == 6) ||
       (sscanf(datetime, "%*3s, %d %3s %d %d:%d:%d", &day, month_str, &year,
               &hour, &minute, &second) == 6) ||
       (sscanf(datetime, "%d-%3s-%d %d:%d:%d", &day, month_str, &year, &hour,
               &minute, &second) == 6)) &&
      year > 1970 && (month = mg_get_month_index(month_str)) != -1) {
    leap_days = mg_num_leap_years(year) - mg_num_leap_years(1970);
    year -= 1970;
    days = year * 365 + days_before_month[month] + (day - 1) + leap_days;
    result = days * 24 * 3600 + hour * 3600 + minute * 60 + second;
  }
  return result;
}


x86 assembly (clang, -O0):
<mg_parse_date_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rcx
lea    0xec6(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%r8
lea    -0x3c(%rbp),%r9
lea    -0x38(%rbp),%r10
lea    -0x34(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
cmp    $0x6,%eax
je     122b <mg_parse_date_string+0xfb>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rcx
lea    0xea5(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%r8
lea    -0x3c(%rbp),%r9
lea    -0x38(%rbp),%r10
lea    -0x34(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
cmp    $0x6,%eax
je     122b <mg_parse_date_string+0xfb>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rcx
lea    0xe65(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%r8
lea    -0x3c(%rbp),%r9
lea    -0x38(%rbp),%r10
lea    -0x34(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
cmp    $0x6,%eax
je     122b <mg_parse_date_string+0xfb>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rcx
lea    0xe44(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%r8
lea    -0x3c(%rbp),%r9
lea    -0x38(%rbp),%r10
lea    -0x34(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
cmp    $0x6,%eax
jne    12bc <mg_parse_date_string+0x18c>
cmpl   $0x7b2,-0x48(%rbp)
jle    12bc <mg_parse_date_string+0x18c>
lea    -0x30(%rbp),%rdi
call   1050 <mg_get_month_index@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
je     12bc <mg_parse_date_string+0x18c>
mov    -0x48(%rbp),%edi
call   1040 <mg_num_leap_years@plt>
mov    %eax,-0x58(%rbp)
mov    $0x7b2,%edi
call   1040 <mg_num_leap_years@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%eax
sub    $0x7b2,%eax
mov    %eax,-0x48(%rbp)
imul   $0x16d,-0x48(%rbp),%eax
movslq -0x44(%rbp),%rdx
lea    0xd77(%rip),%rcx
movzwl (%rcx,%rdx,2),%ecx
add    %ecx,%eax
mov    -0x40(%rbp),%ecx
sub    $0x1,%ecx
add    %ecx,%eax
add    -0x4c(%rbp),%eax
mov    %eax,-0x50(%rbp)
imul   $0x18,-0x50(%rbp),%eax
imul   $0xe10,%eax,%eax
imul   $0xe10,-0x3c(%rbp),%ecx
add    %ecx,%eax
imul   $0x3c,-0x38(%rbp),%ecx
add    %ecx,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mg_parse_date_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
lea    0x1c(%rsp),%rbp
lea    0x18(%rsp),%r14
lea    0xecc(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x14(%rsp),%r9
push   %rbp
push   %r14
call   1030 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
je     11d3 <mg_parse_date_string+0xa3>
lea    0xeb9(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x14(%rsp),%r9
mov    %rbx,%rdi
push   %rbp
push   %r14
call   1030 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
je     11d3 <mg_parse_date_string+0xa3>
lea    0xe84(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x14(%rsp),%r9
mov    %rbx,%rdi
push   %rbp
push   %r14
call   1030 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    1256 <mg_parse_date_string+0x126>
xor    %eax,%eax
cmpl   $0x7b3,0xc(%rsp)
jl     124d <mg_parse_date_string+0x11d>
lea    0x20(%rsp),%rdi
call   1050 <mg_get_month_index@plt>
cmp    $0xffffffff,%eax
je     124b <mg_parse_date_string+0x11b>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1040 <mg_num_leap_years@plt>
mov    %eax,%ebp
mov    $0x7b2,%edi
call   1040 <mg_num_leap_years@plt>
imul   $0x16d,0xc(%rsp),%ecx
not    %eax
add    %ebp,%eax
add    %ecx,%eax
movslq %ebx,%rcx
lea    0xde3(%rip),%rdx
movzwl (%rdx,%rcx,2),%ecx
add    %eax,%ecx
add    0x10(%rsp),%ecx
imul   $0x15180,%ecx,%eax
imul   $0xe10,0x14(%rsp),%ecx
imul   $0x3c,0x18(%rsp),%edx
add    %eax,%ecx
add    %ecx,%edx
mov    0x1c(%rsp),%eax
add    %edx,%eax
add    $0x8901b100,%eax
jmp    124d <mg_parse_date_string+0x11d>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde7(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x14(%rsp),%r9
mov    %rbx,%rdi
push   %rbp
push   %r14
call   1030 <sscanf@plt>
add    $0x10,%rsp
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x6,%ecx
jne    124d <mg_parse_date_string+0x11d>
cmpl   $0x7b2,0xc(%rsp)
jg     11df <mg_parse_date_string+0xaf>
jmp    124d <mg_parse_date_string+0x11d>

LLVM IR (-O0):
@mg_parse_date_string.days_before_month = internal constant [12 x i16] [i16 0, i16 31, i16 59, i16 90, i16 120, i16 151, i16 181, i16 212, i16 243, i16 273, i16 304, i16 334]
@.str = [19 x i8] c"%d/%3s/%d %d:%d:%d\00"
@.str.1 = [19 x i8] c"%d %3s %d %d:%d:%d\00"
@.str.2 = [25 x i8] c"%*3s, %d %3s %d %d:%d:%d\00"
@.str.3 = [19 x i8] c"%d-%3s-%d %d:%d:%d\00"
define i32 @mg_parse_date_string(i8* %0) {
%2 = alloca i8*
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %12
%13 = load i8*, i8** %2
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%15 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %7, i8* %14, i32* %9, i32* %6, i32* %5, i32* %4)
%16 = icmp eq i32 %15, 6
br i1 %16, label %32, label %17
17: ; preds = %1
%18 = load i8*, i8** %2
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%20 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32* %7, i8* %19, i32* %9, i32* %6, i32* %5, i32* %4)
%21 = icmp eq i32 %20, 6
br i1 %21, label %32, label %22
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%25 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32* %7, i8* %24, i32* %9, i32* %6, i32* %5, i32* %4)
%26 = icmp eq i32 %25, 6
br i1 %26, label %32, label %27
27: ; preds = %22
%28 = load i8*, i8** %2
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%30 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32* %7, i8* %29, i32* %9, i32* %6, i32* %5, i32* %4)
%31 = icmp eq i32 %30, 6
br i1 %31, label %32, label %70
32: ; preds = %27, %22, %17, %1
%33 = load i32, i32* %9
%34 = icmp sgt i32 %33, 1970
br i1 %34, label %35, label %70
35: ; preds = %32
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%37 = call i32 @mg_get_month_index(i8* %36)
store i32 %37, i32* %8
%38 = icmp ne i32 %37, -1
br i1 %38, label %39, label %70
39: ; preds = %35
%40 = load i32, i32* %9
%41 = call i32 @mg_num_leap_years(i32 %40)
%42 = call i32 @mg_num_leap_years(i32 1970)
%43 = sub nsw i32 %41, %42
store i32 %43, i32* %10
%44 = load i32, i32* %9
%45 = sub nsw i32 %44, 1970
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = mul nsw i32 %46, 365
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [12 x i16], [12 x i16]* @mg_parse_date_string.days_before_month, i64 0, i64 %49
%51 = load i16, i16* %50
%52 = zext i16 %51 to i32
%53 = add nsw i32 %47, %52
%54 = load i32, i32* %7
%55 = sub nsw i32 %54, 1
%56 = add nsw i32 %53, %55
%57 = load i32, i32* %10
%58 = add nsw i32 %56, %57
store i32 %58, i32* %11
%59 = load i32, i32* %11
%60 = mul nsw i32 %59, 24
%61 = mul nsw i32 %60, 3600
%62 = load i32, i32* %6
%63 = mul nsw i32 %62, 3600
%64 = add nsw i32 %61, %63
%65 = load i32, i32* %5
%66 = mul nsw i32 %65, 60
%67 = add nsw i32 %64, %66
%68 = load i32, i32* %4
%69 = add nsw i32 %67, %68
store i32 %69, i32* %12
br label %70
70: ; preds = %39, %35, %32, %27
%71 = load i32, i32* %12
ret i32 %71
}

LLVM IR (-O2):
@mg_parse_date_string.days_before_month = internal unnamed_addr constant [12 x i16] [i16 0, i16 31, i16 59, i16 90, i16 120, i16 151, i16 181, i16 212, i16 243, i16 273, i16 304, i16 334]
@.str = [19 x i8] c"%d/%3s/%d %d:%d:%d\00"
@.str.1 = [19 x i8] c"%d %3s %d %d:%d:%d\00"
@.str.2 = [25 x i8] c"%*3s, %d %3s %d %d:%d:%d\00"
@.str.3 = [19 x i8] c"%d-%3s-%d %d:%d:%d\00"
define i32 @mg_parse_date_string(i8* nocapture %0) {
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %6, i8* %8, i32* %7, i32* %5, i32* %4, i32* %3)
%15 = icmp eq i32 %14, 6
br i1 %15, label %28, label %16
16: ; preds = %1
%17 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %8, i32* %7, i32* %5, i32* %4, i32* %3)
%18 = icmp eq i32 %17, 6
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32* %6, i8* %8, i32* %7, i32* %5, i32* %4, i32* %3)
%21 = icmp eq i32 %20, 6
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32* %6, i8* %8, i32* %7, i32* %5, i32* %4, i32* %3)
%24 = icmp eq i32 %23, 6
%25 = load i32, i32* %7
%26 = icmp sgt i32 %25, 1970
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %31, label %60
28: ; preds = %19, %16, %1
%29 = load i32, i32* %7
%30 = icmp sgt i32 %29, 1970
br i1 %30, label %31, label %60
31: ; preds = %22, %28
%32 = call i32 @mg_get_month_index(i8* %8)
%33 = icmp eq i32 %32, -1
br i1 %33, label %60, label %34
34: ; preds = %31
%35 = load i32, i32* %7
%36 = call i32 @mg_num_leap_years(i32 %35)
%37 = call i32 @mg_num_leap_years(i32 1970)
%38 = load i32, i32* %7
%39 = mul i32 %38, 365
%40 = add i32 %39, -719050
%41 = sext i32 %32 to i64
%42 = getelementptr inbounds [12 x i16], [12 x i16]* @mg_parse_date_string.days_before_month, i64 0, i64 %41
%43 = load i16, i16* %42
%44 = zext i16 %43 to i32
%45 = load i32, i32* %6
%46 = xor i32 %37, -1
%47 = add i32 %36, %46
%48 = add i32 %47, %40
%49 = add i32 %48, %44
%50 = add i32 %49, %45
%51 = mul i32 %50, 86400
%52 = load i32, i32* %5
%53 = mul nsw i32 %52, 3600
%54 = add nsw i32 %51, %53
%55 = load i32, i32* %4
%56 = mul nsw i32 %55, 60
%57 = add nsw i32 %54, %56
%58 = load i32, i32* %3
%59 = add nsw i32 %57, %58
br label %60
60: ; preds = %34, %31, %28, %22
%61 = phi i32 [ %59, %34 ], [ 0, %31 ], [ 0, %28 ], [ 0, %22 ]
ret i32 %61
}