#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 tm_year;
  int tm_mon;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
scalar_t__ tm_getrepresentation(struct tm);
int tm_diffcalendarmonths(struct tm debut, struct tm fin) {
  if (tm_getrepresentation(debut) != tm_getrepresentation(fin)) {
    errno = EINVAL;
    return 0;
  }
  return 12 * (fin.tm_year - debut.tm_year) + fin.tm_mon - debut.tm_mon;
}


x86 assembly (clang, -O0):
<tm_diffcalendarmonths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <tm_getrepresentation@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <tm_getrepresentation@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     1164 <tm_diffcalendarmonths+0x54>
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8a(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1176 <tm_diffcalendarmonths+0x66>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
imul   $0xc,%eax,%eax
add    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_diffcalendarmonths>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <tm_getrepresentation@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <tm_getrepresentation@plt>
cmp    %rax,%r15
jne    114b <tm_diffcalendarmonths+0x3b>
mov    %rbx,%rax
shr    $0x20,%rax
mov    %r14,%rcx
shr    $0x20,%rcx
sub    %r14d,%ebx
lea    (%rbx,%rbx,2),%edx
sub    %ecx,%eax
lea    (%rax,%rdx,4),%eax
jmp    115f <tm_diffcalendarmonths+0x4f>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    0x2e85(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @tm_diffcalendarmonths(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca %struct.tm
%6 = bitcast %struct.tm* %4 to i64*
store i64 %0, i64* %6
%7 = bitcast %struct.tm* %5 to i64*
store i64 %1, i64* %7
%8 = bitcast %struct.tm* %4 to i64*
%9 = load i64, i64* %8
%10 = call i64 @tm_getrepresentation(i64 %9)
%11 = bitcast %struct.tm* %5 to i64*
%12 = load i64, i64* %11
%13 = call i64 @tm_getrepresentation(i64 %12)
%14 = icmp ne i64 %10, %13
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
store i32 0, i32* %3
br label %30
17: ; preds = %2
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = sub nsw i32 %19, %21
%23 = mul nsw i32 12, %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%25 = load i32, i32* %24
%26 = add nsw i32 %23, %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%28 = load i32, i32* %27
%29 = sub nsw i32 %26, %28
store i32 %29, i32* %3
br label %30
30: ; preds = %17, %15
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @tm_diffcalendarmonths(i64 %0, i64 %1) {
%3 = tail call i64 @tm_getrepresentation(i64 %0)
%4 = tail call i64 @tm_getrepresentation(i64 %1)
%5 = icmp eq i64 %3, %4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %19
8: ; preds = %2
%9 = trunc i64 %1 to i32
%10 = lshr i64 %1, 32
%11 = trunc i64 %10 to i32
%12 = trunc i64 %0 to i32
%13 = lshr i64 %0, 32
%14 = trunc i64 %13 to i32
%15 = sub nsw i32 %9, %12
%16 = mul nsw i32 %15, 12
%17 = sub i32 %11, %14
%18 = add i32 %17, %16
br label %19
19: ; preds = %8, %6
%20 = phi i32 [ 0, %6 ], [ %18, %8 ]
ret i32 %20
}