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

```asm
<cpufreq_duration_to_string>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %rdi,-0x18(%rbp)
  cmpq   $0xf4240,-0x18(%rbp)
  jbe    L85
  mov    -0x18(%rbp),%rcx
  movabs $0x346dc5d63886594b,%rdx
  mov    %rcx,%rax
  mul    %rdx
  mov    %rdx,%rax
  shr    $0xb,%rax
  imul   $0x2710,%rax,%rdx
  mov    %rcx,%rax
  sub    %rdx,%rax
  mov    %rax,-0x8(%rbp)
  cmpq   $0x1387,-0x8(%rbp)
  jbe    L88
  addq   $0x2710,-0x18(%rbp)
L88:
  mov    -0x18(%rbp),%rcx
  movabs $0x431bde82d7b634db,%rdx
  mov    %rcx,%rax
  mul    %rdx
  mov    %rdx,%rax
  shr    $0x12,%rax
  imul   $0xf4240,%rax,%rdx
  mov    %rcx,%rax
  sub    %rdx,%rax
  mov    %eax,%edx
  mov    $0xd1b71759,%eax
  imul   %rdx,%rax
  shr    $0x20,%rax
  shr    $0xd,%eax
  mov    -0x18(%rbp),%rdx
  mov    %edx,%edx
  imul   $0x431bde83,%rdx,%rdx
  shr    $0x20,%rdx
  shr    $0x12,%edx
  mov    %edx,%ecx
  mov    %eax,%edx
  mov    %rcx,%rsi
  lea    D11(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <xasprintf@plt>
  jmp    L43
L85:
  cmpq   $0x186a0,-0x18(%rbp)
  jbe    L47
  mov    -0x18(%rbp),%rcx
  mov    %rcx,%rax
  shr    $0x3,%rax
  movabs $0x20c49ba5e353f7cf,%rdx
  mul    %rdx
  mov    %rdx,%rax
  shr    $0x4,%rax
  imul   $0x3e8,%rax,%rdx
  mov    %rcx,%rax
  sub    %rdx,%rax
  mov    %rax,-0x8(%rbp)
  cmpq   $0x1f3,-0x8(%rbp)
  jbe    L53
  addq   $0x3e8,-0x18(%rbp)
L53:
  mov    -0x18(%rbp),%rax
  mov    %eax,%eax
  imul   $0x10624dd3,%rax,%rax
  shr    $0x20,%rax
  shr    $0x6,%eax
  mov    %eax,%eax
  mov    %rax,%rsi
  lea    D15(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <xasprintf@plt>
  jmp    L43
L47:
  cmpq   $0x3e8,-0x18(%rbp)
  jbe    L14
  mov    -0x18(%rbp),%rcx
  mov    %rcx,%rax
  shr    $0x2,%rax
  movabs $0x28f5c28f5c28f5c3,%rdx
  mul    %rdx
  shr    $0x2,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  lea    0x0(,%rax,4),%rdx
  add    %rdx,%rax
  shl    $0x2,%rax
  sub    %rax,%rcx
  mov    %rcx,%rdx
  mov    %rdx,-0x8(%rbp)
  cmpq   $0x31,-0x8(%rbp)
  jbe    L11
  addq   $0x64,-0x18(%rbp)
L11:
  mov    -0x18(%rbp),%rcx
  mov    %rcx,%rax
  shr    $0x3,%rax
  movabs $0x20c49ba5e353f7cf,%rdx
  mul    %rdx
  mov    %rdx,%rax
  shr    $0x4,%rax
  imul   $0x3e8,%rax,%rdx
  mov    %rcx,%rax
  sub    %rdx,%rax
  mov    %eax,%eax
  imul   $0x51eb851f,%rax,%rax
  shr    $0x20,%rax
  shr    $0x5,%eax
  mov    -0x18(%rbp),%rdx
  mov    %edx,%edx
  imul   $0x10624dd3,%rdx,%rdx
  shr    $0x20,%rdx
  shr    $0x6,%edx
  mov    %edx,%ecx
  mov    %eax,%edx
  mov    %rcx,%rsi
  lea    D37(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <xasprintf@plt>
  jmp    L43
L14:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rsi
  lea    D22(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <xasprintf@plt>
L43:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: data_tag: D11
type: string
name: retrieve_data
arguments: data_tag: D15
type: string
name: retrieve_data
arguments: data_tag: D37
type: string
name: retrieve_data
arguments: data_tag: D22
type: string

tool: D11: %u.%02ums

tool: D15: %uus

tool: D37: %u.%01uus

tool: D22: %luns

assistant: ```c
char *cpufreq_duration_to_string(unsigned long duration) {
  unsigned long tmp;
  if (duration > 1000000) {
    tmp = duration % 10000;
    if (tmp >= 5000)
      duration += 10000;
    return xasprintf("%u.%02ums", ((unsigned int)duration / 1000000), ((unsigned int)(duration % 1000000) / 10000));
  } else if (duration > 100000) {
    tmp = duration % 1000;
    if (tmp >= 500)
      duration += 1000;
    return xasprintf("%uus", ((unsigned int)duration / 1000));
  } else if (duration > 1000) {
    tmp = duration % 100;
    if (tmp >= 50)
      duration += 100;
    return xasprintf("%u.%01uus", ((unsigned int)duration / 1000), ((unsigned int)(duration % 1000) / 100));
  } else
    return xasprintf("%luns", duration);
}
```