// File: /workspace/github_c_makefile_star2_O0/seuscq[P]rtk_hciattach/hciattach.c
// Function: init_uart
static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
{
	struct termios ti;
	int fd, i;
	unsigned long flags = 0;

	if (raw)
		flags |= 1 << HCI_UART_RAW_DEVICE;

	fd = open(dev, O_RDWR | O_NOCTTY);
	if (fd < 0) {
		perror("Can't open serial port");
		return -1;
	}

	tcflush(fd, TCIOFLUSH);

	if (tcgetattr(fd, &ti) < 0) {
		perror("Can't get port settings");
		return -1;
	}

	cfmakeraw(&ti);

	ti.c_cflag |= CLOCAL;
	if (u->flags & FLOW_CTL)
		ti.c_cflag |= CRTSCTS;
	else
		ti.c_cflag &= ~CRTSCTS;

	if (tcsetattr(fd, TCSANOW, &ti) < 0) {
		perror("Can't set port settings");
		return -1;
	}

	/* Set initial baudrate */
	if (set_speed(fd, &ti, u->init_speed) < 0) {
		perror("Can't set initial baud rate");
		return -1;
	}

	tcflush(fd, TCIOFLUSH);

	if (send_break) {
		tcsendbreak(fd, 0);
		usleep(500000);
	}

	if (u->init && u->init(fd, u, &ti) < 0)
		return -1;

	tcflush(fd, TCIOFLUSH);

	/* Set actual baudrate */
	if (set_speed(fd, &ti, u->speed) < 0) {
		perror("Can't set baud rate");
		return -1;
	}

	/* Set TTY to N_HCI line discipline */
	i = N_HCI;
	if (ioctl(fd, TIOCSETD, &i) < 0) {
		perror("Can't set line discipline");
		return -1;
	}

	if (flags && ioctl(fd, HCIUARTSETFLAGS, flags) < 0) {
		perror("Can't set UART flags");
		return -1;
	}

	if (ioctl(fd, HCIUARTSETPROTO, u->proto) < 0) {
		perror("Can't set device");
		return -1;
	}

	if (u->post && u->post(fd, u, &ti) < 0)
		return -1;

	return fd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq $0x0, -0x70(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x3600
movq -0x70(%rbp), %rax
orq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movl $0x102, %esi            # imm = 0x102
movb $0x0, %al
callq 0x21f0
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
jge 0x3631
leaq 0x7cfb(%rip), %rdi      # 0xb31b
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
movl -0x60(%rbp), %edi
movl $0x2, %esi
callq 0x20a0
movl -0x60(%rbp), %edi
leaq -0x5c(%rbp), %rsi
callq 0x21d0
cmpl $0x0, %eax
jge 0x3667
leaq 0x7cdc(%rip), %rdi      # 0xb332
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
leaq -0x5c(%rbp), %rdi
callq 0x21c0
movl -0x54(%rbp), %eax
orl $0x800, %eax            # imm = 0x800
movl %eax, -0x54(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3697
movl -0x54(%rbp), %eax
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, -0x54(%rbp)
jmp 0x36a2
movl -0x54(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x54(%rbp)
movl -0x60(%rbp), %edi
xorl %esi, %esi
leaq -0x5c(%rbp), %rdx
callq 0x21e0
cmpl $0x0, %eax
jge 0x36cd
leaq 0x7acd(%rip), %rdi      # 0xb189
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
movl -0x60(%rbp), %edi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %edx
leaq -0x5c(%rbp), %rsi
callq 0x23e0
cmpl $0x0, %eax
jge 0x36fd
leaq 0x7c5e(%rip), %rdi      # 0xb34a
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
movl -0x60(%rbp), %edi
movl $0x2, %esi
callq 0x20a0
cmpl $0x0, -0x1c(%rbp)
je 0x3724
movl -0x60(%rbp), %edi
xorl %esi, %esi
callq 0x2140
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x22d0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x3755
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x60(%rbp), %edi
movq -0x18(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x3755
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
movl -0x60(%rbp), %edi
movl $0x2, %esi
callq 0x20a0
movl -0x60(%rbp), %edi
movq -0x18(%rbp), %rax
movl 0x18(%rax), %edx
leaq -0x5c(%rbp), %rsi
callq 0x23e0
cmpl $0x0, %eax
jge 0x3792
leaq 0x7be5(%rip), %rdi      # 0xb366
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
movl $0xf, -0x64(%rbp)
movl -0x60(%rbp), %edi
movl $0x5423, %esi           # imm = 0x5423
leaq -0x64(%rbp), %rdx
movb $0x0, %al
callq 0x20e0
cmpl $0x0, %eax
jge 0x37c9
leaq 0x7bc2(%rip), %rdi      # 0xb37a
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
cmpq $0x0, -0x70(%rbp)
je 0x37fd
movl -0x60(%rbp), %edi
movq -0x70(%rbp), %rdx
movl $0x400455cb, %esi       # imm = 0x400455CB
movb $0x0, %al
callq 0x20e0
cmpl $0x0, %eax
jge 0x37fd
leaq 0x7ba5(%rip), %rdi      # 0xb394
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
movl -0x60(%rbp), %edi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
movl $0x400455c8, %esi       # imm = 0x400455C8
movb $0x0, %al
callq 0x20e0
cmpl $0x0, %eax
jge 0x382d
leaq 0x7b8a(%rip), %rdi      # 0xb3a9
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x385b
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x60(%rbp), %edi
movq -0x18(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jge 0x385b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3861
movl -0x60(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)