#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*/ tm;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
  void *tm_sec;
  void *tm_min;
  void *tm_hour;
  void *tm_mday;
  void *tm_mon;
};

/* Variables and functions */
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mktime(struct tm *);
void *parse_dec(char const *, int);
time_t parse_date(const char *s) {
  struct tm tm;
  memset(&tm, 0, sizeof(tm));
  if ((tm.tm_year = parse_dec(s + 0, 4)) < 0 ||
      (tm.tm_mon = parse_dec(s + 4, 2)) < 0 ||
      (tm.tm_mday = parse_dec(s + 6, 2)) < 0)
    return (time_t)-1;
  if (s[8]) {
    if (s[8] != 'T' || (tm.tm_hour = parse_dec(s + 9, 2)) < 0 ||
        (tm.tm_min = parse_dec(s + 11, 2)) < 0)
      return (time_t)-1;
    if (s[13] && (tm.tm_sec = parse_dec(s + 13, 2)) < 0)
      return (time_t)-1;
  }
  tm.tm_year -= 1900;
  return mktime(&tm);
}


x86 assembly (clang, -O0):
<parse_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1040 <parse_dec@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x0,%eax
jl     11a6 <parse_date+0x76>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jb     11a6 <parse_date+0x76>
mov    -0x10(%rbp),%rdi
add    $0x6,%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jae    11b2 <parse_date+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <parse_date+0x146>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x8(%rax)
je     125f <parse_date+0x12f>
mov    -0x10(%rbp),%rax
movsbl 0x8(%rax),%eax
cmp    $0x54,%eax
jne    1211 <parse_date+0xe1>
mov    -0x10(%rbp),%rdi
add    $0x9,%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jb     1211 <parse_date+0xe1>
mov    -0x10(%rbp),%rdi
add    $0xb,%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jae    121d <parse_date+0xed>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <parse_date+0x146>
mov    -0x10(%rbp),%rax
movsbl 0xd(%rax),%eax
cmp    $0x0,%eax
je     125a <parse_date+0x12a>
mov    -0x10(%rbp),%rdi
add    $0xd,%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jae    125a <parse_date+0x12a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <parse_date+0x146>
jmp    125f <parse_date+0x12f>
mov    -0x40(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_date>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <parse_dec@plt>
mov    %eax,0x8(%rsp)
mov    $0xffffffff,%ebp
test   %eax,%eax
js     11ef <parse_date+0xbf>
lea    0x4(%rbx),%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,0x30(%rsp)
lea    0x6(%rbx),%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,0x28(%rsp)
mov    0x8(%rbx),%al
test   %al,%al
je     11db <parse_date+0xab>
cmp    $0x54,%al
jne    11ef <parse_date+0xbf>
lea    0x9(%rbx),%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,0x20(%rsp)
lea    0xb(%rbx),%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,0x18(%rsp)
cmpb   $0x0,0xd(%rbx)
je     11db <parse_date+0xab>
add    $0xd,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <parse_dec@plt>
mov    %rax,0x10(%rsp)
addl   $0xfffff894,0x8(%rsp)
ff
lea    0x8(%rsp),%rdi
call   1050 <mktime@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i8*, i8*, i8*, i8*, i8* }
define i32 @parse_date(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.tm
store i8* %0, i8** %3
%5 = call i32 @memset(%struct.tm* %4, i32 0, i32 48)
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = call i8* @parse_dec(i8* %7, i32 4)
%9 = ptrtoint i8* %8 to i32
%10 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
store i32 %9, i32* %10
%11 = icmp slt i32 %9, 0
br i1 %11, label %24, label %12
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 4
%15 = call i8* @parse_dec(i8* %14, i32 2)
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 5
store i8* %15, i8** %16
%17 = icmp ult i8* %15, null
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 6
%21 = call i8* @parse_dec(i8* %20, i32 2)
%22 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
store i8* %21, i8** %22
%23 = icmp ult i8* %21, null
br i1 %23, label %24, label %25
24: ; preds = %18, %12, %1
store i32 -1, i32* %2
br label %68
25: ; preds = %18
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 8
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
br i1 %29, label %30, label %63
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 8
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 84
br i1 %35, label %48, label %36
36: ; preds = %30
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 9
%39 = call i8* @parse_dec(i8* %38, i32 2)
%40 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
store i8* %39, i8** %40
%41 = icmp ult i8* %39, null
br i1 %41, label %48, label %42
42: ; preds = %36
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 11
%45 = call i8* @parse_dec(i8* %44, i32 2)
%46 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
store i8* %45, i8** %46
%47 = icmp ult i8* %45, null
br i1 %47, label %48, label %49
48: ; preds = %42, %36, %30
store i32 -1, i32* %2
br label %68
49: ; preds = %42
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i64 13
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %49
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i64 13
%58 = call i8* @parse_dec(i8* %57, i32 2)
%59 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
store i8* %58, i8** %59
%60 = icmp ult i8* %58, null
br i1 %60, label %61, label %62
61: ; preds = %55
store i32 -1, i32* %2
br label %68
62: ; preds = %55, %49
br label %63
63: ; preds = %62, %25
%64 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%65 = load i32, i32* %64
%66 = sub nsw i32 %65, 1900
store i32 %66, i32* %64
%67 = call i32 @mktime(%struct.tm* %4)
store i32 %67, i32* %2
br label %68
68: ; preds = %63, %61, %48, %24
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
%struct.tm = type { i32, i8*, i8*, i8*, i8*, i8* }
define i32 @parse_date(i8* %0) {
%2 = alloca %struct.tm
%3 = bitcast %struct.tm* %2 to i8*
%4 = call i32 @memset(%struct.tm* %2, i32 0, i32 48)
%5 = call i8* @parse_dec(i8* %0, i32 4)
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
%8 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i32 %7, i32* %8
%9 = icmp slt i32 %7, 0
br i1 %9, label %36, label %10
10: ; preds = %1
%11 = getelementptr inbounds i8, i8* %0, i64 4
%12 = call i8* @parse_dec(i8* %11, i32 2)
%13 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
store i8* %12, i8** %13
%14 = getelementptr inbounds i8, i8* %0, i64 6
%15 = call i8* @parse_dec(i8* %14, i32 2)
%16 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
store i8* %15, i8** %16
%17 = getelementptr inbounds i8, i8* %0, i64 8
%18 = load i8, i8* %17
switch i8 %18, label %36 [
i8 0, label %32
i8 84, label %19
]
19: ; preds = %10
%20 = getelementptr inbounds i8, i8* %0, i64 9
%21 = call i8* @parse_dec(i8* %20, i32 2)
%22 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
store i8* %21, i8** %22
%23 = getelementptr inbounds i8, i8* %0, i64 11
%24 = call i8* @parse_dec(i8* %23, i32 2)
%25 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i8* %24, i8** %25
%26 = getelementptr inbounds i8, i8* %0, i64 13
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %19
%30 = call i8* @parse_dec(i8* %26, i32 2)
%31 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i8* %30, i8** %31
br label %32
32: ; preds = %10, %29, %19
%33 = load i32, i32* %8
%34 = add nsw i32 %33, -1900
store i32 %34, i32* %8
%35 = call i32 @mktime(%struct.tm* %2)
br label %36
36: ; preds = %10, %1, %32
%37 = phi i32 [ %35, %32 ], [ -1, %1 ], [ -1, %10 ]
ret i32 %37
}