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

```asm
<osfreq>:
  endbr64
  push   %r15
  lea    D79(%rip),%rdi
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  lea    D148(%rip),%rbp
  push   %rbx
  mov    %rbp,%rsi
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  call   <fopen@plt>
  test   %rax,%rax
  je     L155
  mov    %rax,%rdi
  mov    %rax,%r13
  mov    %rsp,%rdx
  xor    %eax,%eax
  lea    D125(%rip),%rsi
  call   <fscanf@plt>
  mov    %r13,%rdi
  mov    %eax,%ebx
  call   <fclose@plt>
  test   %ebx,%ebx
  jg     L298
L155:
  lea    D182(%rip),%r14
  mov    %rbp,%rsi
  mov    %r14,%rdi
  call   <fopen@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L35
  mov    %rsp,%r12
  lea    D31(%rip),%rbx
  lea    D197(%rip),%r13
L152:
  xor    %eax,%eax
  mov    %r12,%rdx
  mov    %rbx,%rsi
  mov    %r15,%rdi
  call   <fscanf@plt>
  test   %eax,%eax
  jg     L109
  je     L387
L70:
  movq   $0x0,(%rsp)
L109:
  mov    %r15,%rdi
  call   <fclose@plt>
  movsd  (%rsp),%xmm0
  ucomisd D155(%rip),%xmm0
  jp     L395
  jne    L395
L35:
  mov    %rbp,%rsi
  mov    %r14,%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L357
  mov    %rsp,%r12
  lea    D2(%rip),%rbx
  lea    D197(%rip),%r14
L161:
  xor    %eax,%eax
  mov    %r12,%rdx
  mov    %rbx,%rsi
  mov    %r13,%rdi
  call   <fscanf@plt>
  test   %eax,%eax
  jg     L399
  je     L26
L245:
  movq   $0x0,(%rsp)
L399:
  mov    %r13,%rdi
  call   <fclose@plt>
  movsd  (%rsp),%xmm0
  ucomisd D155(%rip),%xmm0
  jp     L395
  jne    L395
L357:
  mov    %rbp,%rsi
  lea    D27(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L87
  mov    %rax,%rdi
  mov    %rsp,%rdx
  lea    D125(%rip),%rsi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %r13,%rdi
  mov    %eax,%ebx
  call   <fclose@plt>
  test   %ebx,%ebx
  jg     L50
L87:
  mov    %rbp,%rsi
  lea    D82(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L151
  mov    %rax,%rdi
  mov    %rsp,%rdx
  lea    D125(%rip),%rsi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %r13,%rdi
  mov    %eax,%ebx
  call   <fclose@plt>
  test   %ebx,%ebx
  jg     L50
L151:
  mov    %rbp,%rsi
  lea    D80(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L65
  mov    %rax,%rdi
  mov    %rsp,%rdx
  lea    D125(%rip),%rsi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %r13,%rdi
  mov    %eax,%ebx
  call   <fclose@plt>
  test   %ebx,%ebx
  jg     L298
L65:
  mov    %rbp,%rsi
  lea    D128(%rip),%rdi
  call   <popen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L334
  mov    %rax,%rdi
  mov    %rsp,%rdx
  lea    D149(%rip),%rsi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %r13,%rdi
  mov    %eax,%ebx
  call   <pclose@plt>
  test   %ebx,%ebx
  jle    L334
  movsd  (%rsp),%xmm0
  comisd D155(%rip),%xmm0
  ja     L390
L334:
  mov    %rbp,%rsi
  lea    D101(%rip),%rdi
  call   <popen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L361
  mov    %rax,%rdi
  mov    %rsp,%rdx
  lea    D243(%rip),%rsi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %r13,%rdi
  mov    %eax,%ebx
  call   <pclose@plt>
  test   %ebx,%ebx
  jg     L298
L361:
  mov    %rbp,%rsi
  lea    D220(%rip),%rdi
  call   <popen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L55
  mov    %rsp,%r12
  lea    D206(%rip),%rbx
  lea    D197(%rip),%r13
L67:
  xor    %eax,%eax
  mov    %r12,%rdx
  mov    %rbx,%rsi
  mov    %rbp,%rdi
  call   <fscanf@plt>
  test   %eax,%eax
  jg     L213
  je     L226
L20:
  movq   $0x0,(%rsp)
L213:
  mov    %rbp,%rdi
  call   <pclose@plt>
  movsd  (%rsp),%xmm0
  ucomisd D155(%rip),%xmm0
  jp     L395
  jne    L395
L55:
  lea    D23(%rip),%rdi
  call   <getenv@plt>
  mov    %rax,%rdi
  test   %rax,%rax
  je     L352
  mov    %rsp,%rdx
  lea    D125(%rip),%rsi
  call   <sscanf@plt>
  test   %eax,%eax
  jg     L298
L352:
  pxor   %xmm0,%xmm0
  jmp    L390
  nopl   0x0(%rax,%rax,1)
L387:
  xor    %eax,%eax
  mov    %r13,%rsi
  mov    %r15,%rdi
  call   <fscanf@plt>
  test   %eax,%eax
  jns    L152
  jmp    L70
  nopw   0x0(%rax,%rax,1)
L298:
  movsd  (%rsp),%xmm0
L390:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L124
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L395:
  mulsd  D33(%rip),%xmm0
  jmp    L390
  nopw   0x0(%rax,%rax,1)
L26:
  xor    %eax,%eax
  mov    %r14,%rsi
  mov    %r13,%rdi
  call   <fscanf@plt>
  test   %eax,%eax
  jns    L161
  jmp    L245
  nopw   0x0(%rax,%rax,1)
L50:
  movsd  D174(%rip),%xmm0
  mulsd  (%rsp),%xmm0
  jmp    L390
  nopw   0x0(%rax,%rax,1)
L226:
  xor    %eax,%eax
  mov    %r13,%rsi
  mov    %rbp,%rdi
  call   <fscanf@plt>
  test   %eax,%eax
  jns    L67
  jmp    L20
L124:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_tag: D79
data_type: string
name: unpack_data
arguments: data_tag: D148
data_type: string
name: unpack_data
arguments: data_tag: D125
data_type: string
name: unpack_data
arguments: data_tag: D182
data_type: string
name: unpack_data
arguments: data_tag: D31
data_type: string
name: unpack_data
arguments: data_tag: D197
data_type: string
name: unpack_data
arguments: data_tag: D155
data_type: byte[16]
name: unpack_data
arguments: data_tag: D2
data_type: string
name: unpack_data
arguments: data_tag: D27
data_type: string
name: unpack_data
arguments: data_tag: D82
data_type: string
name: unpack_data
arguments: data_tag: D80
data_type: string
name: unpack_data
arguments: data_tag: D128
data_type: string
name: unpack_data
arguments: data_tag: D149
data_type: string
name: unpack_data
arguments: data_tag: D101
data_type: string
name: unpack_data
arguments: data_tag: D243
data_type: string
name: unpack_data
arguments: data_tag: D220
data_type: string
name: unpack_data
arguments: data_tag: D206
data_type: string
name: unpack_data
arguments: data_tag: D23
data_type: string
name: unpack_data
arguments: data_tag: D33
data_type: f64
name: unpack_data
arguments: data_tag: D174
data_type: f64

tool: D79: /etc/cpucyclespersecond

tool: D148: r

tool: D125: %lf

tool: D182: /proc/cpuinfo

tool: D31: cpu MHz : %lf

tool: D197: %*[^
]


tool: {"D155": [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x84,0x2e,0x41]}

tool: D2: clock : %lf

tool: D27: /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed

tool: D82: /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

tool: D80: /sys/devices/system/cpu/cpu0/clock_tick

tool: D128: sysctl hw.cpufrequency 2>/dev/null

tool: D149: hw.cpufrequency: %lf

tool: D101: /usr/sbin/lsattr -E -l proc0 -a frequency 2>/dev/null

tool: D243: frequency %lf

tool: D220: /usr/sbin/psrinfo -v 2>/dev/null

tool: D206:  The %*s processor operates at %lf MHz

tool: D23: cpucyclespersecond

tool: D33: 1000000

tool: D174: 1000

assistant: ```c
double osfreq(void) {
  FILE *f;
  char *x;
  double result;
  int s;
  f = fopen("/etc/cpucyclespersecond", "r");
  if (f) {
    s = fscanf(f, "%lf", &result);
    fclose(f);
    if (s > 0)
      return result;
  }
  f = fopen("/proc/cpuinfo", "r");
  if (f) {
    for (;;) {
      s = fscanf(f, "cpu MHz : %lf", &result);
      if (s > 0)
        break;
      if (s == 0)
        s = fscanf(f, "%*[^\n]\n");
      if (s < 0) {
        result = 0;
        break;
      }
    }
    fclose(f);
    if (result)
      return 1000000.0 * result;
  }
  f = fopen("/proc/cpuinfo", "r");
  if (f) {
    for (;;) {
      s = fscanf(f, "clock : %lf", &result);
      if (s > 0)
        break;
      if (s == 0)
        s = fscanf(f, "%*[^\n]\n");
      if (s < 0) {
        result = 0;
        break;
      }
    }
    fclose(f);
    if (result)
      return 1000000.0 * result;
  }
  f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", "r");
  if (f) {
    s = fscanf(f, "%lf", &result);
    fclose(f);
    if (s > 0)
      return 1000.0 * result;
  }
  f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
  if (f) {
    s = fscanf(f, "%lf", &result);
    fclose(f);
    if (s > 0)
      return 1000.0 * result;
  }
  f = fopen("/sys/devices/system/cpu/cpu0/clock_tick", "r");
  if (f) {
    s = fscanf(f, "%lf", &result);
    fclose(f);
    if (s > 0)
      return result;
  }
  f = popen("sysctl hw.cpufrequency 2>/dev/null", "r");
  if (f) {
    s = fscanf(f, "hw.cpufrequency: %lf", &result);
    pclose(f);
    if (s > 0)
      if (result > 0)
        return result;
  }
  f = popen("/usr/sbin/lsattr -E -l proc0 -a frequency 2>/dev/null", "r");
  if (f) {
    s = fscanf(f, "frequency %lf", &result);
    pclose(f);
    if (s > 0)
      return result;
  }
  f = popen("/usr/sbin/psrinfo -v 2>/dev/null", "r");
  if (f) {
    for (;;) {
      s = fscanf(f, " The %*s processor operates at %lf MHz", &result);
      if (s > 0)
        break;
      if (s == 0)
        s = fscanf(f, "%*[^\n]\n");
      if (s < 0) {
        result = 0;
        break;
      }
    }
    pclose(f);
    if (result)
      return 1000000.0 * result;
  }
  x = getenv("cpucyclespersecond");
  if (x) {
    s = sscanf(x, "%lf", &result);
    if (s > 0)
      return result;
  }
  return 0;
}
```