LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/examples/custom_stream.c
// Function: main
int main(GT_UNUSED int argc, const char *argv[])
{
  GtNodeStream *custom_stream, *gff3_out_stream;
  GtError *err;
  int had_err;

  if (gt_version_check(GT_MAJOR_VERSION, GT_MINOR_VERSION, GT_MICRO_VERSION)) {
    fprintf(stderr, "error: %s\n", gt_version_check(GT_MAJOR_VERSION,
                                                    GT_MINOR_VERSION,
                                                    GT_MICRO_VERSION));
    return EXIT_FAILURE;
  }

  /* initialize */
  gt_lib_init();

  /* create error object */
  err = gt_error_new();

  /* create custom input stream  */
  custom_stream = custom_stream_new();

  /* create GFF3 output stream */
  gff3_out_stream = gt_gff3_out_stream_new(custom_stream, NULL);

  /* pull the features through the stream */
  had_err = gt_node_stream_pull(gff3_out_stream, err);

  /* handle error */
  if (had_err)
    fprintf(stderr, "%s: error: %s\n", argv[0], gt_error_get(err));

  /* free */
  gt_node_stream_delete(gff3_out_stream);
  gt_node_stream_delete(custom_stream);
  gt_error_delete(err);

  if (had_err)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl $0x1, %ebp
movl $0x1, %edi
movl $0x6, %esi
movl $0x6, %edx
callq 0x1801c
testq %rax, %rax
jne 0xfe02
callq 0x10050
callq 0xfe90
movq %rax, %r14
movq 0x606d8(%rip), %rdi     # 0x70428
testq %rdi, %rdi
jne 0xfd72
leaq 0xba(%rip), %rdx        # 0xfe16
movl $0x18, %edi
xorl %esi, %esi
callq 0x1caf8
movq %rax, %rdi
movq %rax, 0x606b6(%rip)     # 0x70428
xorl %esi, %esi
callq 0x1cb30
movq %rax, %r15
movq 0x606a5(%rip), %rdi     # 0x70428
testq %rdi, %rdi
jne 0xfda5
leaq 0x87(%rip), %rdx        # 0xfe16
movl $0x18, %edi
xorl %esi, %esi
callq 0x1caf8
movq %rax, %rdi
movq %rax, 0x60683(%rip)     # 0x70428
movq %r15, %rsi
callq 0x1cdbb
movb $0x0, 0x10(%rax)
movq %r15, %rdi
xorl %esi, %esi
callq 0x1b948
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
callq 0x1cd21
movl %eax, %r13d
testl %eax, %eax
jne 0xfe09
xorl %ebp, %ebp
testl %r13d, %r13d
setne %bpl
movq %r12, %rdi
callq 0x1cbb2
movq %r15, %rdi
callq 0x1cbb2
movq %r14, %rdi
callq 0x10011
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x46b0
jmp 0xfdf1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x46dd
jmp 0xfdd0
// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/examples/custom_stream.c
// Function: custom_stream_next
static int custom_stream_next(GtNodeStream *ns, GtGenomeNode **gn,
                              GT_UNUSED GtError *err)
{
  CustomStream *cs = custom_stream_cast(ns);
  gt_error_check(err);
  if (!cs->emitted_standard_gene) {
    *gn = gt_feature_node_new_standard_gene();
    cs->emitted_standard_gene = true;
  }
  else
    *gn = NULL;
  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq 0x605fd(%rip), %rdi     # 0x70428
testq %rdi, %rdi
jne 0xfe4d
leaq -0x21(%rip), %rdx       # 0xfe16
movl $0x18, %edi
xorl %esi, %esi
callq 0x1caf8
movq %rax, %rdi
movq %rax, 0x605db(%rip)     # 0x70428
movq %r15, %rsi
callq 0x1cdbb
movq %rax, %r15
testq %r14, %r14
je 0xfe69
movq %r14, %rdi
callq 0xff76
testb %al, %al
jne 0xfe89
cmpb $0x0, 0x10(%r15)
je 0xfe74
xorl %eax, %eax
jmp 0xfe7e
callq 0x18af7
movb $0x1, 0x10(%r15)
movq %rax, (%rbx)
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
callq 0x4714
nop
// File: /workspace/github_c_makefile_star2_O3/stevenmherring[P]DNS/rw-trie.c
// Function: search
int search(const char *string, size_t strlen, int32_t *ip4_address) {
  struct trie_node *found;
  int rv, result;
  pthread_cleanup_push(cleanup_handler,&lock);

  // Skip strings of length 0
  if (strlen == 0)
  return 0;

  // obtain the lock
  rv = pthread_rwlock_rdlock(&rwlock);
  assert(rv == 0);
  found = _search(root, string, strlen);

  if (found && ip4_address)
  *ip4_address = found->ip4_address;

  result = (found != NULL);

  // Return the lock
  pthread_cleanup_pop(1);
  assert(rv == 0);

  return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq %rsp, %rdi
xorl %ebp, %ebp
movl %ebp, %esi
callq 0x11f0
movq %rsp, %rdi
testl %eax, %eax
jne 0x165b
callq 0x11c0
testq %r14, %r14
je 0x164e
leaq 0x4b5a(%rip), %rdi      # 0x6160
callq 0x10e0
testl %eax, %eax
jne 0x1660
movq 0x4b8a(%rip), %rdi      # 0x61a0
movq %r15, %rsi
movq %r14, %rdx
callq 0x14dd
testq %rax, %rax
sete %cl
testq %rbx, %rbx
sete %dl
orb %cl, %dl
jne 0x1636
movl 0xc(%rax), %ecx
movl %ecx, (%rbx)
xorl %ebp, %ebp
testq %rax, %rax
setne %al
movb %al, %bpl
movq %rsp, %rdi
callq 0x10c0
callq 0x136c
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x1240
leaq 0x199d(%rip), %rdi      # 0x3004
leaq 0x199e(%rip), %rsi      # 0x300c
leaq 0x1ab3(%rip), %rcx      # 0x3128
movl $0x8c, %edx
callq 0x10d0
// File: /workspace/github_c_makefile_star2_O3/stevenmherring[P]DNS/rw-trie.c
// Function: print
void print() {
            int rv;
            // Obtain the lock
            rv = pthread_mutex_lock(&lock);
            assert(rv == 0);

            printf("Root is at %p\n", root);
            /* Do a simple depth-first search */
            if (root)
            _print(root,0,0);

            // Unlock
            rv = pthread_mutex_unlock(&lock);
            assert(rv == 0);
          }

// Assembly:
pushq %rax
leaq 0x40e5(%rip), %rdi      # 0x6138
callq 0x1220
testl %eax, %eax
jne 0x2098
movq 0x413d(%rip), %rsi      # 0x61a0
leaq 0x13a5(%rip), %rdi      # 0x340f
xorl %eax, %eax
callq 0x10b0
movq 0x4128(%rip), %rdi      # 0x61a0
testq %rdi, %rdi
je 0x2086
xorl %esi, %esi
xorl %edx, %edx
callq 0x1f31
leaq 0x40ab(%rip), %rdi      # 0x6138
callq 0x1130
testl %eax, %eax
jne 0x20b7
popq %rax
retq
leaq 0xf65(%rip), %rdi       # 0x3004
leaq 0xf66(%rip), %rsi       # 0x300c
leaq 0x1355(%rip), %rcx      # 0x3402
movl $0x1d6, %edx            # imm = 0x1D6
callq 0x10d0
leaq 0xf46(%rip), %rdi       # 0x3004
leaq 0xf47(%rip), %rsi       # 0x300c
leaq 0x1336(%rip), %rcx      # 0x3402
movl $0x1df, %edx            # imm = 0x1DF
callq 0x10d0
nop
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_chip_type
void rtk_get_chip_type(int dd)
{
	unsigned char bytes[READ_DATA_SIZE];
	int retlen;
	struct sigaction sa;
	/* 0xB000A094 */
	unsigned char cmd_buff[] = {0x61, 0xfc,
		0x05, 0x00, 0x94, 0xa0, 0x00, 0xb0};
	struct sk_buff *nskb;
	struct btrtl_info *btrtl = &rtk_hw_cfg;

	nskb = h5_prepare_pkt(btrtl, cmd_buff, sizeof(cmd_buff),
			HCI_COMMAND_PKT);
	if (btrtl->host_last_cmd){
		skb_free(btrtl->host_last_cmd);
		btrtl->host_last_cmd = NULL;
	}

	btrtl->host_last_cmd = nskb;

	write(dd, nskb->data, nskb->data_len);
	RS_INFO("RTK send HCI_VENDOR_READ_CHIP_TYPE_Command\n");

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

	alarm(3);
	while (btrtl->chip_type_cmd_state != event_received) {
		if ((retlen = read_check_rtk(dd, &bytes, READ_DATA_SIZE)) == -1) {
			perror("rtk get chip type: read fail");
			return;
		}
		h5_recv(btrtl, &bytes, retlen);
	}
	alarm(0);
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movl %edi, %ebx
movabsq $-0x4fff5f6bfffa039f, %rax # imm = 0xB000A0940005FC61
leaq -0x18(%rbp), %rdi
movq %rax, (%rdi)
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x603c
movq %rax, %r14
movq 0xd23a(%rip), %rdi      # 0xf700
testq %rdi, %rdi
je 0x24d0
callq 0x2030
movq %r14, 0xd229(%rip)      # 0xf700
movq %r14, %rsi
addq $0x8, %rsi
movl 0x4(%r14), %edx
movl %ebx, %edi
callq 0x2070
movq 0xcb08(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x7770(%rip), %rsi      # 0x9c6a
leaq 0x7038(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
xorl %edi, %edi
callq 0x20f0
leaq -0xc0(%rbp), %r14
movl $0x90, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x20d0
movl $0x1, 0x80(%r14)
leaq 0x6d(%rip), %rax        # 0x25a4
movq %rax, -0x8(%r14)
pushq $0xe
popq %rdi
leaq -0xc8(%rbp), %rsi
xorl %edx, %edx
callq 0x2060
pushq $0x3
popq %rdi
callq 0x20f0
cmpl $0x2, 0xd20d(%rip)      # 0xf768
je 0x2583
leaq -0x30(%rbp), %r14
movl %ebx, %edi
movq %r14, %rsi
callq 0x6241
cmpl $-0x1, %eax
je 0x2596
movq %r14, %rdi
movl %eax, %esi
callq 0x6298
cmpl $0x2, 0xd1e7(%rip)      # 0xf768
jne 0x2561
xorl %edi, %edi
callq 0x20f0
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x76fe(%rip), %rdi      # 0x9c9b
callq 0x2230
jmp 0x258a
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_chip_type_timeout
static void rtk_get_chip_type_timeout(int sig)
{
	static int retries = 0;
	int len = 0;
	struct btrtl_info *btrtl = &rtk_hw_cfg;

	RS_INFO("RTK get HCI_VENDOR_READ_RTK_CHIP_TYPE_Command\n");
	if (retries < btrtl->h5_max_retries) {
		RS_DBG("rtk get chip type timerout, retry:%d\n", retries);
		if (btrtl->host_last_cmd) {
			len = write(btrtl->serial_fd,
				    btrtl->host_last_cmd->data,
				    btrtl->host_last_cmd->data_len);
		}
		retries++;
		alarm(3);
		return;
	}
	tcflush(btrtl->serial_fd, TCIOFLUSH);
	RS_ERR("rtk get chip type cmd complete event timed out\n");
	exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq 0xca47(%rip), %rbx      # 0xeff8
movq (%rbx), %rdi
leaq 0x839f(%rip), %rsi      # 0xa95a
leaq 0x6f77(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
movl 0xe1cd(%rip), %ecx      # 0x1079c
cmpl 0xd13b(%rip), %ecx      # 0xf710
jge 0x262c
cmpb $0x0, 0xcd02(%rip)      # 0xf2e0
jne 0x2612
movq 0xd119(%rip), %rsi      # 0xf700
testq %rsi, %rsi
je 0x25fe
movl 0xd12e(%rip), %edi      # 0xf720
movl 0x4(%rsi), %edx
addq $0x8, %rsi
callq 0x2070
incl 0xe198(%rip)            # 0x1079c
pushq $0x3
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x20f0
movq (%rbx), %rdi
leaq 0x8372(%rip), %rsi      # 0xa98e
leaq 0x6f16(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
jmp 0x25e0
movl 0xd0ee(%rip), %edi      # 0xf720
pushq $0x2
popq %rsi
callq 0x20a0
movq (%rbx), %rdi
leaq 0x8375(%rip), %rsi      # 0xa9b9
leaq 0x6eee(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
pushq $0x1
popq %rdi
callq 0x2290
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach.c
// Function: uart_speed
static int uart_speed(int s)
{
	switch (s) {
	case 9600:
		return B9600;
	case 19200:
		return B19200;
	case 38400:
		return B38400;
	case 57600:
		return B57600;
	case 115200:
		return B115200;
	case 230400:
		return B230400;
	case 460800:
		return B460800;
	case 500000:
		return B500000;
	case 576000:
		return B576000;
	case 921600:
		return B921600;
	case 1000000:
		return B1000000;
	case 1152000:
		return B1152000;
	case 1500000:
		return B1500000;
	case 2000000:
		return B2000000;
#ifdef B2500000
	case 2500000:
		return B2500000;
#endif
#ifdef B3000000
	case 3000000:
		return B3000000;
#endif
#ifdef B3500000
	case 3500000:
		return B3500000;
#endif
#ifdef B4000000
	case 4000000:
		return B4000000;
#endif
	default:
		return B57600;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
cmpl $0xe0fff, %edi          # imm = 0xE0FFF
jg 0x41ce
cmpl $0x1c1ff, %edi          # imm = 0x1C1FF
jle 0x420c
cmpl $0x707ff, %edi          # imm = 0x707FF
jle 0x4288
cmpl $0x70800, %edi          # imm = 0x70800
je 0x42d9
cmpl $0x7a120, %edi          # imm = 0x7A120
je 0x42cb
cmpl $0x8ca00, %edi          # imm = 0x8CA00
jne 0x4267
movl $0x1006, %eax           # imm = 0x1006
jmp 0x42f3
cmpl $0x1e847f, %edi         # imm = 0x1E847F
jle 0x4237
cmpl $0x2dc6bf, %edi         # imm = 0x2DC6BF
jle 0x429f
cmpl $0x2dc6c0, %edi         # imm = 0x2DC6C0
je 0x42e0
cmpl $0x3567e0, %edi         # imm = 0x3567E0
je 0x42d2
cmpl $0x3d0900, %edi         # imm = 0x3D0900
jne 0x4267
movl $0x100f, %eax           # imm = 0x100F
jmp 0x42f3
cmpl $0x95ff, %edi           # imm = 0x95FF
jg 0x4259
movl $0xd, %eax
cmpl $0x2580, %edi           # imm = 0x2580
je 0x42f3
cmpl $0x4b00, %edi           # imm = 0x4B00
jne 0x4267
movl $0xe, %eax
jmp 0x42f3
cmpl $0x1193ff, %edi         # imm = 0x1193FF
jg 0x4271
cmpl $0xe1000, %edi          # imm = 0xE1000
je 0x42b6
cmpl $0xf4240, %edi          # imm = 0xF4240
jne 0x4267
movl $0x1008, %eax           # imm = 0x1008
jmp 0x42f3
cmpl $0x9600, %edi           # imm = 0x9600
je 0x42bd
cmpl $0xe100, %edi           # imm = 0xE100
movl $0x1001, %eax           # imm = 0x1001
jmp 0x42f3
cmpl $0x119400, %edi         # imm = 0x119400
je 0x42c4
cmpl $0x16e360, %edi         # imm = 0x16E360
jne 0x4267
movl $0x100a, %eax           # imm = 0x100A
jmp 0x42f3
cmpl $0x1c200, %edi          # imm = 0x1C200
je 0x42e7
cmpl $0x38400, %edi          # imm = 0x38400
jne 0x4267
movl $0x1003, %eax           # imm = 0x1003
jmp 0x42f3
cmpl $0x1e8480, %edi         # imm = 0x1E8480
je 0x42ee
cmpl $0x2625a0, %edi         # imm = 0x2625A0
jne 0x4267
movl $0x100c, %eax           # imm = 0x100C
jmp 0x42f3
movl $0x1007, %eax           # imm = 0x1007
jmp 0x42f3
movl $0xf, %eax
jmp 0x42f3
movl $0x1009, %eax           # imm = 0x1009
jmp 0x42f3
movl $0x1005, %eax           # imm = 0x1005
jmp 0x42f3
movl $0x100e, %eax           # imm = 0x100E
jmp 0x42f3
movl $0x1004, %eax           # imm = 0x1004
jmp 0x42f3
movl $0x100d, %eax           # imm = 0x100D
jmp 0x42f3
movl $0x1002, %eax           # imm = 0x1002
jmp 0x42f3
movl $0x100b, %eax           # imm = 0x100B
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach.c
// Function: read_hci_event
int read_hci_event(int fd, unsigned char* buf, int size) 
{
	int remain, r;
	int count = 0;

	if (size <= 0)
		return -1;

	/* The first byte identifies the packet type. For HCI event packets, it
	 * should be 0x04, so we read until we get to the 0x04. */
	while (1) {
		r = read(fd, buf, 1);
		if (r <= 0)
			return -1;
		if (buf[0] == 0x04)
			break;
	}
	count++;

	/* The next two bytes are the event code and parameter total length. */
	while (count < 3) {
		r = read(fd, buf + count, 3 - count);
		if (r <= 0)
			return -1;
		count += r;
	}

	/* Now we read the parameters. */
	if (buf[2] < (size - 3)) 
		remain = buf[2];
	else 
		remain = size - 3;

	while ((count - 3) < remain) {
		r = read(fd, buf + count, remain - (count - 3));
		if (r <= 0)
			return -1;
		count += r;
	}

	return count;
}

// Assembly:
testl %edx, %edx
jle 0x43a6
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebx
movq %rsi, %r14
movl %edi, %r15d
movl $0x1, %edx
movl %r15d, %edi
movq %r14, %rsi
callq 0x2110
testl %eax, %eax
jle 0x4398
cmpb $0x4, (%r14)
jne 0x4310
movl $0x1, %r12d
movl %r12d, %esi
addq %r14, %rsi
movl $0x3, %edx
subl %r12d, %edx
movl %r15d, %edi
callq 0x2110
testl %eax, %eax
jle 0x4398
addl %eax, %r12d
cmpl $0x2, %r12d
jle 0x4330
movzbl 0x2(%r14), %eax
addl $-0x3, %ebx
cmpl %eax, %ebx
cmovgel %eax, %ebx
leal -0x3(%r12), %ecx
cmpl %ebx, %ecx
jge 0x43ac
movl %r12d, %esi
addq %r14, %rsi
movl %ebx, %eax
subl %ecx, %eax
movslq %eax, %rdx
movl %r15d, %edi
callq 0x2110
movq %rax, %rcx
testl %ecx, %ecx
jle 0x4398
leal (%r12,%rcx), %eax
addl %r12d, %ecx
addl $-0x3, %ecx
movl %eax, %r12d
cmpl %ebx, %ecx
jl 0x4369
jmp 0x439d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
retq
movl %r12d, %eax
jmp 0x439d
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach.c
// Function: usage
static void usage(void)
{
	printf("hciattach - HCI UART driver initialization utility\n");
	printf("Usage:\n");
	printf("\thciattach [-n] [-p] [-b] [-r] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
	printf("\thciattach -l\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq 0x4525(%rip), %rdi      # 0x92d3
callq 0x2050
leaq 0x454c(%rip), %rdi      # 0x9306
callq 0x2050
leaq 0x4547(%rip), %rdi      # 0x930d
callq 0x2050
leaq 0x45ab(%rip), %rdi      # 0x937d
popq %rbp
jmp 0x2050
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach.c
// Function: bcsp_tshy_sig_alarm
static void bcsp_tshy_sig_alarm(int sig)
{
	unsigned char bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0};
	static int retries = 0;

	if (retries < bcsp_max_retries) {
		retries++;
		if (write(serial_fd, &bcsp_sync_pkt, 10) < 0)
			return;
		alarm(1);
		return;
	}

	tcflush(serial_fd, TCIOFLUSH);
	fprintf(stderr, "BCSP initialization timed out\n");
	exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0xa7fc(%rip), %eax      # 0xf64c
cmpl 0xa47a(%rip), %eax      # 0xf2d0
jge 0x4e89
incl %eax
movl %eax, 0xa7ec(%rip)      # 0xf64c
movl 0xa7e2(%rip), %edi      # 0xf648
leaq 0x41e7(%rip), %rsi      # 0x9054
movl $0xa, %edx
callq 0x2070
testq %rax, %rax
js 0x4e87
movl $0x1, %edi
popq %rbp
jmp 0x20f0
popq %rbp
retq
callq 0x2424
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach.c
// Function: read_check
static int read_check(int fd, void *buf, int count)
{
	int res;

	do {
		res = read(fd, buf, count);
		if (res != -1) {
			buf += res; 
			count -= res;
		}
	} while (count && (errno == 0 || errno == EINTR));

	if (count)
		return -1;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movslq %edx, %r15
movl %edi, -0x2c(%rbp)
movq %r15, %rdx
callq 0x2110
movq %rax, %r12
xorl %r14d, %r14d
cmpl $-0x1, %r12d
sete %r13b
cmovel %r14d, %eax
subl %eax, %r15d
je 0x4f1f
callq 0x2040
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
testl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
jne 0x4f19
movslq %r12d, %rax
xorl %r14d, %r14d
testb $0x1, %r13b
movl $0x0, %ecx
cmoveq %rax, %rcx
addq %rcx, %rbx
movslq %r15d, %r15
movl -0x2c(%rbp), %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2110
movq %rax, %r12
cmpl $-0x1, %r12d
sete %r13b
cmovel %r14d, %eax
subl %eax, %r15d
jne 0x4ed0
jmp 0x4f1f
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach.c
// Function: bcsp_tconf_sig_alarm
static void bcsp_tconf_sig_alarm(int sig)
{
	unsigned char bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0};
	static int retries = 0;

	if (retries < bcsp_max_retries){
		retries++;
		if (write(serial_fd, &bcsp_conf_pkt, 10) < 0)
			return;
		alarm(1);
		return;
	}

	tcflush(serial_fd, TCIOFLUSH);
	fprintf(stderr, "BCSP initialization timed out\n");
	exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0xa715(%rip), %eax      # 0xf650
cmpl 0xa38f(%rip), %eax      # 0xf2d0
jge 0x4f74
incl %eax
movl %eax, 0xa705(%rip)      # 0xf650
movl 0xa6f7(%rip), %edi      # 0xf648
leaq 0x4106(%rip), %rsi      # 0x905e
movl $0xa, %edx
callq 0x2070
testq %rax, %rax
js 0x4f72
movl $0x1, %edi
popq %rbp
jmp 0x20f0
popq %rbp
retq
callq 0x245a
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: util_hexdump
void util_hexdump(const uint8_t *buf, size_t len)
{
	static const char hexdigits[] = "0123456789abcdef";
	char str[16 * 3];
	size_t i;

	if (!buf || !len)
		return;

	for (i = 0; i < len; i++) {
		str[((i % 16) * 3)] = hexdigits[buf[i] >> 4];
		str[((i % 16) * 3) + 1] = hexdigits[buf[i] & 0xf];
		str[((i % 16) * 3) + 2] = ' ';
		if ((i + 1) % 16 == 0) {
			str[16 * 3 - 1] = '\0';
			RS_INFO("%s", str);
		}
	}

	if (i % 16 > 0) {
		str[(i % 16) * 3 - 1] = '\0';
		RS_INFO("%s", str);
	}
}

// Assembly:
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x502d
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x4572(%rip), %r15      # 0x9520
leaq -0x60(%rbp), %r13
xorl %r12d, %r12d
movzbl (%r14,%r12), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movb (%rcx,%r15), %cl
movl %r12d, %edx
andl $0xf, %edx
leaq (%rdx,%rdx,2), %rdx
movb %cl, -0x60(%rbp,%rdx)
andl $0xf, %eax
movb (%rax,%r15), %al
movb %al, -0x5f(%rbp,%rdx)
movb $0x20, -0x5e(%rbp,%rdx)
incq %r12
testb $0xf, %r12b
je 0x4ff1
cmpq %r12, %rbx
jne 0x4fb5
jmp 0x5019
movb $0x0, -0x31(%rbp)
movq 0x9ffc(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x452b(%rip), %rsi      # 0x9531
leaq 0x452c(%rip), %rdx      # 0x9539
movq %r13, %rcx
xorl %eax, %eax
callq 0x2150
jmp 0x4fea
andq $0xf, %rbx
jne 0x502e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x60(%rbp), %rsi
movq %rbx, %rdi
callq 0x265a
jmp 0x501f
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: get_patch_entry
struct patch_info *get_patch_entry(struct btrtl_info *btrtl)
{
	struct patch_info *n = NULL;

	if (btrtl->proto == HCI_UART_3WIRE)
		n = patch_table;
	else
		n = h4_patch_table;
	for (; n->lmp_subver; n++) {
		if ((n->match_flags & RTL_FW_MATCH_CHIP_TYPE) &&
		    n->chip_type != btrtl->chip_type)
			continue;
		if ((n->match_flags & RTL_FW_MATCH_HCI_VER) &&
		    n->hci_ver != btrtl->hci_ver)
			continue;
		if ((n->match_flags & RTL_FW_MATCH_HCI_REV) &&
		    n->hci_rev != btrtl->hci_rev)
			continue;
		if (n->lmp_subver != btrtl->lmp_subver)
			continue;

		break;
	}

	return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
cmpl $0x2, 0x98(%rdi)
leaq 0xa2c2(%rip), %rcx      # 0xf310
leaq 0xa49b(%rip), %rax      # 0xf4f0
cmoveq %rcx, %rax
leaq 0xa2b6(%rip), %rcx      # 0xf316
leaq 0xa48f(%rip), %rdx      # 0xf4f6
cmoveq %rcx, %rdx
movzwl (%rdx), %ecx
testw %cx, %cx
je 0x50b2
movl (%rax), %edx
testb $0x1, %dl
je 0x5084
movb 0x4(%rax), %sil
cmpb 0x34(%rdi), %sil
jne 0x50a8
testb $0x2, %dl
je 0x5093
movb 0xa(%rax), %sil
cmpb 0x2e(%rdi), %sil
jne 0x50a8
testb $0x4, %dl
je 0x50a2
movzwl 0xc(%rax), %edx
cmpw 0x2c(%rdi), %dx
jne 0x50a8
cmpw 0x2a(%rdi), %cx
je 0x50b2
movzwl 0x2e(%rax), %ecx
addq $0x28, %rax
jmp 0x506e
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: os_read
int os_read(int fd, uint8_t * buff, int len)
{
	int n;
	int i;
	int try = 0;

	i = 0;
	n = 0;
	while (n < len) {
		i = read(fd, buff + n, len - n);
		if (i > 0)
			n += i;
		else if (i == 0) {
			RS_DBG("read nothing.");
			continue;
		} else {
			RS_ERR("read error, %s\n", strerror(errno));
			try++;
			if (try > READ_TRY_MAX) {
				RS_ERR("read reaches max try number.\n");
				return -1;
			}
			continue;
		}
	}

	return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testl %edx, %edx
jle 0x514f
movl %edi, %r15d
movl $0x0, -0x2c(%rbp)
movl %edx, %eax
movq %rsi, %r14
xorl %r12d, %r12d
movl %edx, -0x30(%rbp)
movq %rsi, -0x40(%rbp)
movslq %eax, %rbx
movl -0x2c(%rbp), %eax
cmpl $0x7, %eax
movl $0x6, %r13d
cmovgel %eax, %r13d
movl %r15d, %edi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2110
testl %eax, %eax
jg 0x513a
testl %eax, %eax
jne 0x511f
cmpb $0x0, 0xa1ca(%rip)      # 0xf2e0
je 0x50f9
callq 0x270d
jmp 0x50f9
movl -0x2c(%rbp), %edi
movl %r13d, %esi
leaq -0x34(%rbp), %rdx
callq 0x268b
movl -0x34(%rbp), %ecx
movl %ecx, -0x2c(%rbp)
testb $0x1, %al
jne 0x50f9
jmp 0x5164
addl %eax, %r12d
movq -0x40(%rbp), %rsi
leaq (%rsi,%r12), %r14
movl -0x30(%rbp), %eax
subl %r12d, %eax
jg 0x50e6
jmp 0x5152
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x5152
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: hci_dump_evt
void hci_dump_evt(uint8_t * buf, uint16_t len)
{
	int n;
	int i;

	if (!buf || !len) {
		RS_ERR("Invalid parameters %p, %u.\n", buf, len);
		return;
	}

	n = 0;
	for (i = 0; i < len; i++) {
		n += sprintf(hci_dump_buf + n, "%02x ", buf[i]);
		if ((i + 1) % 16 == 0) {
			RS_DBG(" %s\n", hci_dump_buf);
			n = 0;
		}
	}

	if (i % 16)
		RS_DBG(" %s\n", hci_dump_buf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rdi, %rdi
je 0x5214
testw %si, %si
je 0x5214
movl %esi, -0x2c(%rbp)
movzwl %si, %r12d
negq %r12
movl $0x1, %r13d
leaq 0x4423(%rip), %r15      # 0x95c9
xorl %r14d, %r14d
movslq %r14d, %rdi
leaq 0xa4ad(%rip), %rax      # 0xf660
addq %rax, %rdi
movzbl -0x1(%rbx,%r13), %edx
movq %r15, %rsi
xorl %eax, %eax
callq 0x2280
testb $0xf, %r13b
je 0x51d1
addl %eax, %r14d
jmp 0x51dd
xorl %r14d, %r14d
cmpb $0x0, 0xa105(%rip)      # 0xf2e0
jne 0x51ef
leaq (%r12,%r13), %rax
incq %rax
incq %r13
cmpq $0x1, %rax
jne 0x51a9
jmp 0x51f6
callq 0x2731
jmp 0x51dd
testb $0xf, -0x2c(%rbp)
je 0x5205
cmpb $0x0, 0xa0dd(%rip)      # 0xf2e0
jne 0x5248
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9ddd(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movzwl %si, %r8d
leaq 0x4379(%rip), %rsi      # 0x95a2
leaq 0x4309(%rip), %rdx      # 0x9539
movq %rbx, %rcx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2150
callq 0x275c
jmp 0x5205
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: read_hci_evt
int read_hci_evt(int fd, uint8_t * buff, uint8_t evt_code)
{
	uint8_t *evt_buff = buff;
	int ret;
	int try_type = 0;
	uint8_t vendor_evt = 0xff;

start_read:
	do {
		ret = os_read(fd, evt_buff, 1);
		if (ret == 1 && evt_buff[0] == 0x04)
			break;
		else {
			RS_DBG("no pkt type, continue.");
			try_type++;
			continue;
		}
	} while (try_type < 6);

	if (try_type >= 6)
		return -1;

	ret = os_read(fd, evt_buff + 1, 1);
	if (ret < 0) {
		RS_ERR("%s: failed to read event code\n", __func__);
		return -1;
	}

	ret = os_read(fd, evt_buff + 2, 1);
	if (ret < 0) {
		RS_ERR("%s: failed to read parameter total len.\n", __func__);
		return -1;
	}

	ret = os_read(fd, evt_buff + 3, evt_buff[2]);
	if (ret < 0) {
		RS_ERR("%s: failed to read payload of event.\n", __func__);
		return -1;
	}
#ifdef DUMP_HCI_EVT
	hci_dump_evt(evt_buff, ret + 3);
#endif

	/* This event to wake up host. */
	if (evt_buff[1] == vendor_evt) {
		try_type = 0;
		RS_DBG("%s: found vendor evt, continue reading.\n", __func__);
		goto start_read;
	}

	if (evt_buff[1] != evt_code) {
		RS_ERR("%s: event code mismatches, %x, expect %x.\n",
		       __func__, evt_buff[1], evt_code);
		return -1;
	}

	return (ret + 3);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, -0x2c(%rbp)
movq %rsi, %r14
movl %edi, %r15d
leaq 0x1(%rsi), %rax
movq %rax, -0x38(%rbp)
leaq 0x2(%rsi), %r13
leaq 0x3(%rsi), %rbx
xorl %r12d, %r12d
movl %r15d, %edi
movq %r14, %rsi
movl $0x1, %edx
callq 0x50b4
cmpl $0x1, %eax
jne 0x531a
cmpb $0x4, (%r14)
jne 0x531a
movl %r15d, %edi
movq -0x38(%rbp), %rsi
movl $0x1, %edx
callq 0x50b4
testl %eax, %eax
js 0x5377
movl %r15d, %edi
movq %r13, %rsi
movl $0x1, %edx
callq 0x50b4
testl %eax, %eax
js 0x537e
movzbl (%r13), %edx
movl %r15d, %edi
movq %rbx, %rsi
callq 0x50b4
testl %eax, %eax
js 0x5385
movl %eax, %r12d
addl $0x3, %r12d
movzwl %r12w, %esi
movq %r14, %rdi
callq 0x516c
movzbl 0x1(%r14), %r8d
cmpl $0xff, %r8d
jne 0x5343
cmpb $0x0, 0x9fd4(%rip)      # 0xf2e0
movl $0x0, %r12d
je 0x527c
jmp 0x5339
cmpb $0x0, 0x9fbf(%rip)      # 0xf2e0
jne 0x5332
incl %r12d
cmpl $0x6, %r12d
jne 0x527c
jmp 0x538a
callq 0x2787
jmp 0x5323
callq 0x27ab
jmp 0x5279
movl -0x2c(%rbp), %eax
cmpb %al, %r8b
je 0x5390
movzbl %al, %r9d
movq 0x9ca2(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x435f(%rip), %rsi      # 0x96bf
leaq 0x41d2(%rip), %rdx      # 0x9539
leaq 0x42b1(%rip), %rcx      # 0x961f
xorl %eax, %eax
callq 0x2150
jmp 0x538a
callq 0x282c
jmp 0x538a
callq 0x2801
jmp 0x538a
callq 0x27d6
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: bachk
int bachk(const char *str)
{
	if (!str)
		return -1;

	if (strlen(str) != 17)
		return -1;

	while (*str) {
		if (!isxdigit(*str++))
			return -1;

		if (!isxdigit(*str++))
			return -1;

		if (*str == 0)
			break;

		if (*str++ != ':')
			return -1;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x5889
movq %rdi, %rbx
callq 0x2090
cmpq $0x11, %rax
jne 0x5889
xorl %r14d, %r14d
movsbq (%rbx), %r15
testq %r15, %r15
je 0x588f
callq 0x22e0
movq (%rax), %rax
testb $0x10, 0x1(%rax,%r15,2)
je 0x5889
movsbq 0x1(%rbx), %rcx
testb $0x10, 0x1(%rax,%rcx,2)
je 0x5889
movb 0x2(%rbx), %al
testb %al, %al
je 0x588f
addq $0x3, %rbx
cmpb $0x3a, %al
je 0x5855
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_vendor_change_speed_h5
int rtk_vendor_change_speed_h5(int fd, RT_U32 baudrate)
{
	struct sk_buff *cmd_change_bdrate = NULL;
	unsigned char cmd[7] = { 0 };
	int retlen;
	unsigned char bytes[READ_DATA_SIZE];
	struct sigaction sa;

	sa.sa_handler = h5_tinit_sig_alarm;
	sigaction(SIGALRM, &sa, NULL);

	cmd[0] = 0x17;	//ocf
	cmd[1] = 0xfc;	//ogf, vendor specified

	cmd[2] = 4;	//length;

	baudrate = cpu_to_le32(baudrate);
#ifdef BAUDRATE_4BYTES
	memcpy((RT_U16 *) & cmd[3], &baudrate, 4);
#else
	memcpy((RT_U16 *) & cmd[3], &baudrate, 2);

	cmd[5] = 0;
	cmd[6] = 0;
#endif

	RS_DBG("baudrate in change speed command: 0x%x 0x%x 0x%x 0x%x \n",
	       cmd[3], cmd[4], cmd[5], cmd[6]);

	cmd_change_bdrate =
	    h5_prepare_pkt(&rtk_hw_cfg, cmd, 7, HCI_COMMAND_PKT);
	if (!cmd_change_bdrate) {
		RS_ERR("Prepare command packet for change speed fail");
		return -1;
	}

	rtk_hw_cfg.host_last_cmd = cmd_change_bdrate;
	alarm(1);
	write(fd, cmd_change_bdrate->data, cmd_change_bdrate->data_len);

	while (rtk_hw_cfg.link_estab_state == H5_INIT) {
		if ((retlen = read_check_rtk(fd, &bytes, READ_DATA_SIZE)) == -1) {
			perror("read fail");
			return -1;
		}
		//add pure ack check
		h5_recv(&rtk_hw_cfg, &bytes, retlen);
	}

	alarm(0);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movl %esi, %r14d
movl %edi, %ebx
leaq 0xdc(%rip), %rax        # 0x5fd3
leaq -0xc8(%rbp), %rsi
movq %rax, (%rsi)
movl $0xe, %edi
xorl %edx, %edx
callq 0x2060
movw $0xfc17, -0x17(%rbp)    # imm = 0xFC17
movb $0x4, -0x15(%rbp)
movl %r14d, -0x14(%rbp)
cmpb $0x0, 0x93be(%rip)      # 0xf2e0
jne 0x5fac
leaq -0x17(%rbp), %rdi
movl $0x7, %esi
movl $0x1, %edx
callq 0x603c
testq %rax, %rax
je 0x5fb9
movq %rax, %r14
movq %rax, 0x97b6(%rip)      # 0xf700
movl $0x1, %edi
callq 0x20f0
movq %r14, %rsi
addq $0x8, %rsi
movl 0x4(%r14), %edx
movl %ebx, %edi
callq 0x2070
cmpl $0x2, 0x9787(%rip)      # 0xf6f4
jne 0x5f95
leaq -0x30(%rbp), %r14
movl %ebx, %edi
movq %r14, %rsi
callq 0x6241
cmpl $-0x1, %eax
je 0x5fc0
movq %r14, %rdi
movl %eax, %esi
callq 0x6298
cmpl $0x2, 0x9761(%rip)      # 0xf6f4
je 0x5f73
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x20f0
movl %ebx, %eax
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movl %r14d, %edi
callq 0x2c70
jmp 0x5f28
callq 0x2cc2
jmp 0x5fcc
leaq 0x3ce7(%rip), %rdi      # 0x9cae
callq 0x2230
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x5f9e
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: h5_tinit_sig_alarm
static void h5_tinit_sig_alarm(int sig)
{
	static int retries = 0;
	if (retries < rtk_hw_cfg.h5_max_retries) {
		retries++;
		if (rtk_hw_cfg.host_last_cmd) {
			int len =
			    write(rtk_hw_cfg.serial_fd,
				  rtk_hw_cfg.host_last_cmd->data,
				  rtk_hw_cfg.host_last_cmd->data_len);
			RS_DBG("3-wire change baudrate re send:%d, len:%d",
			       retries, len);
			alarm(1);
			return;
		} else {
			RS_DBG
			    ("3-wire init timeout without last command stored\n");
		}
	}

	tcflush(rtk_hw_cfg.serial_fd, TCIOFLUSH);
	RS_ERR("H5 init process timed out");
	exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0xa7b3(%rip), %eax      # 0x10790
cmpl 0x972d(%rip), %eax      # 0xf710
jge 0x602d
incl %eax
movl %eax, 0xa7a3(%rip)      # 0x10790
movq 0x970c(%rip), %rsi      # 0xf700
testq %rsi, %rsi
je 0x601f
movl 0x9721(%rip), %edi      # 0xf720
movl 0x4(%rsi), %edx
addq $0x8, %rsi
callq 0x2070
cmpb $0x0, 0x92ce(%rip)      # 0xf2e0
jne 0x6032
movl $0x1, %edi
popq %rbp
jmp 0x20f0
cmpb $0x0, 0x92ba(%rip)      # 0xf2e0
je 0x602d
callq 0x2d14
callq 0x2d38
movq %rax, %rdi
callq 0x2ce7
jmp 0x6014
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: read_check_rtk
static int read_check_rtk(int fd, void *buf, int count)
{
	int res;
	do {
		res = read(fd, buf, count);
		if (res != -1) {
			buf = (RT_U8 *) buf + res;
			count -= res;
			return res;
		}
	} while (count && (errno == 0 || errno == EINTR));
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %r14d
movl $0x10, %edx
callq 0x2110
cmpl $-0x1, %eax
jne 0x628d
callq 0x2040
movq %rax, %r15
testl $0xfffffffb, (%r15)     # imm = 0xFFFFFFFB
jne 0x6288
movl $0x10, %edx
movl %r14d, %edi
movq %rbx, %rsi
callq 0x2110
cmpl $-0x1, %eax
je 0x6268
jmp 0x628d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: h5_tsync_sig_alarm
static void h5_tsync_sig_alarm(int sig)
{
	unsigned char h5sync[2] = { 0x01, 0x7E };
	static int retries = 0;
	struct itimerval value;

	if (retries < rtk_hw_cfg.h5_max_retries) {
		retries++;
		struct sk_buff *nskb =
		    h5_prepare_pkt(&rtk_hw_cfg, h5sync, sizeof(h5sync),
				   H5_LINK_CTL_PKT);
		int len =
		    write(rtk_hw_cfg.serial_fd, nskb->data, nskb->data_len);
		RS_DBG("3-wire sync pattern resend : %d, len: %d\n", retries,
		       len);

		skb_free(nskb);
		//gordon add 2013-6-7 retry per 250ms
		value.it_value.tv_sec = 0;
		value.it_value.tv_usec = 250000;
		value.it_interval.tv_sec = 0;
		value.it_interval.tv_usec = 250000;
		setitimer(ITIMER_REAL, &value, NULL);
		//gordon end

		return;
	}

	tcflush(rtk_hw_cfg.serial_fd, TCIOFLUSH);
	RS_ERR("H5 sync timed out\n");
	exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x28, %rsp
movw $0x7e01, -0xa(%rbp)     # imm = 0x7E01
movl 0x9e99(%rip), %eax      # 0x10794
cmpl 0x8e0f(%rip), %eax      # 0xf710
jge 0x6978
incl %eax
movl %eax, 0x9e89(%rip)      # 0x10794
leaq -0xa(%rbp), %rdi
movl $0x2, %esi
movl $0xf, %edx
callq 0x603c
movq %rax, %rbx
movl 0x8df9(%rip), %edi      # 0xf720
movl 0x4(%rax), %edx
leaq 0x8(%rax), %rsi
callq 0x2070
cmpb $0x0, 0x89a6(%rip)      # 0xf2e0
jne 0x696e
movq %rbx, %rdi
callq 0x2030
xorl %eax, %eax
leaq -0x30(%rbp), %rsi
movq %rax, 0x10(%rsi)
movl $0x3d090, %ecx          # imm = 0x3D090
movq %rcx, 0x18(%rsi)
movq %rax, (%rsi)
movq %rcx, 0x8(%rsi)
xorl %edi, %edi
xorl %edx, %edx
callq 0x21b0
addq $0x28, %rsp
popq %rbx
popq %rbp
retq
movq %rax, %rdi
callq 0x313d
jmp 0x693c
callq 0x3104
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: h5_tconf_sig_alarm
static void h5_tconf_sig_alarm(int sig)
{
	unsigned char h5conf[3] = { 0x03, 0xFC, 0x14 };
	static int retries = 0;
	struct itimerval value;

	if (retries < rtk_hw_cfg.h5_max_retries) {
		retries++;
		struct sk_buff *nskb =
		    h5_prepare_pkt(&rtk_hw_cfg, h5conf, 3, H5_LINK_CTL_PKT);
		int len =
		    write(rtk_hw_cfg.serial_fd, nskb->data, nskb->data_len);
		RS_DBG("3-wire config pattern resend : %d , len: %d", retries,
		       len);
		skb_free(nskb);

		//gordon add 2013-6-7 retry per 250ms
		value.it_value.tv_sec = 0;
		value.it_value.tv_usec = 250000;
		value.it_interval.tv_sec = 0;
		value.it_interval.tv_usec = 250000;
		setitimer(ITIMER_REAL, &value, NULL);

		return;
	}

	tcflush(rtk_hw_cfg.serial_fd, TCIOFLUSH);
	RS_ERR("H5 config timed out\n");
	exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x28, %rsp
movl 0x9e0c(%rip), %eax      # 0x10798
cmpl 0x8d7e(%rip), %eax      # 0xf710
jge 0x6a0c
incl %eax
movl %eax, 0x9dfc(%rip)      # 0x10798
leaq 0x2b6d(%rip), %rdi      # 0x9510
movl $0x3, %esi
movl $0xf, %edx
callq 0x603c
movq %rax, %rbx
movl 0x8d65(%rip), %edi      # 0xf720
movl 0x4(%rax), %edx
leaq 0x8(%rax), %rsi
callq 0x2070
cmpb $0x0, 0x8912(%rip)      # 0xf2e0
jne 0x6a02
movq %rbx, %rdi
callq 0x2030
xorl %eax, %eax
leaq -0x28(%rbp), %rsi
movq %rax, 0x10(%rsi)
movl $0x3d090, %ecx          # imm = 0x3D090
movq %rcx, 0x18(%rsi)
movq %rax, (%rsi)
movq %rcx, 0x8(%rsi)
xorl %edi, %edi
xorl %edx, %edx
callq 0x21b0
addq $0x28, %rsp
popq %rbx
popq %rbp
retq
movq %rax, %rdi
callq 0x31a3
jmp 0x69d0
callq 0x316a
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_bt_firmware
int rtk_get_bt_firmware(struct btrtl_info *btrtl, RT_U8 **fw_buf)
{
	const char *filename;
	struct stat st;
	int fd = -1;
	size_t fwsize;
	static char firmware_file_name[PATH_MAX] = { 0 };
	int ret = 0;

	sprintf(firmware_file_name, "%s", FIRMWARE_DIRECTORY);
	strcat(firmware_file_name, btrtl->patch_ent->patch_file);
	filename = firmware_file_name;

	if (stat(filename, &st) < 0) {
		RS_ERR("Can't access firmware %s, %s", filename,
		       strerror(errno));
		return -1;
	}

	fwsize = st.st_size;

	if ((fd = open(filename, O_RDONLY)) < 0) {
		RS_ERR("Can't open firmware, errno:%d", errno);
		return -1;
	}

	if (!(*fw_buf = malloc(fwsize))) {
		RS_ERR("Can't alloc memory for fw&config, errno:%d", errno);
		close(fd);
		return -1;
	}

	if (read(fd, *fw_buf, fwsize) < (ssize_t) fwsize) {
		free(*fw_buf);
		*fw_buf = NULL;
		close(fd);
		return -1;
	}
	RS_DBG("Load FW OK");
	close(fd);
	return fwsize;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
movups 0x2f74(%rip), %xmm0     # 0x99d0
movaps %xmm0, 0x8d2d(%rip)     # 0xf790
movabsq $0x2f74626c74722f, %rax # imm = 0x2F74626C74722F
movq %rax, 0x8d29(%rip)      # 0xf79d
leaq 0x8d15(%rip), %r14      # 0xf790
movq 0x90(%rdi), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x2270
leaq -0xa8(%rbp), %rsi
movq %r14, %rdi
callq 0x2160
testl %eax, %eax
js 0x6b20
movq -0x78(%rbp), %r14
leaq 0x8ce4(%rip), %rdi      # 0xf790
xorl %esi, %esi
xorl %eax, %eax
callq 0x2200
testl %eax, %eax
js 0x6b27
movl %eax, %r15d
movq %r14, %rdi
callq 0x2190
movq %rax, (%rbx)
testq %rax, %rax
je 0x6b2e
movl %r15d, %edi
movq %rax, %rsi
movq %r14, %rdx
callq 0x2110
cmpq %r14, %rax
jge 0x6afe
movq (%rbx), %rdi
callq 0x2030
movq $0x0, (%rbx)
movl %r15d, %edi
callq 0x2100
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x6b0f
cmpb $0x0, 0x87db(%rip)      # 0xf2e0
jne 0x6b38
movl %r15d, %edi
callq 0x2100
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x3266
jmp 0x6af6
callq 0x3231
jmp 0x6af6
movl %r15d, %edi
callq 0x31f4
jmp 0x6af6
callq 0x31d0
jmp 0x6b07
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_eversion
void rtk_get_eversion(int dd)
{
	unsigned char bytes[READ_DATA_SIZE];
	int retlen;
	struct sigaction sa;
	unsigned char read_rom_patch_cmd[3] = { 0x6d, 0xfc, 00 };
	struct sk_buff *nskb =
	    h5_prepare_pkt(&rtk_hw_cfg, read_rom_patch_cmd, 3, HCI_COMMAND_PKT);

	if (rtk_hw_cfg.host_last_cmd) {
		skb_free(rtk_hw_cfg.host_last_cmd);
		rtk_hw_cfg.host_last_cmd = NULL;
	}

	rtk_hw_cfg.host_last_cmd = nskb;

	write(dd, nskb->data, nskb->data_len);
	rtk_hw_cfg.rom_version_cmd_state = cmd_has_sent;
	RS_DBG("RTK send HCI_VENDOR_READ_RTK_ROM_VERISION_Command\n");

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

	alarm(3);
	while (rtk_hw_cfg.rom_version_cmd_state != event_received) {
		if ((retlen = read_check_rtk(dd, &bytes, READ_DATA_SIZE)) == -1) {
			perror("rtk get eversion: read fail");
			return;
		}
		h5_recv(&rtk_hw_cfg, &bytes, retlen);
	}
	alarm(0);
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movl %edi, %ebx
leaq 0x42cb(%rip), %rdi      # 0xae21
movl $0x3, %esi
movl $0x1, %edx
callq 0x603c
movq %rax, %r14
movq 0x8b91(%rip), %rdi      # 0xf700
testq %rdi, %rdi
je 0x6b79
callq 0x2030
movq %r14, 0x8b80(%rip)      # 0xf700
movq %r14, %rsi
addq $0x8, %rsi
movl 0x4(%r14), %edx
movl %ebx, %edi
callq 0x2070
movl $0x1, 0x8bc4(%rip)      # 0xf760
cmpb $0x0, 0x873d(%rip)      # 0xf2e0
jne 0x6c3b
xorl %edi, %edi
callq 0x20f0
leaq -0xb0(%rbp), %r14
movl $0x90, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x20d0
movl $0x1, 0x80(%r14)
leaq 0x7b(%rip), %rax        # 0x6c53
movq %rax, -0x8(%r14)
leaq -0xb8(%rbp), %rsi
movl $0xe, %edi
xorl %edx, %edx
callq 0x2060
movl $0x3, %edi
callq 0x20f0
cmpl $0x2, 0x8b60(%rip)      # 0xf760
je 0x6c28
leaq -0x20(%rbp), %r14
movl %ebx, %edi
movq %r14, %rsi
callq 0x6241
cmpl $-0x1, %eax
je 0x6c45
movq %r14, %rdi
movl %eax, %esi
callq 0x6298
cmpl $0x2, 0x8b3a(%rip)      # 0xf760
jne 0x6c06
xorl %edi, %edi
callq 0x20f0
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
callq 0x32aa
jmp 0x6ba9
leaq 0x30a4(%rip), %rdi      # 0x9cf0
callq 0x2230
jmp 0x6c2f
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_eversion_timeout
static void rtk_get_eversion_timeout(int sig)
{
	static int retries = 0;
	int len = 0;

	RS_DBG("RTK get HCI_VENDOR_READ_RTK_ROM_VERISION_Command\n");
	if (retries < rtk_hw_cfg.h5_max_retries) {
		RS_DBG("rtk get eversion timerout, retry:%d\n", retries);
		if (rtk_hw_cfg.host_last_cmd) {
			len = write(rtk_hw_cfg.serial_fd,
				    rtk_hw_cfg.host_last_cmd->data,
				    rtk_hw_cfg.host_last_cmd->data_len);
		}
		retries++;
		alarm(3);
		return;
	}
	tcflush(rtk_hw_cfg.serial_fd, TCIOFLUSH);
	RS_ERR("rtk get eversion cmd complete event timed out\n");
	exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
cmpb $0x0, 0x8682(%rip)      # 0xf2e0
jne 0x6ca6
movl 0x9b3a(%rip), %ecx      # 0x107a0
cmpl 0x8aa4(%rip), %ecx      # 0xf710
jge 0x6cce
cmpb $0x0, 0x866b(%rip)      # 0xf2e0
jne 0x6cad
movq 0x8a82(%rip), %rsi      # 0xf700
testq %rsi, %rsi
je 0x6c95
movl 0x8a97(%rip), %edi      # 0xf720
movl 0x4(%rsi), %edx
addq $0x8, %rsi
callq 0x2070
incl 0x9b05(%rip)            # 0x107a0
movl $0x3, %edi
popq %rbp
jmp 0x20f0
callq 0x32ce
jmp 0x6c60
movq 0x8344(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x3d6d(%rip), %rsi      # 0xaa2b
leaq 0x2874(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
jmp 0x6c77
callq 0x32f2
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_lmp_version
void rtk_get_lmp_version(int dd)
{
	unsigned char bytes[READ_DATA_SIZE];
	int retlen;
	struct sigaction sa;
	unsigned char read_rom_patch_cmd[3] = { 0x01, 0x10, 00 };
	struct sk_buff *nskb = h5_prepare_pkt(&rtk_hw_cfg, read_rom_patch_cmd, 3, HCI_COMMAND_PKT);	//data:len+head:4

	if (rtk_hw_cfg.host_last_cmd) {
		skb_free(rtk_hw_cfg.host_last_cmd);
		rtk_hw_cfg.host_last_cmd = NULL;
	}

	rtk_hw_cfg.host_last_cmd = nskb;

	write(dd, nskb->data, nskb->data_len);
	rtk_hw_cfg.hci_version_cmd_state = cmd_has_sent;
	RS_DBG("RTK send HCI_VENDOR_READ_RTK_ROM_VERISION_Command\n");

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

	alarm(3);
	while (rtk_hw_cfg.hci_version_cmd_state != event_received) {
		if ((retlen = read_check_rtk(dd, &bytes, READ_DATA_SIZE)) == -1) {
			perror("read fail");
			return;
		}
		h5_recv(&rtk_hw_cfg, &bytes, retlen);
	}
	alarm(0);
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movl %edi, %ebx
leaq 0x40f3(%rip), %rdi      # 0xaddd
movl $0x3, %esi
movl $0x1, %edx
callq 0x603c
movq %rax, %r14
movq 0x89fd(%rip), %rdi      # 0xf700
testq %rdi, %rdi
je 0x6d0d
callq 0x2030
movq %r14, 0x89ec(%rip)      # 0xf700
movq %r14, %rsi
addq $0x8, %rsi
movl 0x4(%r14), %edx
movl %ebx, %edi
callq 0x2070
movl $0x1, 0x8a34(%rip)      # 0xf764
cmpb $0x0, 0x85a9(%rip)      # 0xf2e0
jne 0x6dcf
xorl %edi, %edi
callq 0x20f0
leaq -0xb0(%rbp), %r14
movl $0x90, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x20d0
movl $0x1, 0x80(%r14)
leaq 0x7b(%rip), %rax        # 0x6de7
movq %rax, -0x8(%r14)
leaq -0xb8(%rbp), %rsi
movl $0xe, %edi
xorl %edx, %edx
callq 0x2060
movl $0x3, %edi
callq 0x20f0
cmpl $0x2, 0x89d0(%rip)      # 0xf764
je 0x6dbc
leaq -0x20(%rbp), %r14
movl %ebx, %edi
movq %r14, %rsi
callq 0x6241
cmpl $-0x1, %eax
je 0x6dd9
movq %r14, %rdi
movl %eax, %esi
callq 0x6298
cmpl $0x2, 0x89aa(%rip)      # 0xf764
jne 0x6d9a
xorl %edi, %edi
callq 0x20f0
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
callq 0x332b
jmp 0x6d3d
leaq 0x2ece(%rip), %rdi      # 0x9cae
callq 0x2230
jmp 0x6dc3
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_lmp_version_timeout
static void rtk_get_lmp_version_timeout(int sig)
{
	static int retries = 0;
	RS_DBG("RTK get HCI_VENDOR_READ_RTK_LMP_VERISION_Command\n");
	if (retries < rtk_hw_cfg.h5_max_retries) {
		RS_DBG("rtk get lmp version timeout, retry: %d\n", retries);
		if (rtk_hw_cfg.host_last_cmd) {
			int len = write(rtk_hw_cfg.serial_fd,
					rtk_hw_cfg.host_last_cmd->data,
					rtk_hw_cfg.host_last_cmd->data_len);
		}
		retries++;
		alarm(3);
		return;
	}
	tcflush(rtk_hw_cfg.serial_fd, TCIOFLUSH);
	RS_ERR("rtk get lmp version cmd complete event timed out\n");
	exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
cmpb $0x0, 0x84ee(%rip)      # 0xf2e0
jne 0x6e3a
movl 0x99aa(%rip), %ecx      # 0x107a4
cmpl 0x8910(%rip), %ecx      # 0xf710
jge 0x6e62
cmpb $0x0, 0x84d7(%rip)      # 0xf2e0
jne 0x6e41
movq 0x88ee(%rip), %rsi      # 0xf700
testq %rsi, %rsi
je 0x6e29
movl 0x8903(%rip), %edi      # 0xf720
movl 0x4(%rsi), %edx
addq $0x8, %rsi
callq 0x2070
incl 0x9975(%rip)            # 0x107a4
movl $0x3, %edi
popq %rbp
jmp 0x20f0
callq 0x334f
jmp 0x6df4
movq 0x81b0(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x3c74(%rip), %rsi      # 0xaac6
leaq 0x26e0(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
jmp 0x6e0b
callq 0x3373
// File: /workspace/github_c_makefile_star2_O3/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_fw_project_id
uint8_t rtk_get_fw_project_id(uint8_t * p_buf)
{
	uint8_t opcode;
	uint8_t len;
	uint8_t data = 0;

	do {
		opcode = *p_buf;
		len = *(p_buf - 1);
		if (opcode == 0x00) {
			if (len == 1) {
				data = *(p_buf - 2);
				RS_DBG
				    ("rtk_get_fw_project_id: opcode %d, len %d, data %d",
				     opcode, len, data);
				break;
			} else {
				RS_ERR("rtk_get_fw_project_id: invalid len %d",
				       len);
			}
		}
		p_buf -= len + 2;
	} while (*p_buf != 0xFF);

	return data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movb (%rdi), %al
movq 0x8177(%rip), %r13      # 0xeff8
leaq 0x2ebb(%rip), %r14      # 0x9d43
leaq 0x26aa(%rip), %r15      # 0x9539
movzbl -0x1(%rbx), %r12d
testb %al, %al
jne 0x6eb2
cmpl $0x1, %r12d
je 0x6ec7
movq (%r13), %rdi
movq %r14, %rsi
movq %r15, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2150
movl %r12d, %eax
subq %rax, %rbx
movb -0x2(%rbx), %al
addq $-0x2, %rbx
cmpb $-0x1, %al
jne 0x6e8f
xorl %ebx, %ebx
jmp 0x6ed3
movb -0x2(%rbx), %bl
cmpb $0x0, 0x840f(%rip)      # 0xf2e0
jne 0x6ee4
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %bl, %r9d
movq (%r13), %rdi
leaq 0x2e19(%rip), %rsi      # 0x9d0c
leaq 0x263f(%rip), %rdx      # 0x9539
xorl %ecx, %ecx
movl $0x1, %r8d
xorl %eax, %eax
callq 0x2150
jmp 0x6ed3