#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 */
struct tm {
  int const tm_year;
  int const tm_mon;
  int tm_mday;
};

/* Variables and functions */
int CalculateDaysBetweenFFunc(int const, int const);
int CalculateDaysBetweenGFunc(int const);
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
scalar_t__ labs(int);
int CalculateDaysBetween(const struct tm *date1, const struct tm *date2) {
  const int YEAR_LOWER_BOUND = 1900;
  const int MONTH_LOWER_BOUND = 2;
  const int RETURN_VAL_ON_ERROR = -1;
  if (!date1) {
    errno = EINVAL;
    return RETURN_VAL_ON_ERROR;
  }
  if (!date2) {
    errno = EINVAL;
    return RETURN_VAL_ON_ERROR;
  }
  if (date1->tm_year < YEAR_LOWER_BOUND ||
      (date1->tm_year == YEAR_LOWER_BOUND &&
       date1->tm_mon < MONTH_LOWER_BOUND)) {
    errno = EINVAL;
    return RETURN_VAL_ON_ERROR;
  }
  if (date2->tm_year < YEAR_LOWER_BOUND ||
      (date2->tm_year == YEAR_LOWER_BOUND &&
       date2->tm_mon < MONTH_LOWER_BOUND)) {
    errno = EINVAL;
    return RETURN_VAL_ON_ERROR;
  }
  int f1 = CalculateDaysBetweenFFunc(date1->tm_year, date1->tm_mon);
  int g1 = CalculateDaysBetweenGFunc(date1->tm_mon);
  int N1 = 1461 * f1 / 4 + 153 * g1 / 5 + date1->tm_mday;
  int f2 = CalculateDaysBetweenFFunc(date2->tm_year, date2->tm_mon);
  int g2 = CalculateDaysBetweenGFunc(date2->tm_mon);
  int N2 = 1461 * f2 / 4 + 153 * g2 / 5 + date2->tm_mday;
  return (int)labs(N2 - N1);
}


