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

/* Variables and functions */
void *atoi(char const *);
scalar_t__ make_month(char const *);
int /*<<< orphan*/ make_num(char const *);
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
char *strchr(char const *, char);
int strlen(char const *);
scalar_t__ tmSaneValues(struct tm *);
struct tm *parse_date_elements(const char *day, const char *month,
                               const char *year, const char *time,
                               const char *zone) {
  static struct tm tm;
  char *t;
  memset(&tm, 0, sizeof(tm));
  if (!day || !month || !year || !time)
    return NULL;
  tm.tm_mday = atoi(day);
  tm.tm_mon = make_month(month);
  if (tm.tm_mon < 0)
    return NULL;
  tm.tm_year = atoi(year);
  if (strlen(year) == 4)
    tm.tm_year -= 1900;
  else if (tm.tm_year < 70)
    tm.tm_year += 100;
  else if (tm.tm_year > 19000)
    tm.tm_year -= 19000;
  tm.tm_hour = make_num(time);
  t = strchr(time, ':');
  if (!t)
    return NULL;
  t++;
  tm.tm_min = atoi(t);
  t = strchr(t, ':');
  if (t)
    tm.tm_sec = atoi(t + 1);
  return tmSaneValues(&tm) ? &tm : NULL;
}


x86 assembly (clang, -O0):
<parse_date_elements>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    0x2ecd(%rip),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11cb <parse_date_elements+0x5b>
cmpq   $0x0,-0x18(%rbp)
je     11cb <parse_date_elements+0x5b>
cmpq   $0x0,-0x20(%rbp)
je     11cb <parse_date_elements+0x5b>
cmpq   $0x0,-0x28(%rbp)
jne    11d8 <parse_date_elements+0x68>
movq   $0x0,-0x8(%rbp)
jmp    1340 <parse_date_elements+0x1d0>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %rax,0x2ea0(%rip)
mov    -0x18(%rbp),%rdi
call   1060 <make_month@plt>
mov    %rax,0x2e68(%rip)
cmpq   $0x0,0x2e60(%rip)
jge    1213 <parse_date_elements+0xa3>
movq   $0x0,-0x8(%rbp)
jmp    1340 <parse_date_elements+0x1d0>
mov    -0x20(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,0x2e46(%rip)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
jne    124a <parse_date_elements+0xda>
mov    0x2e2e(%rip),%eax
sub    $0x76c,%eax
mov    %eax,0x2e23(%rip)
jmp    1296 <parse_date_elements+0x126>
cmpl   $0x46,0x2e17(%rip)
jge    126b <parse_date_elements+0xfb>
mov    0x2e0b(%rip),%eax
add    $0x64,%eax
mov    %eax,0x2e02(%rip)
jmp    1291 <parse_date_elements+0x121>
cmpl   $0x4a38,0x2df3(%rip)
jle    128c <parse_date_elements+0x11c>
mov    0x2de7(%rip),%eax
sub    $0x4a38,%eax
mov    %eax,0x2ddc(%rip)
jmp    1291 <parse_date_elements+0x121>
jmp    1296 <parse_date_elements+0x126>
mov    -0x28(%rbp),%rdi
call   1090 <make_num@plt>
mov    %eax,0x2ddb(%rip)
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12cf <parse_date_elements+0x15f>
movq   $0x0,-0x8(%rbp)
jmp    1340 <parse_date_elements+0x1d0>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <atoi@plt>
mov    %rax,0x2d8d(%rip)
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     131c <parse_date_elements+0x1ac>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1070 <atoi@plt>
mov    %rax,0x2d54(%rip)
lea    0x2d3d(%rip),%rdi
call   1080 <tmSaneValues@plt>
mov    %rax,%rdx
xor    %eax,%eax
lea    0x2d2c(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_date_elements>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x2ed2(%rip),%r14
xor    %r13d,%r13d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
test   %rbp,%rbp
je     12a2 <parse_date_elements+0x132>
test   %rbx,%rbx
je     12a2 <parse_date_elements+0x132>
test   %r12,%r12
je     12a2 <parse_date_elements+0x132>
test   %r15,%r15
je     12a2 <parse_date_elements+0x132>
mov    %rbp,%rdi
call   1070 <atoi@plt>
mov    %rax,0x2eb5(%rip)
mov    %rbx,%rdi
call   1060 <make_month@plt>
mov    %rax,0x2e7e(%rip)
test   %rax,%rax
js     129f <parse_date_elements+0x12f>
mov    %r12,%rdi
call   1070 <atoi@plt>
mov    %eax,0x2e6f(%rip)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    $0xfffff894,%edx
mov    0x2e5c(%rip),%ecx
cmp    $0x4,%eax
je     1228 <parse_date_elements+0xb8>
mov    $0x64,%edx
cmp    $0x46,%ecx
jl     1228 <parse_date_elements+0xb8>
mov    $0xffffb5c8,%edx
cmp    $0x4a39,%ecx
jb     1230 <parse_date_elements+0xc0>
add    %edx,%ecx
mov    %ecx,0x2e38(%rip)
mov    %r15,%rdi
call   1090 <make_num@plt>
mov    %eax,0x2e42(%rip)
mov    %r15,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     129f <parse_date_elements+0x12f>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    %rax,0x2e12(%rip)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     128b <parse_date_elements+0x11b>
add    $0x1,%rax
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %rax,0x2de5(%rip)
mov    %r14,%rdi
call   1080 <tmSaneValues@plt>
test   %rax,%rax
cmove  %rax,%r14
mov    %r14,%r13
jmp    12a2 <parse_date_elements+0x132>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i64, i32, i8*, i8*, i32, i8* }
@parse_date_elements.tm = internal global %struct.tm zeroinitializer
define %struct.tm* @parse_date_elements(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca %struct.tm*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%13 = call i32 @memset(%struct.tm* @parse_date_elements.tm, i32 0, i32 48)
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %25
16: ; preds = %5
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8*, i8** %9
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %10
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %22, %19, %16, %5
store %struct.tm* null, %struct.tm** %6
br label %84
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = call i8* @atoi(i8* %27)
store i8* %28, i8** getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 5)
%29 = load i8*, i8** %8
%30 = call i64 @make_month(i8* %29)
store i64 %30, i64* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 0)
%31 = load i64, i64* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 0)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %26
store %struct.tm* null, %struct.tm** %6
br label %84
34: ; preds = %26
%35 = load i8*, i8** %9
%36 = call i8* @atoi(i8* %35)
%37 = ptrtoint i8* %36 to i32
store i32 %37, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
%38 = load i8*, i8** %9
%39 = call i32 @strlen(i8* %38)
%40 = icmp eq i32 %39, 4
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i32, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
%43 = sub nsw i32 %42, 1900
store i32 %43, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
br label %58
44: ; preds = %34
%45 = load i32, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
%46 = icmp slt i32 %45, 70
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
%49 = add nsw i32 %48, 100
store i32 %49, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
br label %57
50: ; preds = %44
%51 = load i32, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
%52 = icmp sgt i32 %51, 19000
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
%55 = sub nsw i32 %54, 19000
store i32 %55, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 1)
br label %56
56: ; preds = %53, %50
br label %57
57: ; preds = %56, %47
br label %58
58: ; preds = %57, %41
%59 = load i8*, i8** %10
%60 = call i32 @make_num(i8* %59)
store i32 %60, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 4)
%61 = load i8*, i8** %10
%62 = call i8* @strchr(i8* %61, i8 signext 58)
store i8* %62, i8** %12
%63 = load i8*, i8** %12
%64 = icmp ne i8* %63, null
br i1 %64, label %66, label %65
65: ; preds = %58
store %struct.tm* null, %struct.tm** %6
br label %84
66: ; preds = %58
%67 = load i8*, i8** %12
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %12
%69 = load i8*, i8** %12
%70 = call i8* @atoi(i8* %69)
store i8* %70, i8** getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 3)
%71 = load i8*, i8** %12
%72 = call i8* @strchr(i8* %71, i8 signext 58)
store i8* %72, i8** %12
%73 = load i8*, i8** %12
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %79
75: ; preds = %66
%76 = load i8*, i8** %12
%77 = getelementptr inbounds i8, i8* %76, i64 1
%78 = call i8* @atoi(i8* %77)
store i8* %78, i8** getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i32 0, i32 2)
br label %79
79: ; preds = %75, %66
%80 = call i64 @tmSaneValues(%struct.tm* @parse_date_elements.tm)
%81 = icmp ne i64 %80, 0
%82 = zext i1 %81 to i64
%83 = select i1 %81, %struct.tm* @parse_date_elements.tm, %struct.tm* null
store %struct.tm* %83, %struct.tm** %6
br label %84
84: ; preds = %79, %65, %33, %25
%85 = load %struct.tm*, %struct.tm** %6
ret %struct.tm* %85
}

