// 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_orientation(unsigned short)
uint8_t dmp_set_orientation(uint16_t orient)
{
	uint8_t gyro_regs[3], accel_regs[3];
	const uint8_t gyro_axes[3] = {DINA4C, DINACD, DINA6C};
	const uint8_t accel_axes[3] = {DINA0C, DINAC9, DINA2C};
	const uint8_t gyro_sign[3] = {DINA36, DINA56, DINA76};
	const uint8_t accel_sign[3] = {DINA26, DINA46, DINA66};

	gyro_regs[0] = gyro_axes[orient & 3];
	gyro_regs[1] = gyro_axes[(orient >> 3) & 3];
	gyro_regs[2] = gyro_axes[(orient >> 6) & 3];
	accel_regs[0] = accel_axes[orient & 3];
	accel_regs[1] = accel_axes[(orient >> 3) & 3];
	accel_regs[2] = accel_axes[(orient >> 6) & 3];

	/* Chip-to-body, axes only. */
	if (mpu_write_mem(FCFG_1, 3, gyro_regs))
		return 1;
	if (mpu_write_mem(FCFG_2, 3, accel_regs))
		return 1;

	memcpy(gyro_regs, gyro_sign, 3);
	memcpy(accel_regs, accel_sign, 3);
	if (orient & 4)
	{
		gyro_regs[0] |= 1;
		accel_regs[0] |= 1;
	}
	if (orient & 0x20)
	{
		gyro_regs[1] |= 1;
		accel_regs[1] |= 1;
	}
	if (orient & 0x100)
	{
		gyro_regs[2] |= 1;
		accel_regs[2] |= 1;
	}

	/* Chip-to-body, sign only. */
	if (mpu_write_mem(FCFG_3, 3, gyro_regs))
		return 1;
	if (mpu_write_mem(FCFG_7, 3, accel_regs))
		return 1;
	dmp.orient = orient;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movw %di, %ax
movw %ax, -0x4(%rbp)
movw 0x3c00(%rip), %ax       # 0x91b6
movw %ax, -0xd(%rbp)
movb 0x3bf8(%rip), %al       # 0x91b8
movb %al, -0xb(%rbp)
movw 0x3bef(%rip), %ax       # 0x91b9
movw %ax, -0x10(%rbp)
movb 0x3be7(%rip), %al       # 0x91bb
movb %al, -0xe(%rbp)
movw 0x3bde(%rip), %ax       # 0x91bc
movw %ax, -0x13(%rbp)
movb 0x3bd6(%rip), %al       # 0x91be
movb %al, -0x11(%rbp)
movw 0x3bcd(%rip), %ax       # 0x91bf
movw %ax, -0x16(%rbp)
movb 0x3bc5(%rip), %al       # 0x91c1
movb %al, -0x14(%rbp)
movzwl -0x4(%rbp), %eax
andl $0x3, %eax
cltq
movb -0xd(%rbp,%rax), %al
movb %al, -0x7(%rbp)
movzwl -0x4(%rbp), %eax
sarl $0x3, %eax
andl $0x3, %eax
cltq
movb -0xd(%rbp,%rax), %al
movb %al, -0x6(%rbp)
movzwl -0x4(%rbp), %eax
sarl $0x6, %eax
andl $0x3, %eax
cltq
movb -0xd(%rbp,%rax), %al
movb %al, -0x5(%rbp)
movzwl -0x4(%rbp), %eax
andl $0x3, %eax
cltq
movb -0x10(%rbp,%rax), %al
movb %al, -0xa(%rbp)
movzwl -0x4(%rbp), %eax
sarl $0x3, %eax
andl $0x3, %eax
cltq
movb -0x10(%rbp,%rax), %al
movb %al, -0x9(%rbp)
movzwl -0x4(%rbp), %eax
sarl $0x6, %eax
andl $0x3, %eax
cltq
movb -0x10(%rbp,%rax), %al
movb %al, -0x8(%rbp)
leaq -0x7(%rbp), %rdx
movl $0x426, %edi            # imm = 0x426
movl $0x3, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x568b
movb $0x1, -0x1(%rbp)
jmp 0x5772
leaq -0xa(%rbp), %rdx
movl $0x42a, %edi            # imm = 0x42A
movl $0x3, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x56ab
movb $0x1, -0x1(%rbp)
jmp 0x5772
movw -0x13(%rbp), %ax
movw %ax, -0x7(%rbp)
movb -0x11(%rbp), %al
movb %al, -0x5(%rbp)
movw -0x16(%rbp), %ax
movw %ax, -0xa(%rbp)
movb -0x14(%rbp), %al
movb %al, -0x8(%rbp)
movzwl -0x4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x56e7
movzbl -0x7(%rbp), %eax
orl $0x1, %eax
movb %al, -0x7(%rbp)
movzbl -0xa(%rbp), %eax
orl $0x1, %eax
movb %al, -0xa(%rbp)
movzwl -0x4(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x5707
movzbl -0x6(%rbp), %eax
orl $0x1, %eax
movb %al, -0x6(%rbp)
movzbl -0x9(%rbp), %eax
orl $0x1, %eax
movb %al, -0x9(%rbp)
movzwl -0x4(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x5729
movzbl -0x5(%rbp), %eax
orl $0x1, %eax
movb %al, -0x5(%rbp)
movzbl -0x8(%rbp), %eax
orl $0x1, %eax
movb %al, -0x8(%rbp)
leaq -0x7(%rbp), %rdx
movl $0x440, %edi            # imm = 0x440
movl $0x3, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x5746
movb $0x1, -0x1(%rbp)
jmp 0x5772
leaq -0xa(%rbp), %rdx
movl $0x431, %edi            # imm = 0x431
movl $0x3, %esi
callq 0x4c40
cmpb $0x0, %al
je 0x5763
movb $0x1, -0x1(%rbp)
jmp 0x5772
movw -0x4(%rbp), %ax
movw %ax, 0x6aea(%rip)       # 0xc258
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)