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

/* Variables and functions */
int difftime(int /*<<< orphan*/, int /*<<< orphan*/);
struct tm *localtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ tmcpy(struct tm *, struct tm *);
int diffdays(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 difftime(mktime(&ref), mktime(current)) / 86400;
}


x86 assembly (clang, -O0):
<diffdays>:
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,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1060 <tmcpy@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x5,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x30(%rbp),%rax
movl   $0x5,(%rax)
lea    -0x28(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <mktime@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   1040 <difftime@plt>
mov    $0x15180,%ecx
cltd
idiv   %ecx
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diffdays>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <localtime@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <tmcpy@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movl   $0x5,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rax)
movl   $0x5,(%rax)
mov    %r14,%rdi
call   1050 <mktime@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <mktime@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <difftime@plt>
cltq
imul   $0xffffffffc22e4507,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x10,%eax
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i64, i64 }
define i32 @diffdays(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 2
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
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 2
store i64 0, i64* %17
%18 = load %struct.tm*, %struct.tm** %6
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 1
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 = call i32 @mktime(%struct.tm* %5)
%23 = load %struct.tm*, %struct.tm** %6
%24 = call i32 @mktime(%struct.tm* %23)
%25 = call i32 @difftime(i32 %22, i32 %24)
%26 = sdiv i32 %25, 86400
ret i32 %26
}

LLVM IR (-O2):
%struct.tm = type { i32, i64, i64 }
define i32 @diffdays(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 1
%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 1
%12 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 0
%13 = bitcast i64* %11 to i8*
store i32 5, i32* %12
%14 = call i32 @mktime(%struct.tm* %3)
%15 = call i32 @mktime(%struct.tm* %10)
%16 = call i32 @difftime(i32 %14, i32 %15)
%17 = sdiv i32 %16, 86400
ret i32 %17
}