// File: /workspace/github_c_makefile_star2_O0/ZombiesYard[P]MPU6050-DMP-raspberry-pi/MotionSensor/inv_mpu_lib/inv_mpu.c
// Function: mpu_run_self_test(int*, int*)
uint8_t mpu_run_self_test(int32_t *gyro, int32_t *accel)
{
#ifdef MPU6050
	const uint8_t tries = 2;
	int32_t gyro_st[3], accel_st[3];
	uint8_t accel_result, gyro_result;
#ifdef AK89xx_SECONDARY
	uint8_t compass_result;
#endif
	int ii;
#endif
	int result;
	uint8_t accel_fsr, fifo_sensors, sensors_on;
	uint16_t gyro_fsr, sample_rate, lpf;
	uint8_t dmp_was_on;

	if (st.chip_cfg.dmp_on)
	{
		mpu_set_dmp_state(0);
		dmp_was_on = 1;
	}
	else
		dmp_was_on = 0;

	/* Get initial settings. */
	mpu_get_gyro_fsr(&gyro_fsr);
	mpu_get_accel_fsr(&accel_fsr);
	mpu_get_lpf(&lpf);
	mpu_get_sample_rate(&sample_rate);
	sensors_on = st.chip_cfg.sensors;
	mpu_get_fifo_config(&fifo_sensors);

	/* For older chips, the self-test will be different. */
#if defined MPU6050
	for (ii = 0; ii < tries; ii++)
		if (!get_st_biases(gyro, accel, 0))
			break;
	if (ii == tries)
	{
		/* If we reach this point, we most likely encountered an I2C error.
		 * We'll just report an error for all three sensors.
		 */
		result = 0;
		goto restore;
	}
	for (ii = 0; ii < tries; ii++)
		if (!get_st_biases(gyro_st, accel_st, 1))
			break;
	if (ii == tries)
	{
		/* Again, probably an I2C error. */
		result = 0;
		goto restore;
	}
	accel_result = accel_self_test(accel, accel_st);
	gyro_result = gyro_self_test(gyro, gyro_st);

	result = 0;
	if (!gyro_result)
		result |= 0x01;
	if (!accel_result)
		result |= 0x02;

#ifdef AK89xx_SECONDARY
	compass_result = compass_self_test();
	if (!compass_result)
		result |= 0x04;
#endif
restore:
#elif defined MPU6500
	/* For now, this function will return a "pass" result for all three sensors
	 * for compatibility with current test applications.
	 */
	get_st_biases(gyro, accel, 0);
	result = 0x7;
#endif
	/* Set to invalid values to ensure no I2C writes are skipped. */
	st.chip_cfg.gyro_fsr = 0xFF;
	st.chip_cfg.accel_fsr = 0xFF;
	st.chip_cfg.lpf = 0xFF;
	st.chip_cfg.sample_rate = 0xFFFF;
	st.chip_cfg.sensors = 0xFF;
	st.chip_cfg.fifo_enable = 0xFF;
	st.chip_cfg.clk_src = INV_CLK_PLL;
	mpu_set_gyro_fsr(gyro_fsr);
	mpu_set_accel_fsr(accel_fsr);
	mpu_set_lpf(lpf);
	mpu_set_sample_rate(sample_rate);
	mpu_set_sensors(sensors_on);
	mpu_configure_fifo(fifo_sensors);

	if (dmp_was_on)
		mpu_set_dmp_state(1);

	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x2, -0x11(%rbp)
cmpb $0x0, 0x8239(%rip)      # 0xc244
je 0x401a
xorl %edi, %edi
callq 0x41b0
movb $0x1, -0x43(%rbp)
jmp 0x401e
movb $0x0, -0x43(%rbp)
leaq -0x3e(%rbp), %rdi
callq 0x3580
leaq -0x39(%rbp), %rdi
callq 0x35f0
leaq -0x42(%rbp), %rdi
callq 0x3670
leaq -0x40(%rbp), %rdi
callq 0x36f0
movb 0x81e2(%rip), %al       # 0xc22a
movb %al, -0x3b(%rbp)
leaq -0x3a(%rbp), %rdi
callq 0x3860
movl $0x0, -0x34(%rbp)
cmpl $0x2, -0x34(%rbp)
jge 0x4084
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x4290
cmpl $0x0, %eax
jne 0x4077
jmp 0x4084
jmp 0x4079
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x405b
cmpl $0x2, -0x34(%rbp)
jne 0x4096
movl $0x0, -0x38(%rbp)
jmp 0x411f
movl $0x0, -0x34(%rbp)
cmpl $0x2, -0x34(%rbp)
jge 0x40c9
leaq -0x20(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x1, %edx
callq 0x4290
cmpl $0x0, %eax
jne 0x40bc
jmp 0x40c9
jmp 0x40be
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x409d
cmpl $0x2, -0x34(%rbp)
jne 0x40d8
movl $0x0, -0x38(%rbp)
jmp 0x411f
movq -0x10(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x4990
movb %al, -0x2d(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x4aa0
movb %al, -0x2e(%rbp)
movl $0x0, -0x38(%rbp)
cmpb $0x0, -0x2e(%rbp)
jne 0x410e
movl -0x38(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpb $0x0, -0x2d(%rbp)
jne 0x411d
movl -0x38(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x38(%rbp)
jmp 0x411f
movb $-0x1, 0x8102(%rip)     # 0xc228
movb $-0x1, 0x80fc(%rip)     # 0xc229
movb $-0x1, 0x80f7(%rip)     # 0xc22b
movw $0xffff, 0x80f1(%rip)   # imm = 0xFFFF
movb $-0x1, 0x80e6(%rip)     # 0xc22a
movb $-0x1, 0x80e5(%rip)     # 0xc230
movb $0x1, 0x80da(%rip)      # 0xc22c
movzwl -0x3e(%rbp), %edi
callq 0x23e0
movzbl -0x39(%rbp), %edi
callq 0x24c0
movzwl -0x42(%rbp), %edi
callq 0x2590
movzwl -0x40(%rbp), %edi
callq 0x2670
movzbl -0x3b(%rbp), %edi
callq 0x2aa0
movzbl -0x3a(%rbp), %edi
callq 0x2780
cmpb $0x0, -0x43(%rbp)
je 0x4198
movl $0x1, %edi
callq 0x41b0
movl -0x38(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)