// File: /workspace/github_c_makefile_star2_O0/ZombiesYard[P]MPU6050-DMP-raspberry-pi/MotionSensor/inv_mpu_lib/inv_mpu.c
// Function: mpu_set_accel_bias(int const*)
uint8_t mpu_set_accel_bias(const int32_t *accel_bias)
{
	uint8_t data[6];
	int16_t accel_hw[3];
	int16_t got_accel[3];
	int16_t fg[3];

	if (!accel_bias)
		return 1;
	if (!accel_bias[0] && !accel_bias[1] && !accel_bias[2])
		return 0;

	if (i2c_read(st.hw->addr, 3, 3, data))
		return 1;
	fg[0] = ((data[0] >> 4) + 8) & 0xf;
	fg[1] = ((data[1] >> 4) + 8) & 0xf;
	fg[2] = ((data[2] >> 4) + 8) & 0xf;

	accel_hw[0] = (int16_t)(accel_bias[0] * 2 / (64 + fg[0]));
	accel_hw[1] = (int16_t)(accel_bias[1] * 2 / (64 + fg[1]));
	accel_hw[2] = (int16_t)(accel_bias[2] * 2 / (64 + fg[2]));

	if (i2c_read(st.hw->addr, 0x06, 6, data))
		return 1;

	got_accel[0] = ((int16_t)data[0] << 8) | data[1];
	got_accel[1] = ((int16_t)data[2] << 8) | data[3];
	got_accel[2] = ((int16_t)data[4] << 8) | data[5];

	accel_hw[0] += got_accel[0];
	accel_hw[1] += got_accel[1];
	accel_hw[2] += got_accel[2];

	data[0] = (accel_hw[0] >> 8) & 0xff;
	data[1] = (accel_hw[0]) & 0xff;
	data[2] = (accel_hw[1] >> 8) & 0xff;
	data[3] = (accel_hw[1]) & 0xff;
	data[4] = (accel_hw[2] >> 8) & 0xff;
	data[5] = (accel_hw[2]) & 0xff;

	if (i2c_write(st.hw->addr, 0x06, 6, data))
		return 1;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x306c
movb $0x1, -0x1(%rbp)
jmp 0x3259
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x3092
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x3092
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x3092
movb $0x0, -0x1(%rbp)
jmp 0x3259
movq 0x917f(%rip), %rax      # 0xc218
movb (%rax), %al
leaq -0x16(%rbp), %rcx
movl $0x3, %edx
movzbl %al, %edi
movl %edx, %esi
callq 0x6df0
movsbl %al, %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $-0x1, %edx
cmovnel %ecx, %eax
cmpl $0x0, %eax
je 0x30cc
movb $0x1, -0x1(%rbp)
jmp 0x3259
movzbl -0x16(%rbp), %eax
sarl $0x4, %eax
addl $0x8, %eax
andl $0xf, %eax
movw %ax, -0x28(%rbp)
movzbl -0x15(%rbp), %eax
sarl $0x4, %eax
addl $0x8, %eax
andl $0xf, %eax
movw %ax, -0x26(%rbp)
movzbl -0x14(%rbp), %eax
sarl $0x4, %eax
addl $0x8, %eax
andl $0xf, %eax
movw %ax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shll %eax
movswl -0x28(%rbp), %ecx
addl $0x40, %ecx
cltd
idivl %ecx
movw %ax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
shll %eax
movswl -0x26(%rbp), %ecx
addl $0x40, %ecx
cltd
idivl %ecx
movw %ax, -0x1a(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
shll %eax
movswl -0x24(%rbp), %ecx
addl $0x40, %ecx
cltd
idivl %ecx
movw %ax, -0x18(%rbp)
movq 0x90ce(%rip), %rax      # 0xc218
movb (%rax), %al
leaq -0x16(%rbp), %rcx
movl $0x6, %edx
movzbl %al, %edi
movl %edx, %esi
callq 0x6df0
movsbl %al, %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $-0x1, %edx
cmovnel %ecx, %eax
cmpl $0x0, %eax
je 0x317d
movb $0x1, -0x1(%rbp)
jmp 0x3259
movzbl -0x16(%rbp), %eax
cwtl
shll $0x8, %eax
movzbl -0x15(%rbp), %ecx
orl %ecx, %eax
movw %ax, -0x22(%rbp)
movzbl -0x14(%rbp), %eax
cwtl
shll $0x8, %eax
movzbl -0x13(%rbp), %ecx
orl %ecx, %eax
movw %ax, -0x20(%rbp)
movzbl -0x12(%rbp), %eax
cwtl
shll $0x8, %eax
movzbl -0x11(%rbp), %ecx
orl %ecx, %eax
movw %ax, -0x1e(%rbp)
movswl -0x22(%rbp), %ecx
movswl -0x1c(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x1c(%rbp)
movswl -0x20(%rbp), %ecx
movswl -0x1a(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x1a(%rbp)
movswl -0x1e(%rbp), %ecx
movswl -0x18(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x18(%rbp)
movswl -0x1c(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, -0x16(%rbp)
movswl -0x1c(%rbp), %eax
andl $0xff, %eax
movb %al, -0x15(%rbp)
movswl -0x1a(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, -0x14(%rbp)
movswl -0x1a(%rbp), %eax
andl $0xff, %eax
movb %al, -0x13(%rbp)
movswl -0x18(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, -0x12(%rbp)
movswl -0x18(%rbp), %eax
andl $0xff, %eax
movb %al, -0x11(%rbp)
movq 0x8fe3(%rip), %rax      # 0xc218
movb (%rax), %al
leaq -0x16(%rbp), %rcx
movl $0x6, %edx
movzbl %al, %edi
movl %edx, %esi
callq 0x7360
cmpl $0x0, %eax
je 0x3255
movb $0x1, -0x1(%rbp)
jmp 0x3259
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)