// File: hantaoyin[P]ffxiv-crafting-mcts/ffxiv-crafting-mcts.C
// Function: State::ApplyQualityChange(Action)
void ApplyQualityChange(Action ac) {
    const ActionParams& ac_effect = ALL_ACTIONS[Action2ID(ac)];
    if (!(ac_effect.flags & QUALITY)) {
      return;
    }
    double efficiency;
    if (ac == Action::ByregotsBlessing) {
      ASSERT(inner_quiet > 1) << inner_quiet;
      efficiency = 1.0 + .2 * (inner_quiet - 1);
    } else {
      efficiency = ac_effect.efficiency / 100.;
    }
    double buff_multiplier = 1.;
    if (buff[Buff2ID(Buff::GreatStrides)] > 0) {
      buff_multiplier += 1.;
    }
    if (buff[Buff2ID(Buff::Innovation)] > 0) {
      buff_multiplier += .2;
    }
    efficiency *= buff_multiplier;

    switch (condition) {
    case Condition::Good:      efficiency *= 1.5; break;
    case Condition::Excellent: efficiency *= 4.0; break;
    case Condition::Poor:      efficiency *= 0.5; break;
    default:
      break;
    }

    // Following is a crude formula from fitted data.  It does not take character and recipe level
    // into consideration, which is why base_quality_coef and ig_quality_coef are required.
    double control = params.base_control;
    if (inner_quiet > 1) {
      control *= 1. + 0.2 * (inner_quiet - 1);
    }
    if (control > params.base_control + 3000) {
      control = params.base_control + 3000;
    }
    double coef = buff[Buff2ID(Buff::Ingenuity)] > 0 ? params.ig_quality_coef : params.base_quality_coef;
    quality += efficiency * coef * (1. + 0.01 * control * (1. + 0.0001 * control));
    if (quality > params.max_quality) {
      quality = params.max_quality;
    }
  }

// Assembly:
subq $0x68, %rsp
movb %sil, %al
movq %rdi, 0x60(%rsp)
movb %al, 0x5f(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x28(%rsp)
movzbl 0x5f(%rsp), %edi
callq 0x2740
movzbl %al, %eax
movl %eax, %esi
leaq 0xa510(%rip), %rdi      # 0x1bac0
callq 0x2710
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movzwl 0xe(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x115d0
jmp 0x1186c
cmpb $0x2, 0x5f(%rsp)
jne 0x11607
movq 0x28(%rsp), %rax
movzbl 0x8(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
movsd 0x1ac9(%rip), %xmm1     # 0x130b8
mulsd %xmm1, %xmm0
movsd 0x1a2d(%rip), %xmm1     # 0x13028
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x11626
movq 0x50(%rsp), %rax
movswl 0xc(%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x1a84(%rip), %xmm1     # 0x130a0
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x28(%rsp), %rax
movsd 0x19f5(%rip), %xmm0     # 0x13028
movsd %xmm0, 0x40(%rsp)
addq $0xa, %rax
movq %rax, 0x20(%rsp)
movl $0x1, %edi
callq 0x6b30
movq 0x20(%rsp), %rdi
movzbl %al, %eax
movl %eax, %esi
callq 0x11d30
movzbl (%rax), %eax
cmpl $0x0, %eax
jle 0x11677
movsd 0x19bd(%rip), %xmm0     # 0x13028
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x28(%rsp), %rax
addq $0xa, %rax
movq %rax, 0x18(%rsp)
movl $0x2, %edi
callq 0x6b30
movq 0x18(%rsp), %rdi
movzbl %al, %eax
movl %eax, %esi
callq 0x11d30
movzbl (%rax), %eax
cmpl $0x0, %eax
jle 0x116ba
movsd 0x1a0a(%rip), %xmm0     # 0x130b8
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x28(%rsp), %rax
movsd 0x40(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movb 0x9(%rax), %al
movb %al, 0x17(%rsp)
subb $0x1, %al
je 0x116f6
jmp 0x116e2
movb 0x17(%rsp), %al
subb $0x2, %al
je 0x1170c
jmp 0x116ec
movb 0x17(%rsp), %al
subb $0x3, %al
je 0x11722
jmp 0x11738
movsd 0x1912(%rip), %xmm0     # 0x13010
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x1173a
movsd 0x19ac(%rip), %xmm0     # 0x130c0
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x1173a
movsd 0x191e(%rip), %xmm0     # 0x13048
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x1173a
jmp 0x1173a
movq 0x28(%rsp), %rax
movsd 0x1981(%rip), %xmm0     # 0x130c8
movsd %xmm0, 0x38(%rsp)
movzbl 0x8(%rax), %eax
cmpl $0x1, %eax
jle 0x1178a
movq 0x28(%rsp), %rax
movzbl 0x8(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
movsd 0x194a(%rip), %xmm1     # 0x130b8
mulsd %xmm1, %xmm0
movsd 0x18ae(%rip), %xmm1     # 0x13028
addsd %xmm1, %xmm0
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x1938(%rip), %xmm1     # 0x130d0
ucomisd %xmm1, %xmm0
jbe 0x117ac
movsd 0x192a(%rip), %xmm0     # 0x130d0
movsd %xmm0, 0x38(%rsp)
movq 0x28(%rsp), %rax
addq $0xa, %rax
movq %rax, 0x8(%rsp)
movl $0x6, %edi
callq 0x6b30
movq 0x8(%rsp), %rdi
movzbl %al, %eax
movl %eax, %esi
callq 0x11d30
movq %rax, %rcx
movq 0x28(%rsp), %rax
movzbl (%rcx), %ecx
testl %ecx, %ecx
setg %dl
leaq 0x191e(%rip), %rcx      # 0x13108
movzbl %dl, %edx
movsd 0x10(%rcx,%rdx,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x48(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x38(%rsp), %xmm3
movsd 0x1841(%rip), %xmm1     # 0x13058
movaps %xmm3, %xmm2
mulsd %xmm1, %xmm2
movsd 0x18b2(%rip), %xmm1     # 0x130d8
mulsd %xmm1, %xmm3
movsd 0x17f6(%rip), %xmm1     # 0x13028
addsd %xmm1, %xmm3
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movswl 0x4(%rax), %ecx
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movw %cx, 0x4(%rax)
movswl 0x4(%rax), %eax
cmpl $0x9238, %eax           # imm = 0x9238
jle 0x1186c
movq 0x28(%rsp), %rax
movw $0x9238, 0x4(%rax)      # imm = 0x9238
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)