LLVM IR (-O2):
%struct.tm = type { i64, i32, i8*, i8*, i32, i8* }
@parse_date_elements.tm = internal global %struct.tm zeroinitializer
define %struct.tm* @parse_date_elements(i8* %0, i8* %1, i8* %2, i8* %3, i8* nocapture readnone %4) {
%6 = tail call i32 @memset(%struct.tm* @parse_date_elements.tm, i32 0, i32 48)
%7 = icmp ne i8* %0, null
%8 = icmp ne i8* %1, null
%9 = and i1 %7, %8
%10 = icmp ne i8* %2, null
%11 = and i1 %9, %10
%12 = icmp ne i8* %3, null
%13 = and i1 %11, %12
br i1 %13, label %14, label %48
14: ; preds = %5
%15 = tail call i8* @atoi(i8* %0)
store i8* %15, i8** getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i64 0, i32 5)
%16 = tail call i64 @make_month(i8* %1)
store i64 %16, i64* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i64 0, i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %48, label %18
18: ; preds = %14
%19 = tail call i8* @atoi(i8* %2)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i32
store i32 %21, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i64 0, i32 1)
%22 = tail call i32 @strlen(i8* %2)
%23 = icmp eq i32 %22, 4
%24 = load i32, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i64 0, i32 1)
br i1 %23, label %29, label %25
25: ; preds = %18
%26 = icmp slt i32 %24, 70
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = icmp ugt i32 %24, 19000
br i1 %28, label %29, label %32
29: ; preds = %27, %25, %18
%30 = phi i32 [ -1900, %18 ], [ 100, %25 ], [ -19000, %27 ]
%31 = add nsw i32 %24, %30
store i32 %31, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i64 0, i32 1)
br label %32
32: ; preds = %29, %27
%33 = tail call i32 @make_num(i8* %3)
store i32 %33, i32* getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i64 0, i32 4)
%34 = tail call i8* @strchr(i8* %3, i8 signext 58)
%35 = icmp eq i8* %34, null
br i1 %35, label %48, label %36
36: ; preds = %32
%37 = getelementptr inbounds i8, i8* %34, i64 1
%38 = tail call i8* @atoi(i8* %37)
store i8* %38, i8** getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i64 0, i32 3)
%39 = tail call i8* @strchr(i8* %37, i8 signext 58)
%40 = icmp eq i8* %39, null
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = getelementptr inbounds i8, i8* %39, i64 1
%43 = tail call i8* @atoi(i8* %42)
store i8* %43, i8** getelementptr inbounds (%struct.tm, %struct.tm* @parse_date_elements.tm, i64 0, i32 2)
br label %44
44: ; preds = %41, %36
%45 = tail call i64 @tmSaneValues(%struct.tm* @parse_date_elements.tm)
%46 = icmp eq i64 %45, 0
%47 = select i1 %46, %struct.tm* null, %struct.tm* @parse_date_elements.tm
br label %48
48: ; preds = %32, %14, %5, %44
%49 = phi %struct.tm* [ %47, %44 ], [ null, %5 ], [ null, %14 ], [ null, %32 ]
ret %struct.tm* %49
}