#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 {
  scalar_t__ tm_year;
  int tm_yday;
  int tm_mon;
  int tm_mday;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
scalar_t__ tm_getrepresentation(struct tm);
int /*<<< orphan*/ tm_normalize(struct tm *);
int tm_diffcalendardays(struct tm debut, struct tm fin) {
  if (tm_getrepresentation(debut) != tm_getrepresentation(fin)) {
    errno = EINVAL;
    return 0;
  }
  int coeff = 1;
  int ret = 0;
  if (fin.tm_year < debut.tm_year) {
    struct tm tmp = debut;
    debut = fin;
    fin = tmp;
    coeff = -1;
  }
  ret = fin.tm_yday - debut.tm_yday;
  debut.tm_mon = 11;
  debut.tm_mday = 31;
  for (; debut.tm_year < fin.tm_year; debut.tm_year++) {
    tm_normalize(&debut);
    ret += debut.tm_yday + 1;
  }
  return coeff * ret;
}


x86 assembly (clang, -O0):
<tm_diffcalendardays>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    (%rax),%rcx
mov    %rcx,(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x10(%rsp)
call   1040 <tm_getrepresentation@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,-0x30(%rbp)
mov    (%rax),%rcx
mov    %rcx,(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x10(%rsp)
call   1040 <tm_getrepresentation@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     11ad <tm_diffcalendardays+0x8d>
mov    0x2e42(%rip),%rax
mov    (%rax),%ecx
mov    0x2e41(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    128b <tm_diffcalendardays+0x16b>
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%rax
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    (%rax),%rax
cmp    (%rcx),%rax
jge    1222 <tm_diffcalendardays+0x102>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rcx),%rdx
mov    %rdx,-0x28(%rbp)
mov    0x8(%rcx),%rdx
mov    %rdx,-0x20(%rbp)
mov    0x10(%rcx),%rdx
mov    %rdx,-0x18(%rbp)
mov    (%rax),%rdx
mov    %rdx,(%rcx)
mov    0x8(%rax),%rdx
mov    %rdx,0x8(%rcx)
mov    0x10(%rax),%rdx
mov    %rdx,0x10(%rcx)
mov    -0x28(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rcx
mov    %rcx,0x10(%rax)
movl   $0xffffffff,-0x8(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    0x8(%rcx),%ecx
sub    0x8(%rax),%ecx
mov    %ecx,-0xc(%rbp)
movl   $0xb,0xc(%rax)
movl   $0x1f,0x10(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
cmp    (%rcx),%rax
jge    1281 <tm_diffcalendardays+0x161>
mov    -0x40(%rbp),%rdi
call   1030 <tm_normalize@plt>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%eax
add    $0x1,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1241 <tm_diffcalendardays+0x121>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_diffcalendardays>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x70(%rsp),%rax
mov    %rax,0x10(%rsp)
movaps 0x60(%rsp),%xmm0
movups %xmm0,(%rsp)
call   1040 <tm_getrepresentation@plt>
mov    %rax,%rbx
mov    0x88(%rsp),%rax
mov    %rax,0x10(%rsp)
movups 0x78(%rsp),%xmm0
movups %xmm0,(%rsp)
call   1040 <tm_getrepresentation@plt>
cmp    %rax,%rbx
jne    1205 <tm_diffcalendardays+0xe5>
lea    0x78(%rsp),%r15
lea    0x60(%rsp),%r14
mov    (%r15),%rax
mov    (%r14),%rcx
mov    $0x1,%ebp
cmp    %rcx,%rax
jge    11c2 <tm_diffcalendardays+0xa2>
mov    0x10(%r14),%rax
mov    %rax,0x30(%rsp)
movups (%r14),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x10(%r15),%rax
mov    %rax,0x10(%r14)
movups (%r15),%xmm0
movups %xmm0,(%r14)
mov    0x30(%rsp),%rax
mov    %rax,0x10(%r15)
movaps 0x20(%rsp),%xmm0
movups %xmm0,(%r15)
mov    (%r14),%rcx
mov    (%r15),%rax
mov    $0xffffffff,%ebp
mov    0x8(%r15),%ebx
sub    0x8(%r14),%ebx
movabs $0x1f0000000b,%rdx
mov    %rdx,0xc(%r14)
cmp    %rax,%rcx
jge    1200 <tm_diffcalendardays+0xe0>
nopl   (%rax)
mov    %r14,%rdi
call   1030 <tm_normalize@plt>
mov    0x8(%r14),%eax
add    %eax,%ebx
add    $0x1,%ebx
mov    (%r14),%rax
add    $0x1,%rax
mov    %rax,(%r14)
cmp    (%r15),%rax
jl     11e0 <tm_diffcalendardays+0xc0>
imul   %ebp,%ebx
jmp    1219 <tm_diffcalendardays+0xf9>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    0x2dcb(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i64, i32, i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @tm_diffcalendardays(%struct.tm* byval(%struct.tm) align 8 %0, %struct.tm* byval(%struct.tm) align 8 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.tm
%7 = call i64 @tm_getrepresentation(%struct.tm* byval(%struct.tm) align 8 %0)
%8 = call i64 @tm_getrepresentation(%struct.tm* byval(%struct.tm) align 8 %1)
%9 = icmp ne i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* @EINVAL
store i32 %11, i32* @errno
store i32 0, i32* %3
br label %54
12: ; preds = %2
store i32 1, i32* %4
store i32 0, i32* %5
%13 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 0
%14 = load i64, i64* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 0
%16 = load i64, i64* %15
%17 = icmp slt i64 %14, %16
br i1 %17, label %18, label %25
18: ; preds = %12
%19 = bitcast %struct.tm* %6 to i8*
%20 = bitcast %struct.tm* %0 to i8*
%21 = bitcast %struct.tm* %0 to i8*
%22 = bitcast %struct.tm* %1 to i8*
%23 = bitcast %struct.tm* %1 to i8*
%24 = bitcast %struct.tm* %6 to i8*
store i32 -1, i32* %4
br label %25
25: ; preds = %18, %12
%26 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 1
%29 = load i32, i32* %28
%30 = sub nsw i32 %27, %29
store i32 %30, i32* %5
%31 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 2
store i32 11, i32* %31
%32 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 3
store i32 31, i32* %32
br label %33
33: ; preds = %46, %25
%34 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 0
%35 = load i64, i64* %34
%36 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 0
%37 = load i64, i64* %36
%38 = icmp slt i64 %35, %37
br i1 %38, label %39, label %50
39: ; preds = %33
%40 = call i32 @tm_normalize(%struct.tm* %0)
%41 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 1
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
%44 = load i32, i32* %5
%45 = add nsw i32 %44, %43
store i32 %45, i32* %5
br label %46
46: ; preds = %39
%47 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 0
%48 = load i64, i64* %47
%49 = add nsw i64 %48, 1
store i64 %49, i64* %47
br label %33
50: ; preds = %33
%51 = load i32, i32* %4
%52 = load i32, i32* %5
%53 = mul nsw i32 %51, %52
store i32 %53, i32* %3
br label %54
54: ; preds = %50, %10
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.tm = type { i64, i32, i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @tm_diffcalendardays(%struct.tm* byval(%struct.tm) align 8 %0, %struct.tm* byval(%struct.tm) align 8 %1) {
%3 = alloca %struct.tm
%4 = tail call i64 @tm_getrepresentation(%struct.tm* byval(%struct.tm) align 8 %0)
%5 = tail call i64 @tm_getrepresentation(%struct.tm* byval(%struct.tm) align 8 %1)
%6 = icmp eq i64 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = load i32, i32* @EINVAL
store i32 %8, i32* @errno
br label %46
9: ; preds = %2
%10 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%13 = load i64, i64* %12
%14 = icmp slt i64 %11, %13
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = bitcast %struct.tm* %3 to i8*
%17 = bitcast %struct.tm* %0 to i8*
%18 = bitcast %struct.tm* %1 to i8*
%19 = load i64, i64* %12
%20 = load i64, i64* %10
br label %21
21: ; preds = %15, %9
%22 = phi i64 [ %20, %15 ], [ %11, %9 ]
%23 = phi i64 [ %19, %15 ], [ %13, %9 ]
%24 = phi i32 [ -1, %15 ], [ 1, %9 ]
%25 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%28 = load i32, i32* %27
%29 = sub nsw i32 %26, %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
store i32 11, i32* %30
%31 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
store i32 31, i32* %31
%32 = icmp slt i64 %23, %22
br i1 %32, label %33, label %43
33: ; preds = %21, %33
%34 = phi i32 [ %38, %33 ], [ %29, %21 ]
%35 = call i32 @tm_normalize(%struct.tm* %0)
%36 = load i32, i32* %27
%37 = add i32 %34, 1
%38 = add i32 %37, %36
%39 = load i64, i64* %12
%40 = add nsw i64 %39, 1
store i64 %40, i64* %12
%41 = load i64, i64* %10
%42 = icmp slt i64 %40, %41
br i1 %42, label %33, label %43
43: ; preds = %33, %21
%44 = phi i32 [ %29, %21 ], [ %38, %33 ]
%45 = mul nsw i32 %44, %24
br label %46
46: ; preds = %43, %7
%47 = phi i32 [ 0, %7 ], [ %45, %43 ]
ret i32 %47
}