user: 请从给定的汇编指令推导出C源代码：

```asm
<weight_resource>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  mov    %edx,%ebp
  push   %rbx
  sub    $0x68,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x58(%rsp)
  xor    %eax,%eax
  lea    0x20(%rsp),%rdx
  mov    %rsp,%r13
  call   <cards_getproduction@plt>
  mov    %r13,%rsi
  mov    %ebp,%edi
  call   <data_gettradables@plt>
  mov    0x20(%rsp),%r12d
  test   %r12d,%r12d
  je     L200
  cmpl   $0x1,(%rsp)
  sbb    %r12d,%r12d
  and    $0x5,%r12d
L200:
  mov    0x24(%rsp),%eax
  test   %eax,%eax
  je     L57
  mov    0x4(%rsp),%eax
  test   %eax,%eax
  je     L253
  cmp    $0x1,%eax
  jle    L395
L57:
  mov    0x28(%rsp),%ebx
  test   %ebx,%ebx
  je     L235
L163:
  mov    0x8(%rsp),%r11d
  test   %r11d,%r11d
  jne    L235
  add    $0x5,%r12d
L235:
  mov    0x2c(%rsp),%r10d
  test   %r10d,%r10d
  je     L382
  mov    0xc(%rsp),%eax
  test   %eax,%eax
  je     L144
  cmp    $0x1,%eax
  jle    L337
L382:
  mov    0x30(%rsp),%r9d
  test   %r9d,%r9d
  je     L126
L78:
  mov    0x10(%rsp),%r8d
  test   %r8d,%r8d
  jne    L126
  add    $0x5,%r12d
L126:
  mov    0x34(%rsp),%edi
  test   %edi,%edi
  je     L320
  mov    0x14(%rsp),%esi
  test   %esi,%esi
  jne    L320
  add    $0x5,%r12d
L320:
  mov    0x38(%rsp),%ecx
  test   %ecx,%ecx
  jne    L394
L328:
  xor    %ebx,%ebx
L194:
  mov    %ebp,%esi
  mov    %ebx,%edi
  call   <data_getdir@plt>
  mov    %r13,%rsi
  mov    %eax,%edi
  call   <data_gettradables@plt>
  mov    0x20(%rsp),%eax
  test   %eax,%eax
  je     L336
  mov    (%rsp),%eax
  test   %eax,%eax
  je     L230
  xor    %esi,%esi
  mov    %ebx,%edx
  mov    %ebp,%edi
  call   <get_trade@plt>
  cmp    $0x1,%eax
  sete   %al
  movzbl %al,%eax
  sub    %eax,%r12d
  nopl   (%rax)
L336:
  mov    0x24(%rsp),%eax
  test   %eax,%eax
  je     L283
  mov    0x4(%rsp),%eax
  test   %eax,%eax
  je     L412
  mov    %ebx,%edx
  mov    $0x1,%esi
  mov    %ebp,%edi
  call   <get_trade@plt>
  cmp    $0x1,%eax
  sete   %al
  movzbl %al,%eax
  sub    %eax,%r12d
  cs nopw 0x0(%rax,%rax,1)
L283:
  mov    0x28(%rsp),%eax
  test   %eax,%eax
  je     L392
  mov    0x8(%rsp),%r11d
  test   %r11d,%r11d
  je     L364
  mov    %ebx,%edx
  mov    $0x2,%esi
  mov    %ebp,%edi
  call   <get_trade@plt>
  cmp    $0x1,%eax
  sete   %al
  movzbl %al,%eax
  sub    %eax,%r12d
L392:
  mov    0x2c(%rsp),%r10d
  test   %r10d,%r10d
  je     L181
  mov    0xc(%rsp),%r9d
  test   %r9d,%r9d
  je     L373
  mov    %ebx,%edx
  mov    $0x3,%esi
  mov    %ebp,%edi
  call   <get_trade@plt>
  cmp    $0x1,%eax
  sete   %al
  movzbl %al,%eax
  sub    %eax,%r12d
  nopw   0x0(%rax,%rax,1)
L181:
  mov    0x30(%rsp),%r8d
  test   %r8d,%r8d
  je     L138
  mov    0x10(%rsp),%edi
  test   %edi,%edi
  je     L261
  mov    %ebx,%edx
  mov    $0x4,%esi
  mov    %ebp,%edi
  call   <get_trade@plt>
  cmp    $0x1,%eax
  sete   %al
  movzbl %al,%eax
  sub    %eax,%r12d
  nopl   0x0(%rax,%rax,1)
L138:
  mov    0x34(%rsp),%esi
  test   %esi,%esi
  je     L27
  mov    0x14(%rsp),%ecx
  test   %ecx,%ecx
  je     L236
  mov    %ebx,%edx
  mov    $0x5,%esi
  mov    %ebp,%edi
  call   <get_trade@plt>
  cmp    $0x1,%eax
  sete   %al
  movzbl %al,%eax
  sub    %eax,%r12d
  xchg   %ax,%ax
L27:
  mov    0x38(%rsp),%edx
  test   %edx,%edx
  je     L401
  mov    0x18(%rsp),%eax
  test   %eax,%eax
  je     L414
  mov    %ebx,%edx
  mov    $0x6,%esi
  mov    %ebp,%edi
  call   <get_trade@plt>
  cmp    $0x1,%eax
  sete   %al
  movzbl %al,%eax
  sub    %eax,%r12d
  nopw   0x0(%rax,%rax,1)
L401:
  cmp    $0x1,%ebx
  je     L154
  mov    $0x1,%ebx
  jmp    L194
  nop
L154:
  mov    0x58(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L281
  add    $0x68,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  nopw   0x0(%rax,%rax,1)
L414:
  add    $0x1,%r12d
  jmp    L401
  xchg   %ax,%ax
L261:
  add    $0x1,%r12d
  jmp    L138
  nopl   0x0(%rax)
L236:
  add    $0x1,%r12d
  jmp    L27
  nopl   0x0(%rax)
L230:
  add    $0x1,%r12d
  jmp    L336
  nopl   0x0(%rax)
L412:
  add    $0x1,%r12d
  jmp    L283
  nopl   0x0(%rax)
L364:
  add    $0x1,%r12d
  jmp    L392
  nopl   0x0(%rax)
L373:
  add    $0x1,%r12d
  jmp    L181
  nopl   0x0(%rax)
L394:
  mov    0x18(%rsp),%edx
  test   %edx,%edx
  jne    L328
  add    $0x5,%r12d
  jmp    L328
  nopl   (%rax)
L144:
  add    $0x5,%r12d
L337:
  mov    0x30(%rsp),%r9d
  add    $0x2,%r12d
  test   %r9d,%r9d
  je     L126
  jmp    L78
  nopl   0x0(%rax,%rax,1)
L253:
  add    $0x5,%r12d
L395:
  mov    0x28(%rsp),%ebx
  add    $0x2,%r12d
  test   %ebx,%ebx
  je     L235
  jmp    L163
L281:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int weight_resource(int era, int card, int player) {
  int weight = 0;
  int prod[13];
  cards_getproduction(era, card, prod);
  int trade[7 + 1];
  data_gettradables(player, trade);
  int i, j;
  for (i = 0; i < 7; i++) {
    if (prod[i] && !trade[i])
      weight += 5;
    if (prod[i] && (i == 1 || i == 3) && trade[i] < 2)
      weight += 2;
  }
  for (j = 0; j < 2; j++) {
    data_gettradables(data_getdir(j, player), trade);
    for (i = 0; i < 7; i++) {
      if (prod[i] && !trade[i])
        weight++;
      if (prod[i] && trade[i] && get_trade(player, i, j) == 1)
        weight--;
    }
  }
  return weight;
}
```