x86 assembly (clang, -O0):
<CalculateDaysBetween>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x76c,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117e <CalculateDaysBetween+0x4e>
mov    0x2e71(%rip),%rax
mov    (%rax),%ecx
mov    0x2e70(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <CalculateDaysBetween+0x1c9>
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <CalculateDaysBetween+0x77>
mov    0x2e48(%rip),%rax
mov    (%rax),%ecx
mov    0x2e47(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <CalculateDaysBetween+0x1c9>
mov    -0x10(%rbp),%rax
cmpl   $0x76c,(%rax)
jl     11d5 <CalculateDaysBetween+0xa5>
mov    -0x10(%rbp),%rax
cmpl   $0x76c,(%rax)
jne    11f3 <CalculateDaysBetween+0xc3>
mov    -0x10(%rbp),%rax
cmpl   $0x2,0x4(%rax)
jge    11f3 <CalculateDaysBetween+0xc3>
mov    0x2dfc(%rip),%rax
mov    (%rax),%ecx
mov    0x2dfb(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <CalculateDaysBetween+0x1c9>
mov    -0x18(%rbp),%rax
cmpl   $0x76c,(%rax)
jl     1221 <CalculateDaysBetween+0xf1>
mov    -0x18(%rbp),%rax
cmpl   $0x76c,(%rax)
jne    123f <CalculateDaysBetween+0x10f>
mov    -0x18(%rbp),%rax
cmpl   $0x2,0x4(%rax)
jge    123f <CalculateDaysBetween+0x10f>
mov    0x2db0(%rip),%rax
mov    (%rax),%ecx
mov    0x2daf(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <CalculateDaysBetween+0x1c9>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
call   1050 <CalculateDaysBetweenFFunc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <CalculateDaysBetweenGFunc@plt>
mov    %eax,-0x2c(%rbp)
imul   $0x5b5,-0x28(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
imul   $0x99,-0x2c(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
add    0x8(%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
call   1050 <CalculateDaysBetweenFFunc@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <CalculateDaysBetweenGFunc@plt>
mov    %eax,-0x38(%rbp)
imul   $0x5b5,-0x34(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x40(%rbp)
imul   $0x99,-0x38(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
mov    -0x18(%rbp),%rcx
add    0x8(%rcx),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
sub    -0x30(%rbp),%edi
call   1040 <labs@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateDaysBetween>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     116b <CalculateDaysBetween+0x3b>
mov    %rsi,%r14
test   %rsi,%rsi
je     116b <CalculateDaysBetween+0x3b>
mov    %rdi,%rbx
mov    (%rdi),%edi
cmp    $0x76c,%edi
jl     116b <CalculateDaysBetween+0x3b>
jne    1159 <CalculateDaysBetween+0x29>
cmpl   $0x1,0x4(%rbx)
jle    116b <CalculateDaysBetween+0x3b>
cmpl   $0x76c,(%r14)
jl     116b <CalculateDaysBetween+0x3b>
jne    118d <CalculateDaysBetween+0x5d>
cmpl   $0x1,0x4(%r14)
jg     118d <CalculateDaysBetween+0x5d>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    0x2e65(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x4(%rbx),%esi
call   1050 <CalculateDaysBetweenFFunc@plt>
mov    %eax,%ebp
mov    0x4(%rbx),%edi
call   1030 <CalculateDaysBetweenGFunc@plt>
imul   $0x5b5,%ebp,%ecx
lea    0x3(%rcx),%ebp
test   %ecx,%ecx
cmovns %ecx,%ebp
sar    $0x2,%ebp
imul   $0x99,%eax,%eax
cltq
imul   $0xffffffff99999999,%rax,%r15
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x21,%r15
add    %eax,%r15d
mov    (%r14),%edi
mov    0x4(%r14),%esi
add    0x8(%rbx),%ebp
call   1050 <CalculateDaysBetweenFFunc@plt>
mov    %eax,%ebx
mov    0x4(%r14),%edi
call   1030 <CalculateDaysBetweenGFunc@plt>
imul   $0x5b5,%ebx,%ecx
lea    0x3(%rcx),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
sar    $0x2,%edx
imul   $0x99,%eax,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
sub    %ebp,%r15d
add    %edx,%r15d
add    0x8(%r14),%r15d
add    %eax,%r15d
mov    %r15d,%edi
call   1040 <labs@plt>
jmp    1182 <CalculateDaysBetween+0x52>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @CalculateDaysBetween(%struct.tm* %0, %struct.tm* %1) {
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca %struct.tm*
%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 %struct.tm* %0, %struct.tm** %4
store %struct.tm* %1, %struct.tm** %5
store i32 1900, i32* %6
store i32 2, i32* %7
store i32 -1, i32* %8
%15 = load %struct.tm*, %struct.tm** %4
%16 = icmp ne %struct.tm* %15, null
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = load i32, i32* @EINVAL
store i32 %18, i32* @errno
store i32 -1, i32* %3
br label %108
19: ; preds = %2
%20 = load %struct.tm*, %struct.tm** %5
%21 = icmp ne %struct.tm* %20, null
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = load i32, i32* @EINVAL
store i32 %23, i32* @errno
store i32 -1, i32* %3
br label %108
24: ; preds = %19
%25 = load %struct.tm*, %struct.tm** %4
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = icmp slt i32 %27, 1900
br i1 %28, label %39, label %29
29: ; preds = %24
%30 = load %struct.tm*, %struct.tm** %4
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 1900
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = load %struct.tm*, %struct.tm** %4
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = icmp slt i32 %37, 2
br i1 %38, label %39, label %41
39: ; preds = %34, %24
%40 = load i32, i32* @EINVAL
store i32 %40, i32* @errno
store i32 -1, i32* %3
br label %108
41: ; preds = %34, %29
%42 = load %struct.tm*, %struct.tm** %5
%43 = getelementptr inbounds %struct.tm, %struct.tm* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = icmp slt i32 %44, 1900
br i1 %45, label %56, label %46
46: ; preds = %41
%47 = load %struct.tm*, %struct.tm** %5
%48 = getelementptr inbounds %struct.tm, %struct.tm* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, 1900
br i1 %50, label %51, label %58
51: ; preds = %46
%52 = load %struct.tm*, %struct.tm** %5
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = icmp slt i32 %54, 2
br i1 %55, label %56, label %58
56: ; preds = %51, %41
%57 = load i32, i32* @EINVAL
store i32 %57, i32* @errno
store i32 -1, i32* %3
br label %108
58: ; preds = %51, %46
%59 = load %struct.tm*, %struct.tm** %4
%60 = getelementptr inbounds %struct.tm, %struct.tm* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = load %struct.tm*, %struct.tm** %4
%63 = getelementptr inbounds %struct.tm, %struct.tm* %62, i32 0, i32 1
%64 = load i32, i32* %63
%65 = call i32 @CalculateDaysBetweenFFunc(i32 %61, i32 %64)
store i32 %65, i32* %9
%66 = load %struct.tm*, %struct.tm** %4
%67 = getelementptr inbounds %struct.tm, %struct.tm* %66, i32 0, i32 1
%68 = load i32, i32* %67
%69 = call i32 @CalculateDaysBetweenGFunc(i32 %68)
store i32 %69, i32* %10
%70 = load i32, i32* %9
%71 = mul nsw i32 1461, %70
%72 = sdiv i32 %71, 4
%73 = load i32, i32* %10
%74 = mul nsw i32 153, %73
%75 = sdiv i32 %74, 5
%76 = add nsw i32 %72, %75
%77 = load %struct.tm*, %struct.tm** %4
%78 = getelementptr inbounds %struct.tm, %struct.tm* %77, i32 0, i32 2
%79 = load i32, i32* %78
%80 = add nsw i32 %76, %79
store i32 %80, i32* %11
%81 = load %struct.tm*, %struct.tm** %5
%82 = getelementptr inbounds %struct.tm, %struct.tm* %81, i32 0, i32 0
%83 = load i32, i32* %82
%84 = load %struct.tm*, %struct.tm** %5
%85 = getelementptr inbounds %struct.tm, %struct.tm* %84, i32 0, i32 1
%86 = load i32, i32* %85
%87 = call i32 @CalculateDaysBetweenFFunc(i32 %83, i32 %86)
store i32 %87, i32* %12
%88 = load %struct.tm*, %struct.tm** %5
%89 = getelementptr inbounds %struct.tm, %struct.tm* %88, i32 0, i32 1
%90 = load i32, i32* %89
%91 = call i32 @CalculateDaysBetweenGFunc(i32 %90)
store i32 %91, i32* %13
%92 = load i32, i32* %12
%93 = mul nsw i32 1461, %92
%94 = sdiv i32 %93, 4
%95 = load i32, i32* %13
%96 = mul nsw i32 153, %95
%97 = sdiv i32 %96, 5
%98 = add nsw i32 %94, %97
%99 = load %struct.tm*, %struct.tm** %5
%100 = getelementptr inbounds %struct.tm, %struct.tm* %99, i32 0, i32 2
%101 = load i32, i32* %100
%102 = add nsw i32 %98, %101
store i32 %102, i32* %14
%103 = load i32, i32* %14
%104 = load i32, i32* %11
%105 = sub nsw i32 %103, %104
%106 = call i64 @labs(i32 %105)
%107 = trunc i64 %106 to i32
store i32 %107, i32* %3
br label %108
108: ; preds = %58, %56, %39, %22, %17
%109 = load i32, i32* %3
ret i32 %109
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @CalculateDaysBetween(%struct.tm* %0, %struct.tm* %1) {
%3 = icmp eq %struct.tm* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i32, i32* @EINVAL
store i32 %5, i32* @errno
br label %65
6: ; preds = %2
%7 = icmp eq %struct.tm* %1, null
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
br label %65
10: ; preds = %6
%11 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = icmp slt i32 %12, 1900
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = icmp eq i32 %12, 1900
br i1 %15, label %16, label %22
16: ; preds = %14
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%18 = load i32, i32* %17
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %22
20: ; preds = %16, %10
%21 = load i32, i32* @EINVAL
store i32 %21, i32* @errno
br label %65
22: ; preds = %16, %14
%23 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%24 = load i32, i32* %23
%25 = icmp slt i32 %24, 1900
br i1 %25, label %32, label %26
26: ; preds = %22
%27 = icmp eq i32 %24, 1900
br i1 %27, label %28, label %34
28: ; preds = %26
%29 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%30 = load i32, i32* %29
%31 = icmp slt i32 %30, 2
br i1 %31, label %32, label %34
32: ; preds = %28, %22
%33 = load i32, i32* @EINVAL
store i32 %33, i32* @errno
br label %65
34: ; preds = %28, %26
%35 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%36 = load i32, i32* %35
%37 = tail call i32 @CalculateDaysBetweenFFunc(i32 %12, i32 %36)
%38 = load i32, i32* %35
%39 = tail call i32 @CalculateDaysBetweenGFunc(i32 %38)
%40 = mul nsw i32 %37, 1461
%41 = sdiv i32 %40, -4
%42 = mul nsw i32 %39, 153
%43 = sdiv i32 %42, -5
%44 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%45 = load i32, i32* %44
%46 = load i32, i32* %23
%47 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%48 = load i32, i32* %47
%49 = tail call i32 @CalculateDaysBetweenFFunc(i32 %46, i32 %48)
%50 = load i32, i32* %47
%51 = tail call i32 @CalculateDaysBetweenGFunc(i32 %50)
%52 = mul nsw i32 %49, 1461
%53 = sdiv i32 %52, 4
%54 = mul nsw i32 %51, 153
%55 = sdiv i32 %54, 5
%56 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 2
%57 = load i32, i32* %56
%58 = sub i32 %41, %45
%59 = add i32 %58, %43
%60 = add i32 %59, %53
%61 = add i32 %60, %57
%62 = add i32 %61, %55
%63 = tail call i64 @labs(i32 %62)
%64 = trunc i64 %63 to i32
br label %65
65: ; preds = %34, %32, %20, %8, %4
%66 = phi i32 [ -1, %20 ], [ -1, %32 ], [ %64, %34 ], [ -1, %8 ], [ -1, %4 ]
ret i32 %66
}