#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 */

/* Variables and functions */
int /*<<< orphan*/ date_parse(int *, int *, int *, char *);
int date_years_between(char *from_date, char *to_date) {
  int from_year, from_month, from_day;
  int to_year, to_month, to_day;
  int diff_year, diff_month, diff_day;
  if (!date_parse(&from_year, &from_month, &from_day, from_date)) {
    return -1;
  }
  if (!date_parse(&to_year, &to_month, &to_day, to_date)) {
    return -1;
  }
  diff_year = to_year - from_year;
  diff_month = to_month - from_month;
  diff_day = to_day - from_day;
  if (diff_day < 0)
    diff_month--;
  if (diff_month < 0)
    diff_year--;
  if (diff_year < 0)
    diff_year = 0;
  return diff_year;
}


x86 assembly (clang, -O0):
<date_years_between>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1030 <date_parse@plt>
cmp    $0x0,%eax
jne    114a <date_years_between+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <date_years_between+0xbc>
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <date_parse@plt>
cmp    $0x0,%eax
jne    1174 <date_years_between+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <date_years_between+0xbc>
mov    -0x28(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    11a2 <date_years_between+0x92>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11b5 <date_years_between+0xa5>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11c6 <date_years_between+0xb6>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<date_years_between>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rcx
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1030 <date_parse@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
je     117b <date_years_between+0x6b>
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %r14,%rcx
call   1030 <date_parse@plt>
test   %eax,%eax
je     117b <date_years_between+0x6b>
mov    0x8(%rsp),%eax
sub    0x14(%rsp),%eax
mov    0x4(%rsp),%ebx
sub    0x10(%rsp),%ebx
mov    (%rsp),%ecx
xor    %edx,%edx
cmp    0xc(%rsp),%ecx
setl   %dl
sub    %edx,%ebx
sar    $0x1f,%ebx
xor    %ecx,%ecx
add    %eax,%ebx
cmovs  %ecx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @date_years_between(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%15 = load i8*, i8** %4
%16 = call i32 @date_parse(i32* %6, i32* %7, i32* %8, i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %2
store i32 -1, i32* %3
br label %51
19: ; preds = %2
%20 = load i8*, i8** %5
%21 = call i32 @date_parse(i32* %9, i32* %10, i32* %11, i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %19
store i32 -1, i32* %3
br label %51
24: ; preds = %19
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = sub nsw i32 %25, %26
store i32 %27, i32* %12
%28 = load i32, i32* %10
%29 = load i32, i32* %7
%30 = sub nsw i32 %28, %29
store i32 %30, i32* %13
%31 = load i32, i32* %11
%32 = load i32, i32* %8
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %14
%34 = load i32, i32* %14
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %24
%37 = load i32, i32* %13
%38 = add nsw i32 %37, -1
store i32 %38, i32* %13
br label %39
39: ; preds = %36, %24
%40 = load i32, i32* %13
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %12
%44 = add nsw i32 %43, -1
store i32 %44, i32* %12
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* %12
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45
store i32 0, i32* %12
br label %49
49: ; preds = %48, %45
%50 = load i32, i32* %12
store i32 %50, i32* %3
br label %51
51: ; preds = %49, %23, %18
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
define i32 @date_years_between(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%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 = bitcast i32* %8 to i8*
%15 = call i32 @date_parse(i32* %3, i32* %4, i32* %5, i8* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %36, label %17
17: ; preds = %2
%18 = call i32 @date_parse(i32* %6, i32* %7, i32* %8, i8* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %36, label %20
20: ; preds = %17
%21 = load i32, i32* %6
%22 = load i32, i32* %3
%23 = sub nsw i32 %21, %22
%24 = load i32, i32* %7
%25 = load i32, i32* %4
%26 = sub i32 %24, %25
%27 = load i32, i32* %8
%28 = load i32, i32* %5
%29 = icmp slt i32 %27, %28
%30 = sext i1 %29 to i32
%31 = add nsw i32 %26, %30
%32 = ashr i32 %31, 31
%33 = add nsw i32 %32, %23
%34 = icmp sgt i32 %33, 0
%35 = select i1 %34, i32 %33, i32 0
br label %36
36: ; preds = %17, %2, %20
%37 = phi i32 [ %35, %20 ], [ -1, %2 ], [ -1, %17 ]
ret i32 %37
}