// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movw %si, %ax
movb %dil, %cl
movb %cl, -0x2(%rbp)
movw %ax, -0x4(%rbp)
movzbl -0x2(%rbp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x5bfc
movzwl -0x4(%rbp), %eax
cmpl $0x640, %eax            # imm = 0x640
jle 0x5c05
movb $0x1, -0x1(%rbp)
jmp 0x5e47
movzwl -0x4(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss 0x294b(%rip), %xmm1     # 0x8560
divss %xmm1, %xmm0
movss %xmm0, -0x10(%rbp)
leaq -0x9(%rbp), %rdi
callq 0x35f0
movzbl -0x9(%rbp), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0xe, %eax
ja 0x5d24
movq -0x20(%rbp), %rax
leaq 0x2938(%rip), %rcx      # 0x8580
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movss -0x10(%rbp), %xmm0
movss 0x241a(%rip), %xmm1     # 0x8078
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movw %ax, -0x12(%rbp)
movss -0x10(%rbp), %xmm0
movss 0x2905(%rip), %xmm1     # 0x857c
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movw %ax, -0x14(%rbp)
jmp 0x5d2d
movss -0x10(%rbp), %xmm0
movss 0x28df(%rip), %xmm1     # 0x8574
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movw %ax, -0x12(%rbp)
movss -0x10(%rbp), %xmm0
movss 0x28ca(%rip), %xmm1     # 0x8578
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movw %ax, -0x14(%rbp)
jmp 0x5d2d
movss -0x10(%rbp), %xmm0
movss 0x28a3(%rip), %xmm1     # 0x856c
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movw %ax, -0x12(%rbp)
movss -0x10(%rbp), %xmm0
movss 0x288e(%rip), %xmm1     # 0x8570
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movw %ax, -0x14(%rbp)
jmp 0x5d2d
movss -0x10(%rbp), %xmm0
movss 0x2867(%rip), %xmm1     # 0x8564
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movw %ax, -0x12(%rbp)
movss -0x10(%rbp), %xmm0
movss 0x2852(%rip), %xmm1     # 0x8568
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movw %ax, -0x14(%rbp)
jmp 0x5d2d
movb $0x1, -0x1(%rbp)
jmp 0x5e47
movzwl -0x12(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x8(%rbp)
movzwl -0x12(%rbp), %eax
andl $0xff, %eax
movb %al, -0x7(%rbp)
movzwl -0x14(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x6(%rbp)
movzwl -0x14(%rbp), %eax
andl $0xff, %eax
movb %al, -0x5(%rbp)
movzbl -0x2(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5dab
leaq -0x8(%rbp), %rdx
movl $0x1d4, %edi            # imm = 0x1D4
movl $0x2, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x5d85
movb $0x1, -0x1(%rbp)
jmp 0x5e47
leaq -0x8(%rbp), %rdx
addq $0x2, %rdx
movl $0x124, %edi            # imm = 0x124
movl $0x2, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x5da9
movb $0x1, -0x1(%rbp)
jmp 0x5e47
jmp 0x5dab
movzbl -0x2(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x5df7
leaq -0x8(%rbp), %rdx
movl $0x1d8, %edi            # imm = 0x1D8
movl $0x2, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x5dd4
movb $0x1, -0x1(%rbp)
jmp 0x5e47
leaq -0x8(%rbp), %rdx
addq $0x2, %rdx
movl $0x128, %edi            # imm = 0x128
movl $0x2, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x5df5
movb $0x1, -0x1(%rbp)
jmp 0x5e47
jmp 0x5df7
movzbl -0x2(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x5e43
leaq -0x8(%rbp), %rdx
movl $0x1dc, %edi            # imm = 0x1DC
movl $0x2, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x5e20
movb $0x1, -0x1(%rbp)
jmp 0x5e47
leaq -0x8(%rbp), %rdx
addq $0x2, %rdx
movl $0x12c, %edi            # imm = 0x12C
movl $0x2, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x5e41
movb $0x1, -0x1(%rbp)
jmp 0x5e47
jmp 0x5e43
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x20, %rsp
popq %rbp
retq