// File: /workspace/github_c_makefile_star2_O0/ZombiesYard[P]MPU6050-DMP-raspberry-pi/libs/I2Cdev/I2Cdev.c
// Function: writeWords(unsigned char, unsigned char, unsigned char, unsigned short*)
int writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t* data) {
    int8_t count = 0;
    uint8_t buf[128];
    int i, fd;

    // Should do potential byteswap and call writeBytes() really, but that
    // messes with the callers buffer

    if (length > 63) {
        fprintf(stderr, "Word write count (%d) > 63\n", length);
        return -1;
    }

    fd = open("/dev/i2c-1", O_RDWR);
    if (fd < 0) {
        fprintf(stderr, "Failed to open device: %s\n", strerror(errno));
        return -1;
    }
    if (ioctl(fd, I2C_SLAVE, devAddr) < 0) {
        fprintf(stderr, "Failed to select device: %s\n", strerror(errno));
        close(fd);
        return -1;
    }
    buf[0] = regAddr;
    for (i = 0; i < length; i++) {
        buf[i*2+1] = data[i] >> 8;
        buf[i*2+2] = data[i];
    }
    count = write(fd, buf, length*2+1);
    if (count < 0) {
        fprintf(stderr, "Failed to write device(%d): %s\n", count, strerror(errno));
        close(fd);
        return -1;
    } else if (count != length*2+1) {
        fprintf(stderr, "Short write to device, expected %d, got %d\n", length+1, count);
        close(fd);
        return -1;
    }
    close(fd);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb %dl, %al
movb %sil, %dl
movb %dil, %sil
movb %sil, -0x5(%rbp)
movb %dl, -0x6(%rbp)
movb %al, -0x7(%rbp)
movq %rcx, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
movzbl -0x7(%rbp), %eax
cmpl $0x3f, %eax
jle 0x75e6
movq 0x4a1b(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movzbl -0x7(%rbp), %edx
leaq 0x1d52(%rip), %rsi      # 0x9325
movb $0x0, %al
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x780e
leaq 0x1c09(%rip), %rdi      # 0x91f6
movl $0x2, %esi
movb $0x0, %al
callq 0x1090
movl %eax, -0xa8(%rbp)
cmpl $0x0, -0xa8(%rbp)
jge 0x7649
movq 0x49d1(%rip), %rax      # 0xbfe0
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x1050
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq 0x1bcb(%rip), %rsi      # 0x9201
movb $0x0, %al
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x780e
movl -0xa8(%rbp), %edi
movzbl -0x5(%rbp), %edx
movl $0x703, %esi            # imm = 0x703
movb $0x0, %al
callq 0x10e0
cmpl $0x0, %eax
jge 0x76b0
movq 0x4975(%rip), %rax      # 0xbfe0
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x1050
movq -0xb8(%rbp), %rdi
movq %rax, %rdx
leaq 0x1b8a(%rip), %rsi      # 0x921c
movb $0x0, %al
callq 0x1100
movl -0xa8(%rbp), %edi
callq 0x1130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x780e
movb -0x6(%rbp), %al
movb %al, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movzbl -0x7(%rbp), %ecx
cmpl %ecx, %eax
jge 0x772f
movq -0x10(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0x8, %eax
movb %al, %cl
movl -0xa4(%rbp), %eax
shll %eax
addl $0x1, %eax
cltq
movb %cl, -0xa0(%rbp,%rax)
movq -0x10(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movb %al, %cl
movl -0xa4(%rbp), %eax
shll %eax
addl $0x2, %eax
cltq
movb %cl, -0xa0(%rbp,%rax)
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x76c3
movl -0xa8(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movzbl -0x7(%rbp), %eax
shll %eax
addl $0x1, %eax
movslq %eax, %rdx
callq 0x1060
movb %al, -0x11(%rbp)
movsbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jge 0x77b2
movq 0x4880(%rip), %rax      # 0xbfe0
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
movsbl -0x11(%rbp), %eax
movl %eax, -0xbc(%rbp)
callq 0x1030
movl (%rax), %edi
callq 0x1050
movq -0xc8(%rbp), %rdi
movl -0xbc(%rbp), %edx
movq %rax, %rcx
leaq 0x1b42(%rip), %rsi      # 0x92d9
movb $0x0, %al
callq 0x1100
movl -0xa8(%rbp), %edi
callq 0x1130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x780e
movsbl -0x11(%rbp), %eax
movzbl -0x7(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x77fa
movq 0x4816(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movzbl -0x7(%rbp), %edx
addl $0x1, %edx
movsbl -0x11(%rbp), %ecx
leaq 0x1b1a(%rip), %rsi      # 0x92f9
movb $0x0, %al
callq 0x1100
movl -0xa8(%rbp), %edi
callq 0x1130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x780e
jmp 0x77fc
movl -0xa8(%rbp), %edi
callq 0x1130
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq