user: Converte this assembly snippet into its equivalent C code:

```asm
<fc8300b_tuner_set_pll>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %esi,%ebx
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  lea    (%rdx,%rdx,2),%eax
  movb   $0x0,0x26(%rsp)
  lea    0x0(,%rax,4),%ecx
  movb   $0x0,0x27(%rsp)
  cmp    $0x5b8d80,%ecx
  ja     L43
  mov    %edx,%ecx
  shl    $0x4,%ecx
  cmp    $0x5b8d80,%ecx
  ja     L251
  lea    0x0(,%rax,8),%ecx
  cmp    $0x5b8d80,%ecx
  ja     L68
  mov    %edx,%ecx
  shl    $0x5,%ecx
  cmp    $0x5b8d80,%ecx
  ja     L35
  mov    %eax,%ecx
  shl    $0x4,%ecx
  cmp    $0x5b8d80,%ecx
  ja     L21
  mov    %edx,%ecx
  shl    $0x6,%ecx
  cmp    $0x5b8d80,%ecx
  ja     L58
  shl    $0x5,%eax
  movb   $0x1,0x1f(%rsp)
  movl   $0xf,0x18(%rsp)
  cmp    $0x5b8d80,%eax
  ja     L252
L226:
  mov    %eax,%r13d
  movb   $0x4,0x1e(%rsp)
  movzwl %bx,%ebx
  lea    0x26(%rsp),%r12
  imul   $0x1b4e81b5,%r13,%r13
  lea    0x27(%rsp),%r14
  mov    %r13,%rsi
  shr    $0x2e,%r13
  shr    $0x2b,%rsi
  and    $0x20,%r13d
  imul   $0x4b00,%esi,%edx
  mov    %rsi,%r15
  movzbl %r15b,%r15d
  sub    %edx,%eax
  shl    $0x10,%eax
  imul   $0x1b4e81b5,%rax,%rax
  shr    $0x27,%rax
  mov    %eax,%edx
  movzbl %ah,%esi
  movzbl %al,%eax
  shr    $0x10,%edx
  or     $0x1,%eax
  mov    %esi,0xc(%rsp)
  add    %edx,%r13d
  mov    %eax,0x14(%rsp)
  movzbl %r13b,%edi
  mov    %edi,0x10(%rsp)
L172:
  mov    $0x31,%ecx
  mov    $0x75,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_write@plt>
  xor    %ecx,%ecx
  mov    $0x77,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  mov    $0x2,%r13d
  call   <fc8300b_write@plt>
  mov    0x18(%rsp),%ecx
  mov    $0x51,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_write@plt>
  mov    0x10(%rsp),%ecx
  mov    $0x57,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_write@plt>
  mov    %r15d,%ecx
  mov    $0x5a,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_write@plt>
  mov    $0xe3,%ecx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  mov    $0x50,%edx
  call   <fc8300b_write@plt>
  mov    $0xff,%ecx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  mov    $0x50,%edx
  call   <fc8300b_write@plt>
  mov    0xc(%rsp),%ecx
  mov    $0x58,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_write@plt>
  mov    0x14(%rsp),%ecx
  mov    $0x59,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_write@plt>
  mov    $0x2,%edi
  call   <msWait@plt>
L97:
  mov    %r12,%rcx
  mov    $0x64,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_read@plt>
  mov    %r14,%rcx
  mov    $0x65,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_read@plt>
  movzbl 0x26(%rsp),%eax
  and    $0x11,%eax
  cmp    $0x11,%al
  je     L100
  cmp    $0x5,%r13b
  je     L69
L33:
  add    $0x1,%r13d
  jmp    L97
  nopl   0x0(%rax)
L100:
  cmpb   $0x1,0x27(%rsp)
  ja     L256
  cmp    $0x5,%r13b
  jne    L33
  nopl   (%rax)
L124:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L161
  add    $0x38,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L256:
  mov    %r14,%rcx
  mov    $0x76,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_read@plt>
  cmpb   $0x3d,0x27(%rsp)
  jbe    L192
L224:
  movzbl 0x26(%rsp),%eax
  and    $0x11,%eax
  cmp    $0x11,%al
  je     L124
  nopl   (%rax)
L69:
  mov    %r12,%rcx
  mov    $0x74,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <fc8300b_read@plt>
  movzbl 0x26(%rsp),%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   <vco_cal@plt>
  subb   $0x1,0x1e(%rsp)
  jne    L172
  jmp    L124
L192:
  cmpb   $0x0,0x1f(%rsp)
  je     L224
  mov    %ebx,%esi
  mov    %rbp,%rdi
  mov    $0x2,%ecx
  mov    $0x77,%edx
  call   <fc8300b_write@plt>
  mov    %ebx,%esi
  mov    %rbp,%rdi
  mov    $0xe3,%ecx
  mov    $0x50,%edx
  call   <fc8300b_write@plt>
  mov    $0xff,%ecx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  mov    $0x50,%edx
  call   <fc8300b_write@plt>
  jmp    L224
L43:
  mov    $0x8,%eax
  xor    %ecx,%ecx
  nopl   (%rax)
L103:
  imul   %edx,%eax
  lea    0x1(%rcx,%rcx,1),%esi
  movzbl %sil,%edi
  mov    %edi,0x18(%rsp)
  cmp    $0x5e9ac0,%eax
  seta   %dl
  and    $0x1,%ecx
  or     %ecx,%edx
  mov    %dl,0x1f(%rsp)
  jmp    L226
L251:
  mov    $0xc,%eax
  mov    $0x1,%ecx
  jmp    L103
L68:
  mov    $0x10,%eax
  mov    $0x2,%ecx
  jmp    L103
L35:
  mov    $0x18,%eax
  mov    $0x3,%ecx
  jmp    L103
L21:
  mov    $0x20,%eax
  mov    $0x4,%ecx
  jmp    L103
L58:
  mov    $0x30,%eax
  mov    $0x5,%ecx
  jmp    L103
L252:
  mov    $0x40,%eax
  mov    $0x6,%ecx
  jmp    L103
L161:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int fc8300b_tuner_set_pll(void *handle, unsigned short devid, unsigned int freq, unsigned int offset) {
  unsigned char data_0x51, data_0x57, lo_select;
  unsigned int f_diff, f_diff_shifted, n_val, k_val, f_vco;
  unsigned int f_vco_max = 6000000;
  unsigned char lo_divide_ratio[8] = {8, 12, 16, 24, 32, 48, 64, 96};
  unsigned char pre_shift_bits = 4;
  unsigned char lock_detect = 0;
  unsigned char lock_bank = 0;
  unsigned char lock_condition = 0x11;
  unsigned char i, j;
  for (lo_select = 0; lo_select < 7; lo_select++)
    if (f_vco_max < freq * lo_divide_ratio[lo_select + 1])
      break;
  f_vco = freq * lo_divide_ratio[lo_select];
  n_val = f_vco / 19200;
  f_diff = f_vco - 19200 * n_val;
  f_diff_shifted = f_diff << (20 - pre_shift_bits);
  k_val = f_diff_shifted / (19200 >> pre_shift_bits);
  k_val = k_val | 1;
  data_0x57 = ((n_val >> 3) & 0x20);
  data_0x57 += (k_val >> 16);
  data_0x51 = 0x00;
  data_0x51 += (lo_select * 2) + 1;
  for (j = 0; j < 4; j++) {
    fc8300b_write(handle, devid, 0x75, 0x31);
    fc8300b_write(handle, devid, 0x77, 0x00);
    fc8300b_write(handle, devid, 0x51, data_0x51);
    fc8300b_write(handle, devid, 0x57, data_0x57);
    fc8300b_write(handle, devid, 0x5a, (unsigned char)n_val);
    fc8300b_write(handle, devid, 0x50, 0xe3);
    fc8300b_write(handle, devid, 0x50, 0xff);
    fc8300b_write(handle, devid, 0x58, (unsigned char)((k_val >> 8) & 0xff));
    fc8300b_write(handle, devid, 0x59, (unsigned char)((k_val)&0xff));
    msWait(2);
    for (i = 1; i < 5; i++) {
      fc8300b_read(handle, devid, 0x64, &lock_detect);
      fc8300b_read(handle, devid, 0x65, &lock_bank);
      if (((lock_detect & lock_condition) == lock_condition) && (lock_bank > 1)) {
        fc8300b_read(handle, devid, 0x76, &lock_bank);
        if (lock_bank < 62) {
          if (((lo_select % 2) != 0) || (f_vco > 6200000)) {
            fc8300b_write(handle, devid, 0x77, 0x02);
            fc8300b_write(handle, devid, 0x50, 0xe3);
            fc8300b_write(handle, devid, 0x50, 0xff);
          }
        }
        break;
      }
    }
    if ((lock_detect & lock_condition) != lock_condition) {
      fc8300b_read(handle, devid, 0x74, &lock_detect);
      vco_cal(handle, devid, lock_detect);
    } else {
      break;
    }
  }
  return 0;
}
```