// File: /workspace/github_c_makefile_star2_O1/ZombiesYard[P]MPU6050-DMP-raspberry-pi/MotionSensor/inv_mpu_lib/inv_mpu_dmp_motion_driver.c
// Function: dmp_set_tap_thresh(unsigned char, unsigned short)
uint8_t dmp_set_tap_thresh(uint8_t axis, uint16_t thresh)
{
	uint8_t tmp[4], accel_fsr;
	float scaled_thresh;
	uint16_t dmp_thresh, dmp_thresh_2;
	if (!(axis & TAP_XYZ) || thresh > 1600)
		return 1;

	scaled_thresh = (float)thresh / DMP_SAMPLE_RATE;

	mpu_get_accel_fsr(&accel_fsr);
	switch (accel_fsr)
	{
	case 2:
		dmp_thresh = (uint16_t)(scaled_thresh * 16384);
		/* dmp_thresh * 0.75 */
		dmp_thresh_2 = (uint16_t)(scaled_thresh * 12288);
		break;
	case 4:
		dmp_thresh = (uint16_t)(scaled_thresh * 8192);
		/* dmp_thresh * 0.75 */
		dmp_thresh_2 = (uint16_t)(scaled_thresh * 6144);
		break;
	case 8:
		dmp_thresh = (uint16_t)(scaled_thresh * 4096);
		/* dmp_thresh * 0.75 */
		dmp_thresh_2 = (uint16_t)(scaled_thresh * 3072);
		break;
	case 16:
		dmp_thresh = (uint16_t)(scaled_thresh * 2048);
		/* dmp_thresh * 0.75 */
		dmp_thresh_2 = (uint16_t)(scaled_thresh * 1536);
		break;
	default:
		return 1;
	}
	tmp[0] = (uint8_t)(dmp_thresh >> 8);
	tmp[1] = (uint8_t)(dmp_thresh & 0xFF);
	tmp[2] = (uint8_t)(dmp_thresh_2 >> 8);
	tmp[3] = (uint8_t)(dmp_thresh_2 & 0xFF);

	if (axis & TAP_X)
	{
		if (mpu_write_mem(DMP_TAP_THX, 2, tmp))
			return 1;
		if (mpu_write_mem(D_1_36, 2, tmp+2))
			return 1;
	}
	if (axis & TAP_Y)
	{
		if (mpu_write_mem(DMP_TAP_THY, 2, tmp))
			return 1;
		if (mpu_write_mem(D_1_40, 2, tmp+2))
			return 1;
	}
	if (axis & TAP_Z)
	{
		if (mpu_write_mem(DMP_TAP_THZ, 2, tmp))
			return 1;
		if (mpu_write_mem(D_1_44, 2, tmp+2))
			return 1;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebp
testb $0x7, %bpl
sete %al
cmpl $0x641, %esi            # imm = 0x641
setae %cl
orb %al, %cl
movb $0x1, %bl
jne 0x4467
movl %esi, %r14d
leaq 0x7(%rsp), %r15
movq %r15, %rdi
callq 0x2b1b
movzbl (%r15), %eax
addl $-0x2, %eax
rorl %eax
cmpl $0x7, %eax
ja 0x4467
movl $0x8b, %ecx
btl %eax, %ecx
jae 0x4467
movzwl %r14w, %ecx
cvtsi2ss %ecx, %xmm0
divss 0x2173(%rip), %xmm0     # 0x64f4
movl %eax, %eax
leaq 0x2dae(%rip), %rcx      # 0x7138
leaq 0x2dc7(%rip), %rdx      # 0x7158
movss (%rcx,%rax,4), %xmm1
mulss %xmm0, %xmm1
mulss (%rdx,%rax,4), %xmm0
cvttss2si %xmm0, %eax
cvttss2si %xmm1, %ecx
movb %ch, 0x3(%rsp)
leaq 0x5(%rsp), %r14
movb %cl, -0x1(%r14)
movb %ah, 0x5(%rsp)
movb %al, 0x1(%r14)
testb $0x1, %bpl
jne 0x43d5
testb $0x2, %bpl
jne 0x4405
testb $0x4, %bpl
jne 0x4435
xorl %ebx, %ebx
jmp 0x4467
leaq 0x3(%rsp), %rdx
movl $0x1d4, %edi            # imm = 0x1D4
movl $0x2, %esi
callq 0x39a0
testb %al, %al
jne 0x4467
movl $0x124, %edi            # imm = 0x124
movl $0x2, %esi
movq %r14, %rdx
callq 0x39a0
testb %al, %al
jne 0x4467
jmp 0x43c2
leaq 0x3(%rsp), %rdx
movl $0x1d8, %edi            # imm = 0x1D8
movl $0x2, %esi
callq 0x39a0
testb %al, %al
jne 0x4467
movl $0x128, %edi            # imm = 0x128
movl $0x2, %esi
movq %r14, %rdx
callq 0x39a0
testb %al, %al
jne 0x4467
jmp 0x43c8
leaq 0x3(%rsp), %rdx
movl $0x1dc, %edi            # imm = 0x1DC
movl $0x2, %esi
callq 0x39a0
testb %al, %al
jne 0x4467
movl $0x12c, %edi            # imm = 0x12C
movl $0x2, %esi
movq %r14, %rdx
callq 0x39a0
testb %al, %al
je 0x43ce
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq