ylfeng/ReF-Decompile-dataset huggingface dataset:
user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<glq_weights>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r12
  push   %rbx
  mov    %edi,-0x44(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %rdx,-0x58(%rbp)
  cmpl   $0x1,-0x44(%rbp)
  jg     L34
  mov    $0x1,%eax
  jmp    L10
L34:
  cmpq   $0x0,-0x50(%rbp)
  jne    L67
  mov    $0x2,%eax
  jmp    L10
L67:
  cmpq   $0x0,-0x58(%rbp)
  jne    L93
  mov    $0x3,%eax
  jmp    L10
L93:
  mov    $0x0,%r12d
  jmp    L11
L63:
  movslq %r12d,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  movsd  %xmm0,-0x28(%rbp)
  movsd  D28(%rip),%xmm0
  movsd  %xmm0,-0x30(%rbp)
  movsd  -0x28(%rbp),%xmm0
  movsd  %xmm0,-0x38(%rbp)
  mov    $0x2,%ebx
  jmp    L55
L76:
  movsd  -0x30(%rbp),%xmm0
  movsd  %xmm0,-0x18(%rbp)
  movsd  -0x38(%rbp),%xmm0
  movsd  %xmm0,-0x30(%rbp)
  lea    (%rbx,%rbx,1),%eax
  sub    $0x1,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  mulsd  -0x28(%rbp),%xmm0
  mulsd  -0x30(%rbp),%xmm0
  lea    -0x1(%rbx),%eax
  pxor   %xmm1,%xmm1
  cvtsi2sd %eax,%xmm1
  mulsd  -0x18(%rbp),%xmm1
  subsd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2sd %ebx,%xmm1
  divsd  %xmm1,%xmm0
  movsd  %xmm0,-0x38(%rbp)
  add    $0x1,%ebx
L55:
  cmp    -0x44(%rbp),%ebx
  jle    L76
  pxor   %xmm1,%xmm1
  cvtsi2sdl -0x44(%rbp),%xmm1
  movsd  -0x28(%rbp),%xmm0
  mulsd  -0x38(%rbp),%xmm0
  subsd  -0x30(%rbp),%xmm0
  mulsd  %xmm0,%xmm1
  movsd  -0x28(%rbp),%xmm0
  mulsd  %xmm0,%xmm0
  movsd  D28(%rip),%xmm3
  movapd %xmm0,%xmm2
  subsd  %xmm3,%xmm2
  divsd  %xmm2,%xmm1
  movapd %xmm1,%xmm0
  movsd  %xmm0,-0x20(%rbp)
  movsd  -0x28(%rbp),%xmm0
  movapd %xmm0,%xmm1
  mulsd  %xmm0,%xmm1
  movsd  D28(%rip),%xmm0
  subsd  %xmm1,%xmm0
  mulsd  -0x20(%rbp),%xmm0
  movapd %xmm0,%xmm1
  mulsd  -0x20(%rbp),%xmm1
  movslq %r12d,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  D10(%rip),%xmm0
  divsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  add    $0x1,%r12d
L11:
  cmp    -0x44(%rbp),%r12d
  jl     L63
  mov    $0x0,%eax
L10:
  pop    %rbx
  pop    %r12
  pop    %rbp
  ret
```

tool_calls: name: unpack_data
arguments: tag: D28
type_guessed: f64
name: unpack_data
arguments: tag: D10
type_guessed: f64

tool: D28: 1

tool: D10: 2

assistant: ```c
int glq_weights(int order, double *nodes, double *weights) {
  register int i, n;
  double xi, pn, pn_2, pn_1, pn_line;
  if (order < 2) {
    return 1;
  }
  if (nodes == NULL) {
    return 2;
  }
  if (weights == NULL) {
    return 3;
  }
  for (i = 0; i < order; i++) {
    xi = nodes[i];
    pn_1 = 1;
    pn = xi;
    for (n = 2; n <= order; n++) {
      pn_2 = pn_1;
      pn_1 = pn;
      pn = ((2 * n - 1) * xi * pn_1 - (n - 1) * pn_2) / n;
    }
    pn_line = order * (xi * pn - pn_1) / (xi * xi - 1.);
    weights[i] = 2. / ((1 - xi * xi) * pn_line * pn_line);
  }
  return 0;
}
```
user: What would the C source look like for the assembly code provided here?

```asm
<glq_weights>:
  endbr64
  mov    %rsi,%r8
  mov    %rdx,%r9
  mov    $0x1,%eax
  cmp    $0x1,%edi
  jle    L48
  test   %rsi,%rsi
  je     L39
  test   %rdx,%rdx
  je     L51
  mov    %edi,%r10d
  mov    $0x0,%esi
  lea    0x1(%rdi),%ecx
  movsd  D15(%rip),%xmm7
  movapd %xmm7,%xmm5
  movsd  D18(%rip),%xmm6
  jmp    L55
L49:
  movapd %xmm0,%xmm2
L35:
  pxor   %xmm0,%xmm0
  cvtsi2sd %edx,%xmm0
  mulsd  %xmm3,%xmm0
  mulsd  %xmm2,%xmm0
  lea    -0x1(%rax),%r11d
  pxor   %xmm1,%xmm1
  cvtsi2sd %r11d,%xmm1
  mulsd  %xmm4,%xmm1
  subsd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2sd %eax,%xmm1
  divsd  %xmm1,%xmm0
  add    $0x1,%eax
  add    $0x2,%edx
  movapd %xmm2,%xmm4
  cmp    %ecx,%eax
  jne    L49
  movapd %xmm3,%xmm1
  mulsd  %xmm3,%xmm1
  mulsd  %xmm0,%xmm3
  subsd  %xmm2,%xmm3
  pxor   %xmm0,%xmm0
  cvtsi2sd %edi,%xmm0
  mulsd  %xmm0,%xmm3
  movapd %xmm1,%xmm0
  subsd  %xmm5,%xmm0
  divsd  %xmm0,%xmm3
  movapd %xmm5,%xmm0
  subsd  %xmm1,%xmm0
  mulsd  %xmm3,%xmm0
  mulsd  %xmm3,%xmm0
  movapd %xmm6,%xmm1
  divsd  %xmm0,%xmm1
  movsd  %xmm1,(%r9,%rsi,8)
  add    $0x1,%rsi
  cmp    %r10,%rsi
  je     L69
L55:
  movsd  (%r8,%rsi,8),%xmm3
  movapd %xmm3,%xmm2
  mov    $0x3,%edx
  movapd %xmm7,%xmm4
  mov    $0x2,%eax
  jmp    L35
L69:
  mov    $0x0,%eax
  ret
L39:
  mov    $0x2,%eax
  ret
L51:
  mov    $0x3,%eax
L48:
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D15
type: f64
name: extract_symbolic_data
arguments: data_label: D18
type: f64

tool: D15: 1

tool: D18: 2

assistant: ```c
int glq_weights(int order, double *nodes, double *weights) {
  register int i, n;
  double xi, pn, pn_2, pn_1, pn_line;
  if (order < 2) {
    return 1;
  }
  if (nodes == NULL) {
    return 2;
  }
  if (weights == NULL) {
    return 3;
  }
  for (i = 0; i < order; i++) {
    xi = nodes[i];
    pn_1 = 1;
    pn = xi;
    for (n = 2; n <= order; n++) {
      pn_2 = pn_1;
      pn_1 = pn;
      pn = ((2 * n - 1) * xi * pn_1 - (n - 1) * pn_2) / n;
    }
    pn_line = order * (xi * pn - pn_1) / (xi * xi - 1.);
    weights[i] = 2. / ((1 - xi * xi) * pn_line * pn_line);
  }
  return 0;
}
```
user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<glq_weights>:
  endbr64
  mov    %rsi,%r9
  mov    %rdx,%r10
  mov    $0x1,%eax
  cmp    $0x1,%edi
  jle    L35
  test   %rsi,%rsi
  je     L42
  test   %rdx,%rdx
  je     L56
  pxor   %xmm6,%xmm6
  movslq %edi,%r11
  lea    0x1(%rdi),%esi
  xor    %r8d,%r8d
  cvtsi2sd %edi,%xmm6
  movsd  D1(%rip),%xmm4
  movsd  D16(%rip),%xmm5
  nopl   0x0(%rax,%rax,1)
L53:
  movsd  (%r9,%r8,8),%xmm3
  mov    $0x3,%edx
  movapd %xmm4,%xmm7
  mov    $0x2,%eax
  movapd %xmm3,%xmm2
  jmp    L19
  nopw   0x0(%rax,%rax,1)
L32:
  movapd %xmm0,%xmm2
L19:
  pxor   %xmm0,%xmm0
  lea    -0x1(%rax),%ecx
  pxor   %xmm1,%xmm1
  cvtsi2sd %edx,%xmm0
  add    $0x2,%edx
  cvtsi2sd %ecx,%xmm1
  mulsd  %xmm3,%xmm0
  mulsd  %xmm7,%xmm1
  movapd %xmm2,%xmm7
  mulsd  %xmm2,%xmm0
  subsd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2sd %eax,%xmm1
  add    $0x1,%eax
  divsd  %xmm1,%xmm0
  cmp    %esi,%eax
  jne    L32
  movapd %xmm3,%xmm1
  mulsd  %xmm3,%xmm1
  mulsd  %xmm0,%xmm3
  movapd %xmm1,%xmm0
  subsd  %xmm2,%xmm3
  subsd  %xmm4,%xmm0
  mulsd  %xmm6,%xmm3
  divsd  %xmm0,%xmm3
  movapd %xmm4,%xmm0
  subsd  %xmm1,%xmm0
  movapd %xmm5,%xmm1
  mulsd  %xmm3,%xmm0
  mulsd  %xmm3,%xmm0
  divsd  %xmm0,%xmm1
  movsd  %xmm1,(%r10,%r8,8)
  add    $0x1,%r8
  cmp    %r8,%r11
  jne    L53
  xor    %eax,%eax
  ret
L56:
  mov    $0x3,%eax
L35:
  ret
L42:
  mov    $0x2,%eax
  ret
```

tool_calls: name: disassemble_data
arguments: data_label: D1
type_guessed: f64
name: disassemble_data
arguments: data_label: D16
type_guessed: f64

tool: D1: 1

tool: D16: 2

assistant: ```c
int glq_weights(int order, double *nodes, double *weights) {
  register int i, n;
  double xi, pn, pn_2, pn_1, pn_line;
  if (order < 2) {
    return 1;
  }
  if (nodes == NULL) {
    return 2;
  }
  if (weights == NULL) {
    return 3;
  }
  for (i = 0; i < order; i++) {
    xi = nodes[i];
    pn_1 = 1;
    pn = xi;
    for (n = 2; n <= order; n++) {
      pn_2 = pn_1;
      pn_1 = pn;
      pn = ((2 * n - 1) * xi * pn_1 - (n - 1) * pn_2) / n;
    }
    pn_line = order * (xi * pn - pn_1) / (xi * xi - 1.);
    weights[i] = 2. / ((1 - xi * xi) * pn_line * pn_line);
  }
  return 0;
}
```
user: Demonstrate the C code that generates the assembly output below:

```asm
<glq_weights>:
  endbr64
  mov    %rsi,%r9
  mov    %rdx,%r10
  mov    $0x1,%eax
  cmp    $0x1,%edi
  jle    L52
  test   %rsi,%rsi
  je     L37
  test   %rdx,%rdx
  je     L12
  pxor   %xmm6,%xmm6
  movslq %edi,%r11
  lea    0x1(%rdi),%esi
  xor    %r8d,%r8d
  cvtsi2sd %edi,%xmm6
  movsd  D12(%rip),%xmm4
  movsd  D11(%rip),%xmm5
  nopl   0x0(%rax,%rax,1)
L30:
  movsd  (%r9,%r8,8),%xmm3
  mov    $0x3,%edx
  movapd %xmm4,%xmm7
  mov    $0x2,%eax
  movapd %xmm3,%xmm2
  jmp    L15
  nopw   0x0(%rax,%rax,1)
L5:
  movapd %xmm0,%xmm2
L15:
  pxor   %xmm0,%xmm0
  lea    -0x1(%rax),%ecx
  pxor   %xmm1,%xmm1
  cvtsi2sd %edx,%xmm0
  add    $0x2,%edx
  cvtsi2sd %ecx,%xmm1
  mulsd  %xmm3,%xmm0
  mulsd  %xmm7,%xmm1
  movapd %xmm2,%xmm7
  mulsd  %xmm2,%xmm0
  subsd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2sd %eax,%xmm1
  add    $0x1,%eax
  divsd  %xmm1,%xmm0
  cmp    %esi,%eax
  jne    L5
  movapd %xmm3,%xmm1
  mulsd  %xmm3,%xmm1
  mulsd  %xmm0,%xmm3
  movapd %xmm1,%xmm0
  subsd  %xmm2,%xmm3
  subsd  %xmm4,%xmm0
  mulsd  %xmm6,%xmm3
  divsd  %xmm0,%xmm3
  movapd %xmm4,%xmm0
  subsd  %xmm1,%xmm0
  movapd %xmm5,%xmm1
  mulsd  %xmm3,%xmm0
  mulsd  %xmm3,%xmm0
  divsd  %xmm0,%xmm1
  movsd  %xmm1,(%r10,%r8,8)
  add    $0x1,%r8
  cmp    %r8,%r11
  jne    L30
  xor    %eax,%eax
  ret
L12:
  mov    $0x3,%eax
L52:
  ret
L37:
  mov    $0x2,%eax
  ret
```

tool_calls: name: parse_data
arguments: data_tag: D12
data_type: f64
name: parse_data
arguments: data_tag: D11
data_type: f64

tool: D12: 1

tool: D11: 2

assistant: ```c
int glq_weights(int order, double *nodes, double *weights) {
  register int i, n;
  double xi, pn, pn_2, pn_1, pn_line;
  if (order < 2) {
    return 1;
  }
  if (nodes == NULL) {
    return 2;
  }
  if (weights == NULL) {
    return 3;
  }
  for (i = 0; i < order; i++) {
    xi = nodes[i];
    pn_1 = 1;
    pn = xi;
    for (n = 2; n <= order; n++) {
      pn_2 = pn_1;
      pn_1 = pn;
      pn = ((2 * n - 1) * xi * pn_1 - (n - 1) * pn_2) / n;
    }
    pn_line = order * (xi * pn - pn_1) / (xi * xi - 1.);
    weights[i] = 2. / ((1 - xi * xi) * pn_line * pn_line);
  }
  return 0;
}
```
user: 下面的汇编指令对应的C源代码是什么：

```asm
<SKNormalizeDirection>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x10,%rsp
  movsd  %xmm0,-0x8(%rbp)
  mov    -0x8(%rbp),%rax
  mov    $0x6,%edi
  movq   %rax,%xmm0
  call   <fmod@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x8(%rbp)
  pxor   %xmm0,%xmm0
  comisd -0x8(%rbp),%xmm0
  jbe    L6
  movsd  -0x8(%rbp),%xmm1
  movsd  D4(%rip),%xmm0
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rbp)
L6:
  movsd  -0x8(%rbp),%xmm0
  movq   %xmm0,%rax
  movq   %rax,%xmm0
  leave
  ret
