user: 请将以下的汇编代码转换成C语言代码：

```asm
<getbattery>:
  endbr64
  push   %r14
  mov    $0xc,%edi
  push   %r13
  lea    D96(%rip),%r13
  push   %r12
  push   %rbp
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  movq   $0x0,0x10(%rsp)
  call   <malloc@plt>
  mov    %r13,%rsi
  lea    D94(%rip),%rdi
  mov    %rax,%r12
  call   <fopen@plt>
  test   %rax,%rax
  je     L1
  lea    D27(%rip),%r14
  lea    0x8(%rsp),%rdx
  mov    %rax,%rbp
  mov    %rax,%rdi
  mov    %r14,%rsi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r13,%rsi
  lea    D66(%rip),%rdi
  call   <fopen@plt>
  lea    0x10(%rsp),%rdx
  mov    %r14,%rsi
  mov    %rax,%rbp
  mov    %rax,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r13,%rsi
  lea    D22(%rip),%rdi
  call   <fopen@plt>
  mov    %r12,%rdx
  lea    D5(%rip),%rsi
  mov    %rax,%rbp
  mov    %rax,%rdi
  xor    %eax,%eax
  call   <fscanf@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  lea    D14(%rip),%rsi
  mov    %r12,%rdi
  call   <strcmp@plt>
  lea    D108(%rip),%rsi
  mov    %r12,%rdi
  cmp    $0x1,%rax
  sbb    %ebp,%ebp
  call   <strcmp@plt>
  and    $0xffffffec,%ebp
  lea    D28(%rip),%rsi
  mov    %r12,%rdi
  add    $0x3f,%ebp
  test   %rax,%rax
  mov    $0x2d,%eax
  cmove  %eax,%ebp
  call   <strcmp@plt>
  mov    0x10(%rsp),%rsi
  movabs $0xa3d70a3d70a3d70b,%rdx
  lea    D93(%rip),%rdi
  test   %rax,%rax
  mov    $0x3d,%eax
  cmove  %eax,%ebp
  mov    %rsi,%rax
  imul   %rdx
  mov    0x8(%rsp),%rax
  lea    (%rdx,%rsi,1),%rcx
  sar    $0x3f,%rsi
  cqto
  sar    $0x6,%rcx
  sub    %rsi,%rcx
  mov    %ebp,%esi
  idiv   %rcx
  mov    %rax,%rdx
  xor    %eax,%eax
  call   <smprintf@plt>
L4:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L3
  add    $0x28,%rsp
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
  xchg   %ax,%ax
L1:
  lea    D99(%rip),%rdi
  xor    %eax,%eax
  call   <smprintf@plt>
  jmp    L4
L3:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_tag: D96
data_type: string
name: unpack_data
arguments: data_tag: D94
data_type: string
name: unpack_data
arguments: data_tag: D27
data_type: string
name: unpack_data
arguments: data_tag: D66
data_type: string
name: unpack_data
arguments: data_tag: D22
data_type: string
name: unpack_data
arguments: data_tag: D5
data_type: string
name: unpack_data
arguments: data_tag: D14
data_type: string
name: unpack_data
arguments: data_tag: D108
data_type: string
name: unpack_data
arguments: data_tag: D28
data_type: string
name: unpack_data
arguments: data_tag: D93
data_type: string
name: unpack_data
arguments: data_tag: D99
data_type: string

tool: D96: r

tool: D94: /sys/class/power_supply/BAT0/charge_now

tool: D27: %ld


tool: D66: /sys/class/power_supply/BAT0/charge_full

tool: D22: /sys/class/power_supply/BAT0/status

tool: D5: %s


tool: D14: Charging

tool: D108: Discharging

tool: D28: Full

tool: D93: %c%ld%%

tool: 

assistant: ```c
char *getbattery() {
  long lnum1, lnum2 = 0;
  char *status = malloc(sizeof(char) * 12);
  char s = '?';
  FILE *fp = NULL;
  if ((fp = fopen("/sys/class/power_supply/BAT0/charge_now", "r"))) {
    fscanf(fp, "%ld\n", &lnum1);
    fclose(fp);
    fp = fopen("/sys/class/power_supply/BAT0/charge_full", "r");
    fscanf(fp, "%ld\n", &lnum2);
    fclose(fp);
    fp = fopen("/sys/class/power_supply/BAT0/status", "r");
    fscanf(fp, "%s\n", status);
    fclose(fp);
    if (strcmp(status, "Charging") == 0)
      s = '+';
    if (strcmp(status, "Discharging") == 0)
      s = '-';
    if (strcmp(status, "Full") == 0)
      s = '=';
    return smprintf("%c%ld%%", s, (lnum1 / (lnum2 / 100)));
  } else
    return smprintf("");
}
```