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

#ifdef DEBUG
    printf("write %#x %#x\n",devAddr,regAddr);
#endif
    if (length > 127) {
        fprintf(stderr, "Byte write count (%d) > 127\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;
    memcpy(buf+1,data,length);
    count = write(fd, buf, length+1);
    if (count < 0) {
        fprintf(stderr, "Failed to write device(%d): %s\n", count, strerror(errno));
        close(fd);
        return -1;
    } else if (count != length+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 $0x7f, %eax
jle 0x73b6
movq 0x4c4b(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movzbl -0x7(%rbp), %edx
leaq 0x1f19(%rip), %rsi      # 0x92bc
movb $0x0, %al
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x757e
leaq 0x1e39(%rip), %rdi      # 0x91f6
movl $0x2, %esi
movb $0x0, %al
callq 0x1090
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jge 0x7419
movq 0x4c01(%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 0x1dfb(%rip), %rsi      # 0x9201
movb $0x0, %al
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x757e
movl -0xa4(%rbp), %edi
movzbl -0x5(%rbp), %edx
movl $0x703, %esi            # imm = 0x703
movb $0x0, %al
callq 0x10e0
cmpl $0x0, %eax
jge 0x7480
movq 0x4ba5(%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 0x1dba(%rip), %rsi      # 0x921c
movb $0x0, %al
callq 0x1100
movl -0xa4(%rbp), %edi
callq 0x1130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x757e
movb -0x6(%rbp), %al
movb %al, -0xa0(%rbp)
leaq -0xa0(%rbp), %rdi
addq $0x1, %rdi
movq -0x10(%rbp), %rsi
movzbl -0x7(%rbp), %eax
movl %eax, %edx
callq 0x10a0
movl -0xa4(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movzbl -0x7(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
callq 0x1060
movb %al, -0x11(%rbp)
movsbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jge 0x7524
movq 0x4b0e(%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 0x1dd0(%rip), %rsi      # 0x92d9
movb $0x0, %al
callq 0x1100
movl -0xa4(%rbp), %edi
callq 0x1130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x757e
movsbl -0x11(%rbp), %eax
movzbl -0x7(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x756a
movq 0x4aa6(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movzbl -0x7(%rbp), %edx
addl $0x1, %edx
movsbl -0x11(%rbp), %ecx
leaq 0x1daa(%rip), %rsi      # 0x92f9
movb $0x0, %al
callq 0x1100
movl -0xa4(%rbp), %edi
callq 0x1130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x757e
jmp 0x756c
movl -0xa4(%rbp), %edi
callq 0x1130
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)