```

tool_calls: name: unpack_data
arguments: data_label: D4
type: byte[8]

tool: {"D4": [0x18,0x2d,0x44,0x54,0xfb,0x21,0x19,0x40]}

assistant: ```c
double SKNormalizeDirection(double x) {
  x = fmod(x, 2 * 3.14159265358979323846);
  if (x < 0) {
    x += 2 * 3.14159265358979323846;
  }
  return x;
}
```
user: What would the C source look like for the assembly code provided here?

```asm
<SKNormalizeDirection>:
  endbr64
  sub    $0x8,%rsp
  mov    $0x6,%edi
  call   <fmod@plt>
  pxor   %xmm1,%xmm1
  comisd %xmm0,%xmm1
  ja     L9
L2:
  add    $0x8,%rsp
  ret
L9:
  addsd  D4(%rip),%xmm0
  jmp    L2
```

tool_calls: name: disassemble_data
arguments: data_label: D4
data_type: byte[8]

tool: {"D4": [0x18,0x2d,0x44,0x54,0xfb,0x21,0x19,0x40]}

assistant: ```c
double SKNormalizeDirection(double x) {
  x = fmod(x, 2 * 3.14159265358979323846);
  if (x < 0) {
    x += 2 * 3.14159265358979323846;
  }
  return x;
}
```
user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<SKNormalizeDirection>:
  endbr64
  sub    $0x8,%rsp
  mov    $0x6,%edi
  call   <fmod@plt>
  pxor   %xmm1,%xmm1
  comisd %xmm0,%xmm1
  jbe    L3
  addsd  D0(%rip),%xmm0
L3:
  add    $0x8,%rsp
  ret
```

