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

```asm
<charts_fixmax>:
  endbr64
  mov    %rdi,%rax
  mov    %rdx,%rdi
  movabs $0xdcef33a6f838000,%rdx
  cmp    %rdx,%rax
  jbe    L79
  movabs $0x6f05b59d3b1ffff,%rdx
  movabs $0x49c97747490f,%r8
  add    %rax,%rdx
  shr    $0x11,%rdx
  mov    %rdx,%rax
  mul    %r8
  movabs $0x6f05b59d3b20000,%rax
  shr    $0x18,%rdx
  mov    %rdx,(%rcx)
  imul   %rax,%rdx
  test   %rdx,%rdx
  js     L48
  pxor   %xmm0,%xmm0
  movl   $0x1,(%rdi)
  cvtsi2sd %rdx,%xmm0
  addl   $0x6,(%rsi)
  ret
  nopl   0x0(%rax,%rax,1)
L79:
  movabs $0x1617eb90b26c000,%rdx
  cmp    %rdx,%rax
  jbe    L39
  movabs $0x11c37937e07fff,%rdx
  pxor   %xmm0,%xmm0
  movabs $0x39a5652fb1137857,%r8
  add    %rdx,%rax
  mul    %r8
  movabs $0x11c37937e08000,%rax
  shr    $0x32,%rdx
  mov    %rdx,(%rcx)
  imul   %rax,%rdx
  movl   $0x0,(%rdi)
  addl   $0x5,(%rsi)
  cvtsi2sd %rdx,%xmm0
  ret
  nopl   0x0(%rax)
L39:
  movabs $0x388f27d8d3000,%rdx
  cmp    %rdx,%rax
  ja     L87
  movabs $0x5a7ea627b800,%rdx
  cmp    %rdx,%rax
  jbe    L3
  movabs $0x48c27394fff,%rdx
  pxor   %xmm0,%xmm0
  movabs $0x384b84d092ed0385,%r8
  add    %rdx,%rax
  mul    %r8
  movabs $0x48c27395000,%rax
  shr    $0x28,%rdx
  mov    %rdx,(%rcx)
  imul   %rax,%rdx
  movl   $0x0,(%rdi)
  addl   $0x4,(%rsi)
  cvtsi2sd %rdx,%xmm0
  ret
  nopl   0x0(%rax)
L48:
  shr    %rdx
  pxor   %xmm0,%xmm0
  movl   $0x1,(%rdi)
  cvtsi2sd %rdx,%xmm0
  addl   $0x6,(%rsi)
  addsd  %xmm0,%xmm0
  ret
  nopw   0x0(%rax,%rax,1)
L87:
  movabs $0x1c6bf52633fff,%rdx
  pxor   %xmm0,%xmm0
  movabs $0x24075f3dceac3,%r8
  add    %rax,%rdx
  shr    $0xe,%rdx
  mov    %rdx,%rax
  mul    %r8
  movabs $0x1c6bf52634000,%rax
  shr    $0x14,%rdx
  mov    %rdx,(%rcx)
  imul   %rax,%rdx
  movl   $0x1,(%rdi)
  addl   $0x5,(%rsi)
  cvtsi2sd %rdx,%xmm0
  ret
  nopl   0x0(%rax)
L3:
  movabs $0xe7aa9f1e00,%rdx
  cmp    %rdx,%rax
  ja     L5
  movabs $0x172aa98300,%rdx
  cmp    %rdx,%rax
  jbe    L123
  movabs $0x12a05f1ff,%rdx
  pxor   %xmm0,%xmm0
  movabs $0xdbe6fecebdedd5bf,%r8
  add    %rdx,%rax
  mul    %r8
  movabs $0x12a05f200,%rax
  shr    $0x20,%rdx
  mov    %rdx,(%rcx)
  imul   %rax,%rdx
  movl   $0x0,(%rdi)
  addl   $0x3,(%rsi)
  cvtsi2sd %rdx,%xmm0
  ret
  nopl   0x0(%rax)
L5:
  movabs $0x746a5287ff,%rdx
  pxor   %xmm0,%xmm0
  movabs $0x232f33025bd42233,%r8
  add    %rdx,%rax
  mul    %r8
  movabs $0x746a528800,%rax
  shr    $0x24,%rdx
  mov    %rdx,(%rcx)
  imul   %rax,%rdx
  movl   $0x1,(%rdi)
  addl   $0x4,(%rsi)
  cvtsi2sd %rdx,%xmm0
  ret
  nopw   0x0(%rax,%rax,1)
L123:
  cmp    $0x3b4e7ec0,%rax
  jbe    L86
  lea    0x1dcd64ff(%rax),%rdx
  pxor   %xmm0,%xmm0
  movabs $0x44b82fa09b5a53,%r8
  shr    $0x8,%rdx
  mov    %rdx,%rax
  mul    %r8
  shr    $0xb,%rdx
  mov    %rdx,(%rcx)
  imul   $0x1dcd6500,%rdx,%rdx
  movl   $0x1,(%rdi)
  addl   $0x3,(%rsi)
  cvtsi2sd %rdx,%xmm0
  ret
L86:
  cmp    $0x5ee3fe0,%rax
  jbe    L72
  lea    0x4c4b3f(%rax),%rdx
  pxor   %xmm0,%xmm0
  movabs $0xd6bf94d5e57a42bd,%r8
  mov    %rdx,%rax
  mul    %r8
  shr    $0x16,%rdx
  mov    %rdx,(%rcx)
  imul   $0x4c4b40,%rdx,%rdx
  movl   $0x0,(%rdi)
  addl   $0x2,(%rsi)
  cvtsi2sd %rdx,%xmm0
  ret
L72:
  cmp    $0xf2eb8,%rax
  jbe    L23
  lea    0x7a11f(%rax),%rdx
  pxor   %xmm0,%xmm0
  movabs $0x431bde82d7b634db,%r8
  mov    %rdx,%rax
  mul    %r8
  shr    $0x11,%rdx
  mov    %rdx,(%rcx)
  imul   $0x7a120,%rdx,%rdx
  movl   $0x1,(%rdi)
  addl   $0x2,(%rsi)
  cvtsi2sd %rdx,%xmm0
  ret
L23:
  cmp    $0x184ac,%rax
  jbe    L53
  add    $0x1387,%rax
  mov    $0x1388,%r8d
  pxor   %xmm0,%xmm0
  xor    %edx,%edx
  div    %r8
  mov    %rax,(%rcx)
  imul   $0x1388,%rax,%rax
  movl   $0x0,(%rdi)
  addl   $0x1,(%rsi)
  cvtsi2sd %rax,%xmm0
  ret
L53:
  cmp    $0x3e3,%rax
  jbe    L61
  add    $0x1f3,%rax
  mov    $0x1f4,%r8d
  pxor   %xmm0,%xmm0
  xor    %edx,%edx
  div    %r8
  mov    %rax,(%rcx)
  imul   $0x1f4,%rax,%rax
  movl   $0x1,(%rdi)
  addl   $0x1,(%rsi)
  cvtsi2sd %rax,%xmm0
  ret
L61:
  cmp    $0x63,%rax
  jbe    L62
  add    $0x4,%rax
  mov    $0x5,%esi
  pxor   %xmm0,%xmm0
  xor    %edx,%edx
  div    %rsi
  mov    %rax,(%rcx)
  lea    (%rax,%rax,4),%rax
  cvtsi2sd %rax,%xmm0
  movl   $0x0,(%rdi)
  ret
L62:
  test   %rax,%rax
  mov    $0x1,%edx
  pxor   %xmm0,%xmm0
  cmove  %rdx,%rax
  lea    (%rax,%rax,1),%rdx
  imul   $0xa,%rax,%rax
  mov    %rdx,(%rcx)
  movl   $0x1,(%rdi)
  cvtsi2sd %rax,%xmm0
  divsd  D3(%rip),%xmm0
  ret
```

