#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 dummy;
};

/* Variables and functions */
int tm_diffmonths(struct tm, struct tm, int *, int *);
int tm_diffyears(struct tm debut, struct tm fin, int *months, int *days,
                 int *seconds) {
  int m = tm_diffmonths(debut, fin, days, seconds);
  int d = days ? *days : 0;
  int s = seconds ? *seconds : 0;
  if (months)
    *months = m >= 0 ? m % 12 : -((-m) % 12);
  else {
    if (days)
      *days = d;
    if (seconds)
      *seconds = s;
  }
  return m / 12;
}


x86 assembly (clang, -O0):
<tm_diffyears>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <tm_diffmonths@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1159 <tm_diffyears+0x49>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
jmp    1163 <tm_diffyears+0x53>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    1163 <tm_diffyears+0x53>
mov    -0x38(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1182 <tm_diffyears+0x72>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    118c <tm_diffyears+0x7c>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    118c <tm_diffyears+0x7c>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11dc <tm_diffyears+0xcc>
cmpl   $0x0,-0x2c(%rbp)
jl     11ba <tm_diffyears+0xaa>
mov    -0x2c(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %edx,-0x40(%rbp)
jmp    11ce <tm_diffyears+0xbe>
xor    %eax,%eax
sub    -0x2c(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
sub    %edx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1209 <tm_diffyears+0xf9>
cmpq   $0x0,-0x20(%rbp)
je     11f0 <tm_diffyears+0xe0>
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1204 <tm_diffyears+0xf4>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    1209 <tm_diffyears+0xf9>
mov    -0x2c(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_diffyears>:
push   %r15
push   %r14
push   %rbx
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rcx,%rdx
mov    %r8,%rcx
call   1030 <tm_diffmonths@plt>
xor    %ecx,%ecx
mov    $0x0,%edx
test   %rbx,%rbx
je     1137 <tm_diffyears+0x27>
mov    (%rbx),%edx
test   %r15,%r15
je     113f <tm_diffyears+0x2f>
mov    (%r15),%ecx
cltq
test   %r14,%r14
je     1169 <tm_diffyears+0x59>
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x21,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,2),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %edx,(%r14)
jmp    1178 <tm_diffyears+0x68>
test   %rbx,%rbx
je     1170 <tm_diffyears+0x60>
mov    %edx,(%rbx)
test   %r15,%r15
je     1178 <tm_diffyears+0x68>
mov    %ecx,(%r15)
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define i32 @tm_diffyears(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca %struct.tm
%7 = alloca %struct.tm
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
store i32 %0, i32* %14
%15 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
store i32 %1, i32* %15
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%16 = load i32*, i32** %9
%17 = load i32*, i32** %10
%18 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @tm_diffmonths(i32 %19, i32 %21, i32* %16, i32* %17)
store i32 %22, i32* %11
%23 = load i32*, i32** %9
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %5
%26 = load i32*, i32** %9
%27 = load i32, i32* %26
br label %29
28: ; preds = %5
br label %29
29: ; preds = %28, %25
%30 = phi i32 [ %27, %25 ], [ 0, %28 ]
store i32 %30, i32* %12
%31 = load i32*, i32** %10
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32*, i32** %10
%35 = load i32, i32* %34
br label %37
36: ; preds = %29
br label %37
37: ; preds = %36, %33
%38 = phi i32 [ %35, %33 ], [ 0, %36 ]
store i32 %38, i32* %13
%39 = load i32*, i32** %8
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %55
41: ; preds = %37
%42 = load i32, i32* %11
%43 = icmp sge i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* %11
%46 = srem i32 %45, 12
br label %52
47: ; preds = %41
%48 = load i32, i32* %11
%49 = sub nsw i32 0, %48
%50 = srem i32 %49, 12
%51 = sub nsw i32 0, %50
br label %52
52: ; preds = %47, %44
%53 = phi i32 [ %46, %44 ], [ %51, %47 ]
%54 = load i32*, i32** %8
store i32 %53, i32* %54
br label %68
55: ; preds = %37
%56 = load i32*, i32** %9
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %12
%60 = load i32*, i32** %9
store i32 %59, i32* %60
br label %61
61: ; preds = %58, %55
%62 = load i32*, i32** %10
%63 = icmp ne i32* %62, null
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* %13
%66 = load i32*, i32** %10
store i32 %65, i32* %66
br label %67
67: ; preds = %64, %61
br label %68
68: ; preds = %67, %52
%69 = load i32, i32* %11
%70 = sdiv i32 %69, 12
ret i32 %70
}

LLVM IR (-O2):
define i32 @tm_diffyears(i32 %0, i32 %1, i32* writeonly %2, i32* %3, i32* %4) {
%6 = tail call i32 @tm_diffmonths(i32 %0, i32 %1, i32* %3, i32* %4)
%7 = icmp eq i32* %3, null
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = load i32, i32* %3
br label %10
10: ; preds = %5, %8
%11 = phi i32 [ %9, %8 ], [ 0, %5 ]
%12 = icmp eq i32* %4, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = load i32, i32* %4
br label %15
15: ; preds = %10, %13
%16 = phi i32 [ %14, %13 ], [ 0, %10 ]
%17 = icmp eq i32* %2, null
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = srem i32 %6, 12
store i32 %19, i32* %2
br label %24
20: ; preds = %15
br i1 %7, label %22, label %21
21: ; preds = %20
store i32 %11, i32* %3
br label %22
22: ; preds = %21, %20
br i1 %12, label %24, label %23
23: ; preds = %22
store i32 %16, i32* %4
br label %24
24: ; preds = %22, %23, %18
%25 = sdiv i32 %6, 12
ret i32 %25
}