tool_calls: name: retrieve_data
arguments: label: D0
type_guessed: byte[8]

tool: {"D0": [0x18,0x2d,0x44,0x54,0xfb,0x21,0x19,0x40]}

assistant: ```c
double SKNormalizeDirection(double x) {
  x = fmod(x, 2 * 3.14159265358979323846);
  if (x < 0) {
    x += 2 * 3.14159265358979323846;
  }
  return x;
}
```
user: 请将以下的汇编代码转换成C语言代码：

```asm
<SKNormalizeDirection>:
  endbr64
  sub    $0x8,%rsp
  mov    $0x6,%edi
  call   <fmod@plt>
  pxor   %xmm1,%xmm1
  comisd %xmm0,%xmm1
  jbe    L7
  addsd  D6(%rip),%xmm0
L7:
  add    $0x8,%rsp
  ret
```

tool_calls: name: read_data
arguments: data_tag: D6
type: byte[8]

tool: {"D6": [0x18,0x2d,0x44,0x54,0xfb,0x21,0x19,0x40]}

assistant: ```c
double SKNormalizeDirection(double x) {
  x = fmod(x, 2 * 3.14159265358979323846);
  if (x < 0) {
    x += 2 * 3.14159265358979323846;
  }
  return x;
}
```
user: What is the c source code of the assembly code below?

