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

```asm
<compute_all_permutations>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %edi,0xc(%rsp)
  mov    %rsi,%rbp
  test   %edi,%edi
  jle    L113
  lea    0x1(%rdi),%edx
  mov    $0x1,%eax
L17:
  mov    %eax,-0x4(%rbp,%rax,4)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L17
L113:
  mov    0xc(%rsp),%edi
  movslq %edi,%r15
  lea    0x0(,%r15,4),%rax
  mov    %rax,0x10(%rsp)
  lea    -0x1(%rdi),%eax
  mov    %eax,0x1c(%rsp)
  movslq %eax,%rcx
  mov    %rcx,0x38(%rsp)
  lea    0x0(,%rcx,4),%rsi
  mov    %rsi,0x28(%rsp)
  mov    %eax,%eax
  lea    0x4(%rbp,%rax,4),%r14
  lea    -0x2(%rdi),%eax
  cltq
  shl    $0x2,%rax
  mov    %rax,0x20(%rsp)
  movl   $0x1,0x18(%rsp)
  lea    -0x4(%rsi),%rax
  mov    %rax,0x30(%rsp)
  mov    %rbp,%r13
L127:
  mov    0xc(%rsp),%ebx
  mov    %ebx,%edi
  call   <factorial@plt>
  cmp    0x18(%rsp),%eax
  jle    L96
  mov    %r13,%rax
  test   %ebx,%ebx
  jle    L71
L122:
  mov    (%rax),%edx
  mov    %edx,(%rax,%r15,4)
  add    $0x4,%rax
  cmp    %r14,%rax
  jne    L122
L71:
  add    0x10(%rsp),%r13
  mov    0xc(%rsp),%ebx
  sub    $0x2,%ebx
  js     L60
  mov    0x20(%rsp),%rax
  add    %r13,%rax
L40:
  mov    0x4(%rax),%ecx
  cmp    %ecx,(%rax)
  jl     L60
  test   %ebx,%ebx
  je     L96
  sub    $0x1,%ebx
  sub    $0x4,%rax
  cmp    $0xffffffff,%ebx
  jne    L40
L60:
  movslq %ebx,%rax
  mov    %rax,0x40(%rsp)
  lea    0x0(,%rax,4),%r12
  lea    0x0(%r13,%r12,1),%rdi
  mov    (%rdi),%ecx
  mov    %r13,0x48(%rsp)
  mov    0x28(%rsp),%rax
  lea    (%rax,%r13,1),%rsi
  cmp    0x0(%r13,%rax,1),%ecx
  jl     L8
  mov    0x1c(%rsp),%edx
  test   %edx,%edx
  js     L96
  mov    0x30(%rsp),%rax
  add    %r13,%rax
L78:
  sub    $0x1,%edx
  mov    %rax,%rsi
  cmp    %ecx,(%rax)
  jg     L8
  sub    $0x4,%rax
  test   %edx,%edx
  jns    L78
L96:
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L8:
  call   <swap@plt>
  lea    0x1(%rbx),%ebp
  cmp    %ebp,0x1c(%rsp)
  jle    L93
  lea    0x4(%r13,%r12,1),%r12
  mov    0x40(%rsp),%rax
  add    0x38(%rsp),%rax
  mov    0x48(%rsp),%rdi
  lea    (%rdi,%rax,2),%rax
  lea    0x4(%rax,%rax,1),%rax
  mov    %r14,0x40(%rsp)
  mov    0xc(%rsp),%r14d
  mov    %r13,0x48(%rsp)
  mov    %ebx,%r13d
  mov    %rax,%rbx
L105:
  mov    %rbx,%rsi
  sub    %r12,%rsi
  mov    %r12,%rdi
  call   <swap@plt>
  add    $0x1,%ebp
  add    $0x4,%r12
  mov    %r14d,%eax
  sub    %ebp,%eax
  add    %r13d,%eax
  cmp    %eax,%ebp
  jl     L105
  mov    0x40(%rsp),%r14
  mov    0x48(%rsp),%r13
L93:
  addl   $0x1,0x18(%rsp)
  add    0x10(%rsp),%r14
  jmp    L127
```

assistant: ```c
void compute_all_permutations(int n, int *res) {
  int i;
  int *curr = res;
  for (i = 1; i <= n; i++) {
    res[i - 1] = i;
  }
  int found = 1;
  while (found < factorial(n)) {
    int k;
    for (k = 0; k < n; k++) {
      curr[k + n] = curr[k];
    }
    curr += n;
    int j;
    for (j = n - 2; j >= 0 && curr[j] >= curr[j + 1]; j--) {
      if (j == 0) {
        return;
      }
    }
    int l;
    for (l = n - 1; curr[j] >= curr[l]; l--) {
      if (l < 0) {
        return;
      }
    }
    swap(&curr[j], &curr[l]);
    for (k = j + 1, l = n - 1; k < l;) {
      swap(&curr[k], &curr[l]);
      k++;
      l--;
    }
    found++;
  }
}
```