#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 */

/* Variables and functions */
long day(double);
long day_from_year(long);
scalar_t__ in_leap_year(double);
long year_from_time(double);
double date_from_time(double t) {
  long y = year_from_time(t);
  long d = day(t) - day_from_year(y);
  d -= 31 + 28;
  if (d < 0)
    return d < -28 ? d + 31 + 28 + 1 : d + 28 + 1;
  if (in_leap_year(t)) {
    if (d == 0)
      return 29;
    --d;
  }
  long mdays, mstart;
  switch (d / 30) {
  case 0:
    return d + 1;
  case 1:
    mdays = 31;
    mstart = 31;
    break;
  case 2:
    mdays = 30;
    mstart = 31 + 30;
    break;
  case 3:
    mdays = 31;
    mstart = 31 + 30 + 31;
    break;
  case 4:
    mdays = 30;
    mstart = 31 + 30 + 31 + 30;
    break;
  case 5:
    mdays = 31;
    mstart = 31 + 30 + 31 + 30 + 31;
    break;
  case 6:
    mdays = 31;
    mstart = 31 + 30 + 31 + 30 + 31 + 31;
    break;
  case 7:
    mdays = 30;
    mstart = 31 + 30 + 31 + 30 + 31 + 31 + 30;
    break;
  case 8:
    mdays = 31;
    mstart = 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
    break;
  case 9:
    mdays = 30;
    mstart = 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
    break;
  default:
    return d - (31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) + 1;
  }
  d -= mstart;
  if (d < 0)
    d += mdays;
  return d + 1;
}