```asm
<SafeMemCopy>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %rdi,-0x8(%rbp)
  mov    %rsi,-0x10(%rbp)
  mov    %edx,-0x14(%rbp)
  mov    %rcx,-0x20(%rbp)
  mov    %r8d,-0x18(%rbp)
  mov    -0x20(%rbp),%rax
  mov    (%rax),%eax
  sub    -0x14(%rbp),%eax
  cmp    %eax,-0x18(%rbp)
  jle    L26
  mov    -0x18(%rbp),%edx
  mov    -0x14(%rbp),%eax
  add    %eax,%edx
  mov    -0x20(%rbp),%rax
  mov    %edx,(%rax)
  cmpq   $0x0,-0x8(%rbp)
  je     L0
  mov    -0x20(%rbp),%rax
  mov    (%rax),%edx
  mov    -0x8(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <erealloc@plt>
  cltq
  mov    %rax,-0x8(%rbp)
  jmp    L26
L0:
  mov    -0x20(%rbp),%rax
  mov    (%rax),%eax
  mov    %eax,%edi
  mov    $0x0,%eax
  call   <emalloc@plt>
  cltq
  mov    %rax,-0x8(%rbp)
L26:
  mov    -0x18(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x14(%rbp),%eax
  movslq %eax,%rcx
  mov    -0x8(%rbp),%rax
  add    %rax,%rcx
  mov    -0x10(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x8(%rbp),%rax
  leave
  ret
```

