// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: cs_timegm
double cs_timegm(const struct tm *tm) {
  /* Month-to-day offset for non-leap-years. */
  static const int month_day[12] = {0,   31,  59,  90,  120, 151,
                                    181, 212, 243, 273, 304, 334};

  /* Most of the calculation is easy; leap years are the main difficulty. */
  int month = tm->tm_mon % 12;
  int year = tm->tm_year + tm->tm_mon / 12;
  int year_for_leap;
  int64_t rt;

  if (month < 0) { /* Negative values % 12 are still negative. */
    month += 12;
    --year;
  }

  /* This is the number of Februaries since 1900. */
  year_for_leap = (month > 1) ? year + 1 : year;

  rt =
      tm->tm_sec /* Seconds */
      +
      60 *
          (tm->tm_min /* Minute = 60 seconds */
           +
           60 * (tm->tm_hour /* Hour = 60 minutes */
                 +
                 24 * (month_day[month] + tm->tm_mday - 1 /* Day = 24 hours */
                       + 365 * (year - 70)                /* Year = 365 days */
                       + (year_for_leap - 69) / 4 /* Every 4 years is leap... */
                       - (year_for_leap - 1) / 100 /* Except centuries... */
                       + (year_for_leap + 299) / 400))); /* Except 400s. */
  return rt < 0 ? -1 : (double) rt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl $0xc, %ecx
cltd
idivl %ecx
movl %edx, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl $0xc, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x24(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0xc(%rbp)
jge 0x50c5
movl -0xc(%rbp), %eax
addl $0xc, %eax
movl %eax, -0xc(%rbp)
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
cmpl $0x1, -0xc(%rbp)
jle 0x50d6
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x50dc
movl -0x10(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
movslq -0xc(%rbp), %rdx
leaq 0x1a2c9(%rip), %rax     # 0x1f3d0
movl (%rax,%rdx,4), %esi
movq -0x8(%rbp), %rax
addl 0xc(%rax), %esi
subl $0x1, %esi
movl -0x10(%rbp), %eax
subl $0x46, %eax
imull $0x16d, %eax, %eax      # imm = 0x16D
addl %eax, %esi
movl -0x14(%rbp), %eax
subl $0x45, %eax
movl $0x4, %edi
cltd
idivl %edi
addl %eax, %esi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl $0x64, %edi
cltd
idivl %edi
subl %eax, %esi
movl -0x14(%rbp), %eax
addl $0x12b, %eax            # imm = 0x12B
movl $0x190, %edi            # imm = 0x190
cltd
idivl %edi
movl -0x30(%rbp), %edx
movl %eax, %edi
movl -0x2c(%rbp), %eax
addl %edi, %esi
imull $0x18, %esi, %esi
addl %esi, %edx
imull $0x3c, %edx, %edx
addl %edx, %ecx
imull $0x3c, %ecx, %ecx
addl %ecx, %eax
cltq
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x5187
movsd 0x1a178(%rip), %xmm0    # 0x1f2f8
movsd %xmm0, -0x38(%rbp)
jmp 0x5192
cvtsi2sdq -0x20(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
popq %rbp
retq
nopl (%rax)