#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_hour;
  scalar_t__ tm_min;
  scalar_t__ tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ tm_adddays(struct tm *, int);
int tm_diffcalendardays(struct tm, struct tm);
int tm_diffseconds(struct tm, struct tm);
scalar_t__ tm_getrepresentation(struct tm);
int tm_diffdays(struct tm debut, struct tm fin, int *seconds) {
  if (tm_getrepresentation(debut) != tm_getrepresentation(fin)) {
    errno = EINVAL;
    return 0;
  }
  int coeff = 1;
  if (tm_diffseconds(debut, fin) < 0) {
    struct tm tmp = debut;
    debut = fin;
    fin = tmp;
    coeff = -1;
  }
  int ret = tm_diffcalendardays(debut, fin);
  if (fin.tm_hour < debut.tm_hour ||
      (fin.tm_hour == debut.tm_hour && fin.tm_min < debut.tm_min) ||
      (fin.tm_hour == debut.tm_hour && fin.tm_min == debut.tm_min &&
       fin.tm_sec < debut.tm_sec))
    if (ret > 0)
      ret--;
  if (seconds) {
    tm_adddays(&debut, ret);
    *seconds = coeff * tm_diffseconds(debut, fin);
  }
  return coeff * ret;
}


x86 assembly (clang, -O0):
<tm_diffdays>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    %rdi,-0x10(%rbp)
mov    (%rax),%rcx
mov    %rcx,(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x10(%rsp)
call   1050 <tm_getrepresentation@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,-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   1050 <tm_getrepresentation@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     11d4 <tm_diffdays+0x94>
mov    0x2e1b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1a(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    13c5 <tm_diffdays+0x285>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
movl   $0x1,-0x14(%rbp)
mov    (%rcx),%rdx
mov    %rdx,(%rsp)
mov    0x8(%rcx),%rdx
mov    %rdx,0x8(%rsp)
mov    0x10(%rcx),%rcx
mov    %rcx,0x10(%rsp)
mov    (%rax),%rcx
mov    %rcx,0x18(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x20(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x28(%rsp)
call   1040 <tm_diffseconds@plt>
cmp    $0x0,%eax
jge    1277 <tm_diffdays+0x137>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    (%rcx),%rdx
mov    %rdx,-0x30(%rbp)
mov    0x8(%rcx),%rdx
mov    %rdx,-0x28(%rbp)
mov    0x10(%rcx),%rdx
mov    %rdx,-0x20(%rbp)
mov    (%rax),%rdx
mov    %rdx,(%rcx)
mov    0x8(%rax),%rdx
mov    %rdx,0x8(%rcx)
mov    0x10(%rax),%rdx
mov    %rdx,0x10(%rcx)
mov    -0x30(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rcx
mov    %rcx,0x10(%rax)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    (%rcx),%rdx
mov    %rdx,(%rsp)
mov    0x8(%rcx),%rdx
mov    %rdx,0x8(%rsp)
mov    0x10(%rcx),%rcx
mov    %rcx,0x10(%rsp)
mov    (%rax),%rcx
mov    %rcx,0x18(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x20(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x28(%rsp)
call   1060 <tm_diffcalendardays@plt>
mov    -0x50(%rbp),%rcx
mov    %eax,%edx
mov    -0x48(%rbp),%rax
mov    %edx,-0x34(%rbp)
mov    (%rax),%rax
cmp    (%rcx),%rax
jl     133a <tm_diffdays+0x1fa>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
cmp    (%rcx),%rax
jne    12fa <tm_diffdays+0x1ba>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
cmp    0x8(%rcx),%rax
jl     133a <tm_diffdays+0x1fa>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
cmp    (%rcx),%rax
jne    1352 <tm_diffdays+0x212>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
cmp    0x8(%rcx),%rax
jne    1352 <tm_diffdays+0x212>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%rax
cmp    0x10(%rcx),%rax
jge    1352 <tm_diffdays+0x212>
cmpl   $0x0,-0x34(%rbp)
jle    134d <tm_diffdays+0x20d>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1352 <tm_diffdays+0x212>
cmpq   $0x0,-0x10(%rbp)
je     13bb <tm_diffdays+0x27b>
mov    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1030 <tm_adddays@plt>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    -0x14(%rbp),%edx
mov    %edx,-0x54(%rbp)
mov    (%rcx),%rdx
mov    %rdx,(%rsp)
mov    0x8(%rcx),%rdx
mov    %rdx,0x8(%rsp)
mov    0x10(%rcx),%rcx
mov    %rcx,0x10(%rsp)
mov    (%rax),%rcx
mov    %rcx,0x18(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x20(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x28(%rsp)
call   1040 <tm_diffseconds@plt>
mov    -0x54(%rbp),%ecx
imul   %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
imul   -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_diffdays>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%r14
mov    0x90(%rsp),%rax
mov    %rax,0x10(%rsp)
movaps 0x80(%rsp),%xmm0
movups %xmm0,(%rsp)
call   1050 <tm_getrepresentation@plt>
mov    %rax,%rbx
mov    0xa8(%rsp),%rax
mov    %rax,0x10(%rsp)
movups 0x98(%rsp),%xmm0
movups %xmm0,(%rsp)
call   1050 <tm_getrepresentation@plt>
cmp    %rax,%rbx
jne    124a <tm_diffdays+0x10a>
lea    0x98(%rsp),%r15
lea    0x80(%rsp),%rbx
mov    0x10(%r15),%rax
mov    %rax,0x28(%rsp)
movups (%r15),%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rbx),%rax
mov    %rax,0x10(%rsp)
movups (%rbx),%xmm0
movups %xmm0,(%rsp)
call   1040 <tm_diffseconds@plt>
mov    $0x1,%r12d
test   %eax,%eax
jns    1210 <tm_diffdays+0xd0>
mov    0x10(%rbx),%rax
mov    %rax,0x40(%rsp)
movups (%rbx),%xmm0
movaps %xmm0,0x30(%rsp)
mov    0x10(%r15),%rax
mov    %rax,0x10(%rbx)
movups (%r15),%xmm0
movups %xmm0,(%rbx)
mov    0x40(%rsp),%rax
mov    %rax,0x10(%r15)
movaps 0x30(%rsp),%xmm0
movups %xmm0,(%r15)
mov    $0xffffffff,%r12d
mov    0x10(%r15),%rax
mov    %rax,0x28(%rsp)
movups (%r15),%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rbx),%rax
mov    %rax,0x10(%rsp)
movups (%rbx),%xmm0
movups %xmm0,(%rsp)
call   1060 <tm_diffcalendardays@plt>
mov    %eax,%ebp
mov    (%rbx),%rax
cmp    %rax,(%r15)
jge    1260 <tm_diffdays+0x120>
test   %ebp,%ebp
jle    1278 <tm_diffdays+0x138>
add    $0xffffffff,%ebp
jmp    1278 <tm_diffdays+0x138>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    0x2d86(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebp,%ebp
jmp    12b9 <tm_diffdays+0x179>
jne    1278 <tm_diffdays+0x138>
mov    0x8(%rbx),%rax
cmp    %rax,0x8(%r15)
jl     1241 <tm_diffdays+0x101>
jne    1278 <tm_diffdays+0x138>
mov    0x10(%r15),%rax
cmp    0x10(%rbx),%rax
jl     1241 <tm_diffdays+0x101>
test   %r14,%r14
je     12b5 <tm_diffdays+0x175>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <tm_adddays@plt>
mov    0x10(%r15),%rax
mov    %rax,0x28(%rsp)
movups (%r15),%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rbx),%rax
mov    %rax,0x10(%rsp)
movups (%rbx),%xmm0
movups %xmm0,(%rsp)
call   1040 <tm_diffseconds@plt>
imul   %r12d,%eax
mov    %eax,(%r14)
imul   %r12d,%ebp
mov    %ebp,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i64, i64, i64 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @tm_diffdays(%struct.tm* byval(%struct.tm) align 8 %0, %struct.tm* byval(%struct.tm) align 8 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %struct.tm
%8 = alloca i32
store i32* %2, i32** %5
%9 = call i64 @tm_getrepresentation(%struct.tm* byval(%struct.tm) align 8 %0)
%10 = call i64 @tm_getrepresentation(%struct.tm* byval(%struct.tm) align 8 %1)
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32, i32* @EINVAL
store i32 %13, i32* @errno
store i32 0, i32* %4
br label %82
14: ; preds = %3
store i32 1, i32* %6
%15 = call i32 @tm_diffseconds(%struct.tm* byval(%struct.tm) align 8 %0, %struct.tm* byval(%struct.tm) align 8 %1)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = bitcast %struct.tm* %7 to i8*
%19 = bitcast %struct.tm* %0 to i8*
%20 = bitcast %struct.tm* %0 to i8*
%21 = bitcast %struct.tm* %1 to i8*
%22 = bitcast %struct.tm* %1 to i8*
%23 = bitcast %struct.tm* %7 to i8*
store i32 -1, i32* %6
br label %24
24: ; preds = %17, %14
%25 = call i32 @tm_diffcalendardays(%struct.tm* byval(%struct.tm) align 8 %0, %struct.tm* byval(%struct.tm) align 8 %1)
store i32 %25, i32* %8
%26 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 0
%27 = load i64, i64* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 0
%29 = load i64, i64* %28
%30 = icmp slt i64 %27, %29
br i1 %30, label %61, label %31
31: ; preds = %24
%32 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 0
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 0
%35 = load i64, i64* %34
%36 = icmp eq i64 %33, %35
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 1
%39 = load i64, i64* %38
%40 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 1
%41 = load i64, i64* %40
%42 = icmp slt i64 %39, %41
br i1 %42, label %61, label %43
43: ; preds = %37, %31
%44 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 0
%45 = load i64, i64* %44
%46 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 0
%47 = load i64, i64* %46
%48 = icmp eq i64 %45, %47
br i1 %48, label %49, label %68
49: ; preds = %43
%50 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 1
%51 = load i64, i64* %50
%52 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 1
%53 = load i64, i64* %52
%54 = icmp eq i64 %51, %53
br i1 %54, label %55, label %68
55: ; preds = %49
%56 = getelementptr inbounds %struct.tm, %struct.tm* %1, i32 0, i32 2
%57 = load i64, i64* %56
%58 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 2
%59 = load i64, i64* %58
%60 = icmp slt i64 %57, %59
br i1 %60, label %61, label %68
61: ; preds = %55, %37, %24
%62 = load i32, i32* %8
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* %8
%66 = add nsw i32 %65, -1
store i32 %66, i32* %8
br label %67
67: ; preds = %64, %61
br label %68
68: ; preds = %67, %55, %49, %43
%69 = load i32*, i32** %5
%70 = icmp ne i32* %69, null
br i1 %70, label %71, label %78
71: ; preds = %68
%72 = load i32, i32* %8
%73 = call i32 @tm_adddays(%struct.tm* %0, i32 %72)
%74 = load i32, i32* %6
%75 = call i32 @tm_diffseconds(%struct.tm* byval(%struct.tm) align 8 %0, %struct.tm* byval(%struct.tm) align 8 %1)
%76 = mul nsw i32 %74, %75
%77 = load i32*, i32** %5
store i32 %76, i32* %77
br label %78
78: ; preds = %71, %68
%79 = load i32, i32* %6
%80 = load i32, i32* %8
%81 = mul nsw i32 %79, %80
store i32 %81, i32* %4
br label %82
82: ; preds = %78, %12
%83 = load i32, i32* %4
ret i32 %83
}

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