tool_calls: name: disassemble_data
arguments: label: D3
datatype: f64

tool: D3: 10

assistant: ```c
double charts_fixmax(uint64_t max, uint8_t *scale, uint8_t *mode, uint16_t *base) {
  double rmax;
  if (max > 995000000000000000ULL) {
    (*base) = (max + 499999999999999999ULL) / 500000000000000000ULL;
    rmax = (*base) * 500000000000000000ULL;
    (*mode) = 1;
    (*scale) += 6;
  } else if (max > 99500000000000000ULL) {
    (*base) = (max + 4999999999999999ULL) / 5000000000000000ULL;
    rmax = (*base) * 5000000000000000ULL;
    (*mode) = 0;
    (*scale) += 5;
  } else if (max > 995000000000000ULL) {
    (*base) = (max + 499999999999999ULL) / 500000000000000ULL;
    rmax = (*base) * 500000000000000ULL;
    (*mode) = 1;
    (*scale) += 5;
  } else if (max > 99500000000000ULL) {
    (*base) = (max + 4999999999999ULL) / 5000000000000ULL;
    rmax = (*base) * 5000000000000ULL;
    (*mode) = 0;
    (*scale) += 4;
  } else if (max > 995000000000ULL) {
    (*base) = (max + 499999999999ULL) / 500000000000ULL;
    rmax = (*base) * 500000000000ULL;
    (*mode) = 1;
    (*scale) += 4;
  } else if (max > 99500000000ULL) {
    (*base) = (max + 4999999999ULL) / 5000000000ULL;
    rmax = (*base) * 5000000000ULL;
    (*mode) = 0;
    (*scale) += 3;
  } else if (max > 995000000ULL) {
    (*base) = (max + 499999999ULL) / 500000000ULL;
    rmax = (*base) * 500000000ULL;
    (*mode) = 1;
    (*scale) += 3;
  } else if (max > 99500000ULL) {
    (*base) = (max + 4999999ULL) / 5000000ULL;
    rmax = (*base) * 5000000ULL;
    (*mode) = 0;
    (*scale) += 2;
  } else if (max > 995000ULL) {
    (*base) = (max + 499999ULL) / 500000ULL;
    rmax = (*base) * 500000ULL;
    (*mode) = 1;
    (*scale) += 2;
  } else if (max > 99500ULL) {
    (*base) = (max + 4999ULL) / 5000ULL;
    rmax = (*base) * 5000ULL;
    (*mode) = 0;
    (*scale) += 1;
  } else if (max > 995ULL) {
    (*base) = (max + 499ULL) / 500ULL;
    rmax = (*base) * 500ULL;
    (*mode) = 1;
    (*scale) += 1;
  } else if (max > 99ULL) {
    (*base) = (max + 4ULL) / 5ULL;
    rmax = (*base) * 5ULL;
    (*mode) = 0;
  } else {
    if (max == 0) {
      max = 1;
    }
    (*base) = max * 2;
    rmax = ((*base) * 5) / 10.0;
    (*mode) = 1;
  }
  return rmax;
}
```