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

```asm
<sign_by_pkey>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %rcx,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x28(%rbp)
  movq   $0x0,-0x18(%rbp)
  cmpq   $0x0,-0x50(%rbp)
  je     L24
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <get_evp_pkey@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L154
  lea    D8(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L98
L154:
  mov    -0x18(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_new@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L155
  lea    D80(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L98
L155:
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <EVP_PKEY_sign_init@plt>
  test   %rax,%rax
  jg     L136
  lea    D118(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L98
L136:
  movq   $0x0,-0x20(%rbp)
  lea    -0x20(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_get_signature_md@plt>
  mov    %eax,-0x2c(%rbp)
  mov    -0x20(%rbp),%rax
  test   %rax,%rax
  je     L38
  lea    D58(%rip),%rax
  jmp    L81
L38:
  lea    D18(%rip),%rax
L81:
  mov    -0x2c(%rbp),%ecx
  mov    %rax,%rdx
  mov    %ecx,%esi
  lea    D33(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x0,%eax
  call   <EVP_sha256@plt>
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_set_signature_md@plt>
  test   %rax,%rax
  jg     L41
  lea    D34(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L98
L41:
  mov    -0x48(%rbp),%rsi
  mov    -0x40(%rbp),%rcx
  lea    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  mov    %rsi,%r8
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_sign@plt>
  test   %rax,%rax
  jg     L6
  lea    D75(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L98
L6:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    -0x50(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0x50(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L90
  lea    D19(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L98
L90:
  mov    -0x50(%rbp),%rax
  mov    (%rax),%rsi
  mov    -0x48(%rbp),%rdi
  mov    -0x40(%rbp),%rcx
  lea    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  mov    %rdi,%r8
  mov    %rax,%rdi
  call   <EVP_PKEY_sign@plt>
  test   %rax,%rax
  jg     L98
  lea    D109(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L98
L24:
  nop
L98:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <EVP_PKEY_free@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D26(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  movl   $0x0,-0x30(%rbp)
  jmp    L150
L50:
  mov    -0x50(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0x30(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,%esi
  lea    D97(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  addl   $0x1,-0x30(%rbp)
L150:
  mov    -0x30(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x28(%rbp),%rax
  cmp    %rax,%rdx
  jb     L50
  mov    $0x0,%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L108
  call   <__stack_chk_fail@plt>
L108:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: data_label: D8
data_type: string
name: disassemble_data
arguments: data_label: D80
data_type: string
name: disassemble_data
arguments: data_label: D118
data_type: string
name: disassemble_data
arguments: data_label: D58
data_type: string
name: disassemble_data
arguments: data_label: D18
data_type: string
name: disassemble_data
arguments: data_label: D33
data_type: string
name: disassemble_data
arguments: data_label: D34
data_type: string
name: disassemble_data
arguments: data_label: D75
data_type: string
name: disassemble_data
arguments: data_label: D19
data_type: string
name: disassemble_data
arguments: data_label: D109
data_type: string
name: disassemble_data
arguments: data_label: D26
data_type: string
name: disassemble_data
arguments: data_label: D97
data_type: string

tool: D8: Failed to load private key.

tool: D80: Failed to create pkey ctx

tool: D118: Failed to do sign init

tool: D58: not null

tool: D18: null

tool: D33: md_type = %d%s


tool: D34: Fail to set signature md

tool: D75: Failed to get sign len

tool: D19: Failed to allocate mem for sign

tool: D109: Failed to sign with pkey

tool: D26: sign_len = %d


tool: D97: %02x 

assistant: ```c
int sign_by_pkey(const char *pkey_file, uint8_t *sign_data, size_t sdata_len, uint8_t **out) {
  size_t sign_len = 0;
  EVP_PKEY_CTX *ctx;
  EVP_PKEY *pkey = NULL;
  do {
    if (!out)
      break;
    if (!(pkey = get_evp_pkey(pkey_file))) {
      printf("Failed to load private key."
             "\n");
      break;
    }
    ctx = EVP_PKEY_CTX_new(pkey, NULL);
    if (!ctx) {
      printf("Failed to create pkey ctx"
             "\n");
      break;
    }
    if (EVP_PKEY_sign_init(ctx) <= 0) {
      printf("Failed to do sign init"
             "\n");
      break;
    }
    EVP_MD *md_ptr = NULL;
    int md_type = EVP_PKEY_CTX_get_signature_md(ctx, &md_ptr);
    printf("md_type = %d%s\n", md_type, md_ptr ? "not null" : "null");
    if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) {
      printf("Fail to set signature md"
             "\n");
      break;
    }
    if (EVP_PKEY_sign(ctx, NULL, &sign_len, sign_data, sdata_len) <= 0) {
      printf("Failed to get sign len"
             "\n");
      break;
    }
    *out = malloc(sign_len);
    if (!*out) {
      printf("Failed to allocate mem for sign"
             "\n");
      break;
    }
    if (EVP_PKEY_sign(ctx, *out, &sign_len, sign_data, sdata_len) <= 0) {
      printf("Failed to sign with pkey"
             "\n");
      break;
    }
  } while (0);
  EVP_PKEY_free(pkey);
  printf("sign_len = %d\n", sign_len);
  for (int i = 0; i < sign_len; i++) {
    printf("%02x ", (*out)[i]);
  }
  return 0;
}
```