x86 assembly (clang, -O0):
<date_from_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <year_from_time@plt>
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <day@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <day_from_year@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x3b,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11de <date_from_time+0x9e>
cmpq   $0xffffffffffffffe4,-0x20(%rbp)
jge    11bb <date_from_time+0x7b>
mov    -0x20(%rbp),%rax
add    $0x1f,%rax
add    $0x1c,%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11cb <date_from_time+0x8b>
mov    -0x20(%rbp),%rax
add    $0x1c,%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    138e <date_from_time+0x24e>
movsd  -0x10(%rbp),%xmm0
call   1040 <in_leap_year@plt>
cmp    $0x0,%rax
je     121b <date_from_time+0xdb>
cmpq   $0x0,-0x20(%rbp)
jne    120f <date_from_time+0xcf>
movsd  0xdfb(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    138e <date_from_time+0x24e>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
movabs $0x8888888888888889,%rdx
88 88 88
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
add    %rcx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x4,%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
sub    $0x9,%rax
ja     1339 <date_from_time+0x1f9>
mov    -0x48(%rbp),%rax
lea    0xdac(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    138e <date_from_time+0x24e>
movq   $0x1f,-0x28(%rbp)
movq   $0x1f,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
movq   $0x1e,-0x28(%rbp)
movq   $0x3d,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
movq   $0x1f,-0x28(%rbp)
movq   $0x5c,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
movq   $0x1e,-0x28(%rbp)
movq   $0x7a,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
movq   $0x1f,-0x28(%rbp)
movq   $0x99,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
movq   $0x1f,-0x28(%rbp)
movq   $0xb8,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
movq   $0x1e,-0x28(%rbp)
movq   $0xd6,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
movq   $0x1f,-0x28(%rbp)
movq   $0xf5,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
movq   $0x1e,-0x28(%rbp)
movq   $0x113,-0x30(%rbp)
jmp    1356 <date_from_time+0x216>
mov    -0x20(%rbp),%rax
sub    $0x113,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    138e <date_from_time+0x24e>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    137c <date_from_time+0x23c>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<date_from_time>:
push   %r14
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
call   1060 <year_from_time@plt>
mov    %rax,%r14
movsd  (%rsp),%xmm0
call   1050 <day@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <day_from_year@plt>
sub    %rax,%rbx
cmp    $0x3a,%rbx
jg     118c <date_from_time+0x4c>
lea    -0x1e(%rbx),%rax
lea    0x1(%rbx),%rcx
cmp    $0x1f,%rbx
cmovl  %rcx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
jmp    125d <date_from_time+0x11d>
lea    -0x3b(%rbx),%r14
movsd  (%rsp),%xmm0
call   1040 <in_leap_year@plt>
test   %rax,%rax
je     11ab <date_from_time+0x6b>
test   %r14,%r14
je     11ea <date_from_time+0xaa>
add    $0xffffffffffffffc4,%rbx
mov    %rbx,%r14
movabs $0x8888888888888889,%rcx
88 88 88
mov    %r14,%rax
mul    %rcx
shr    $0x4,%rdx
cmp    $0x9,%rdx
ja     11f4 <date_from_time+0xb4>
mov    $0xffffffffffffffe1,%rcx
mov    $0x1f,%eax
lea    0xe30(%rip),%rsi
movslq (%rsi,%rdx,4),%rdx
add    %rsi,%rdx
jmp    *%rdx
mov    $0xffffffffffffffc3,%rcx
jmp    123a <date_from_time+0xfa>
movsd  0xe0e(%rip),%xmm0
jmp    125d <date_from_time+0x11d>
add    $0xfffffffffffffeed,%r14
jmp    1251 <date_from_time+0x111>
mov    $0xffffffffffffffa4,%rcx
jmp    123f <date_from_time+0xff>
mov    $0xffffffffffffff86,%rcx
jmp    123a <date_from_time+0xfa>
mov    $0xffffffffffffff67,%rcx
jmp    123f <date_from_time+0xff>
mov    $0xffffffffffffff48,%rcx
jmp    123f <date_from_time+0xff>
mov    $0xffffffffffffff2a,%rcx
jmp    123a <date_from_time+0xfa>
mov    $0xffffffffffffff0b,%rcx
jmp    123f <date_from_time+0xff>
mov    $0xfffffffffffffeed,%rcx
mov    $0x1e,%eax
add    %r14,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
and    %edx,%eax
add    %rcx,%rax
mov    %rax,%r14
add    $0x1,%r14
xorps  %xmm0,%xmm0
cvtsi2sd %r14,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @date_from_time(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store double %0, double* %3
%8 = load double, double* %3
%9 = call i64 @year_from_time(double %8)
store i64 %9, i64* %4
%10 = load double, double* %3
%11 = call i64 @day(double %10)
%12 = load i64, i64* %4
%13 = call i64 @day_from_year(i64 %12)
%14 = sub nsw i64 %11, %13
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = sub nsw i64 %15, 59
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %34
19: ; preds = %1
%20 = load i64, i64* %5
%21 = icmp slt i64 %20, -28
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i64, i64* %5
%24 = add nsw i64 %23, 31
%25 = add nsw i64 %24, 28
%26 = add nsw i64 %25, 1
br label %31
27: ; preds = %19
%28 = load i64, i64* %5
%29 = add nsw i64 %28, 28
%30 = add nsw i64 %29, 1
br label %31
31: ; preds = %27, %22
%32 = phi i64 [ %26, %22 ], [ %30, %27 ]
%33 = sitofp i64 %32 to double
store double %33, double* %2
br label %80
34: ; preds = %1
%35 = load double, double* %3
%36 = call i64 @in_leap_year(double %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i64, i64* %5
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
store double 2.900000e+01, double* %2
br label %80
42: ; preds = %38
%43 = load i64, i64* %5
%44 = add nsw i64 %43, -1
store i64 %44, i64* %5
br label %45
45: ; preds = %42, %34
%46 = load i64, i64* %5
%47 = sdiv i64 %46, 30
switch i64 %47, label %61 [
i64 0, label %48
i64 1, label %52
i64 2, label %53
i64 3, label %54
i64 4, label %55
i64 5, label %56
i64 6, label %57
i64 7, label %58
i64 8, label %59
i64 9, label %60
]
48: ; preds = %45
%49 = load i64, i64* %5
%50 = add nsw i64 %49, 1
%51 = sitofp i64 %50 to double
store double %51, double* %2
br label %80
52: ; preds = %45
store i64 31, i64* %6
store i64 31, i64* %7
br label %66
53: ; preds = %45
store i64 30, i64* %6
store i64 61, i64* %7
br label %66
54: ; preds = %45
store i64 31, i64* %6
store i64 92, i64* %7
br label %66
55: ; preds = %45
store i64 30, i64* %6
store i64 122, i64* %7
br label %66
56: ; preds = %45
store i64 31, i64* %6
store i64 153, i64* %7
br label %66
57: ; preds = %45
store i64 31, i64* %6
store i64 184, i64* %7
br label %66
58: ; preds = %45
store i64 30, i64* %6
store i64 214, i64* %7
br label %66
59: ; preds = %45
store i64 31, i64* %6
store i64 245, i64* %7
br label %66
60: ; preds = %45
store i64 30, i64* %6
store i64 275, i64* %7
br label %66
61: ; preds = %45
%62 = load i64, i64* %5
%63 = sub nsw i64 %62, 275
%64 = add nsw i64 %63, 1
%65 = sitofp i64 %64 to double
store double %65, double* %2
br label %80
66: ; preds = %60, %59, %58, %57, %56, %55, %54, %53, %52
%67 = load i64, i64* %7
%68 = load i64, i64* %5
%69 = sub nsw i64 %68, %67
store i64 %69, i64* %5
%70 = load i64, i64* %5
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %66
%73 = load i64, i64* %6
%74 = load i64, i64* %5
%75 = add nsw i64 %74, %73
store i64 %75, i64* %5
br label %76
76: ; preds = %72, %66
%77 = load i64, i64* %5
%78 = add nsw i64 %77, 1
%79 = sitofp i64 %78 to double
store double %79, double* %2
br label %80
80: ; preds = %76, %61, %48, %41, %31
%81 = load double, double* %2
ret double %81
}

LLVM IR (-O2):
define double @date_from_time(double %0) {
%2 = tail call i64 @year_from_time(double %0)
%3 = tail call i64 @day(double %0)
%4 = tail call i64 @day_from_year(i64 %2)
%5 = sub nsw i64 %3, %4
%6 = add nsw i64 %5, -59
%7 = icmp slt i64 %5, 59
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = icmp slt i64 %5, 31
%10 = select i1 %9, i64 1, i64 -30
%11 = add nsw i64 %10, %5
%12 = sitofp i64 %11 to double
br label %44
13: ; preds = %1
%14 = tail call i64 @in_leap_year(double %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = icmp eq i64 %6, 0
br i1 %17, label %44, label %18
18: ; preds = %16
%19 = add nsw i64 %5, -60
br label %20
20: ; preds = %18, %13
%21 = phi i64 [ %19, %18 ], [ %6, %13 ]
%22 = udiv i64 %21, 30
switch i64 %22, label %31 [
i64 0, label %40
i64 1, label %33
i64 2, label %23
i64 3, label %24
i64 4, label %25
i64 5, label %26
i64 6, label %27
i64 7, label %28
i64 8, label %29
i64 9, label %30
]
23: ; preds = %20
br label %33
24: ; preds = %20
br label %33
25: ; preds = %20
br label %33
26: ; preds = %20
br label %33
27: ; preds = %20
br label %33
28: ; preds = %20
br label %33
29: ; preds = %20
br label %33
30: ; preds = %20
br label %33
31: ; preds = %20
%32 = add nsw i64 %21, -275
br label %40
33: ; preds = %20, %30, %29, %28, %27, %26, %25, %24, %23
%34 = phi i64 [ 30, %30 ], [ 31, %29 ], [ 30, %28 ], [ 31, %27 ], [ 31, %26 ], [ 30, %25 ], [ 31, %24 ], [ 30, %23 ], [ 31, %20 ]
%35 = phi i64 [ -275, %30 ], [ -245, %29 ], [ -214, %28 ], [ -184, %27 ], [ -153, %26 ], [ -122, %25 ], [ -92, %24 ], [ -61, %23 ], [ -31, %20 ]
%36 = add nsw i64 %35, %21
%37 = icmp slt i64 %36, 0
%38 = select i1 %37, i64 %34, i64 0
%39 = add nsw i64 %38, %36
br label %40
40: ; preds = %20, %33, %31
%41 = phi i64 [ %32, %31 ], [ %39, %33 ], [ %21, %20 ]
%42 = add nsw i64 %41, 1
%43 = sitofp i64 %42 to double
br label %44
44: ; preds = %16, %40, %8
%45 = phi double [ %12, %8 ], [ %43, %40 ], [ 2.900000e+01, %16 ]
ret double %45
}