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

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ tmcpy(struct tm *, struct tm *);
int diffmonths(const time_t *startDate, const time_t *endDate) {
  struct tm ref, *current;
  current = localtime(endDate);
  tmcpy(&ref, current);
  ref.tm_sec = 0;
  ref.tm_min = 0;
  ref.tm_hour = 5;
  current = localtime(startDate);
  current->tm_sec = 0;
  current->tm_min = 0;
  current->tm_hour = 5;
  return (ref.tm_mon + 12 * ref.tm_year) -
         (current->tm_mon + 12 * current->tm_year);
}


x86 assembly (clang, -O0):
<diffmonths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1040 <tmcpy@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x5,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    -0x38(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x38(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x2c(%rbp),%eax
imul   $0xc,-0x28(%rbp),%ecx
add    %ecx,%eax
mov    -0x38(%rbp),%rcx
mov    0x4(%rcx),%ecx
mov    -0x38(%rbp),%rdx
imul   $0xc,0x8(%rdx),%edx
add    %edx,%ecx
sub    %ecx,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diffmonths>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <localtime@plt>
mov    %rsp,%rdi
mov    %rax,%rsi
call   1040 <tmcpy@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movl   $0x5,(%rsp)
mov    %rbx,%rdi
call   1030 <localtime@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rax)
movl   $0x5,(%rax)
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%edx
sub    0x8(%rax),%edx
lea    (%rdx,%rdx,2),%edx
sub    0x4(%rax),%ecx
lea    (%rcx,%rdx,4),%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i64, i64 }
define i32 @diffmonths(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca %struct.tm
%6 = alloca %struct.tm*
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %8, %struct.tm** %6
%9 = load %struct.tm*, %struct.tm** %6
%10 = call i32 @tmcpy(%struct.tm* %5, %struct.tm* %9)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
store i32 5, i32* %13
%14 = load i32*, i32** %3
%15 = call %struct.tm* @localtime(i32* %14)
store %struct.tm* %15, %struct.tm** %6
%16 = load %struct.tm*, %struct.tm** %6
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 4
store i64 0, i64* %17
%18 = load %struct.tm*, %struct.tm** %6
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 3
store i64 0, i64* %19
%20 = load %struct.tm*, %struct.tm** %6
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 0
store i32 5, i32* %21
%22 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
%25 = load i32, i32* %24
%26 = mul nsw i32 12, %25
%27 = add nsw i32 %23, %26
%28 = load %struct.tm*, %struct.tm** %6
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = load %struct.tm*, %struct.tm** %6
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 2
%33 = load i32, i32* %32
%34 = mul nsw i32 12, %33
%35 = add nsw i32 %30, %34
%36 = sub nsw i32 %27, %35
ret i32 %36
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i64, i64 }
define i32 @diffmonths(i32* %0, i32* %1) {
%3 = alloca %struct.tm
%4 = bitcast %struct.tm* %3 to i8*
%5 = tail call %struct.tm* @localtime(i32* %1)
%6 = call i32 @tmcpy(%struct.tm* %3, %struct.tm* %5)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%8 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%9 = bitcast i64* %7 to i8*
store i32 5, i32* %8
%10 = call %struct.tm* @localtime(i32* %0)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 3
%12 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 0
%13 = bitcast i64* %11 to i8*
store i32 5, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 2
%21 = load i32, i32* %20
%22 = sub i32 %17, %21
%23 = mul i32 %22, 12
%24 = sub i32 %15, %19
%25 = add i32 %24, %23
ret i32 %25
}