// File: /workspace/github_c_makefile_star2_O2/koendv[P]stm32duino-raspberrypi/Arduino_Tools/src/stm32flash/i2c.c
// Function: i2c_open
static port_err_t i2c_open(struct port_interface *port,
			   struct port_options *ops)
{
	struct i2c_priv *h;
	int fd, addr, ret;
	unsigned long funcs;

	/* 1. check device name match */
	if (strncmp(ops->device, "/dev/i2c-", strlen("/dev/i2c-")))
		return PORT_ERR_NODEV;

	/* 2. check options */
	addr = ops->bus_addr;
	if (addr < 0x03 || addr > 0x77) {
		fprintf(stderr, "I2C address out of range [0x03-0x77]\n");
		return PORT_ERR_UNKNOWN;
	}

	/* 3. open it */
	h = calloc(sizeof(*h), 1);
	if (h == NULL) {
		fprintf(stderr, "End of memory\n");
		return PORT_ERR_UNKNOWN;
	}
	fd = open(ops->device, O_RDWR);
	if (fd < 0) {
		fprintf(stderr, "Unable to open special file \"%s\"\n",
			ops->device);
		free(h);
		return PORT_ERR_UNKNOWN;
	}

	/* 3.5. Check capabilities */
	ret = ioctl(fd, I2C_FUNCS, &funcs);
	if (ret < 0) {
		fprintf(stderr, "I2C ioctl(funcs) error %d\n", errno);
		close(fd);
		free(h);
		return PORT_ERR_UNKNOWN;
	}
	if ((funcs & I2C_FUNC_I2C) == 0) {
		fprintf(stderr, "Error: controller is not I2C, only SMBUS.\n");
		close(fd);
		free(h);
		return PORT_ERR_UNKNOWN;
	}

	/* 4. set options */
	ret = ioctl(fd, I2C_SLAVE, addr);
	if (ret < 0) {
		fprintf(stderr, "I2C ioctl(slave) error %d\n", errno);
		close(fd);
		free(h);
		return PORT_ERR_UNKNOWN;
	}

	h->fd = fd;
	h->addr = addr;
	port->private = h;
	return PORT_ERR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %r14
movq (%rsi), %r13
leaq 0x4faf(%rip), %rsi      # 0x73a6
pushq $0x9
popq %rdx
movq %r13, %rdi
callq 0x2050
testl %eax, %eax
je 0x240f
pushq $0x1
popq %r12
jmp 0x2498
movl 0x18(%r12), %r15d
leal -0x78(%r15), %eax
cmpl $-0x76, %eax
jbe 0x24aa
pushq $0x8
popq %rdi
pushq $0x1
popq %rsi
callq 0x2150
testq %rax, %rax
je 0x24bf
movq %rax, %rbx
pushq $0x2
popq %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2230
testl %eax, %eax
js 0x24e0
movl %eax, %ebp
movq %rsp, %rdx
movl $0x705, %esi            # imm = 0x705
movl %eax, %edi
xorl %eax, %eax
callq 0x2110
testl %eax, %eax
js 0x24fe
testb $0x1, (%rsp)
je 0x2518
xorl %r12d, %r12d
movl $0x703, %esi            # imm = 0x703
movl %ebp, %edi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2110
testl %eax, %eax
js 0x2536
movl %ebp, (%rbx)
movl %r15d, 0x4(%rbx)
movq %rbx, 0x50(%r14)
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xab3f(%rip), %rax      # 0xcff0
movq (%rax), %rcx
leaq 0x4ef5(%rip), %rdi      # 0x73b0
pushq $0x25
jmp 0x24d2
movq 0xab2a(%rip), %rax      # 0xcff0
movq (%rax), %rcx
leaq 0x4f06(%rip), %rdi      # 0x73d6
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x22b0
jmp 0x2567
movq 0xab09(%rip), %rax      # 0xcff0
movq (%rax), %rdi
movq (%r12), %rdx
leaq 0x4ef0(%rip), %rsi      # 0x73e5
xorl %eax, %eax
callq 0x2170
jmp 0x255f
movq 0xaaeb(%rip), %rax      # 0xcff0
movq (%rax), %r14
callq 0x2040
movl (%rax), %edx
leaq 0x4ef1(%rip), %rsi      # 0x7407
jmp 0x254e
movq 0xaad1(%rip), %rax      # 0xcff0
movq (%rax), %rcx
leaq 0x4ef9(%rip), %rdi      # 0x7422
pushq $0x2a
popq %rsi
pushq $0x1
popq %rdx
callq 0x22b0
jmp 0x2558
movq 0xaab3(%rip), %rax      # 0xcff0
movq (%rax), %r14
callq 0x2040
movl (%rax), %edx
leaq 0x4eff(%rip), %rsi      # 0x744d
movq %r14, %rdi
xorl %eax, %eax
callq 0x2170
movl %ebp, %edi
callq 0x2120
movq %rbx, %rdi
callq 0x2030
pushq $0x3
jmp 0x2408