#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_year;
  int tm_mon;
  int tm_mday;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
float difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mktime(struct tm *);
int diffdays(int newd, int oldd) {
  int ano, mes, dia;
  float fsec;
  time_t ttnew, ttold;
  struct tm tmnew = {0}, tmold = {0};
  ano = oldd / 10000;
  oldd -= ano * 10000;
  mes = oldd / 100;
  oldd -= mes * 100;
  dia = oldd;
  tmold.tm_year = ano - 1900;
  tmold.tm_mon = mes - 1;
  tmold.tm_mday = dia;
  ttold = mktime(&tmold);
  ano = newd / 10000;
  newd -= ano * 10000;
  mes = newd / 100;
  newd -= mes * 100;
  dia = newd;
  tmnew.tm_year = ano - 1900;
  tmnew.tm_mon = mes - 1;
  tmnew.tm_mday = dia;
  ttnew = mktime(&tmnew);
  fsec = difftime(ttnew, ttold);
  dia = fsec / 86400.0;
  return dia;
}


x86 assembly (clang, -O0):
<diffdays>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
imul   $0x2710,-0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
imul   $0x64,-0x10(%rbp),%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
imul   $0x2710,-0xc(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
imul   $0x64,-0x10(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <difftime@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdbb(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diffdays>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
movl   $0x0,0x24(%rsp)
movl   $0x0,0x14(%rsp)
movslq %esi,%rcx
imul   $0x68db8bad,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rax
lea    (%rax,%rdx,1),%esi
imul   $0xffffd8f0,%esi,%esi
add    %esi,%ecx
movslq %ecx,%rcx
imul   $0x51eb851f,%rcx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x25,%rsi
lea    (%rsi,%rdi,1),%ebp
imul   $0xffffff9c,%ebp,%ebp
add    %ebp,%ecx
add    %edx,%eax
add    $0xfffff894,%eax
mov    %eax,0x8(%rsp)
lea    -0x1(%rsi,%rdi,1),%eax
mov    %eax,0xc(%rsp)
mov    %ecx,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <mktime@plt>
mov    %eax,%ebp
movslq %ebx,%rcx
imul   $0x68db8bad,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rax
lea    (%rax,%rdx,1),%esi
imul   $0xffffd8f0,%esi,%esi
add    %esi,%ecx
movslq %ecx,%rcx
imul   $0x51eb851f,%rcx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x25,%rsi
lea    (%rsi,%rdi,1),%ebx
imul   $0xffffff9c,%ebx,%ebx
add    %ebx,%ecx
add    %edx,%eax
add    $0xfffff894,%eax
mov    %eax,0x18(%rsp)
lea    -0x1(%rsi,%rdi,1),%eax
mov    %eax,0x1c(%rsp)
mov    %ecx,0x20(%rsp)
lea    0x18(%rsp),%rdi
call   1040 <mktime@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1030 <difftime@plt>
cvtss2sd %xmm0,%xmm0
divsd  0xdf5(%rip),%xmm0
cvttsd2si %xmm0,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32 }
define i32 @diffdays(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.tm
%12 = alloca %struct.tm
store i32 %0, i32* %3
store i32 %1, i32* %4
%13 = bitcast %struct.tm* %11 to i8*
%14 = bitcast %struct.tm* %12 to i8*
%15 = load i32, i32* %4
%16 = sdiv i32 %15, 10000
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 10000
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, %18
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = sdiv i32 %21, 100
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = mul nsw i32 %23, 100
%25 = load i32, i32* %4
%26 = sub nsw i32 %25, %24
store i32 %26, i32* %4
%27 = load i32, i32* %4
store i32 %27, i32* %7
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1900
%30 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* %6
%32 = sub nsw i32 %31, 1
%33 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* %7
%35 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 2
store i32 %34, i32* %35
%36 = call i32 @mktime(%struct.tm* %12)
store i32 %36, i32* %10
%37 = load i32, i32* %3
%38 = sdiv i32 %37, 10000
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = mul nsw i32 %39, 10000
%41 = load i32, i32* %3
%42 = sub nsw i32 %41, %40
store i32 %42, i32* %3
%43 = load i32, i32* %3
%44 = sdiv i32 %43, 100
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = mul nsw i32 %45, 100
%47 = load i32, i32* %3
%48 = sub nsw i32 %47, %46
store i32 %48, i32* %3
%49 = load i32, i32* %3
store i32 %49, i32* %7
%50 = load i32, i32* %5
%51 = sub nsw i32 %50, 1900
%52 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 0
store i32 %51, i32* %52
%53 = load i32, i32* %6
%54 = sub nsw i32 %53, 1
%55 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 1
store i32 %54, i32* %55
%56 = load i32, i32* %7
%57 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 2
store i32 %56, i32* %57
%58 = call i32 @mktime(%struct.tm* %11)
store i32 %58, i32* %9
%59 = load i32, i32* %9
%60 = load i32, i32* %10
%61 = call float @difftime(i32 %59, i32 %60)
store float %61, float* %8
%62 = load float, float* %8
%63 = fpext float %62 to double
%64 = fdiv double %63, 8.640000e+04
%65 = fptosi double %64 to i32
store i32 %65, i32* %7
%66 = load i32, i32* %7
ret i32 %66
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32 }
define i32 @diffdays(i32 %0, i32 %1) {
%3 = alloca %struct.tm
%4 = alloca %struct.tm
%5 = bitcast %struct.tm* %3 to i8*
%6 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
store i32 0, i32* %6
%7 = bitcast %struct.tm* %4 to i8*
%8 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
store i32 0, i32* %8
%9 = sdiv i32 %1, 10000
%10 = mul nsw i32 %9, -10000
%11 = add i32 %10, %1
%12 = sdiv i32 %11, 100
%13 = mul nsw i32 %12, -100
%14 = add i32 %13, %11
%15 = add nsw i32 %9, -1900
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
store i32 %15, i32* %16
%17 = add nsw i32 %12, -1
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
store i32 %14, i32* %19
%20 = call i32 @mktime(%struct.tm* %4)
%21 = sdiv i32 %0, 10000
%22 = mul nsw i32 %21, -10000
%23 = add i32 %22, %0
%24 = sdiv i32 %23, 100
%25 = mul nsw i32 %24, -100
%26 = add i32 %25, %23
%27 = add nsw i32 %21, -1900
%28 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
store i32 %27, i32* %28
%29 = add nsw i32 %24, -1
%30 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
store i32 %26, i32* %31
%32 = call i32 @mktime(%struct.tm* %3)
%33 = tail call float @difftime(i32 %32, i32 %20)
%34 = fpext float %33 to double
%35 = fdiv double %34, 8.640000e+04
%36 = fptosi double %35 to i32
ret i32 %36
}