assistant: ```c
unsigned char *SafeMemCopy(dest, orig, off_dest, sz_dest, len)
unsigned char *dest;
unsigned char *orig;
int off_dest;
int *sz_dest;
int len;
{
  if (len > (*sz_dest - off_dest)) {
    *sz_dest = len + off_dest;
    if (dest)
      dest = (unsigned char *)erealloc(dest, *sz_dest);
    else
      dest = (unsigned char *)emalloc(*sz_dest);
  }
  memcpy(dest + off_dest, orig, len);
  return (dest);
}
```
user: 这段汇编代码用C语言表示是什么样的?

```asm
<SafeMemCopy>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    %rdi,%r12
  mov    %rsi,%r13
  mov    %edx,%ebx
  mov    %r8d,%ebp
  mov    (%rcx),%eax
  sub    %edx,%eax
  cmp    %r8d,%eax
  jge    L16
  lea    (%rdx,%r8,1),%esi
  mov    %esi,(%rcx)
  test   %rdi,%rdi
  je     L21
  mov    $0x0,%eax
  call   <erealloc@plt>
  movslq %eax,%r12
L16:
  movslq %ebx,%rdi
  add    %r12,%rdi
  movslq %ebp,%rdx
  mov    %r13,%rsi
  call   <memcpy@plt>
  mov    %r12,%rax
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L21:
  mov    %esi,%edi
  mov    $0x0,%eax
  call   <emalloc@plt>
  movslq %eax,%r12
  jmp    L16
```

