user: Please show me the C implementation that matches the assembly code listed below:

```asm
<xgetdate_r>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  sub    $0x78,%rsp
  mov    (%rdx),%rsi
  mov    %fs:0x28,%rax
  mov    %rax,0x68(%rsp)
  xor    %eax,%eax
  test   %rsi,%rsi
  je     L39
  mov    D8(%rip),%r12
  mov    %rdi,%rbx
  lea    0x8(%rdx),%r13
  nopw   0x0(%rax,%rax,1)
L82:
  mov    (%r12),%rax
  mov    %rbp,%rdx
  mov    %rbx,%rdi
  movl   $0xffffffff,0x38(%rbp)
  movq   $0x0,0x48(%rbp)
  movq   %rax,%xmm0
  mov    %rax,0x30(%rbp)
  movq   $0x0,0x40(%rbp)
  punpcklqdq %xmm0,%xmm0
  movups %xmm0,0x0(%rbp)
  movups %xmm0,0x10(%rbp)
  movups %xmm0,0x20(%rbp)
  call   <my_strptime@plt>
  test   %rax,%rax
  je     L42
  cmpb   $0x0,(%rax)
  je     L274
L42:
  mov    0x0(%r13),%rsi
  add    $0x8,%r13
  test   %rsi,%rsi
  jne    L82
  test   %rax,%rax
  je     L39
  cmpb   $0x0,(%rax)
  je     L274
L39:
  mov    $0x7,%eax
L61:
  mov    0x68(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L325
  add    $0x78,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  nopl   0x0(%rax)
L274:
  lea    0x8(%rsp),%r13
  mov    %r13,%rdi
  call   <time@plt>
  lea    0x10(%rsp),%rsi
  mov    %r13,%rdi
  call   <localtime_r@plt>
  mov    0x18(%rbp),%rsi
  cmp    $0x6,%rsi
  jbe    L317
  mov    (%r12),%rcx
  mov    0x8(%rbp),%r8
  xor    %r9d,%r9d
  mov    0x0(%rbp),%rdi
L289:
  cmp    $0xb,%r8
  ja     L168
  cmp    %rcx,0x10(%rbp)
  je     L100
L168:
  mov    0x20(%rbp),%rax
  mov    0x30(%rbp),%rdx
  mov    0x28(%rbp),%rsi
  cmp    %rcx,%rax
  je     L102
L123:
  cmp    $0x17,%rax
  ja     L67
  cmp    %rcx,%rdi
  je     L355
L54:
  cmp    %rcx,%rax
  je     L121
L118:
  cmp    %rcx,%rdx
  je     L358
L145:
  cmp    %rcx,%rsi
  je     L190
L62:
  test   %r9d,%r9d
  jne    L5
  mov    0x0(%rbp),%rax
  mov    0x10(%rbp),%rdx
  mov    0x8(%rbp),%rsi
  lea    0x76c(%rax),%rdi
  call   <check_mday@plt>
  test   %eax,%eax
  je     L339
L5:
  mov    %rbp,%rdi
  call   <mktime@plt>
  cmp    $0xffffffffffffffff,%rax
  sete   %al
  movzbl %al,%eax
  shl    $0x3,%eax
  jmp    L61
  nopl   0x0(%rax)
L317:
  mov    0x0(%rbp),%rdi
  mov    (%r12),%rcx
  xor    %r9d,%r9d
  mov    0x8(%rbp),%r8
  cmp    %rcx,%rdi
  jne    L289
  cmp    %r8,%rdi
  jne    L289
  cmp    0x10(%rbp),%rdi
  jne    L168
  mov    %rsi,%r9
  sub    0x28(%rsp),%r9
  mov    0x10(%rsp),%rdi
  movabs $0x4924924924924925,%rdx
  add    $0x7,%r9
  mov    0x18(%rsp),%r8
  mov    %r9,%rax
  mov    %rdi,0x0(%rbp)
  imul   %rdx
  mov    %r8,0x8(%rbp)
  mov    %rdx,%rax
  mov    %r9,%rdx
  sar    $0x3f,%rdx
  sar    %rax
  sub    %rdx,%rax
  lea    0x0(,%rax,8),%rdx
  sub    %rax,%rdx
  mov    %r9,%rax
  mov    $0x1,%r9d
  sub    %rdx,%rax
  add    0x20(%rsp),%rax
  mov    %rax,0x10(%rbp)
  jmp    L289
  cs nopw 0x0(%rax,%rax,1)
L355:
  mov    0x10(%rsp),%rdi
  mov    %rdi,%r8
  cmp    %rcx,0x8(%rbp)
  jne    L184
  cmp    %rcx,0x10(%rbp)
  jne    L184
  cmp    %rcx,0x18(%rbp)
  jne    L184
  mov    %rax,%r8
  sub    0x30(%rsp),%r8
  movq   %rdi,%xmm0
  mov    $0x1,%r9d
  shr    $0x3f,%r8
  add    0x20(%rsp),%r8
  movhps 0x18(%rsp),%xmm0
  mov    %r8,0x10(%rbp)
  movups %xmm0,0x0(%rbp)
  nopl   0x0(%rax,%rax,1)
L67:
  cmp    %rcx,%rdi
  jne    L54
  mov    0x10(%rsp),%r8
L184:
  mov    %r8,0x0(%rbp)
  cmp    %rcx,%rax
  jne    L118
L121:
  movq   $0x0,0x20(%rbp)
  cmp    %rcx,%rdx
  jne    L145
L358:
  movq   $0x0,0x30(%rbp)
  cmp    %rcx,%rsi
  jne    L62
L190:
  movq   $0x0,0x28(%rbp)
  jmp    L62
L100:
  cmp    %rcx,%rdi
  je     L111
L345:
  mov    %esi,%edx
  mov    %r8,%rsi
  call   <first_wday@plt>
  mov    (%r12),%rcx
  mov    0x0(%rbp),%rdi
  mov    $0x1,%r9d
  mov    %rax,0x10(%rbp)
  jmp    L168
  nopl   0x0(%rax,%rax,1)
L102:
  cmp    %rcx,%rdx
  jne    L123
  cmp    %rcx,%rsi
  jne    L123
  mov    0x30(%rsp),%rax
  mov    0x40(%rsp),%rdx
  mov    0x38(%rsp),%rsi
  mov    %rax,0x20(%rbp)
  mov    %rdx,0x30(%rbp)
  mov    %rsi,0x28(%rbp)
  jmp    L123
L339:
  mov    $0x8,%eax
  jmp    L61
L111:
  mov    %r8,%rdi
  sub    0x18(%rsp),%rdi
  shr    $0x3f,%rdi
  add    0x10(%rsp),%rdi
  mov    %rdi,0x0(%rbp)
  jmp    L345
L325:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int xgetdate_r(const char *string, struct tm *tp, const char *const *template) {
  const char *line;
  char *result = NULL;
  time_t timer;
  struct tm tm;
  int mday_ok = 0;
  line = NULL;
  while ((line = *template ++)) {
    tp->tm_year = tp->tm_mon = tp->tm_mday = tp->tm_wday = INT_MIN;
    tp->tm_hour = tp->tm_sec = tp->tm_min = INT_MIN;
    tp->tm_isdst = -1;
    tp->tm_gmtoff = 0;
    tp->tm_zone = NULL;
    result = my_strptime(string, line, tp);
    if (result && *result == '\0')
      break;
  }
  if (result == NULL || *result != '\0')
    return 7;
  time(&timer);
  localtime_r(&timer, &tm);
  if (tp->tm_wday >= 0 && tp->tm_wday <= 6 && tp->tm_year == INT_MIN && tp->tm_mon == INT_MIN && tp->tm_mday == INT_MIN) {
    tp->tm_year = tm.tm_year;
    tp->tm_mon = tm.tm_mon;
    tp->tm_mday = tm.tm_mday + (tp->tm_wday - tm.tm_wday + 7) % 7;
    mday_ok = 1;
  }
  if (tp->tm_mon >= 0 && tp->tm_mon <= 11 && tp->tm_mday == INT_MIN) {
    if (tp->tm_year == INT_MIN)
      tp->tm_year = tm.tm_year + (((tp->tm_mon - tm.tm_mon) < 0) ? 1 : 0);
    tp->tm_mday = first_wday(tp->tm_year, tp->tm_mon, tp->tm_wday);
    mday_ok = 1;
  }
  if (tp->tm_hour == INT_MIN && tp->tm_min == INT_MIN && tp->tm_sec == INT_MIN) {
    tp->tm_hour = tm.tm_hour;
    tp->tm_min = tm.tm_min;
    tp->tm_sec = tm.tm_sec;
  }
  if (tp->tm_hour >= 0 && tp->tm_hour <= 23 && tp->tm_year == INT_MIN && tp->tm_mon == INT_MIN && tp->tm_mday == INT_MIN && tp->tm_wday == INT_MIN) {
    tp->tm_year = tm.tm_year;
    tp->tm_mon = tm.tm_mon;
    tp->tm_mday = tm.tm_mday + ((tp->tm_hour - tm.tm_hour) < 0 ? 1 : 0);
    mday_ok = 1;
  }
  if (tp->tm_year == INT_MIN)
    tp->tm_year = tm.tm_year;
  if (tp->tm_hour == INT_MIN)
    tp->tm_hour = 0;
  if (tp->tm_min == INT_MIN)
    tp->tm_min = 0;
  if (tp->tm_sec == INT_MIN)
    tp->tm_sec = 0;
  if ((!mday_ok && !check_mday(1900 + tp->tm_year, tp->tm_mon, tp->tm_mday)) || mktime(tp) == (time_t)-1)
    return 8;
  return 0;
}
```