// File: /workspace/github_c_makefile_star2_O0/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_init_h5
int rtk_init_h5(int fd, struct termios *ti)
{
	unsigned char bytes[READ_DATA_SIZE];
	struct sigaction sa;
	int retlen;
	struct itimerval value;

	/* set even parity */
	ti->c_cflag |= PARENB;
	ti->c_cflag &= ~(PARODD);
	if (tcsetattr(fd, TCSANOW, ti) < 0) {
		RS_ERR("Can't set port settings");
		return -1;
	}

	rtk_hw_cfg.h5_max_retries = H5_MAX_RETRY_COUNT;

	alarm(0);
	memset(&sa, 0, sizeof(sa));
	sa.sa_flags = SA_NOCLDSTOP;
	sa.sa_handler = h5_tsync_sig_alarm;
	sigaction(SIGALRM, &sa, NULL);

	/* h5 sync */
	h5_tsync_sig_alarm(0);
	rtk_hw_cfg.link_estab_state = H5_SYNC;
	while (rtk_hw_cfg.link_estab_state == H5_SYNC) {
		if ((retlen = read_check_rtk(fd, &bytes, READ_DATA_SIZE)) == -1) {
			RS_ERR("H5 Read Sync Response Failed");

			value.it_value.tv_sec = 0;
			value.it_value.tv_usec = 0;
			value.it_interval.tv_sec = 0;
			value.it_interval.tv_usec = 0;
			setitimer(ITIMER_REAL, &value, NULL);

			return -1;
		}
		h5_recv(&rtk_hw_cfg, &bytes, retlen);
	}

	value.it_value.tv_sec = 0;
	value.it_value.tv_usec = 0;
	value.it_interval.tv_sec = 0;
	value.it_interval.tv_usec = 0;
	setitimer(ITIMER_REAL, &value, NULL);

	/* h5 config */
	sa.sa_handler = h5_tconf_sig_alarm;
	sigaction(SIGALRM, &sa, NULL);
	h5_tconf_sig_alarm(0);
	while (rtk_hw_cfg.link_estab_state == H5_CONFIG) {
		if ((retlen = read_check_rtk(fd, &bytes, READ_DATA_SIZE)) == -1) {
			RS_ERR("H5 Read Config Response Failed");
			value.it_value.tv_sec = 0;
			value.it_value.tv_usec = 0;
			value.it_interval.tv_sec = 0;
			value.it_interval.tv_usec = 0;
			setitimer(ITIMER_REAL, &value, NULL);
			return -1;
		}
		h5_recv(&rtk_hw_cfg, &bytes, retlen);
	}

	value.it_value.tv_sec = 0;
	value.it_value.tv_usec = 0;
	value.it_interval.tv_sec = 0;
	value.it_interval.tv_usec = 0;
	setitimer(ITIMER_REAL, &value, NULL);

	rtk_send_pure_ack_down(fd);
	RS_DBG("H5 init finished\n");

	rtk_hw_cfg.rom_version_cmd_state = cmd_not_send;
	rtk_hw_cfg.hci_version_cmd_state = cmd_not_send;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xfffffdff, %ecx       # imm = 0xFFFFFDFF
movl %ecx, 0x8(%rax)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rdx
xorl %esi, %esi
callq 0x21e0
cmpl $0x0, %eax
jge 0x5da2
jmp 0x5d77
movq 0xa27a(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x5e12(%rip), %rsi      # 0xbb9a
leaq 0x57fa(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6052
movl $0x28, 0xa954(%rip)     # 0x10700
xorl %edi, %edi
callq 0x20f0
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
movl $0x98, %edx
callq 0x20d0
movl $0x1, -0x30(%rbp)
leaq 0x28c(%rip), %rax       # 0x6060
movq %rax, -0xb8(%rbp)
movl $0xe, %edi
leaq -0xb8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2060
xorl %edi, %edi
callq 0x6060
movl $0x0, 0xa8e3(%rip)      # 0x106e4
cmpl $0x0, 0xa8dc(%rip)      # 0x106e4
jne 0x5eb0
movl -0x8(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x10, %edx
callq 0x5850
movl %eax, -0xbc(%rbp)
cmpl $-0x1, %eax
jne 0x5e95
jmp 0x5e2c
movq 0xa1c5(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x5d80(%rip), %rsi      # 0xbbbd
leaq 0x5745(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xd8(%rbp)
xorl %edi, %edi
leaq -0xe0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x21b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6052
movl -0xbc(%rbp), %edx
leaq 0xa82e(%rip), %rdi      # 0x106d0
leaq -0x20(%rbp), %rsi
callq 0x58f0
jmp 0x5e01
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xd8(%rbp)
xorl %edi, %edi
leaq -0xe0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x21b0
leaq 0x28b(%rip), %rax       # 0x6180
movq %rax, -0xb8(%rbp)
movl $0xe, %edi
leaq -0xb8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2060
xorl %edi, %edi
callq 0x6180
cmpl $0x1, 0xa7c5(%rip)      # 0x106e4
jne 0x5fc7
movl -0x8(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x10, %edx
callq 0x5850
movl %eax, -0xbc(%rbp)
cmpl $-0x1, %eax
jne 0x5fac
jmp 0x5f43
movq 0xa0ae(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x5c91(%rip), %rsi      # 0xbbe5
leaq 0x562e(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xd8(%rbp)
xorl %edi, %edi
leaq -0xe0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x21b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6052
movl -0xbc(%rbp), %edx
leaq 0xa717(%rip), %rdi      # 0x106d0
leaq -0x20(%rbp), %rsi
callq 0x58f0
jmp 0x5f18
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xd8(%rbp)
xorl %edi, %edi
leaq -0xe0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x21b0
movl -0x8(%rbp), %edi
callq 0x62b0
cmpb $0x0, 0xa2bc(%rip)      # 0x102d0
je 0x6035
movq 0x9fdb(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x5be8(%rip), %rsi      # 0xbc0f
leaq 0x555b(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
jmp 0x6037
movl $0x0, 0xa70f(%rip)      # 0x10750
movl $0x0, 0xa709(%rip)      # 0x10754
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nop