assistant: ```c
unsigned char *SafeMemCopy(dest, orig, off_dest, sz_dest, len)
unsigned char *dest;
unsigned char *orig;
int off_dest;
int *sz_dest;
int len;
{
  if (len > (*sz_dest - off_dest)) {
    *sz_dest = len + off_dest;
    if (dest)
      dest = (unsigned char *)erealloc(dest, *sz_dest);
    else
      dest = (unsigned char *)emalloc(*sz_dest);
  }
  memcpy(dest + off_dest, orig, len);
  return (dest);
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<SafeMemCopy>:
  endbr64
  push   %r13
  mov    %rsi,%r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  mov    %r8d,%ebp
  push   %rbx
  mov    %edx,%ebx
  sub    $0x8,%rsp
  mov    (%rcx),%eax
  sub    %edx,%eax
  cmp    %r8d,%eax
  jge    L5
  lea    (%rdx,%r8,1),%esi
  mov    %esi,(%rcx)
  test   %rdi,%rdi
  je     L16
  xor    %eax,%eax
  call   <erealloc@plt>
  movslq %eax,%r12
L5:
  movslq %ebx,%rdi
  movslq %ebp,%rdx
  mov    %r13,%rsi
  add    %r12,%rdi
  call   <memcpy@plt>
  add    $0x8,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  cs nopw 0x0(%rax,%rax,1)
L16:
  mov    %esi,%edi
  xor    %eax,%eax
  call   <emalloc@plt>
  movslq %eax,%r12
  jmp    L5
```

assistant: ```c
unsigned char *SafeMemCopy(dest, orig, off_dest, sz_dest, len)
unsigned char *dest;
unsigned char *orig;
int off_dest;
int *sz_dest;
int len;
{
  if (len > (*sz_dest - off_dest)) {
    *sz_dest = len + off_dest;
    if (dest)
      dest = (unsigned char *)erealloc(dest, *sz_dest);
    else
      dest = (unsigned char *)emalloc(*sz_dest);
  }
  memcpy(dest + off_dest, orig, len);
  return (dest);
}
```
user: Translate the below assembly code into C programming language:

```asm
<SafeMemCopy>:
  endbr64
  push   %r13
  mov    %rsi,%r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  mov    %r8d,%ebp
  push   %rbx
  mov    %edx,%ebx
  sub    $0x8,%rsp
  mov    (%rcx),%eax
  sub    %edx,%eax
  cmp    %r8d,%eax
  jge    L12
  lea    (%rdx,%r8,1),%esi
  mov    %esi,(%rcx)
  test   %rdi,%rdi
  je     L4
  xor    %eax,%eax
  call   <erealloc@plt>
  movslq %eax,%r12
L12:
  movslq %ebx,%rdi
  movslq %ebp,%rdx
  mov    %r13,%rsi
  add    %r12,%rdi
  call   <memcpy@plt>
  add    $0x8,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  cs nopw 0x0(%rax,%rax,1)
L4:
  mov    %esi,%edi
  xor    %eax,%eax
  call   <emalloc@plt>
  movslq %eax,%r12
  jmp    L12
```

assistant: ```c
unsigned char *SafeMemCopy(dest, orig, off_dest, sz_dest, len)
unsigned char *dest;
unsigned char *orig;
int off_dest;
int *sz_dest;
int len;
{
  if (len > (*sz_dest - off_dest)) {
    *sz_dest = len + off_dest;
    if (dest)
      dest = (unsigned char *)erealloc(dest, *sz_dest);
    else
      dest = (unsigned char *)emalloc(*sz_dest);
  }
  memcpy(dest + off_dest, orig, len);
  return (dest);
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<USBDevEndpointConfigGet>:
  endbr64
  mov    %rcx,%rax
  testl  $0x2000,(%rcx)
  je     L11
  movl   $0x2000,(%rcx)
  lea    -0x10(%rdi,%rsi,1),%ecx
  lea    0x110(%rcx),%esi
  movslq %esi,%rsi
  movzwl (%rsi),%esi
  movzwl %si,%esi
  mov    %esi,(%rdx)
  add    $0x113,%ecx
  movslq %ecx,%rcx
  movzbl (%rcx),%edx
  test   %dl,%dl
  js     L113
L7:
  test   $0x10,%dl
  je     L3
  test   $0x4,%dl
  je     L124
  orl    $0x10,(%rax)
L3:
  test   $0x40,%dl
  jne    L17
  orl    $0x100,(%rax)
  ret
L113:
  orl    $0x1,(%rax)
  jmp    L7
L124:
  orl    $0x8,(%rax)
  jmp    L3
L11:
  movl   $0x0,(%rcx)
  lea    -0x10(%rdi,%rsi,1),%ecx
  lea    0x114(%rcx),%esi
  movslq %esi,%rsi
  movzwl (%rsi),%esi
  movzwl %si,%esi
  mov    %esi,(%rdx)
  add    $0x117,%ecx
  movslq %ecx,%rcx
  movzbl (%rcx),%edx
  test   %dl,%dl
  js     L92
L74:
  test   $0x20,%dl
  je     L67
  test   $0x8,%dl
  je     L71
  orl    $0x10,(%rax)
L67:
  test   $0x40,%dl
  jne    L17
  orl    $0x100,(%rax)
L17:
  ret
L92:
  orl    $0x4,(%rax)
  jmp    L74
L71:
  orl    $0x8,(%rax)
  jmp    L67
```

assistant: ```c
void USBDevEndpointConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t *pui32MaxPacketSize, uint32_t *pui32Flags) {
  uint32_t ui32Register;
  ;
  ;

  ;
  if (*pui32Flags & 0x00002000) {
    *pui32Flags = 0x00002000;
    *pui32MaxPacketSize = (uint32_t)(*((volatile unsigned short *)(ui32Base + (ui32Endpoint - 0x10) + 0x00000110)));
    ui32Register = (uint32_t)(*((volatile unsigned char *)(ui32Base + (ui32Endpoint - 0x10) + 0x00000113)));
    if (ui32Register & 0x00000080) {
      *pui32Flags |= 0x00000001;
    }
    if (ui32Register & 0x00000010) {
      if (ui32Register & 0x00000004) {
        *pui32Flags |= 0x00000010;
      } else {
        *pui32Flags |= 0x00000008;
      }
    }
    if (ui32Register & 0x00000040) {
      *pui32Flags |= 0x00000000;
    } else {
      *pui32Flags |= 0x00000100;
    }
  } else {
    *pui32Flags = 0x00000000;
    *pui32MaxPacketSize = (uint32_t)(*((volatile unsigned short *)(ui32Base + (ui32Endpoint - 0x10) + 0x00000114)));
    ui32Register = (uint32_t)(*((volatile unsigned char *)(ui32Base + (ui32Endpoint - 0x10) + 0x00000117)));
    if (ui32Register & 0x00000080) {
      *pui32Flags |= 0x00000004;
    }
    if (ui32Register & 0x00000020) {
      if (ui32Register & 0x00000008) {
        *pui32Flags |= 0x00000010;
      } else {
        *pui32Flags |= 0x00000008;
      }
    }
    if (ui32Register & 0x00000040) {
      *pui32Flags |= 0x00000000;
    } else {
      *pui32Flags |= 0x00000100;
    }
  }
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<USBDevEndpointConfigGet>:
  endbr64
  mov    %rcx,%rax
  lea    -0x10(%rdi,%rsi,1),%ecx
  testl  $0x2000,(%rax)
  je     L37
  lea    0x110(%rcx),%esi
  add    $0x113,%ecx
  movl   $0x2000,(%rax)
  movslq %esi,%rsi
  movslq %ecx,%rcx
  movzwl (%rsi),%esi
  mov    %esi,(%rdx)
  movzbl (%rcx),%edx
  test   %dl,%dl
  js     L13
  test   $0x10,%dl
  jne    L42
L25:
  and    $0x40,%edx
  jne    L61
  orl    $0x100,(%rax)
L61:
  ret
  nopl   0x0(%rax)
L37:
  lea    0x114(%rcx),%esi
  add    $0x117,%ecx
  movl   $0x0,(%rax)
  movslq %esi,%rsi
  movslq %ecx,%rcx
  movzwl (%rsi),%esi
  mov    %esi,(%rdx)
  movzbl (%rcx),%edx
  test   %dl,%dl
  js     L107
  test   $0x20,%dl
  je     L25
L84:
  mov    (%rax),%ecx
  mov    %ecx,%esi
  or     $0x10,%ecx
  or     $0x8,%esi
  test   $0x8,%dl
  cmove  %esi,%ecx
  mov    %ecx,(%rax)
  jmp    L25
  nopl   (%rax)
L42:
  mov    (%rax),%ecx
  mov    %ecx,%esi
  or     $0x10,%ecx
  or     $0x8,%esi
  test   $0x4,%dl
  cmove  %esi,%ecx
  mov    %ecx,(%rax)
  jmp    L25
  nopl   0x0(%rax)
L107:
  orl    $0x4,(%rax)
  test   $0x20,%dl
  je     L25
  jmp    L84
  nopw   0x0(%rax,%rax,1)
L13:
  orl    $0x1,(%rax)
  test   $0x10,%dl
  je     L25
  jmp    L42
```

assistant: ```c
void USBDevEndpointConfigGet(uint32_t ui32Base, uint32_t ui32Endpoint, uint32_t *pui32MaxPacketSize, uint32_t *pui32Flags) {
  uint32_t ui32Register;
  ;
  ;

  ;
  if (*pui32Flags & 0x00002000) {
    *pui32Flags = 0x00002000;
    *pui32MaxPacketSize = (uint32_t)(*((volatile unsigned short *)(ui32Base + (ui32Endpoint - 0x10) + 0x00000110)));
    ui32Register = (uint32_t)(*((volatile unsigned char *)(ui32Base + (ui32Endpoint - 0x10) + 0x00000113)));
    if (ui32Register & 0x00000080) {
      *pui32Flags |= 0x00000001;
    }
    if (ui32Register & 0x00000010) {
      if (ui32Register & 0x00000004) {
        *pui32Flags |= 0x00000010;
      } else {
        *pui32Flags |= 0x00000008;
      }
    }
    if (ui32Register & 0x00000040) {
      *pui32Flags |= 0x00000000;
    } else {
      *pui32Flags |= 0x00000100;
    }
  } else {
    *pui32Flags = 0x00000000;
    *pui32MaxPacketSize = (uint32_t)(*((volatile unsigned short *)(ui32Base + (ui32Endpoint - 0x10) + 0x00000114)));
    ui32Register = (uint32_t)(*((volatile unsigned char *)(ui32Base + (ui32Endpoint - 0x10) + 0x00000117)));
    if (ui32Register & 0x00000080) {
      *pui32Flags |= 0x00000004;
    }
    if (ui32Register & 0x00000020) {
      if (ui32Register & 0x00000008) {
        *pui32Flags |= 0x00000010;
      } else {
        *pui32Flags |= 0x00000008;
      }
    }
    if (ui32Register & 0x00000040) {
      *pui32Flags |= 0x00000000;
    } else {
      *pui32Flags |= 0x00000100;
    }
  }
}
```